Skip to content

Commit

Permalink
Remove trait LayoutVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Feb 17, 2025
1 parent e498f7d commit f100172
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 279 deletions.
24 changes: 7 additions & 17 deletions crates/kas-core/src/core/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use crate::Id;
use kas_macros::autoimpl;

#[allow(unused)] use super::{Events, Tile, Widget};
#[allow(unused)]
use crate::layout::{self, AlignPair, LayoutVisitor};
#[allow(unused)] use crate::layout::{self, AlignPair};
#[allow(unused)] use kas_macros as macros;

/// Positioning and drawing routines for [`Widget`]s
Expand Down Expand Up @@ -85,11 +84,8 @@ pub trait Layout {
///
/// ## Default implementation
///
/// The `#[widget]` macro
/// [may generate a default implementation](macros::widget#layout-1) by
/// implementing [`LayoutVisitor`] for `Self`.
/// In this case the default impl of this method is
/// `self.layout_visitor().size_rules(/* ... */)`.
/// The `#[widget]` macro may implement this method as a wrapper over
/// the corresponding [`MacroDefinedLayout`].
fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules;

/// Set size and position
Expand Down Expand Up @@ -125,11 +121,8 @@ pub trait Layout {
///
/// ## Default implementation
///
/// The `#[widget]` macro
/// [may generate a default implementation](macros::widget#layout-1) by
/// implementing [`LayoutVisitor`] for `Self`.
/// In this case the default impl of this method is
/// `self.layout_visitor().set_rect(/* ... */)`.
/// The `#[widget]` macro may implement this method as a wrapper over
/// the corresponding [`MacroDefinedLayout`].
///
/// [`Stretch`]: crate::layout::Stretch
fn set_rect(&mut self, cx: &mut ConfigCx, rect: Rect, hints: AlignHints);
Expand Down Expand Up @@ -184,11 +177,8 @@ pub trait Layout {
///
/// ## Default implementation
///
/// The `#[widget]` macro
/// [may generate a default implementation](macros::widget#layout-1) by
/// implementing [`LayoutVisitor`] for `Self`.
/// In this case the default impl of this method is
/// `self.layout_visitor().draw(/* ... */)`.
/// The `#[widget]` macro may implement this method as a wrapper over
/// the corresponding [`MacroDefinedLayout`].
///
/// ## Method modification
///
Expand Down
19 changes: 3 additions & 16 deletions crates/kas-core/src/core/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use kas_macros::autoimpl;

#[allow(unused)] use super::{Events, Widget};
#[allow(unused)]
use crate::layout::{self, AlignPair, LayoutVisitor};
use crate::layout::{self, AlignPair};
#[allow(unused)] use crate::theme::DrawCx;
#[allow(unused)] use kas_macros as macros;

Expand Down Expand Up @@ -193,23 +193,10 @@ pub trait Tile: Layout {
///
/// ## Default implementation
///
/// ## Default implementation
///
/// The `#[widget]` macro
/// [may generate a default implementation](macros::widget#layout-1) by
/// implementing [`LayoutVisitor`] for `Self`.
/// In this case the default impl of this method is
/// `self.layout_visitor().set_rect(/* ... */)`.
/// The underlying implementation considers all children of the `layout`
/// property and of fields, like this:
/// The `#[widget]` macro may implement this method as:
/// ```ignore
/// let coord = coord + self.translation();
/// for child in ITER_OVER_CHILDREN {
/// if let Some(id) = child.try_probe(coord) {
/// return Some(id);
/// }
/// }
/// self.id()
/// MacroDefinedLayout::try_probe(self, coord).unwrap_or_else(|| self.id())
/// ```
fn probe(&mut self, coord: Coord) -> Id
where
Expand Down
1 change: 0 additions & 1 deletion crates/kas-core/src/core/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use super::{Node, Tile};
#[allow(unused)] use crate::event::Used;
use crate::event::{ConfigCx, Event, EventCx, IsUsed, Scroll, Unused};
#[allow(unused)] use crate::layout::LayoutVisitor;
use crate::Id;
#[allow(unused)] use kas_macros as macros;
use kas_macros::autoimpl;
Expand Down
40 changes: 2 additions & 38 deletions crates/kas-core/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
//!
//! [`RowPositionSolver`] may be used with widgets set out by [`RowSetter`]
//! to quickly locate children from a `coord` or `rect`.
//!
//! [`Layout`]: crate::Layout
mod align;
mod grid_solver;
Expand All @@ -46,7 +48,6 @@ mod storage;
mod visitor;

use crate::dir::{Direction, Directional, Directions};
use crate::Layout;

pub use align::{Align, AlignHints, AlignPair};
pub use grid_solver::{DefaultWithLen, GridCellInfo, GridDimensions, GridSetter, GridSolver};
Expand Down Expand Up @@ -147,43 +148,6 @@ impl From<AxisInfo> for Directions {
}
}

/// Macro-generated implementation of layout over a [`Visitor`]
///
/// This method is implemented by the [`#widget`] macro when a [`layout`]
/// specification is provided.
/// Direct implementations of this trait are not supported.
///
/// This trait may be used in user-code where a `layout` specification is used
/// *and* custom behaviour is provided for one or more layout methods, for example:
/// ```
/// # extern crate kas_core as kas;
/// use kas::prelude::*;
///
/// impl_scope! {
/// #[widget {
/// Data = ();
/// layout = "Example";
/// }]
/// struct Example {
/// core: widget_core!(),
/// }
/// impl Layout for Self {
/// fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules {
/// self.layout_visitor()
/// .size_rules(sizer, axis)
/// .with_stretch(Stretch::High)
/// }
/// }
/// }
/// ```
///
/// [`#widget`]: crate::widget
/// [`layout`]: crate::widget#layout-1
pub trait LayoutVisitor {
/// Layout defined by a [`Visitor`]
fn layout_visitor(&mut self) -> Visitor<impl Layout>;
}

#[cfg(test)]
#[test]
fn size() {
Expand Down
4 changes: 1 addition & 3 deletions crates/kas-core/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ pub use crate::event::{ConfigCx, Event, EventCx, EventState, IsUsed, Unused, Use
#[doc(no_inline)]
pub use crate::geom::{Coord, Offset, Rect, Size};
#[doc(no_inline)]
pub use crate::layout::{
Align, AlignHints, AlignPair, AxisInfo, LayoutVisitor, SizeRules, Stretch,
};
pub use crate::layout::{Align, AlignHints, AlignPair, AxisInfo, SizeRules, Stretch};
#[doc(no_inline)] pub use crate::text::AccessString;
#[doc(no_inline)] pub use crate::theme::{DrawCx, SizeCx};
#[doc(no_inline)] pub use crate::Action;
Expand Down
Loading

0 comments on commit f100172

Please sign in to comment.