Skip to content

Commit

Permalink
Merge pull request #399 from kas-gui/work1
Browse files Browse the repository at this point in the history
Mgr → Cx, revise widget constructor methods, and Tab widget, remove TextButton
  • Loading branch information
dhardy authored Aug 1, 2023
2 parents 76445c9 + 23ee44d commit b2ee6d5
Show file tree
Hide file tree
Showing 101 changed files with 2,365 additions and 2,292 deletions.
8 changes: 4 additions & 4 deletions crates/kas-core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ bitflags! {
/// Action required after processing
///
/// This type is returned by many widgets on modification to self and is tracked
/// internally by [`event::EventMgr`] to determine which updates are needed to
/// internally by [`event::EventCx`] to determine which updates are needed to
/// the UI.
///
/// Two `Action` values may be combined via bit-or (`a | b`). Bit-or
/// assignments are supported by both `Action` and [`event::EventMgr`].
/// assignments are supported by both `Action` and [`event::EventCx`].
///
/// Users receiving a value of this type from a widget update method should
/// usually handle with `*mgr |= action;`. Before the event loop starts
/// usually handle with `*cx |= action;`. Before the event loop starts
/// (`toolkit.run()`) or if the widget in question is not part of a UI these
/// values can be ignored.
#[must_use]
#[derive(Copy, Clone, Default)]
pub struct Action: u32 {
/// The whole window requires redrawing
///
/// Note that [`event::EventMgr::redraw`] can instead be used for more
/// Note that [`event::EventCx::redraw`] can instead be used for more
/// selective redrawing.
const REDRAW = 1 << 0;
/// Some widgets within a region moved
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-core/src/core/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use super::WidgetId;
#[allow(unused)] use super::{Layout, Widget};
use crate::dir::Direction;
#[allow(unused)] use crate::event::EventMgr;
#[allow(unused)] use crate::event::EventCx;
use crate::geom::Rect;

#[cfg(feature = "winit")] pub use winit::window::Icon;
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Clone for CoreData {
///
/// A pop-up is in some ways an ordinary child widget and in some ways not.
/// The pop-up widget should be a permanent child of its parent, but is not
/// visible until [`EventMgr::add_popup`] is called.
/// visible until [`EventCx::add_popup`] is called.
///
/// A pop-up widget's rect is not contained by its parent, therefore the parent
/// must not call any [`Layout`] methods on the pop-up (whether or not it is
Expand Down
34 changes: 17 additions & 17 deletions crates/kas-core/src/core/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

//! Widget method implementations

use crate::event::{ConfigMgr, Event, EventMgr, Response};
use crate::event::{ConfigCx, Event, EventCx, Response};
#[cfg(debug_assertions)] use crate::util::IdentifyWidget;
use crate::{Erased, Events, Layout, NavAdvance, Node, Widget, WidgetId};

/// Generic implementation of [`Widget::_configure`]
pub fn _configure<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
cx: &mut ConfigCx,
data: &<W as Widget>::Data,
cx: &mut ConfigMgr,
id: WidgetId,
) {
widget.pre_configure(cx, id);
Expand All @@ -28,16 +28,16 @@ pub fn _configure<W: Widget + Events<Data = <W as Widget>::Data>>(
}

widget.configure(cx);
widget.update(data, cx);
widget.update(cx, data);
}

/// Generic implementation of [`Widget::_update`]
pub fn _update<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
cx: &mut ConfigCx,
data: &<W as Widget>::Data,
cx: &mut ConfigMgr,
) {
widget.update(data, cx);
widget.update(cx, data);
let start = cx.recurse_start.take().unwrap_or(0);
let end = cx.recurse_end.take().unwrap_or(widget.num_children());
let mut node = widget.as_node(data);
Expand All @@ -49,8 +49,8 @@ pub fn _update<W: Widget + Events<Data = <W as Widget>::Data>>(
/// Generic implementation of [`Widget::_send`]
pub fn _send<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
cx: &mut EventCx,
data: &<W as Widget>::Data,
cx: &mut EventMgr,
id: WidgetId,
disabled: bool,
event: Event,
Expand All @@ -61,8 +61,8 @@ pub fn _send<W: Widget + Events<Data = <W as Widget>::Data>>(
return response;
}

response |= widget.pre_handle_event(data, cx, event);
} else if widget.steal_event(data, cx, &id, &event).is_used() {
response |= widget.pre_handle_event(cx, data, event);
} else if widget.steal_event(cx, data, &id, &event).is_used() {
response = Response::Used;
} else {
cx.assert_post_steal_unused();
Expand All @@ -76,7 +76,7 @@ pub fn _send<W: Widget + Events<Data = <W as Widget>::Data>>(

if found {
if let Some(scroll) = cx.post_send(index) {
widget.handle_scroll(data, cx, scroll);
widget.handle_scroll(cx, data, scroll);
}
} else {
#[cfg(debug_assertions)]
Expand All @@ -88,12 +88,12 @@ pub fn _send<W: Widget + Events<Data = <W as Widget>::Data>>(
}

if response.is_unused() && event.is_reusable() {
response = widget.handle_event(data, cx, event);
response = widget.handle_event(cx, data, event);
}
}

if cx.has_msg() {
widget.handle_messages(data, cx);
widget.handle_messages(cx, data);
}

response
Expand All @@ -102,8 +102,8 @@ pub fn _send<W: Widget + Events<Data = <W as Widget>::Data>>(
/// Generic implementation of [`Widget::_replay`]
pub fn _replay<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
cx: &mut EventCx,
data: &<W as Widget>::Data,
cx: &mut EventMgr,
id: WidgetId,
msg: Erased,
) {
Expand All @@ -116,11 +116,11 @@ pub fn _replay<W: Widget + Events<Data = <W as Widget>::Data>>(

if found {
if let Some(scroll) = cx.post_send(index) {
widget.handle_scroll(data, cx, scroll);
widget.handle_scroll(cx, data, scroll);
}

if cx.has_msg() {
widget.handle_messages(data, cx);
widget.handle_messages(cx, data);
}
} else {
#[cfg(debug_assertions)]
Expand All @@ -131,7 +131,7 @@ pub fn _replay<W: Widget + Events<Data = <W as Widget>::Data>>(
}
} else if id == widget.id_ref() {
cx.push_erased(msg);
widget.handle_messages(data, cx);
widget.handle_messages(cx, data);
} else {
#[cfg(debug_assertions)]
log::debug!(
Expand All @@ -144,8 +144,8 @@ pub fn _replay<W: Widget + Events<Data = <W as Widget>::Data>>(
/// Generic implementation of [`Widget::_nav_next`]
pub fn _nav_next<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
cx: &mut EventCx,
data: &<W as Widget>::Data,
cx: &mut EventMgr,
focus: Option<&WidgetId>,
advance: NavAdvance,
) -> Option<WidgetId> {
Expand All @@ -155,7 +155,7 @@ pub fn _nav_next<W: Widget + Events<Data = <W as Widget>::Data>>(

fn nav_next(
mut widget: Node<'_>,
cx: &mut EventMgr,
cx: &mut EventCx,
focus: Option<&WidgetId>,
advance: NavAdvance,
navigable: bool,
Expand Down
16 changes: 8 additions & 8 deletions crates/kas-core/src/core/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

//! Layout and LayoutExt traits

use crate::event::ConfigMgr;
use crate::event::ConfigCx;
use crate::geom::{Coord, Offset, Rect};
use crate::layout::{AxisInfo, SizeRules};
use crate::theme::{DrawMgr, SizeMgr};
use crate::theme::{DrawCx, SizeCx};
use crate::util::IdentifyWidget;
use crate::WidgetId;
use kas_macros::autoimpl;
Expand Down Expand Up @@ -139,7 +139,7 @@ pub trait Layout {
///
/// For row/column/grid layouts, a [`crate::layout::RulesSolver`] engine
/// may be useful.
fn size_rules(&mut self, size_mgr: SizeMgr, axis: AxisInfo) -> SizeRules;
fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules;

/// Set size and position
///
Expand All @@ -159,15 +159,15 @@ pub trait Layout {
/// regardless of the [`Stretch`] policy used. If the widget should never
/// stretch, it must align itself.
/// Example: the `CheckBox` widget uses an [`AlignPair`] (set from
/// `size_rules`'s [`AxisInfo`]) and uses [`ConfigMgr::align_feature`].
/// `size_rules`'s [`AxisInfo`]) and uses [`ConfigCx::align_feature`].
/// Another example: `Label` uses a `Text` object which handles alignment
/// internally.
///
/// Default implementation when not using the `layout` property: set `rect`
/// field of `widget_core!()` to the input `rect`.
///
/// [`Stretch`]: crate::layout::Stretch
fn set_rect(&mut self, mgr: &mut ConfigMgr, rect: Rect);
fn set_rect(&mut self, cx: &mut ConfigCx, rect: Rect);

/// Navigation in spatial order
///
Expand Down Expand Up @@ -197,7 +197,7 @@ pub trait Layout {
///
/// Affects event handling via [`Layout::find_id`] and affects the positioning
/// of pop-up menus. [`Layout::draw`] must be implemented directly using
/// [`DrawMgr::with_clip_region`] to offset contents.
/// [`DrawCx::with_clip_region`] to offset contents.
///
/// Default implementation: return [`Offset::ZERO`]
#[inline]
Expand Down Expand Up @@ -266,8 +266,8 @@ pub trait Layout {
/// The `draw` parameter is pre-parameterized with this widget's
/// [`WidgetId`], allowing drawn components to react to input state. This
/// implies that when calling `draw` on children, the child's `id` must be
/// supplied via [`DrawMgr::re_id`] or [`DrawMgr::recurse`].
fn draw(&mut self, draw: DrawMgr);
/// supplied via [`DrawCx::re_id`] or [`DrawCx::recurse`].
fn draw(&mut self, draw: DrawCx);
}

/// Extension trait over widgets
Expand Down
Loading

0 comments on commit b2ee6d5

Please sign in to comment.