1
0
Fork 0
forked from wry/wry

create event system

This commit is contained in:
atagen 2026-04-07 16:13:45 +10:00
parent 21819e27d2
commit 18a0c78657
9 changed files with 65 additions and 5 deletions

View file

@ -29,6 +29,7 @@ use {
clonecell::CloneCell,
double_click_state::DoubleClickState,
errorfmt::ErrorFmt,
event_listener::LazyEventSource,
hash_map_ext::HashMapExt,
linkedlist::{LinkedList, LinkedNode, NodeRef},
numcell::NumCell,
@ -140,6 +141,10 @@ pub struct ContainerNode {
attention_requests: ThresholdCounter,
pending_layout_damage: Cell<bool>,
layout_damage_timeout: Cell<Option<SpawnedFuture<()>>>,
pub layout_complete: Rc<LazyEventSource>,
pub child_added: Rc<LazyEventSource>,
pub child_removed: Rc<LazyEventSource>,
pub all_children_resized: Rc<LazyEventSource>,
}
impl Debug for ContainerNode {
@ -258,6 +263,10 @@ impl ContainerNode {
attention_requests: Default::default(),
pending_layout_damage: Cell::new(false),
layout_damage_timeout: Cell::new(None),
layout_complete: state.post_layout_event_sources.create_source(),
child_added: state.lazy_event_sources.create_source(),
child_removed: state.lazy_event_sources.create_source(),
all_children_resized: state.post_layout_event_sources.create_source(),
});
child.tl_set_parent(slf.clone());
slf.pull_child_properties(&child_node_ref);
@ -368,6 +377,7 @@ impl ContainerNode {
// log::info!("add_child");
self.schedule_layout();
self.cancel_seat_ops();
self.child_added.trigger();
}
fn cancel_seat_ops(&self) {
@ -461,6 +471,22 @@ impl ContainerNode {
}
}
fn all_children_match_body(&self) -> bool {
if let Some(mono) = self.mono_child.get() {
let body = self.mono_body.get();
let content = mono.content.get();
return content.width() == body.width() && content.height() == body.height();
}
for child in self.children.iter() {
let body = child.body.get();
let content = child.content.get();
if content.width() != body.width() || content.height() != body.height() {
return false;
}
}
true
}
fn perform_layout(self: &Rc<Self>) {
if self.num_children.get() == 0 {
return;
@ -475,6 +501,7 @@ impl ContainerNode {
// log::info!("perform_layout");
self.schedule_render_titles();
self.schedule_compute_render_positions();
self.layout_complete.trigger();
if self.pending_layout_damage.get() {
let slf = self.clone();
let timeout = self.state.eng.spawn("layout damage timeout", async move {
@ -1832,6 +1859,9 @@ impl Node for ContainerNode {
if let Some(node) = cn.get(&child.node_id()) {
self.update_child_size(node, width, height);
}
if self.pending_layout_damage.get() && self.all_children_match_body() {
self.all_children_resized.trigger();
}
self.flush_layout_damage();
}
@ -2115,6 +2145,7 @@ impl ContainingNode for ContainerNode {
// log::info!("cnode_remove_child2");
self.schedule_layout();
self.cancel_seat_ops();
self.child_removed.trigger();
}
fn cnode_accepts_child(&self, _node: &dyn Node) -> bool {