Skip to content

Commit

Permalink
Remove kas::layout::Visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Feb 17, 2025
1 parent f100172 commit 0043683
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 523 deletions.
3 changes: 1 addition & 2 deletions crates/kas-core/src/core/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use crate::{HasId, Id, Layout};
use kas_macros::autoimpl;

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

Expand Down
6 changes: 0 additions & 6 deletions crates/kas-core/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ mod size_rules;
mod size_types;
mod sizer;
mod storage;
mod visitor;

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

Expand All @@ -57,11 +56,6 @@ pub use size_rules::SizeRules;
pub use size_types::*;
pub use sizer::{solve_size_rules, RulesSetter, RulesSolver, SolveCache};
pub use storage::*;
pub use visitor::{FrameStorage, PackStorage};

#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(docsrs, doc(cfg(internal_doc)))]
pub use visitor::{LayoutList, Visitor};

/// Information on which axis is being resized
///
Expand Down
49 changes: 48 additions & 1 deletion crates/kas-core/src/layout/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,57 @@

//! Layout solver — storage
use super::SizeRules;
use super::{AxisInfo, SizeRules};
use crate::dir::Directional;
use crate::geom::{Offset, Rect, Size};
use crate::theme::{FrameStyle, SizeCx};
use kas_macros::impl_scope;
use std::fmt::Debug;

/// Layout storage for pack
#[derive(Clone, Default, Debug)]
pub struct PackStorage {
/// Ideal size
pub size: Size,
}

/// Layout storage for frame
#[derive(Clone, Default, Debug)]
pub struct FrameStorage {
/// Size used by frame (sum of widths of borders)
pub size: Size,
/// Offset of frame contents from parent position
pub offset: Offset,
/// [`Rect`] assigned to whole frame
///
/// NOTE: for a top-level layout component this is redundant with the
/// widget's rect. For frames deeper within a widget's layout we *could*
/// instead recalculate this (in every draw call etc.).
pub rect: Rect,
}
impl FrameStorage {
/// Calculate child's "other axis" size
pub fn child_axis(&self, mut axis: AxisInfo) -> AxisInfo {
axis.sub_other(self.size.extract(axis.flipped()));
axis
}

/// Generate [`SizeRules`]
pub fn size_rules(
&mut self,
sizer: SizeCx,
axis: AxisInfo,
child_rules: SizeRules,
style: FrameStyle,
) -> SizeRules {
let frame_rules = sizer.frame(style, axis);
let (rules, offset, size) = frame_rules.surround(child_rules);
self.offset.set_component(axis, offset);
self.size.set_component(axis, size);
rules
}
}

/// Requirements of row solver storage type
///
/// Usually this is set by a [`crate::layout::RowSolver`] from
Expand Down
Loading

0 comments on commit 0043683

Please sign in to comment.