M7: test platform — Platform traits, Application, TestPlatform, VisualTestContext (#7)
This commit was merged in pull request #7.
This commit is contained in:
1 parent
fbe4c081e6
commit
73c67825b2
25 files changed
+3592
-83
No files matched your search
+17
-33
@@ -1,8 +1,9 @@
|
||||
// A headless example of what exists so far (M0-M6): a view renders a card
|
||||
// with GPUI's `div()` and fluent styles; the window lays it out, paints it
|
||||
// into a Scene and dispatches a simulated click. There is no renderer or
|
||||
// text yet (text lines are placeholder bars), so the output is a report of
|
||||
// the scene's draw batches and quads.
|
||||
// A headless example of what exists so far (M0-M7): a view renders a card
|
||||
// with GPUI's `div()` and fluent styles inside a `TestPlatform` window,
|
||||
// and `VisualTestContext` simulates a hover and click while pumping frames
|
||||
// automatically. There is no renderer or text yet (text lines are
|
||||
// placeholder bars), so the output is a report of the scene's draw batches
|
||||
// and quads.
|
||||
//
|
||||
// Run with: moon run src/examples/card --target js
|
||||
|
||||
@@ -84,40 +85,23 @@ fn describe(
|
||||
///|
|
||||
/// Builds the report printed by `main`.
|
||||
fn report() -> String {
|
||||
let app = @app.App::new()
|
||||
let window = @window.Window::new(
|
||||
app,
|
||||
@geometry.size(@geometry.px(400.0), @geometry.px(240.0)),
|
||||
let cx = @test_platform.TestAppContext::new()
|
||||
let (card, vcx) = cx.add_window_view(
|
||||
size=@geometry.size(@geometry.px(400.0), @geometry.px(240.0)),
|
||||
fn(_, _) { { expanded: false, clicks: 0, } },
|
||||
)
|
||||
let card : @app.Entity[Card] = app.new_entity(fn(_) {
|
||||
{ expanded: false, clicks: 0, }
|
||||
})
|
||||
window.set_root_view(card)
|
||||
let card : @app.Entity[Card] = card
|
||||
let lines = []
|
||||
describe("first frame", window.draw(), lines)
|
||||
describe("first frame", vcx.scene(), lines)
|
||||
// Hover the card, then click it: the view expands and the window redraws.
|
||||
let inside = @geometry.point(@geometry.px(100.0), @geometry.px(60.0))
|
||||
ignore(
|
||||
window.dispatch_mouse_event(
|
||||
MouseMove({ ..Default::default(), position: inside, }),
|
||||
),
|
||||
)
|
||||
ignore(window.draw_if_dirty())
|
||||
ignore(
|
||||
window.dispatch_mouse_event(
|
||||
MouseDown({ ..Default::default(), position: inside, click_count: 1, }),
|
||||
),
|
||||
)
|
||||
ignore(
|
||||
window.dispatch_mouse_event(
|
||||
MouseUp({ ..Default::default(), position: inside, click_count: 1, }),
|
||||
),
|
||||
)
|
||||
let state = card.read(app)
|
||||
ignore(vcx.simulate_mouse_move(inside))
|
||||
vcx.simulate_click(inside)
|
||||
let state = cx.read_entity(card)
|
||||
lines.push(
|
||||
"clicked: expanded = \{state.expanded}, clicks = \{state.clicks}, dirty = \{window.is_dirty()}",
|
||||
"clicked: expanded = \{state.expanded}, clicks = \{state.clicks}, frames = \{vcx.draw_count()}, dirty = \{vcx.window().is_dirty()}",
|
||||
)
|
||||
describe("after click (hovered)", window.draw(), lines)
|
||||
describe("after click (hovered)", vcx.scene(), lines)
|
||||
lines.join("\n")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user