Skip to content

Commit

Permalink
Rename OnUpdate -> AdaptEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Dec 8, 2023
1 parent 7445a19 commit d129a22
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
8 changes: 5 additions & 3 deletions crates/kas-widgets/src/adapt/adapt_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ use kas::{autoimpl, impl_scope, widget_index, Events, LayoutExt, Widget};
use std::fmt::Debug;

impl_scope! {
/// Wrapper to call a closure on update
/// Wrapper with configure / update / message handling callbacks.
///
/// This type is constructed by some [`AdaptWidget`](super::AdaptWidget) methods.
#[autoimpl(Deref, DerefMut using self.inner)]
#[autoimpl(Scrollable using self.inner where W: trait)]
#[widget {
layout = self.inner;
}]
pub struct OnUpdate<W: Widget> {
pub struct AdaptEvents<W: Widget> {
core: widget_core!(),
#[widget]
pub inner: W,
Expand All @@ -30,7 +32,7 @@ impl_scope! {
/// Construct
#[inline]
pub fn new(inner: W) -> Self {
OnUpdate {
AdaptEvents {
core: Default::default(),
inner,
on_configure: None,
Expand Down
18 changes: 9 additions & 9 deletions crates/kas-widgets/src/adapt/adapt_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//! Widget extension traits
use super::{AdaptConfigCx, AdaptEventCx, Map, MapAny, OnUpdate, Reserve, WithLabel};
use super::{AdaptConfigCx, AdaptEventCx, AdaptEvents, Map, MapAny, Reserve, WithLabel};
use kas::cast::{Cast, CastFloat};
use kas::dir::Directional;
use kas::geom::Vec2;
Expand Down Expand Up @@ -48,22 +48,22 @@ pub trait AdaptWidget: Widget + Sized {
///
/// Returns a wrapper around the input widget.
#[must_use]
fn on_configure<F>(self, f: F) -> OnUpdate<Self>
fn on_configure<F>(self, f: F) -> AdaptEvents<Self>
where
F: Fn(&mut AdaptConfigCx, &mut Self) + 'static,
{
OnUpdate::new(self).on_configure(f)
AdaptEvents::new(self).on_configure(f)
}

/// Call the given closure on [`Events::update`]
///
/// Returns a wrapper around the input widget.
#[must_use]
fn on_update<F>(self, f: F) -> OnUpdate<Self>
fn on_update<F>(self, f: F) -> AdaptEvents<Self>
where
F: Fn(&mut AdaptConfigCx, &mut Self, &Self::Data) + 'static,
{
OnUpdate::new(self).on_update(f)
AdaptEvents::new(self).on_update(f)
}

/// Add a handler on message of type `M`
Expand All @@ -72,23 +72,23 @@ pub trait AdaptWidget: Widget + Sized {
///
/// Returns a wrapper around the input widget.
#[must_use]
fn on_message<M, H>(self, handler: H) -> OnUpdate<Self>
fn on_message<M, H>(self, handler: H) -> AdaptEvents<Self>
where
M: Debug + 'static,
H: Fn(&mut AdaptEventCx, &mut Self, M) + 'static,
{
OnUpdate::new(self).on_message(handler)
AdaptEvents::new(self).on_message(handler)
}

/// Add a generic message handler
///
/// Returns a wrapper around the input widget.
#[must_use]
fn on_messages<H>(self, handler: H) -> OnUpdate<Self>
fn on_messages<H>(self, handler: H) -> AdaptEvents<Self>
where
H: Fn(&mut AdaptEventCx, &mut Self, &Self::Data) + 'static,
{
OnUpdate::new(self).on_messages(handler)
AdaptEvents::new(self).on_messages(handler)
}

/// Construct a wrapper, setting minimum size in pixels
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-widgets/src/adapt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod with_label;

pub use adapt::{Adapt, Map};
pub use adapt_cx::{AdaptConfigCx, AdaptEventCx};
pub use adapt_events::OnUpdate;
pub use adapt_events::AdaptEvents;
pub use adapt_widget::*;
#[doc(inline)] pub use kas::hidden::MapAny;
pub use reserve::Reserve;
Expand Down
8 changes: 4 additions & 4 deletions examples/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ fn widgets() -> Box<dyn Widget<Data = AppData>> {
}
});

let ui =
adapt::OnUpdate::new(ui).on_update(|cx, _, data: &AppData| cx.set_disabled(data.disabled));
let ui = adapt::AdaptEvents::new(ui)
.on_update(|cx, _, data: &AppData| cx.set_disabled(data.disabled));

Box::new(ScrollBarRegion::new(ui))
}
Expand Down Expand Up @@ -398,8 +398,8 @@ fn filter_list() -> Box<dyn Widget<Data = AppData>> {
SelectionMsg::Select(i) => println!("Selected: {}", &data.list[i]),
_ => (),
});
let ui =
adapt::OnUpdate::new(ui).on_update(|cx, _, data: &AppData| cx.set_disabled(data.disabled));
let ui = adapt::AdaptEvents::new(ui)
.on_update(|cx, _, data: &AppData| cx.set_disabled(data.disabled));
Box::new(ui)
}

Expand Down

0 comments on commit d129a22

Please sign in to comment.