From 786c71f812594e243f3fff56a356447073beace3 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 07:07:21 +0000 Subject: [PATCH] craft-ui: remove Divider::length; regenerate contract-api.md Divider::length has no caller since the ribbon groups fill their line; its story and trial go with it (the filling divider trial stays). docs/contract-api.md is regenerated with the contract-api bin and lists ContainerProps::least_height and Row::least_height. --- crates/ui-widgets/src/display/divider.rs | 24 ++-------- .../ui-widgets/src/display/divider/stories.rs | 19 -------- .../ui-widgets/tests/it/layout/cross_fill.rs | 32 ------------- docs/contract-api.md | 45 ++++++++++++++----- 4 files changed, 37 insertions(+), 83 deletions(-) diff --git a/crates/ui-widgets/src/display/divider.rs b/crates/ui-widgets/src/display/divider.rs index e96bfd3f2..91495429b 100644 --- a/crates/ui-widgets/src/display/divider.rs +++ b/crates/ui-widgets/src/display/divider.rs @@ -33,35 +33,23 @@ enum Axis { /// A separator line in the divider colour, snapped to the pixel grid. A horizontal line takes the width it is /// offered (at least one control height; in a content-sized column it never widens the column) and a vertical one the height of its row, at least a control's height. In a bar it -/// shows only with the member after it. A line given its [`length`](Divider::length) takes that length and fills -/// nothing. Decoration: it is not in the AccessKit tree. +/// shows only with the member after it. Decoration: it is not in the AccessKit tree. #[derive(crate::contract::Component)] pub struct Divider { #[common] common: Common, axis: Axis, - /// The line's own length, in points; `None` fills the room as the axis says. - length: Option, } impl Divider { /// A line across the width offered. pub fn horizontal() -> Self { - Divider { common: Common::new(), axis: Axis::Horizontal, length: None } + Divider { common: Common::new(), axis: Axis::Horizontal } } /// A line down the full height of its row. pub fn vertical() -> Self { - Divider { common: Common::new(), axis: Axis::Vertical, length: None } - } - - /// The line is `points` long, along its axis, whatever the room: it fills nothing. A separator whose owner knows its - /// own extent (a ribbon group, as tall as its content and title) takes that, so the line never sets the extent of - /// the row it sits in. A length that is not a finite positive number is ignored, and the line fills as before. - // design: allow[props/point-size](the length is the measured extent of the owner's content (a group as tall as its content and title), not a chosen size) - pub fn length(mut self, points: f32) -> Self { - self.length = (points.is_finite() && points > 0.0).then_some(points); - self + Divider { common: Common::new(), axis: Axis::Vertical } } } @@ -88,7 +76,7 @@ impl Component for Divider { fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { let width = cx.style.width.points(cx.ui.ctx().pixels_per_point()); - let length = self.length.unwrap_or(cx.style.length); + let length = cx.style.length; match self.axis { Axis::Horizontal if cx.env.get::().0 => Vec2::new(length, width + 2.0 * cx.style.separator_pad), Axis::Horizontal => Vec2::new(length, width), @@ -98,10 +86,6 @@ impl Component for Divider { } fn fills(&self) -> Option { - // A line given its length keeps it. - if self.length.is_some() { - return None; - } Some(match self.axis { Axis::Horizontal => craft_behavior::Axis::X, Axis::Vertical => craft_behavior::Axis::Y, diff --git a/crates/ui-widgets/src/display/divider/stories.rs b/crates/ui-widgets/src/display/divider/stories.rs index a38465cfe..bbc4941d2 100644 --- a/crates/ui-widgets/src/display/divider/stories.rs +++ b/crates/ui-widgets/src/display/divider/stories.rs @@ -2,9 +2,7 @@ use super::Divider; use crate::contract::Show as _; -use crate::contract::ShowContainer as _; use crate::display::Text; -use crate::layout_components::{Row, Stack}; use crate::testing::{Drive, StoryData, StoryOutput, story}; use egui::Ui; @@ -13,23 +11,6 @@ fn divider(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { Divider::horizontal().show(ui).into() } -/// A vertical line given its length beside a taller stack and a shorter text: it keeps its length, neither filling the -/// row nor setting its height. -#[story(Divider, covers = [], drive = Drive::Never, title = "Given length")] -fn divider_length(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { - Row::new() - .show(ui, |ui, _| { - Stack::new().show(ui, |ui, _| { - for line in ["First", "Second", "Third"] { - Text::new(line).show(ui); - } - }); - Divider::vertical().length(24.0).show(ui); - Text::new("Right").show(ui); - }) - .into() -} - #[story(Divider, covers = [], drive = Drive::Never)] fn divider_vertical(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { ui.horizontal(|ui| { diff --git a/crates/ui-widgets/tests/it/layout/cross_fill.rs b/crates/ui-widgets/tests/it/layout/cross_fill.rs index fafe77e17..9580b2c29 100644 --- a/crates/ui-widgets/tests/it/layout/cross_fill.rs +++ b/crates/ui-widgets/tests/it/layout/cross_fill.rs @@ -61,35 +61,3 @@ fn a_vertical_divider_spans_the_line_of_a_content_height_row_without_setting_it( check(&seen, "once settled"); assert!(last_pass_measuring_runs(&frames.ctx).is_empty(), "a settled frame measures nothing"); } - -/// A vertical divider given its length keeps it: beside a taller stack it does not span the row, and longer than the -/// stack it sets the row's height, in a column given the screen's height as in a content-sized one. -#[trial] -fn a_vertical_divider_given_its_length_keeps_it_whatever_the_row() { - for length in [12.0_f32, 400.0] { - let mut frames = Frames::new(); - let seen = Cell::new((Rect::NOTHING, Rect::NOTHING, Rect::NOTHING)); - for _ in 0..2 { - frames.idle(4, |ui| { - Stack::new().fill().show_at(ui, ui.available_rect_before_wrap(), |ui, _| { - let parts = Cell::new((Rect::NOTHING, Rect::NOTHING)); - let row = Row::new().show(ui, |ui, _| { - let stack = Stack::new().show(ui, |ui, _| { - for label in ["Bevel", "Stroke", "Inner Shadow"] { - Button::new(label).show(ui); - } - }); - let divider = Divider::vertical().length(length).show(ui).rect; - parts.set((stack.output.rect, divider)); - }); - let (stack, divider) = parts.get(); - seen.set((row.output.rect, stack, divider)); - }); - }); - let (row, stack, divider) = seen.get(); - assert!((divider.height() - length).abs() <= SNAP, "the divider {divider:?} is {length} long"); - let tallest = stack.height().max(length); - assert!((row.height() - tallest).abs() <= SNAP, "the row {row:?} is as tall as its tallest child ({tallest})"); - } - } -} diff --git a/docs/contract-api.md b/docs/contract-api.md index f6d907325..db116da2b 100644 --- a/docs/contract-api.md +++ b/docs/contract-api.md @@ -538,11 +538,11 @@ The dock model: the tree of splits over panel frames, the side of a group a drop - `pub fn add_document(&mut self, document: &D)`. Adds `document` to the first docked group, or to a new docked group when there is none. A document a group - `pub fn to_actions(&self, layout: &Layout

, panel_of: impl Fn(u64) -> P) -> Vec>`. The dock actions that put `self` into `layout`, for the dock to draw the windows. The - `craft_behavior::dock::Floating`: `pub struct Floating

{ pub id: u64, pub column: Column

, pub rect: Rect, pub native: Option, pub edge: Option }`. A floating window: one column of groups, the same [`Column`] a dock holds. Nothing sits beside the column - - `pub fn new(column: Column

, rect: Rect) -> Self`. A window holding `column`. Each call makes a new window, with a fresh [`Self::id`]: build - - `pub fn single(panels: Vec

, active: usize, rect: Rect) -> Self`. A window with one group. Each call makes a new window, as [`Self::new`] does. - - `pub fn with_id(mut self, id: u64) -> Self`. The window with `id`, for a layout the app builds in code, such as a default layout: + - `pub fn new(id: u64, column: Column

, rect: Rect) -> Self`. The window `id` holding `column`. Ids are unique within a layout; a window added to a live layout takes its id + - `pub fn single(id: u64, panels: Vec

, active: usize, rect: Rect) -> Self`. The window `id` with one group. + - `pub fn with_id(mut self, id: u64) -> Self`. The window with `id` in place of its own. Ids must be unique within a layout. - `pub fn panels(&self) -> impl Iterator`. Every panel in the window, top group first. - - `pub fn stack(groups: Vec>, rect: Rect) -> Option`. A window of `groups`, stacked top to bottom, expanded. `None` without groups. Each call makes a new window, + - `pub fn stack(id: u64, groups: Vec>, rect: Rect) -> Option`. The window `id` of `groups`, stacked top to bottom, expanded. `None` without groups. - `pub fn groups(&self) -> &[Group

]`. The window's groups, top to bottom. - `pub fn contains(&self, panel: &Q) -> bool where P: std::borrow::Borrow,`. True when a group of this window holds `panel`. Takes any borrowed form of `P`, such - `craft_behavior::dock::Group`: `pub struct Group

{ pub panels: Vec

, pub active: usize, pub minimized: bool, pub height: Option, pub flyout_width: Option, pub flyout_offset: Option }`. Tabs that move, minimize and size together in a column, docked or floating. @@ -553,7 +553,9 @@ The dock model: the tree of splits over panel frames, the side of a group a drop - `pub const fn with_flyout_width(mut self, width: Option) -> Self`. The location with the group's flyout `width` points wide. - `pub const fn with_flyout_offset(mut self, offset: Option) -> Self`. The location with the group's flyout top `offset` points from its icons' top. - `craft_behavior::dock::Layout`: `pub struct Layout

{ pub root: Option>, pub floating: Vec> }`. The panels of a workspace: a docked tree plus floating windows. Every panel occurs once. - - `pub fn new(root: Option>, floating: Vec>) -> Self`. A layout with the docked tree `root` and the floating windows `floating`. + - `pub fn new(root: Option>, floating: Vec>) -> Self`. A layout with the docked tree `root` and the floating windows `floating`. New windows take ids above every id + - `pub fn fresh_window_id(&mut self) -> u64`. An id for a new floating window: above every window id the layout held when it was built or loaded and every + - `pub fn window_floor(&self) -> u64`. The least id above every id the layout holds or has held. - `pub fn validate(&self) -> Result<(), DockError>`. Check depth, allocation bounds, geometry, selection, globally unique panel ownership and - `pub fn panels(&self) -> Vec<&P>`. Iterate identities without recursion. On excessive input returns no more than the limit. - `pub fn contains(&self, panel: &P) -> bool`. Whether the layout holds `panel`, docked or floating. @@ -600,10 +602,17 @@ The dock model: the tree of splits over panel frames, the side of a group a drop - `pub fn new_dock(side: DockEdge) -> Self`. Builds [`Target::NewDock`]. - `pub fn float(rect: Rect) -> Self`. Builds [`Target::Float`] with no edge: the area takes the edge nearer `rect`. - `pub fn float_with_edge(rect: Rect, edge: Option) -> Self`. Builds [`Target::Float`] with the edge a collapsed window keeps to. -- `craft_behavior::dock::Workspace`: `pub struct Workspace

{ pub version: u32, pub layout: Layout

, pub hidden: Vec<(P, Location

)>, pub floated: Vec<(P, Location

)> }`. A saved arrangement of panels: the [`Layout`] and the closed panels' former places. +- `craft_behavior::dock::Workspace`: `pub struct Workspace

`. A saved arrangement of panels: the [`Layout`] and the closed panels' former places. - `pub const VERSION: u32`. The format version written to files. Version 4 saves a floating window as one column; older floating - - `pub fn revision(&self) -> u64`. The revision of this live workspace: it changes with every [`replace`](Self::replace) and nothing else. - - `pub fn replace(&mut self, with: Workspace

)`. Replaces the arrangement with `with` and moves to the next revision. + - `pub fn version(&self) -> u32`. The format version the workspace was read with. + - `pub fn layout(&self) -> &Layout

`. The current arrangement. + - `pub fn hidden(&self) -> &[(P, Location

)]`. The closed panels, and panels the application does not register now, with where each one goes back. + - `pub fn floated(&self) -> &[(P, Location

)]`. The floating panels with the docked location each one left. + - `pub fn revision(&self) -> Revision`. The revision of this workspace value: it moves with every write, and no other value has it. + - `pub fn generation(&self) -> u64`. The generation of this live workspace: it moves with every [`replace`](Self::replace) and nothing else. + - `pub fn raise_window_floor(&mut self, floor: u64)`. Keeps the ids of new floating windows at or above `floor`. A dock that showed windows below `floor` raises a + - `pub fn forget_hidden(&mut self, forget: impl Fn(&P) -> bool)`. Drops the closed-panel records of the panels `forget` names, so reopening them does not restore their place. + - `pub fn replace(&mut self, with: Workspace

)`. Replaces the arrangement with `with` and moves to the next generation. The windows of `with` take ids this - `pub fn apply(&mut self, action: Action

, locked: bool, permissions: impl Fn(&P) -> Permissions) -> Result, DockError>`. Apply one action. Closed panels record where they go back, so each one can be reopened - `pub fn apply_all(&mut self, actions: impl IntoIterator>, locked: bool, permissions: impl Fn(&P) -> Permissions,) -> Result, DockError>`. Apply every action in order, or none, as [`Self::apply`] does. Returns the panels the - `craft_behavior::dock::WorkspaceChrome`: `pub struct WorkspaceChrome { pub menu_bar: bool, pub tool_rail: bool, pub options_bar: bool, pub status_bar: bool }`. Chrome a workspace remembers beside the dock layout: which bars show. The default shows every bar. @@ -1955,6 +1964,7 @@ The component traits, context types, `PaintUi`, `Looks`, the pipeline and its st - `pub fn labelled_with(&mut self, ui: &mut Ui, key: impl Hash + Debug, label: Label, side: SideLabel, child: C, content: D,) -> C::Output`. `labelled`, with `content` shown inside the label after its text (a sample of what the option picks). The - `pub fn style(&self) -> Option<&'a C::Style>`. The style of the container `C` whose body this is, as step 2 resolved it for this pass: the one way a body - `pub fn gap(&self) -> Option`. The gap the body's layout puts between its children (`ContainerProps::body_gap`), for a body that places + - `pub fn derived(&self, key: &K, build: impl FnOnce() -> V) -> std::sync::Arc`. The value this body derives from `key`: kept while `key` is unchanged, else built by `build` - `pub fn take_cancel(&mut self) -> bool`. Takes the Escape of this pass that no component took: a field that clears on Escape passes it on once it - `craft_ui::contract::BodyLayout`: `pub enum BodyLayout { Stack, Row { wrap: bool, align: RowAlign }, Grid { columns: Cow<'static, [ColumnWidth]>, fit: GridFit, cells: CellAlign } }`. How a body lays out its children, in reading order: mirrored under a right-to-left direction. - `pub const fn stack() -> Self`. Children one under another. @@ -1971,7 +1981,7 @@ The component traits, context types, `PaintUi`, `Looks`, the pipeline and its st - `pub const fn initially_open(mut self, on: bool) -> Self`. Whether the body starts open. - `pub const fn animated(mut self, on: bool) -> Self`. Whether opening and closing animate. - `craft_ui::contract::CollectionEvent`: `pub enum CollectionEvent { Selection(SelectionChange), LeadMoved { key: K, by: LeadSource }, Activate(K), Rested(K), EmptyActivated, EmptyContextMenu { at: Pos2 }, Preview(K), ContextMenu(ContextMenuRequest), EdgePressed { above: K, below: K, mods: craft_keymap::Mods }, CommandClick { key: K, mods: craft_keymap::Mods }, Delete(Vec), Open(OpenChange), Reorder(EditEvent>), Move(EditEvent), Dropped { at: DropAt, op: DropOperation, payload: DropPayload }, Zoom { factor: f32, about: Pos2 }, Rename(EditEvent>), Toggle(EditEvent>), Column(ColumnEvent), Item(K, E) }`. What a collection reports, in drawing order. -- `craft_ui::contract::CollectionProps`: `pub struct CollectionProps { pub select: SelectMode, pub reorder: Option, pub rename: bool, pub rename_column: Option, pub slow_click_rename: bool, pub columns: Vec, pub sort: Option, pub empty: Option