logiguard fork v3: full patch set on verified 8c74db0 tree
Includes prior-session patches (carry forward so the app compiles): - crates/gpui/build.rs: cross-compile manifest fix - crates/gpui/src/platform.rs: PlatformWindow::activate_with_token trait method - crates/gpui/src/window.rs: Window::activate_with_token public API - crates/gpui_linux/src/linux/wayland/window.rs: WaylandWindow::activate_with_token + activate() keyboard-serial fix Plus the focus-serial fix: - serial.rs: SerialKind::KeyboardEnter - client.rs: store wl_keyboard.enter serial; latest_serial_of() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
50
crates/gpui/examples/ownership_post.rs
Normal file
50
crates/gpui/examples/ownership_post.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
#![cfg_attr(target_family = "wasm", no_main)]
|
||||
|
||||
use gpui::{App, Context, Entity, EventEmitter, prelude::*};
|
||||
use gpui_platform::application;
|
||||
|
||||
struct Counter {
|
||||
count: usize,
|
||||
}
|
||||
|
||||
struct Change {
|
||||
increment: usize,
|
||||
}
|
||||
|
||||
impl EventEmitter<Change> for Counter {}
|
||||
|
||||
fn run_example() {
|
||||
application().run(|cx: &mut App| {
|
||||
let counter: Entity<Counter> = cx.new(|_cx| Counter { count: 0 });
|
||||
let subscriber = cx.new(|cx: &mut Context<Counter>| {
|
||||
cx.subscribe(&counter, |subscriber, _emitter, event, _cx| {
|
||||
subscriber.count += event.increment * 2;
|
||||
})
|
||||
.detach();
|
||||
|
||||
Counter {
|
||||
count: counter.read(cx).count * 2,
|
||||
}
|
||||
});
|
||||
|
||||
counter.update(cx, |counter, cx| {
|
||||
counter.count += 2;
|
||||
cx.notify();
|
||||
cx.emit(Change { increment: 2 });
|
||||
});
|
||||
|
||||
assert_eq!(subscriber.read(cx).count, 4);
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
fn main() {
|
||||
run_example();
|
||||
}
|
||||
|
||||
#[cfg(target_family = "wasm")]
|
||||
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||
pub fn start() {
|
||||
gpui_platform::web_init();
|
||||
run_example();
|
||||
}
|
||||
Reference in New Issue
Block a user