Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoLayout → LayoutVisitor #434

Merged
merged 13 commits into from
Jan 16, 2024
Prev Previous commit
Next Next commit
Doc: visibility for Visitor / Visitable*.
dhardy committed Jan 15, 2024
commit c4a460d7b2c270455e08dfb75c4691df04cb0ef3
13 changes: 8 additions & 5 deletions crates/kas-core/src/layout/visitor.rs
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ use crate::{dir::Directional, dir::Directions, Layout};
///
/// Unlike when implementing a widget, all methods of this trait must be
/// implemented directly.
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
#[crate::autoimpl(for<T: trait + ?Sized> &'_ mut T, Box<T>)]
pub trait Visitable {
/// Get size rules for the given axis
@@ -52,6 +54,8 @@ pub trait Visitable {
///
/// This is templated over `cell_info: C` where `C = ()` for lists or
/// `C = GridChildInfo` for grids.
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
pub trait VisitableList<C> {
/// List length
fn len(&self) -> usize;
@@ -78,15 +82,14 @@ impl<C> VisitableList<C> for () {

/// A layout visitor
///
/// This constitutes a "visitor" which iterates over each child widget. Layout
/// algorithm details are implemented over this visitor.
/// Objects are generated by [`layout`] syntax. These all have limited lifetime.
///
/// This is an internal API and may be subject to unexpected breaking changes.
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
/// [`layout`]: crate::widget#layout-1
pub struct Visitor<V: Visitable>(V);

/// These methods would be free functions, but `Visitable` is a useful namespace
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
impl<'a> Visitor<Box<dyn Visitable + 'a>> {
/// Construct a single-item layout
pub fn single(widget: &'a mut dyn Layout) -> Visitor<impl Visitable + 'a> {