From 81078945af03e2257a7c7e4fc833aec2b1f03b2b Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 15:59:53 +0000 Subject: [PATCH 01/10] A row given its height centres its line; a fill-width row on that line fills it; top and bottom shell panes lay their bar on one line A container given its height whose body is an unwrapped row sets the row's line at the middle of its band and pads only along the line. A fill-width container with a row body on such a line is given the line's height, so a bar in a top or bottom slot fills the slot. A container whose first line is its own row's line sits on an outer row's line by it even with a child of two lines. The shell's top and bottom panes lay their content out as a row; the egui centring wrapper and the slot's surface under the bar are gone. --- crates/ui-contract/src/contract/body/hooks.rs | 28 ++++++--- crates/ui-contract/src/contract/body/size.rs | 25 +++++++- crates/ui-contract/src/contract/run.rs | 13 +++- crates/ui-contract/src/contract/run/typed.rs | 4 ++ crates/ui-contract/src/layout/body.rs | 7 ++- crates/ui-shell/src/shell/app_shell.rs | 26 +++----- crates/ui-shell/tests/it/shell/app_shell.rs | 63 ++++++++++++++++++- crates/ui-widgets/src/bars/bar.rs | 3 +- 8 files changed, 135 insertions(+), 34 deletions(-) diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index 6ea4318eae..95906aa1ef 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -288,7 +288,7 @@ impl ShapeHooks for BodyHooks<'_> { self.overflow = self.wanted_width(props).map_or(0.0, |wanted| (wanted - room.max(0.0)).max(0.0)); let (header, end) = (self.measured_header.unwrap_or(Vec2::ZERO), self.measured_end.unwrap_or(Vec2::ZERO)); let height = self.regions_size(props, body, header, self.measured_footer, end).y; - Vec2::new(width, height) + Vec2::splat(2.0 * pad_of(scx.tokens, props.pad)) + Vec2::new(width, height) + 2.0 * self.pads(props, scx.tokens) } /// The regions run once in an invisible sizing pass over the room, as `content` runs them, and the container takes @@ -371,7 +371,7 @@ impl ShapeHooks for BodyHooks<'_> { if at.ui.is_sizing_pass() && self.given == (true, true) && self.room.is_finite() && !scrolled_share { return self.room; } - let pad = Vec2::splat(2.0 * pad_of(at.scx.tokens, props.pad)); + let pad = 2.0 * self.pads(&props, at.scx.tokens); let vertical = scroll_of(&props).is_some_and(|scroll| scroll.vertical_on()); let tolerance = measure_tolerance(crate::runtime::egui::scale::pixels_per_point(&ctx)); // A record a run of this pass left serves as before; a kept one serves only while the inputs it was measured @@ -500,7 +500,13 @@ impl ShapeHooks for BodyHooks<'_> { // where it is shown: its measure never sets the column's width. let held = !self.given.0 && self.held(props, &Env::of(ui)); let room = if held { room.min(crate::layout::flow_room(ui).x) } else { room }; - Vec2::new(crate::layout::fill_size(ui, id, craft_behavior::Axis::X, size.x, room, self.given.0 || held), size.y) + // Given the height of the row line it sits on, it fills that line (`given_axes`). + let height = if self.given.1 { + crate::layout::fill_size(ui, id, craft_behavior::Axis::Y, size.y, crate::layout::flow_room(ui).y, true) + } else { + size.y + }; + Vec2::new(crate::layout::fill_size(ui, id, craft_behavior::Axis::X, size.x, room, self.given.0 || held), height) } Sizing::Content => size, } @@ -520,6 +526,12 @@ impl ShapeHooks for BodyHooks<'_> { layout_memory::measured(ctx, sub(id, "first")).map(|found| found.took.y) } + /// A container with no header whose body is an unwrapped row reports that row's line as its first line. + fn first_is_row_line(&self, comp: &C) -> bool { + let props = comp.props(Internal::new()); + props.header.is_none() && super::size::unwrapped_row(props) + } + fn member(&self, comp: &C) -> bool { comp.props(Internal::new()).label.is_some() } @@ -539,7 +551,7 @@ impl ShapeHooks for BodyHooks<'_> { return None; } let tokens = cx.tokens; - let inner = content.shrink(pad_of(tokens, props.pad)); + let inner = content.shrink2(self.pads(&props, tokens)); let regions = self.regions(&props, inner, pad_of(tokens, props.pad), self.room_size(rect, inner), rtl, self.measured_sizes()); let (_, slots) = self.header_line(regions.header, pad_of(tokens, header.inset), parts, rtl); Some(std::rc::Rc::new(slots)) @@ -550,7 +562,7 @@ impl ShapeHooks for BodyHooks<'_> { let ctx = pcx.ui.ctx().clone(); let rtl = pcx.flow.is_rtl(); let tokens = pcx.tokens; - let inner = pcx.content_rect.shrink(pad_of(tokens, props.pad)); + let inner = pcx.content_rect.shrink2(self.pads(&props, tokens)); let room = self.room_size(rect, inner); let regions = self.regions(&props, inner, pad_of(tokens, props.pad), room, rtl, self.measured_sizes()); let scroll = scroll_of(&props); @@ -678,7 +690,7 @@ impl ShapeHooks for BodyHooks<'_> { let node = matches!(C::ROLE, Role::Node(_)); let scroll = scroll_of(&props); let pad = pad_of(&env.tokens, props.pad); - let inner = cx.core.content_rect.shrink(pad); + let inner = cx.core.content_rect.shrink2(self.pads(&props, &env.tokens)); let room = self.room_size(rect, inner); let mut regions = self.regions(&props, inner, pad, room, rtl, self.measured_sizes()); let surface_slot = SurfaceSlot::reserve(ui, matches!(props.mount, Mount::Layer(_))); @@ -781,6 +793,8 @@ impl ShapeHooks for BodyHooks<'_> { (regions.body, regions.beside) = (placed.body, placed.beside); } let line = shared_line(&props, beside); + // A row given its height sets its line at the middle of its band: the line is as high as the band. + let line = if self.centres_line(&props) { Some(line.unwrap_or(0.0).max(regions.body.height())) } else { line }; // B2 label: the control gets the rect the label leaves; the label column adds to the container's extent. let mut body_rect = regions.body; let mut label_rect = Rect::NOTHING; @@ -1246,7 +1260,7 @@ impl BodyHooks<'_> { ) -> Vec2 { let props = Arc::clone(&self.props); let (id, ctx) = (cx.core.id, at.ui.ctx().clone()); - let pad = Vec2::splat(2.0 * pad_of(at.scx.tokens, props.pad)); + let pad = 2.0 * self.pads(&props, at.scx.tokens); #[cfg(feature = "testing")] crate::runtime::measure::count_body(&ctx, id); layout_memory::begin_measure(&ctx, id); diff --git a/crates/ui-contract/src/contract/body/size.rs b/crates/ui-contract/src/contract/body/size.rs index ac0bee7c66..155d84b24e 100644 --- a/crates/ui-contract/src/contract/body/size.rs +++ b/crates/ui-contract/src/contract/body/size.rs @@ -117,9 +117,13 @@ impl<'b> BodyHooks<'b> { /// The axes the container is given where `env` is its parent's: a rect it is shown at gives both; an inline /// container that fills an axis takes the room only where its parent was given that axis. + /// + /// A fill-width container whose body is a row, shown on the line of a row given its height, is given that height + /// too: the line is a fixed cross extent, and the container fills it (a bar in a shell slot). pub(super) fn given_axes(&self, props: &ContainerProps, env: &Env, at: ShowAt) -> (bool, bool) { let sizing = self.sizing(props); - let (x, y) = (sizing != Sizing::Content, sizing == Sizing::Fill); + let fills_line = sizing == Sizing::FillWidth && unwrapped_row(props) && env.row_line.is_some(); + let (x, y) = (sizing != Sizing::Content, sizing == Sizing::Fill || fills_line); match (at, &props.mount) { (ShowAt::Rect(_), _) => (true, true), (ShowAt::Flow, Mount::Inline) => (x && env.gives_width(), y && !env.content.1), @@ -134,6 +138,20 @@ impl<'b> BodyHooks<'b> { matches!((at, &props.mount), (ShowAt::Flow, Mount::Inline)) && self.sizing(props) == Sizing::Content && env.given_column } + /// Whether the container centres its body's line in the height it is given: its body is a row that does not scroll + /// along the height, and the container is given its height (a rect it is shown at, a fill, a fixed row line it + /// fills). Its padding then keeps the members off the start and end edges only (`pads`). + pub(super) fn centres_line(&self, props: &ContainerProps) -> bool { + self.given.1 && unwrapped_row(props) && !scroll_of(props).is_some_and(|scroll| scroll.vertical_on()) + } + + /// The container's padding along each axis: `ContainerProps::pad` on both, or along the line only where the + /// container centres its line in its height. + pub(super) fn pads(&self, props: &ContainerProps, tokens: &crate::style::UiTokens) -> Vec2 { + let pad = super::regions::pad_of(tokens, props.pad); + Vec2::new(pad, if self.centres_line(props) { 0.0 } else { pad }) + } + /// Whether the container's body is laid out across the width it is offered: the container is given the width, /// passes it on, or is held across the width its column settled on. pub(super) fn wide(&self) -> bool { @@ -293,3 +311,8 @@ impl<'b> BodyHooks<'b> { } } } + +/// Whether the container's body is a `Row` that does not wrap: its children sit on one line. +pub(super) fn unwrapped_row(props: &ContainerProps) -> bool { + matches!(props.layout, crate::layout::BodyLayout::Row { wrap: false, .. }) +} diff --git a/crates/ui-contract/src/contract/run.rs b/crates/ui-contract/src/contract/run.rs index d86c8ea5d8..7e0acd15b2 100644 --- a/crates/ui-contract/src/contract/run.rs +++ b/crates/ui-contract/src/contract/run.rs @@ -144,6 +144,13 @@ pub(crate) trait ShapeHooks { Some(height / 2.0) } + /// Whether the root's first line is the line of its own unwrapped `Row` body: it sits on a `Row`'s line by that + /// line even where a child of more than one line makes it taller, so the members of a row nested in a row share + /// the outer row's line. + fn first_is_row_line(&self, _comp: &C) -> bool { + false + } + /// Whether the root is one member of a bar's line, shown whole or not at all: a leaf is; a body is when it has a /// side label (a captioned field), and otherwise only lays out the members it holds. fn member(&self, _comp: &C) -> bool { @@ -557,6 +564,7 @@ pub(crate) trait ErasedPass<'a> { fn sized(&self, ui: &Ui, id: Id, size: Vec2) -> Vec2; fn fills_width(&self) -> bool; fn first_line(&self, ctx: &Context, id: Id, height: f32) -> Option; + fn first_is_row_line(&self) -> bool; fn member(&self) -> bool; fn fills_width_only(&self) -> bool; fn arena(&self) -> bool; @@ -804,7 +812,8 @@ fn place_root(p: &Pass<'_, '_, '_>, ui: &mut Ui, at: ShowAt, env: &Env, size: Ve .then(|| crate::layout::flow_room(ui).x) .filter(|width| width.is_finite()) .unwrap_or(0.0); - let flowed = steps::place(ui, at, Vec2::new(p.measured.x.min(size.x), size.y), InFlow { fill: false, first: first(size.y) }); + let line = p.p.first_is_row_line(); + let flowed = steps::place(ui, at, Vec2::new(p.measured.x.min(size.x), size.y), InFlow { fill: false, first: first(size.y), line }); // The column's first sweep learns which of its held children measured narrower than it settles on. if let Some(ColumnSweep::Count(column)) = env.column { crate::layout::report_held(&ctx, column, flowed.width()); @@ -814,7 +823,7 @@ fn place_root(p: &Pass<'_, '_, '_>, ui: &mut Ui, at: ShowAt, env: &Env, size: Ve } else { let fill = p.p.fills_width() && !p.p.fills_width_only(); let size = if inert { Vec2::ZERO } else { size }; - steps::place(ui, at, size, InFlow { fill, first: first(size.y) }) + steps::place(ui, at, size, InFlow { fill, first: first(size.y), line: p.p.first_is_row_line() }) }; (rect, held) } diff --git a/crates/ui-contract/src/contract/run/typed.rs b/crates/ui-contract/src/contract/run/typed.rs index 4086d41354..1ef59e1ad6 100644 --- a/crates/ui-contract/src/contract/run/typed.rs +++ b/crates/ui-contract/src/contract/run/typed.rs @@ -405,6 +405,10 @@ impl<'a, C: Component> ErasedPass<'a> for TypedPass<'_, 'a, C> { self.hooks.first_line(self.comp, ctx, id, height) } + fn first_is_row_line(&self) -> bool { + self.hooks.first_is_row_line(self.comp) + } + fn member(&self) -> bool { self.hooks.member(self.comp) } diff --git a/crates/ui-contract/src/layout/body.rs b/crates/ui-contract/src/layout/body.rs index 88ee769c64..4f0a14fa6a 100644 --- a/crates/ui-contract/src/layout/body.rs +++ b/crates/ui-contract/src/layout/body.rs @@ -898,6 +898,9 @@ pub(crate) struct InFlow { /// rows run along Y, or a container whose first child is one. The child is one line when that centre lies at /// half its height (`one_line`). pub first: Option, + /// `first` is the line of the child's own unwrapped `Row` body: the child sits on a row's line by it even when it + /// is more than one line (a nested row with a child of two lines). + pub line: bool, } /// How far a one-line child's first-line centre may lie from half its height: half a pixel at the scales the box runs. @@ -919,7 +922,7 @@ fn one_line(first: Option, height: f32) -> Option { /// sits at the vertical centre of its cell. #[doc(hidden)] pub fn place_in_flow(ui: &mut Ui, size: Vec2) -> Rect { - place_in_cell(ui, size, InFlow { fill: false, first: Some(size.y / 2.0) }) + place_in_cell(ui, size, InFlow { fill: false, first: Some(size.y / 2.0), line: false }) } /// `place_in_flow` for a child that is `child`. In a measuring run the child reports its line to the row around it @@ -927,7 +930,7 @@ pub fn place_in_flow(ui: &mut Ui, size: Vec2) -> Rect { pub(crate) fn place_in_cell(ui: &mut Ui, size: Vec2, child: InFlow) -> Rect { let env = Env::of(ui); let (line, target) = (env.row_line, env.first_line); - let child = InFlow { first: one_line(child.first, size.y), ..child }; + let child = InFlow { first: if child.line { child.first } else { one_line(child.first, size.y) }, ..child }; let above = line.and_then(|line| line.centre).zip(child.first).map_or(0.0, |(centre, first)| (centre - first).max(0.0)); let slot = Vec2::new(size.x, line.and_then(|line| line.height).map_or(above + size.y, |height| height.max(above + size.y))); let (rect, in_cell) = take_in(ui, env.grid, slot); diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index 46cb009331..0bb3898492 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -14,7 +14,7 @@ use super::screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeFollow}; use super::words::ShellWords; use crate::contract::overlay::Resize; use crate::contract::{ - Bind, BodyCx, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, PaneEdge, Props as _, Remember as _, Role, ShellPane, + Bind, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, PaneEdge, Props as _, Remember as _, Role, ShellPane, ShowContainer as _, Sizing, }; use crate::notices::ToastStack; @@ -120,9 +120,12 @@ impl ShellRegion { ShellRegion { common: Common::new(), props, shell: Some(shell), senses_surface: false } } - /// A pane of the window; it fills the room its edge gives it. + /// A pane of the window; it fills the room its edge gives it. A top or bottom pane lays its content along its edge + /// on one line at the middle of its height, so a bar in it fills that height and centres its members there; a + /// start, end or centre pane stacks its content. pub fn pane(pane: ShellPane) -> Self { - let props = ContainerProps::new().mount(Mount::Pane(pane)).focus(FocusPolicy::PANE); + let layout = if matches!(pane.edge, PaneEdge::Top | PaneEdge::Bottom) { BodyLayout::row() } else { BodyLayout::stack() }; + let props = ContainerProps::new().mount(Mount::Pane(pane)).focus(FocusPolicy::PANE).layout(layout); ShellRegion { common: Common::new(), props, shell: None, senses_surface: false } } } @@ -520,26 +523,13 @@ impl<'a, S> AppShell<'a, S> { continue; } let extent = placed.extent(&tokens); - let Placed { slot, edge, named, add, title, .. } = placed; + let Placed { slot, edge, named, add, .. } = placed; let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent).at(rect_of(slot.key())); let mut region = ShellRegion::pane(pane).id_salt(("slot", slot.key())); - // A bar is as high as its content and the slot as high as its token, so the slot paints the bar's - // surface under it, and the bar sits at the slot's centre line: no band of the backdrop shows - // between the bar and the body. - let centred = !*title && matches!(edge, PaneEdge::Top | PaneEdge::Bottom); - if centred { - region = region.surface(SurfaceKind::Chrome); - } if let Some(label) = slot.name().cloned().or_else(|| named.map(|name| name(&words))) { region = region.label(label); } - region.show(ui, |ui, bcx| { - if centred { - ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| add(ui, bcx, app)); - } else { - add(ui, bcx, app); - } - }); + region.show(ui, |ui, bcx| add(ui, bcx, app)); } }; show_slots(ui, false, app); diff --git a/crates/ui-shell/tests/it/shell/app_shell.rs b/crates/ui-shell/tests/it/shell/app_shell.rs index 79517abae1..dcaba02035 100644 --- a/crates/ui-shell/tests/it/shell/app_shell.rs +++ b/crates/ui-shell/tests/it/shell/app_shell.rs @@ -1,10 +1,17 @@ -//! The app shell's named slots: a slot keeps its region name on either edge. +//! The app shell's named slots: a slot keeps its region name on either edge, and a bar in a top or bottom slot fills +//! it with its members on the slot's middle. -use craft_ui::contract::{PaneEdge, Role, Show as _}; +use craft_ui::bars::{Bar, BarKind}; +use craft_ui::buttons::Button; +use craft_ui::contract::{PaneEdge, Role, Show as _, ShowContainer as _}; use craft_ui::display::Text; +use craft_ui::layout_components::{Row, Stack}; use craft_ui::runtime::env::WindowKey; use craft_ui::shell::AppShell; -use craft_ui::testing::{Frames, trial}; +use craft_ui::testing::{Fixture, Frames, trial}; +use egui::{Rect, Vec2}; +use std::cell::Cell; +use std::rc::Rc; /// A tool rail placed at the end edge sits at the window's end and screen readers still find it as the Tools region. #[trial] @@ -29,3 +36,53 @@ fn the_tool_rail_at_the_end_edge_is_the_tools_region() { let names: Vec<&str> = tree.with_role(Role::GROUP).into_iter().filter_map(|key| tree.name_of(key)).collect(); assert!(names.contains(&"Tools"), "the end-edge rail is the Tools region: {names:?}"); } + +/// What the options-bar trial saw: the slot, the bar, a member of the bar and a member of a row nested in it. +#[derive(Clone, Copy)] +struct InSlot { + slot: Rect, + bar: Rect, + member: Rect, + nested: Rect, +} + +/// A bar in the options slot is as high as the slot, whatever its own padding and members take, and its members sit +/// on the slot's middle: a member of the bar's own row and a member of a row nested in it beside a child of two lines. +#[trial] +fn a_bar_in_a_top_slot_fills_it_and_centres_its_members_on_one_line() { + let seen = Rc::new(Cell::new(None::)); + let out = Rc::clone(&seen); + let mut fixture = Fixture::new(move |ui| { + let (mut bar, mut member, mut nested) = (Rect::NOTHING, Rect::NOTHING, Rect::NOTHING); + let shown = AppShell::new(WindowKey::main()) + .options_bar(true, |ui, _, _: &mut ()| { + bar = Bar::new("Options", BarKind::Options) + .show(ui, |ui, _| { + member = Button::new("Alpha").show(ui).rect; + Row::new().show(ui, |ui, _| { + nested = Button::new("Beta").show(ui).rect; + Stack::new().show(ui, |ui, _| { + Text::new("Above").show(ui); + Text::new("Below").show(ui); + }); + }); + }) + .output + .response + .rect; + }) + .body(|_, _, _| {}) + .show(ui, &mut ()); + let slot = shown.regions.slots.iter().find(|(key, _)| *key == "options").map(|(_, rect)| *rect); + if let Some(slot) = slot { + out.set(Some(InSlot { slot, bar, member, nested })); + } + }); + fixture.room(Vec2::new(600.0, 300.0)).settle(); + let InSlot { slot, bar, member, nested } = seen.get().expect("the options slot shows"); + const SLACK: f32 = 1.0; + assert!((bar.min.y - slot.min.y).abs() <= SLACK && (bar.max.y - slot.max.y).abs() <= SLACK, "the bar {bar:?} fills the slot {slot:?}"); + for (name, rect) in [("the bar's member", member), ("the nested row's member", nested)] { + assert!((rect.center().y - slot.center().y).abs() <= SLACK, "{name} {rect:?} sits on the middle of the slot {slot:?}"); + } +} diff --git a/crates/ui-widgets/src/bars/bar.rs b/crates/ui-widgets/src/bars/bar.rs index ce38541120..a968c9a837 100644 --- a/crates/ui-widgets/src/bars/bar.rs +++ b/crates/ui-widgets/src/bars/bar.rs @@ -77,7 +77,8 @@ impl Outcome for BarOutput { /// A bar over a chrome surface whose body holds the members in reading order: a tool bar's at the standard control /// size, an options or status bar's at the small one. They are one roving group unless the bar is made of /// [`tab_stops`](Bar::tab_stops). The bar is as tall as its tallest member plus the control padding, and takes the -/// width it is offered. A bar of one row lays its body out as a row; a bar of several rows as a stack whose rows the +/// width it is offered. On the line of a row given its height (a top or bottom slot of the shell) it fills that height +/// and its members sit on the line's middle, with its padding at the start and end only. A bar of one row lays its body out as a row; a bar of several rows as a stack whose rows the /// caller makes with `Row`. A member that fills (a leaf with `Sizing::FillWidth`, a fill-width `Row`) takes the room the view /// leaves. A row too long for the bar first narrows its selects and elidable text, the last first, down to their /// readable least (`TextRun::READABLE_CHARACTERS`), then scrolls, so a member past the edge is reached by Tab and From 8296832417a4dd323daa62150a2f1beabe2e7f50 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 16:02:09 +0000 Subject: [PATCH 02/10] A field takes its content width among a bar's members ContainerProps::content_in_bar keeps a container from the width in a bar; Field sets it, and an explicit sizing clears it. The Content sizing every bar set on its fields is gone. --- crates/draw/src/ui/crop/bar.rs | 8 ++++---- crates/draw/src/ui/crop/size_cells.rs | 6 +++--- crates/draw/src/ui/measure/bar.rs | 4 ++-- crates/draw/src/ui/paint_bar.rs | 9 +++------ crates/draw/src/ui/shape/bar.rs | 6 ++---- crates/imaging/src/ui/vanishing_point/bar.rs | 4 ++-- crates/text/src/ui/type_bar.rs | 5 ++--- crates/ui-contract/src/contract/body/size.rs | 4 +++- crates/ui-contract/src/contract/container.rs | 12 ++++++++++++ crates/ui-macros/src/component.rs | 1 + crates/ui-widgets/src/bars/constraint_fields.rs | 6 +++--- crates/ui-widgets/src/bars/status_readout.rs | 3 +-- crates/ui-widgets/src/bars/stories.rs | 13 ++++++------- crates/ui-widgets/src/form/field.rs | 9 +++++++-- 14 files changed, 51 insertions(+), 39 deletions(-) diff --git a/crates/draw/src/ui/crop/bar.rs b/crates/draw/src/ui/crop/bar.rs index 8ffb10527b..04b96d8a59 100644 --- a/crates/draw/src/ui/crop/bar.rs +++ b/crates/draw/src/ui/crop/bar.rs @@ -10,7 +10,7 @@ use craft_behavior::{EditEvent, EditEvents, IconId, NumberCodec}; use craft_ui::buttons::{Button, IconButton, ToggleButton}; use craft_ui::choice::Checkbox; use craft_ui::contract::{ - Bind, BodyCx, Entry, Gap, LabelKind, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked, + Bind, BodyCx, Entry, Gap, LabelKind, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, clicked, }; use craft_ui::display::Divider; use craft_ui::form::Field; @@ -179,7 +179,7 @@ impl<'a> CropBar<'a> { settings.clear(); report.ratio = Some(CropRatioChange { editing: false }); } - Field::new(words.angle.clone()).id_salt("angle").sizing(Sizing::Content).enabled(angle.is_some()).show(ui, |ui, _| { + Field::new(words.angle.clone()).id_salt("angle").enabled(angle.is_some()).show(ui, |ui, _| { let field = NumberField::new(words.angle.clone(), Bind::given(angle)).unit_kind(UnitKind::Degrees).range(-180.0..=180.0).show(ui); if let Some(turned) = field.value().copied().flatten() { report.angle = Some(turned); @@ -192,7 +192,7 @@ impl<'a> CropBar<'a> { Checkbox::new(Bind::bound(&mut settings.delete_pixels)).label(words.delete_pixels.clone()).show(ui); let background = if settings.delete_pixels { words.fill_background.clone() } else { words.fill_transparent.clone() }; let fills = [Entry::new(CropFill::Background, background), Entry::new(CropFill::ContentAware, words.fill_content_aware.clone())]; - Field::new(words.fill_name.clone()).id_salt("fill").sizing(Sizing::Content).show(ui, |ui, _| { + Field::new(words.fill_name.clone()).id_salt("fill").show(ui, |ui, _| { let pick = Select::new(words.fill_name.clone(), Bind::given(settings.fill), &fills).show(ui); if let Some(fill) = pick.value().copied() { settings.fill = fill; @@ -285,7 +285,7 @@ fn ratio_field( let current = shown.get(side).copied().unwrap_or(0.0); let salt = if side == 0 { "ratio-width" } else { "ratio-height" }; let mut events = EditEvents::new(); - Field::new(caption.clone()).side(SideLabel::new().kind(LabelKind::Hidden)).id_salt(salt).sizing(Sizing::Content).show(ui, |ui, _| { + Field::new(caption.clone()).side(SideLabel::new().kind(LabelKind::Hidden)).id_salt(salt).show(ui, |ui, _| { let codec = NumberCodec::new(units.reader(None), RATIO_DECIMALS); let field = NumberField::new(caption.clone(), Bind::given((current > 0.0).then_some(current))) .codec(codec) diff --git a/crates/draw/src/ui/crop/size_cells.rs b/crates/draw/src/ui/crop/size_cells.rs index c20e76e8d4..8a4d5f6cc8 100644 --- a/crates/draw/src/ui/crop/size_cells.rs +++ b/crates/draw/src/ui/crop/size_cells.rs @@ -4,7 +4,7 @@ use super::options::{CropLength, FIELD_MAX, LENGTH_MIN, ResolutionUnit, trim_num use super::{CropBarWords, CropDocument, CropSizeFields}; use craft_behavior::{IconId, NumberCodec}; use craft_ui::buttons::IconButton; -use craft_ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Sizing, clicked}; +use craft_ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, clicked}; use craft_ui::form::Field; use craft_ui::pickers::Select; use craft_ui::runtime::env::{LengthUnits, UnitKind, Units}; @@ -100,7 +100,7 @@ pub(super) fn show( let resolution = size.resolution.trim().replace(',', ".").parse::().ok().filter(|v| v.is_finite() && *v > 0.0); let mut typed = None; let mut alert = None; - Field::new(words.resolution.clone()).id_salt("size-resolution").sizing(Sizing::Content).show(ui, |ui, _| { + Field::new(words.resolution.clone()).id_salt("size-resolution").show(ui, |ui, _| { let codec = NumberCodec::new(units.reader(None), limits.resolution_decimals); let field = NumberField::new(words.resolution.clone(), Bind::given(resolution)).codec(codec).range(low..=high).automatic(true).show(ui); typed = field.value().copied(); @@ -155,7 +155,7 @@ fn length_field( let mut typed = None; let mut typed_unit = None; let mut alert = None; - Field::new(caption.clone()).id_salt(salt).sizing(Sizing::Content).show(ui, |ui, _| { + Field::new(caption.clone()).id_salt(salt).show(ui, |ui, _| { let lengths = LengthUnits::new(unit, unit, pixels_per_inch); let range = limits.length_range(unit, pixels_per_inch, points_per_inch); let field = NumberField::length(caption.clone(), Bind::given(value.map(|length| length.value)), lengths).range(range).show(ui); diff --git a/crates/draw/src/ui/measure/bar.rs b/crates/draw/src/ui/measure/bar.rs index 10da7ca524..8de160b61d 100644 --- a/crates/draw/src/ui/measure/bar.rs +++ b/crates/draw/src/ui/measure/bar.rs @@ -6,7 +6,7 @@ use super::words::RulerWords; use craft_ui::buttons::Button; use craft_ui::canvas::CanvasRulers; use craft_ui::choice::Checkbox; -use craft_ui::contract::{Bind, Gap, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, Sizing, clicked}; +use craft_ui::contract::{Bind, Gap, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, clicked}; use craft_ui::display::{Divider, Text}; use craft_ui::form::Field; use craft_ui::layout_components::Row; @@ -122,7 +122,7 @@ impl<'a> RulerBar<'a> { /// One readout: a caption above a tabular value, named `name` for AccessKit. fn readout(ui: &mut Ui, salt: &'static str, name: Label, value: String) { - Field::new(name).id_salt(salt).sizing(Sizing::Content).value(value.clone()).show(ui, |ui, _| { + Field::new(name).id_salt(salt).value(value.clone()).show(ui, |ui, _| { Text::new(value.clone()).role(TypeRole::Mono).show(ui); }); } diff --git a/crates/draw/src/ui/paint_bar.rs b/crates/draw/src/ui/paint_bar.rs index 8574dd7922..6610c84589 100644 --- a/crates/draw/src/ui/paint_bar.rs +++ b/crates/draw/src/ui/paint_bar.rs @@ -8,7 +8,7 @@ use craft_theme::Srgba; use craft_ui::buttons::IconButton; use craft_ui::choice::{Checkbox, Swatch}; use craft_ui::contract::{ - Bind, BodyCx, Entry, Gap, LabelKind, PopupKind, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Sizing, Trigger, clicked, + Bind, BodyCx, Entry, Gap, LabelKind, PopupKind, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Trigger, clicked, }; use craft_ui::display::Divider; use craft_ui::form::Field; @@ -355,7 +355,7 @@ impl Pass<'_, M> { // once in a pass and only the run that reads the input reports its events, so every run's events are collected. let collected: RefCell> = RefCell::new(EditEvents::new()); let _ = - Field::new(caption.clone()).side(SideLabel::new().kind(LabelKind::Hidden)).id_salt("size").sizing(Sizing::Content).enabled(enabled).show( + Field::new(caption.clone()).side(SideLabel::new().kind(LabelKind::Hidden)).id_salt("size").enabled(enabled).show( ui, |ui, _| { for event in BrushSizeField::new(caption.clone(), Bind::given(current), max).show(ui).edit.events.clone() { @@ -372,7 +372,7 @@ impl Pass<'_, M> { // The body may run more than once in a pass and only the run that reads the input reports its events, so every // run's events and alert are collected. let collected: RefCell<(EditEvents>, Option)> = RefCell::new((EditEvents::new(), None)); - let _ = Field::new(caption.clone()).side(SideLabel::new().scrub(true)).id_salt(salt).sizing(Sizing::Content).enabled(enabled).show( + let _ = Field::new(caption.clone()).side(SideLabel::new().scrub(true)).id_salt(salt).enabled(enabled).show( ui, |ui, _| { let field = NumberField::new(caption.clone(), Bind::given(Some(current * 100.0))) @@ -417,7 +417,6 @@ impl Pass<'_, M> { let current = self.values.mode.clone(); let pick = Field::new(caption.clone()) .id_salt("mode") - .sizing(Sizing::Content) .show(ui, |ui, _| Select::new(caption.clone(), Bind::given(current.clone()), entries).show(ui).value().cloned()) .inner .flatten(); @@ -437,7 +436,6 @@ impl Pass<'_, M> { let current = *mode; let pick = Field::new(words.mode.clone()) .id_salt("mode") - .sizing(Sizing::Content) .show(ui, |ui, _| Select::new(words.mode.clone(), Bind::given(current), &entries).show(ui).value().copied()) .inner .flatten(); @@ -499,7 +497,6 @@ impl Pass<'_, M> { let pick = Field::new(words.combination.clone()) .side(SideLabel::new().kind(LabelKind::Hidden)) .id_salt("mixer-combination") - .sizing(Sizing::Content) .show(ui, |ui, _| Select::new(words.combination.clone(), Bind::given(shown), &entries).show(ui).value().copied()) .inner .flatten(); diff --git a/crates/draw/src/ui/shape/bar.rs b/crates/draw/src/ui/shape/bar.rs index 28d3a66735..5c3f9ec285 100644 --- a/crates/draw/src/ui/shape/bar.rs +++ b/crates/draw/src/ui/shape/bar.rs @@ -7,7 +7,7 @@ use craft_behavior::EditEvent; use craft_color::ui::{PaintChip, PaintChipOutput, ScreenPickGesture}; use craft_theme::Srgba; use craft_ui::choice::Checkbox; -use craft_ui::contract::{Bind, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing}; +use craft_ui::contract::{Bind, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel}; use craft_ui::display::Divider; use craft_ui::form::Field; use craft_ui::layout_components::Row; @@ -125,13 +125,12 @@ impl<'a> ShapeBar<'a> { let fill = Field::new(words.fill_color.clone()) .id_salt("fill") .side(hidden) - .sizing(Sizing::Content) .show(ui, |ui, _| pass.chip(ui, ShapePaint::Fill)); if let Some(out) = fill.inner { pass.take_chip(ShapePaint::Fill, out); } let stroke = - Field::new(words.stroke.clone()).id_salt("stroke").sizing(Sizing::Content).show(ui, |ui, _| pass.chip(ui, ShapePaint::Stroke)); + Field::new(words.stroke.clone()).id_salt("stroke").show(ui, |ui, _| pass.chip(ui, ShapePaint::Stroke)); if let Some(out) = stroke.inner { pass.take_chip(ShapePaint::Stroke, out); } @@ -164,7 +163,6 @@ impl<'a> ShapeBar<'a> { let (events, alert) = Field::new(cell.caption.clone()) .id_salt(cell.key) .side(side) - .sizing(Sizing::Content) .show(ui, |ui, _| cell.show(ui)) .inner .unwrap_or_default(); diff --git a/crates/imaging/src/ui/vanishing_point/bar.rs b/crates/imaging/src/ui/vanishing_point/bar.rs index 2ea2ac63fa..bfeb18ed92 100644 --- a/crates/imaging/src/ui/vanishing_point/bar.rs +++ b/crates/imaging/src/ui/vanishing_point/bar.rs @@ -7,7 +7,7 @@ use egui::{Response, Ui}; use craft_behavior::EditEvents; use craft_ui::bars::{Bar, BarKind}; use craft_ui::choice::Checkbox; -use craft_ui::contract::{Bind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing}; +use craft_ui::contract::{Bind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel}; use craft_ui::display::Divider; use craft_ui::form::Field; use craft_ui::runtime::env::{Env, Label, UnitKind}; @@ -130,7 +130,7 @@ impl<'a> VanishingPointBar<'a> { /// One captioned number cell: the edit of `value`, if the user made one this pass. fn number(ui: &mut Ui, key: &'static str, caption: &Label, value: f64, range: RangeInclusive, kind: UnitKind) -> EditEvents { let mut edited = EditEvents::new(); - Field::new(caption.clone()).id_salt(key).side(SideLabel::new().scrub(true)).sizing(Sizing::Content).show(ui, |ui, _| { + Field::new(caption.clone()).id_salt(key).side(SideLabel::new().scrub(true)).show(ui, |ui, _| { let out = NumberField::new(caption.clone(), Bind::given(Some(value))).range(range.clone()).unit_kind(kind).scrub_by_label().show(ui); edited = out.edit.events.map(|v| v.unwrap_or(value)); }); diff --git a/crates/text/src/ui/type_bar.rs b/crates/text/src/ui/type_bar.rs index 7c3256ccf7..a8159fea4d 100644 --- a/crates/text/src/ui/type_bar.rs +++ b/crates/text/src/ui/type_bar.rs @@ -6,7 +6,7 @@ use craft_theme::Srgba; use craft_ui::buttons::{IconButton, ToggleButton}; use craft_ui::choice::Swatch; use craft_ui::contract::{ - Bind, Entry, FieldLayout, Gap, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked, + Bind, Entry, FieldLayout, Gap, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, clicked, }; use craft_ui::display::Divider; use craft_ui::form::Field; @@ -192,7 +192,7 @@ impl<'a> TypeBar<'a> { let (event, _) = lengths.row(ui, size); edits.extend(number_change(event, CharacterChange::Size).into_iter().map(|event| event.map(TypeBarChange::Character))); - let method = Field::new(option_words.anti_alias.clone()).side(hidden_side()).sizing(Sizing::Content).show(ui, |ui, _| { + let method = Field::new(option_words.anti_alias.clone()).side(hidden_side()).show(ui, |ui, _| { Select::new(option_words.anti_alias.clone(), Bind::given(mixed(anti_alias)), &method_entries).placeholder("—").show(ui).events }); edits.extend(method.inner.unwrap_or_default().map(TypeBarChange::AntiAlias)); @@ -207,7 +207,6 @@ impl<'a> TypeBar<'a> { let side = SideLabel::new().kind(LabelKind::Hidden).layout(FieldLayout::Beside); let well = Field::new(character_words.text_color.clone()) .side(side) - .sizing(Sizing::Content) .show(ui, |ui, _| Swatch::new(character_words.text_color.clone(), color).picker(COLOR_KEY).show(ui).pick_color); if let Some(request) = well.inner.flatten() { requests.request_color(request); diff --git a/crates/ui-contract/src/contract/body/size.rs b/crates/ui-contract/src/contract/body/size.rs index 155d84b24e..75d2fd0216 100644 --- a/crates/ui-contract/src/contract/body/size.rs +++ b/crates/ui-contract/src/contract/body/size.rs @@ -118,12 +118,14 @@ impl<'b> BodyHooks<'b> { /// The axes the container is given where `env` is its parent's: a rect it is shown at gives both; an inline /// container that fills an axis takes the room only where its parent was given that axis. /// + /// A container that fits its content in a bar (`ContainerProps::content_in_bar`) is not given the width there. /// A fill-width container whose body is a row, shown on the line of a row given its height, is given that height /// too: the line is a fixed cross extent, and the container fills it (a bar in a shell slot). pub(super) fn given_axes(&self, props: &ContainerProps, env: &Env, at: ShowAt) -> (bool, bool) { let sizing = self.sizing(props); let fills_line = sizing == Sizing::FillWidth && unwrapped_row(props) && env.row_line.is_some(); - let (x, y) = (sizing != Sizing::Content, sizing == Sizing::Fill || fills_line); + let fits_bar = props.content_in_bar && env.values.get::().0; + let (x, y) = (sizing != Sizing::Content && !fits_bar, sizing == Sizing::Fill || fills_line); match (at, &props.mount) { (ShowAt::Rect(_), _) => (true, true), (ShowAt::Flow, Mount::Inline) => (x && env.gives_width(), y && !env.content.1), diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 7209982a9f..32a5599747 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -674,6 +674,9 @@ pub struct ContainerProps { pub pad: Pad, /// How the size follows the content. pub sizing: Sizing, + /// Among the members of a bar (`InBar`) the container takes its content width, whatever `sizing` says: a field + /// fills the width of a form and fits its content in a bar. Setting `sizing` clears it. + pub content_in_bar: bool, /// The height the body offers its children in flow, in place of the flow's (unbounded in a scrolling body): the /// most a child takes. Every child takes its content height, a child that fills or scrolls at most this height, /// as a scrolling list is as tall as its rows until they outgrow the room. A host that shows content of either @@ -759,6 +762,7 @@ impl ContainerProps { && self.surface == other.surface && self.pad == other.pad && self.sizing == other.sizing + && self.content_in_bar == other.content_in_bar && self.room_height == other.room_height && self.layout == other.layout && self.header == other.header @@ -787,6 +791,7 @@ impl ContainerProps { surface: None, pad: Pad::None, sizing: Sizing::Content, + content_in_bar: false, room_height: None, layout: BodyLayout::Stack, header: None, @@ -841,6 +846,13 @@ impl ContainerProps { /// How the size follows the content. pub const fn sizing(mut self, sizing: Sizing) -> Self { self.sizing = sizing; + self.content_in_bar = false; + self + } + + /// Takes the content width among the members of a bar ([`content_in_bar`](Self::content_in_bar)). + pub const fn content_in_bar(mut self) -> Self { + self.content_in_bar = true; self } diff --git a/crates/ui-macros/src/component.rs b/crates/ui-macros/src/component.rs index eb317656d7..90e66c05ba 100644 --- a/crates/ui-macros/src/component.rs +++ b/crates/ui-macros/src/component.rs @@ -500,6 +500,7 @@ pub(crate) fn derive(input: TokenStream) -> syn::Result { quote! { fn set_sizing(&mut self, sizing: #k::contract::Sizing, _: #k::contract::Internal) { self.#field.sizing = sizing; + self.#field.content_in_bar = false; } } }); diff --git a/crates/ui-widgets/src/bars/constraint_fields.rs b/crates/ui-widgets/src/bars/constraint_fields.rs index 4162cec6e8..c8c1b00e49 100644 --- a/crates/ui-widgets/src/bars/constraint_fields.rs +++ b/crates/ui-widgets/src/bars/constraint_fields.rs @@ -3,7 +3,7 @@ use super::words::BarWords; use crate::buttons::IconButton; -use crate::contract::{Bind, Entry, Gap, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked}; +use crate::contract::{Bind, Entry, Gap, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, clicked}; use crate::form::Field; use crate::layout_components::Row; use crate::menu::Menu; @@ -150,7 +150,7 @@ impl<'a> ConstraintFields<'a> { Entry::new(StyleChoice::FixedRatio, words.constraint_fixed_ratio.clone()), Entry::new(StyleChoice::FixedSize, words.constraint_fixed_size.clone()), ]; - Field::new(words.constraint_style.clone()).id_salt("style").sizing(Sizing::Content).show(ui, |ui, _| { + Field::new(words.constraint_style.clone()).id_salt("style").show(ui, |ui, _| { let pick = Select::new(words.constraint_style.clone(), Bind::given(StyleChoice::of(before)), &styles).show(ui); if let Some(picked) = pick.value().copied() && picked != StyleChoice::of(before) @@ -259,7 +259,7 @@ impl Cells<'_> { low.min(high)..=low.max(high) }); let mut edited = None; - Field::new(cell.caption.clone()).id_salt(cell.key).enabled(cell.enabled).side(SideLabel::new().scrub(true)).sizing(Sizing::Content).show( + Field::new(cell.caption.clone()).id_salt(cell.key).enabled(cell.enabled).side(SideLabel::new().scrub(true)).show( ui, |ui, _| { let mut field = NumberField::new(cell.caption.clone(), Bind::given(Some(shown))).range(range.clone()).scrub_by_label(); diff --git a/crates/ui-widgets/src/bars/status_readout.rs b/crates/ui-widgets/src/bars/status_readout.rs index 73f3953ef4..cc986c9730 100644 --- a/crates/ui-widgets/src/bars/status_readout.rs +++ b/crates/ui-widgets/src/bars/status_readout.rs @@ -3,7 +3,7 @@ use super::words::BarWords; use crate::buttons::IconButton; -use crate::contract::{Bind, Entry, GlyphLabel, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing}; +use crate::contract::{Bind, Entry, GlyphLabel, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel}; use crate::display::{Elide, Text}; use crate::form::Field; use crate::layout_components::Row; @@ -213,7 +213,6 @@ impl<'a> StatusReadout<'a> { let glyph = SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::icon(IconId::new("zoom_in")))).scrub(true); let field = Field::new(words.readout_zoom.clone()) .side(glyph) - .sizing(Sizing::Content) .show(ui, |ui, _| ZoomField::new(words.readout_zoom.clone(), current, document).scrub(true).show(ui)); let field = field.inner.map(|zoom| { invalid_zoom = zoom.invalid_zoom; diff --git a/crates/ui-widgets/src/bars/stories.rs b/crates/ui-widgets/src/bars/stories.rs index 52491ba9b0..96be78c5ea 100644 --- a/crates/ui-widgets/src/bars/stories.rs +++ b/crates/ui-widgets/src/bars/stories.rs @@ -3,7 +3,7 @@ use super::{Bar, BarHome, BarItem, BarItems, BarKind, BarTool, ItemDisplay, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues}; use crate::buttons::Link; use crate::choice::{Checkbox, Segmented}; -use crate::contract::{Bind, Entry, Props as _, Sizing}; +use crate::contract::{Bind, Entry, Props as _}; use crate::contract::{Show as _, ShowContainer as _}; use crate::display::{Divider, Shade, Text}; use crate::form::Field; @@ -55,11 +55,10 @@ fn bar_options(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let shown = Bar::new("Brush options", BarKind::Options).commit_cancel("Commit transform", "Cancel transform").show(ui, |ui, _| { BarHome::new("Home", Bind::bound(&mut home)).show(ui); BarTool::new(IconId::new("brush"), "Brush").show(ui); - Field::new("Size").sizing(Sizing::Content).show(ui, |ui, _| NumberField::new("Size", Bind::bound(&mut size)).range(1.0..=5000.0).show(ui)); + Field::new("Size").show(ui, |ui, _| NumberField::new("Size", Bind::bound(&mut size)).range(1.0..=5000.0).show(ui)); Field::new("Opacity") - .sizing(Sizing::Content) .show(ui, |ui, _| NumberField::new("Opacity", Bind::bound(&mut opacity)).range(1.0..=100.0).show(ui)); - Field::new("Mode").sizing(Sizing::Content).show(ui, |ui, _| Select::new("Mode", Bind::bound(&mut mode), &modes).show(ui)); + Field::new("Mode").show(ui, |ui, _| Select::new("Mode", Bind::bound(&mut mode), &modes).show(ui)); Divider::vertical().show(ui); Checkbox::new(Bind::bound(&mut sample_all)).label("Sample All Layers").show(ui); Text::new("Samples the visible image").shade(Shade::Faint).show(ui); @@ -78,11 +77,11 @@ fn bar_captioned(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { let modes = [Entry::new(0u8, "Light"), Entry::new(1, "Dark"), Entry::new(2, "System")]; Bar::new("Appearance", BarKind::Options) .trailing(|ui, _| { - Field::new("Workspace").sizing(Sizing::Content).show(ui, |ui, _| Segmented::new("Workspace", Bind::given(0u8), &modes).show(ui)); + Field::new("Workspace").show(ui, |ui, _| Segmented::new("Workspace", Bind::given(0u8), &modes).show(ui)); }) .show(ui, |ui, _| { - Field::new("Theme").sizing(Sizing::Content).show(ui, |ui, _| Select::new("Theme", Bind::given(0u8), &themes).show(ui)); - Field::new("Mode").sizing(Sizing::Content).show(ui, |ui, _| Segmented::new("Mode", Bind::given(1u8), &modes).show(ui)); + Field::new("Theme").show(ui, |ui, _| Select::new("Theme", Bind::given(0u8), &themes).show(ui)); + Field::new("Mode").show(ui, |ui, _| Segmented::new("Mode", Bind::given(1u8), &modes).show(ui)); }) .into() } diff --git a/crates/ui-widgets/src/form/field.rs b/crates/ui-widgets/src/form/field.rs index cb6a0fa6d3..5f634c2fd7 100644 --- a/crates/ui-widgets/src/form/field.rs +++ b/crates/ui-widgets/src/form/field.rs @@ -52,9 +52,14 @@ pub struct Field { } impl Field { - /// A field labelled `label`, beside its control, filling the width offered. + /// A field labelled `label`, beside its control, filling the width offered; among the members of a bar it takes + /// its content width. `sizing` overrides both. pub fn new(label: impl Into