Skip to content

Commit

Permalink
Remove ConfigCx::push{_erased} methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Dec 2, 2024
1 parent e4ab819 commit 20fbca8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 4 additions & 6 deletions crates/kas-core/src/event/cx/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ use super::PendingNavFocus;
use crate::event::{EventState, FocusSource};
use crate::geom::{Rect, Size};
use crate::layout::AlignPair;
use crate::messages::Erased;
use crate::text::format::FormattableText;
use crate::theme::{Feature, SizeCx, Text, ThemeSize};
use crate::{Id, Node};
use cast::Cast;
use std::fmt::Debug;
use std::ops::{Deref, DerefMut};

#[allow(unused)] use crate::event::{Event, EventCx};
Expand Down Expand Up @@ -92,13 +90,12 @@ 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.
///
/// TODO: `id` should not be part of the function signature?
pub fn push<M: Debug + 'static>(&mut self, id: Id, msg: M) {
pub fn push<M: Debug + 'static>(&mut self, msg: M) {
self.send(id, msg);
}
Expand All @@ -110,9 +107,10 @@ impl<'a> ConfigCx<'a> {
/// 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, id: Id, msg: Erased) {
pub fn push_erased(&mut self, msg: Erased) {
self.send_erased(id, msg);
}
*/

/// Align a feature's rect
///
Expand Down
10 changes: 9 additions & 1 deletion crates/kas-core/src/event/cx/cx_pub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,19 @@ impl EventState {
}

/// Send a message to `id`
///
/// 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`]
/// by the widget itself, its parent, or any ancestor.
pub fn send<M: Debug + 'static>(&mut self, id: Id, msg: M) {
self.send_erased(id, Erased::new(msg));
}

/// Send an erased message to `id`
/// Push a type-erased message to the stack
///
/// This is a lower-level variant of [`Self::send`].
pub fn send_erased(&mut self, id: Id, msg: Erased) {
self.send_queue.push_back((id, msg));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Demonstration of *as-you-type* formatting from **Markdown**.
.with_text(DOC),
ScrollLabel::new(Markdown::new(DOC).unwrap())
.on_configure(|cx, label| {
cx.push(label.id(), SetLabelId(label.id()));
cx.send(label.id(), SetLabelId(label.id()));
})
.on_message(|cx, label, text| {
let act = label.set_text(text);
Expand Down

0 comments on commit 20fbca8

Please sign in to comment.