From 766984fa939e55f07bced323329b2bf45141eeb1 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 23 Jan 2025 11:55:00 +0000 Subject: [PATCH 1/2] Drop intention to support fn push on ConfigCx Tracking the current widget's Id is not practical for ConfigCx (although it is for EventCx). Also, fn send is sufficient for the few usages. --- crates/kas-core/src/event/cx/config.rs | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/crates/kas-core/src/event/cx/config.rs b/crates/kas-core/src/event/cx/config.rs index 8a0c145d..9e3a0f2f 100644 --- a/crates/kas-core/src/event/cx/config.rs +++ b/crates/kas-core/src/event/cx/config.rs @@ -94,28 +94,6 @@ impl<'a> ConfigCx<'a> { widget._update(self); } - /* TODO: can we support these (i.e. track `id`)? - /// Push a message (replay) - /// - /// Unlike [`EventCx::push`], this is not handled while unwinding - /// from event sending, but via a fresh traversal of the widget tree. - pub fn push(&mut self, msg: M) { - self.send(id, msg); - } - - /// Push a type-erased message (replay) - /// - /// Unlike [`EventCx::push_erased`], this is not handled while unwinding - /// from event sending, but via a fresh traversal of the widget tree. - /// - /// The message may be [popped](EventCx::try_pop) or - /// [observed](EventCx::try_observe) from [`Events::handle_messages`] - /// by the widget itself, its parent, or any ancestor. - pub fn push_erased(&mut self, msg: Erased) { - self.send_erased(id, msg); - } - */ - /// Align a feature's rect /// /// In case the input `rect` is larger than desired on either axis, it is From aee963afae4292daa1d7f50971dd9478629463c4 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 23 Jan 2025 11:59:10 +0000 Subject: [PATCH 2/2] Rename fn try_observe -> try_peek --- crates/kas-core/src/core/widget.rs | 2 +- crates/kas-core/src/event/cx/cx_pub.rs | 10 +++++----- crates/kas-core/src/messages.rs | 2 +- crates/kas-widgets/src/combobox.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/kas-core/src/core/widget.rs b/crates/kas-core/src/core/widget.rs index 077e3e0e..d2d90f65 100644 --- a/crates/kas-core/src/core/widget.rs +++ b/crates/kas-core/src/core/widget.rs @@ -233,7 +233,7 @@ pub trait Events: Widget + Sized { /// This is the secondary event handler (see [documentation](crate::event)). /// /// It is implied that the stack contains at least one message. - /// Use [`EventCx::try_pop`] and/or [`EventCx::try_observe`]. + /// Use [`EventCx::try_pop`] and/or [`EventCx::try_peek`]. /// /// [`EventCx::last_child`] may be called to find the message's sender. /// This may return [`None`] (if no child was visited, which implies that diff --git a/crates/kas-core/src/event/cx/cx_pub.rs b/crates/kas-core/src/event/cx/cx_pub.rs index 19c9cf19..f516641e 100644 --- a/crates/kas-core/src/event/cx/cx_pub.rs +++ b/crates/kas-core/src/event/cx/cx_pub.rs @@ -600,7 +600,7 @@ impl EventState { /// Similar to [`EventCx::push`], the message is sent as part of a widget /// tree traversal. /// The message may be [popped](EventCx::try_pop) or - /// [observed](EventCx::try_observe) from [`Events::handle_messages`] + /// [peeked](EventCx::try_peek) from [`Events::handle_messages`] /// by the widget itself, its parent, or any ancestor. pub fn send(&mut self, id: Id, msg: M) { self.send_erased(id, Erased::new(msg)); @@ -730,7 +730,7 @@ impl<'a> EventCx<'a> { /// then pushed to the stack. /// /// The message may be [popped](EventCx::try_pop) or - /// [observed](EventCx::try_observe) from [`Events::handle_messages`] + /// [peeked](EventCx::try_peek) from [`Events::handle_messages`] /// by the widget itself, its parent, or any ancestor. pub fn push(&mut self, msg: M) { self.push_erased(Erased::new(msg)); @@ -741,7 +741,7 @@ impl<'a> EventCx<'a> { /// This is a lower-level variant of [`Self::push`]. /// /// The message may be [popped](EventCx::try_pop) or - /// [observed](EventCx::try_observe) from [`Events::handle_messages`] + /// [peeked](EventCx::try_peek) from [`Events::handle_messages`] /// by the widget itself, its parent, or any ancestor. pub fn push_erased(&mut self, msg: Erased) { self.messages.push_erased(msg); @@ -762,8 +762,8 @@ impl<'a> EventCx<'a> { /// Try observing the last message on the stack without popping /// /// This method may be called from [`Events::handle_messages`]. - pub fn try_observe(&self) -> Option<&M> { - self.messages.try_observe() + pub fn try_peek(&self) -> Option<&M> { + self.messages.try_peek() } /// Try getting a debug representation of the last message on the stack diff --git a/crates/kas-core/src/messages.rs b/crates/kas-core/src/messages.rs index f6ab3378..8231262c 100644 --- a/crates/kas-core/src/messages.rs +++ b/crates/kas-core/src/messages.rs @@ -186,7 +186,7 @@ impl MessageStack { /// Try observing the last message on the stack without popping /// /// This method may be called from [`Events::handle_messages`]. - pub fn try_observe(&self) -> Option<&M> { + pub fn try_peek(&self) -> Option<&M> { if self.has_any() { self.stack.last().and_then(|m| m.downcast_ref::()) } else { diff --git a/crates/kas-widgets/src/combobox.rs b/crates/kas-widgets/src/combobox.rs index 46efbf97..1bc8ffb4 100644 --- a/crates/kas-widgets/src/combobox.rs +++ b/crates/kas-widgets/src/combobox.rs @@ -234,7 +234,7 @@ impl ComboBox { mark: Mark::new(MarkStyle::Point(Direction::Down)), popup: Popup::new( AdaptEvents::new(Column::new(entries)).on_messages(|cx, _, _| { - if let Some(_) = cx.try_observe::() { + if let Some(_) = cx.try_peek::() { if let Some(index) = cx.last_child() { cx.push(IndexMsg(index)); }