diff --git a/crates/automation/src/ui/actions/body.rs b/crates/automation/src/ui/actions/body.rs index 94706b358..b0618d003 100644 --- a/crates/automation/src/ui/actions/body.rs +++ b/crates/automation/src/ui/actions/body.rs @@ -6,7 +6,7 @@ use craft_theme::variant::Tone; use craft_ui::buttons::Button; use craft_ui::contract::{ Bind, CollectionEvent, ColumnKey, ColumnKind, ColumnSpec, ListDrag, OpenChange, Outcome as _, Pad, Props as _, ReorderMove, ReorderRule, Scroll, - SelectMode, Show as _, ShowCollection as _, ShowContainer as _, SpaceAction, ToggleColumn, ToggleEdit, request_rename, + SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing, SpaceAction, ToggleColumn, ToggleEdit, request_rename, }; use craft_ui::display::Text; use craft_ui::layout_components::{Row, Stack}; @@ -119,7 +119,7 @@ fn show_buttons(ui: &mut Ui, body: &Body<'_>) -> BodyOutput { } for &index in actions { let Some(action) = list.action(index) else { continue }; - let mut button = Button::new(action.name.clone()).fill_width(true).align(HAlign::Start); + let mut button = Button::new(action.name.clone()).sizing(Sizing::FillWidth).align(HAlign::Start); if let Some(color) = action.color.label_color() { button = button.tint(color.fill()); } diff --git a/crates/browse/src/ui/bin/mod.rs b/crates/browse/src/ui/bin/mod.rs index c427dc0e6..2e775e243 100644 --- a/crates/browse/src/ui/bin/mod.rs +++ b/crates/browse/src/ui/bin/mod.rs @@ -697,7 +697,7 @@ where TextField::search(words.search.clone(), Bind::bound(&mut local.search)) .placeholder(words.search.clone()) .drives(list_id) - .fill_width(true) + .sizing(Sizing::FillWidth) .show(ui); if local.search != typed { events.push(BinEvent::Search(local.search.clone())); diff --git a/crates/color/src/ui/picker/full.rs b/crates/color/src/ui/picker/full.rs index a95a9a3e7..10e6a7c28 100644 --- a/crates/color/src/ui/picker/full.rs +++ b/crates/color/src/ui/picker/full.rs @@ -5,7 +5,7 @@ use craft_theme::{ColorModel, HsbModel, OklchModel, RgbModel, Srgba}; use craft_ui::choice::{Checkbox, Radio, RadioGroup, Swatch}; use craft_ui::contract::{ Bind, Common, Component, Cx, GlyphLabel, LabelKind, LabelScheme, MeasureCx, Outcome, PaintUi, Props as _, Role, Show as _, ShowContainer as _, - SideLabel, + SideLabel, Sizing, }; use craft_ui::display::{Icon, Shade, Text}; use craft_ui::form::{Field, FieldGroup}; @@ -204,9 +204,9 @@ impl<'a> Body<'a> { let caption = |text: &str| Text::new(text.to_owned()).role(TypeRole::Caption).shade(Shade::Muted); Stack::new().show(ui, |ui, _| { caption(words.new_caption.as_str()).show(ui); - Swatch::new(words.new_color.as_str().to_owned(), pass.shows(pass.shown.color)).fill().show(ui); + Swatch::new(words.new_color.as_str().to_owned(), pass.shows(pass.shown.color)).sizing(Sizing::FillWidth).show(ui); let restore = words.restore.as_str().to_owned(); - if Swatch::new(restore.clone(), current).tooltip(restore).fill().show(ui).clicked + if Swatch::new(restore.clone(), current).tooltip(restore).sizing(Sizing::FillWidth).show(ui).clicked && let Mixed::Same(current) = current { got.clicks.push(current); diff --git a/crates/dialogs/src/ui/file_list.rs b/crates/dialogs/src/ui/file_list.rs index 8d767a371..e4a50ee5e 100644 --- a/crates/dialogs/src/ui/file_list.rs +++ b/crates/dialogs/src/ui/file_list.rs @@ -6,7 +6,7 @@ use craft_host::{PickId, PickKind, PickRequest}; use craft_ui::buttons::Button; use craft_ui::contract::{ Bind, BodyCx, CollectionEvent, Entry, Held, NoValue, Outcome, Pad, Props as _, Remember as _, ReorderRule, SelectMode, Show as _, - ShowCollection as _, ShowContainer as _, clicked, + ShowCollection as _, ShowContainer as _, Sizing, clicked, }; use craft_ui::display::{Shade, Text}; use craft_ui::form::Field; @@ -205,7 +205,7 @@ impl<'a> FileListPicker<'a> { let (mut browse, mut remove, mut add_open, mut sort) = (false, false, false, false); Stack::new().show(ui, |ui, _| { let button = |ui: &mut Ui, label: &Label, key: &'static str, enabled: bool| { - clicked(&Button::new(label.clone()).enabled(enabled).fill_width(true).id_salt(key).show(ui)) + clicked(&Button::new(label.clone()).enabled(enabled).sizing(Sizing::FillWidth).id_salt(key).show(ui)) }; browse = button(ui, &words.browse, "browse", true); remove = button(ui, &words.remove, "remove", !folder && now.selected.is_some()); diff --git a/crates/draw/src/ui/gradient/swatch.rs b/crates/draw/src/ui/gradient/swatch.rs index 8e36beb93..5ee072488 100644 --- a/crates/draw/src/ui/gradient/swatch.rs +++ b/crates/draw/src/ui/gradient/swatch.rs @@ -1,8 +1,10 @@ //! [`GradientSwatch`]: a well that shows a gradient. -use craft_behavior::{Axis, CursorIcon, CursorPriority, Metrics, Sense}; +use craft_behavior::{CursorIcon, CursorPriority, Metrics, Sense}; use craft_ui::choice::SwatchMetrics; -use craft_ui::contract::{Access, Common, Component, Cx, DisabledLook, MeasureCx, Outcome, PaintUi, Pointer as _, PopupKind, Props as _, Role}; +use craft_ui::contract::{ + Access, Common, Component, Cx, DisabledLook, MeasureCx, Outcome, PaintUi, Pointer as _, PopupKind, Props as _, Role, Sizing, +}; use craft_ui::style::{ComponentStyle, FocusLook, StyleColor, StyleCx}; use egui::{CornerRadius, Response, Vec2}; @@ -52,9 +54,9 @@ impl Outcome for GradientSwatchOutput { /// /// The ramp is drawn over the checkerboard where it is translucent, inside the swatch's ring. The /// swatch edits nothing; a click is the host's cue. The well has the gradient chip aspect -/// (`GradientRamp::CHIP_ASPECT`); `fill` takes the wider width the layout offers (an options bar -/// cell). AccessKit sees a button named by the label, with `has_popup` when the host opens a -/// dialog on the click. +/// (`GradientRamp::CHIP_ASPECT`); with `Sizing::FillWidth` it takes the wider width the layout +/// offers (an options bar cell). AccessKit sees a button named by the label, with `has_popup` +/// when the host opens a dialog on the click. #[derive(craft_ui::contract::Component, craft_ui::contract::Props)] #[component(content_painter)] pub struct GradientSwatch<'a> { @@ -67,9 +69,6 @@ pub struct GradientSwatch<'a> { /// Samples the gradient instead of [`default_sampler`]. #[prop] sampler: Option<&'a Sampler>, - /// Takes the width the layout offers, at the control height. - #[prop(flag)] - fill: bool, /// Tells AccessKit that a click opens a dialog. #[prop(flag)] has_popup: bool, @@ -79,8 +78,7 @@ pub struct GradientSwatch<'a> { impl<'a> GradientSwatch<'a> { /// A swatch of `stops`; `label` names it for a screen reader. pub fn new(label: impl Into, stops: &'a GradientStops) -> Self { - GradientSwatch { common: Common::new(), stops, rows: StopRows::Split, sampler: None, fill: false, has_popup: false, clicked: false } - .label(label) + GradientSwatch { common: Common::new(), stops, rows: StopRows::Split, sampler: None, has_popup: false, clicked: false }.label(label) } } @@ -101,14 +99,14 @@ impl Component for GradientSwatch<'_> { let height = cx.style.side; let (wide, high) = GradientRamp::CHIP_ASPECT; let chip = height * f32::from(wide) / f32::from(high); - let width = if self.fill { cx.room.filter(|room| room.is_finite()).map_or(chip, |room| room.max(chip)) } else { chip }; + let width = if cx.resolved.sizing() == Some(Sizing::FillWidth) { + cx.room.filter(|room| room.is_finite()).map_or(chip, |room| room.max(chip)) + } else { + chip + }; Vec2::new(width, height) } - fn fills(&self) -> Option { - self.fill.then_some(Axis::X) - } - fn sense(&self) -> Sense { Sense::CLICK | Sense::FOCUS } diff --git a/crates/draw/src/ui/gradient/swatch/stories.rs b/crates/draw/src/ui/gradient/swatch/stories.rs index aa98715df..7b0409693 100644 --- a/crates/draw/src/ui/gradient/swatch/stories.rs +++ b/crates/draw/src/ui/gradient/swatch/stories.rs @@ -3,7 +3,7 @@ use super::GradientSwatch; use crate::ui::gradient::{ColorStop, GradientStops, OpacityStop, StopRows}; use craft_theme::Srgba; -use craft_ui::contract::{Props as _, Show as _, ShowContainer as _}; +use craft_ui::contract::{Props as _, Show as _, ShowContainer as _, Sizing}; use craft_ui::display::{Shade, Text}; use craft_ui::layout_components::{Row, Stack}; use craft_ui::runtime::env::Env; @@ -50,7 +50,7 @@ fn gradient_swatch(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { clicked |= GradientSwatch::new(name, stops).rows(rows).has_popup().show(ui).clicked; Text::new(name).shade(Shade::Muted).show(ui); }); - clicked |= GradientSwatch::new(name, stops).rows(rows).fill().show(ui).clicked; + clicked |= GradientSwatch::new(name, stops).rows(rows).sizing(Sizing::FillWidth).show(ui).clicked; } }); if clicked { diff --git a/crates/layers/src/ui/rows/mod.rs b/crates/layers/src/ui/rows/mod.rs index 4d2eb6806..fbcce712d 100644 --- a/crates/layers/src/ui/rows/mod.rs +++ b/crates/layers/src/ui/rows/mod.rs @@ -134,11 +134,13 @@ impl<'a> BlendRows<'a> { let mut events = Vec::new(); let block = Stack::new().fill_width().show(ui, |ui, _| { // Opacity ends the blend row and Fill ends the lock row, as in Photoshop, so the two fields share one - // column. A section gap keeps each caption with its field rather than with the group before it. - Row::new().fill_width().align(RowAlign::SpaceBetween).gap(Gap::Section).show(ui, |ui, _| { + // column; the blend select takes the room before Opacity. A section gap keeps each caption with its field + // rather than with the group before it. + Row::new().fill_width().gap(Gap::Section).show(ui, |ui, _| { let blend_name = words.blend_mode.clone(); let picked = Select::new(blend_name.clone(), Bind::given(props.blend_key.clone()), blend_modes) .preview() + .sizing(Sizing::FillWidth) .enabled(editable) .tooltip(TooltipSpec::new(blend_name).disabled_text(unavailable.clone())) .show(ui); diff --git a/crates/text/src/ui/character.rs b/crates/text/src/ui/character.rs index 762dc77e5..e5c592fa6 100644 --- a/crates/text/src/ui/character.rs +++ b/crates/text/src/ui/character.rs @@ -19,7 +19,7 @@ use craft_theme::{Rgba, Srgba}; use craft_ui::choice::Swatch; #[cfg(feature = "font-picker")] use craft_ui::contract::Bind; -use craft_ui::contract::{Entry, GlyphLabel, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel}; +use craft_ui::contract::{Entry, GlyphLabel, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing}; use craft_ui::form::Field; use craft_ui::layout_components::{Grid, Stack}; use craft_ui::patterns::form_dialogs::HostRequests; @@ -563,7 +563,7 @@ impl<'a> CharacterControls<'a> { let side = SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::text(words.color.clone()))); let well = Field::new(words.text_color.clone()) .side(side) - .show(ui, |ui, _| Swatch::new(words.text_color.clone(), color).picker(COLOR_KEY).fill().show(ui).pick_color); + .show(ui, |ui, _| Swatch::new(words.text_color.clone(), color).picker(COLOR_KEY).sizing(Sizing::FillWidth).show(ui).pick_color); if let Some(request) = well.inner.flatten() { requests.request_color(request); } diff --git a/crates/timeline/src/ui/transport.rs b/crates/timeline/src/ui/transport.rs index 16ce5b04f..7710931ca 100644 --- a/crates/timeline/src/ui/transport.rs +++ b/crates/timeline/src/ui/transport.rs @@ -7,7 +7,7 @@ use craft_behavior::{EditEvents, IconId}; use craft_ui::bars::{Bar, BarKind}; use craft_ui::buttons::{Button, IconButton, ToggleButton}; use craft_ui::choice::Checkbox; -use craft_ui::contract::{Bind, BodyCx, Held, NoValue, Outcome, Pattern, PopupKind, Props, Show as _, ShowContainer as _, clicked}; +use craft_ui::contract::{Bind, BodyCx, Held, NoValue, Outcome, Pattern, PopupKind, Props, Show as _, ShowContainer as _, Sizing, clicked}; use craft_ui::display::{Divider, Text}; use craft_ui::layout::RowAlign; use craft_ui::popover::Popover; @@ -375,7 +375,8 @@ impl MediaControls { nudge = Some(NUDGE); } let range = if playable { 0.0..=duration } else { 0.0..=1.0 }; - let mut slider = Slider::new(Bind::given(position), range).step(NUDGE).fill_width(true).enabled(playable).label(words.seek.clone()); + let mut slider = + Slider::new(Bind::given(position), range).step(NUDGE).sizing(Sizing::FillWidth).enabled(playable).label(words.seek.clone()); if let Some((start, end)) = trim.filter(|_| playable) { slider = slider.trim(start, end); } diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 462f41d75..1144b4883 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -390,9 +390,10 @@ pub trait Component: Meta + Sized { } /// The axis along which the component takes all the room the flow offers when that is more than it measured, - /// as a container with `Sizing::Fill` does: a vertical rule fills its row's height. + /// as a container with `Sizing::Fill` does: the width when its caller set `Sizing::FillWidth` (a search field + /// before a count). A component that fills by what it is overrides it: a vertical rule fills its row's height. fn fills(&self) -> Option { - None + (self.common(Internal::new()).sizing == Some(Sizing::FillWidth)).then_some(craft_behavior::Axis::X) } /// Whether the content is made to be cut where it does not fit: an elided line or a path. In a row too short for diff --git a/crates/ui-contract/src/contract/props.rs b/crates/ui-contract/src/contract/props.rs index cb6fb5187..b5345dae0 100644 --- a/crates/ui-contract/src/contract/props.rs +++ b/crates/ui-contract/src/contract/props.rs @@ -113,8 +113,8 @@ pub trait Props: Meta + Sized { /// How the component takes its size. A container or collection takes it over its own default (`ContainerProps`). /// A leaf with `Sizing::Content` is as wide as its content, without the ideal width its style asks for where the - /// room allows (a field's `size.length.field`); a leaf otherwise keeps that width, and fills only along the axis - /// its `Component::fills` names. + /// room allows (a field's `size.length.field`); a leaf otherwise keeps that width, and with `Sizing::FillWidth` it + /// takes the room its row leaves after the other members, or the width its column offers (`Component::fills`). fn sizing(mut self, sizing: Sizing) -> Self { self.set_sizing(sizing, Internal::new()); self diff --git a/crates/ui-contract/src/contract/run/typed.rs b/crates/ui-contract/src/contract/run/typed.rs index 3b5983fbe..c9038eb39 100644 --- a/crates/ui-contract/src/contract/run/typed.rs +++ b/crates/ui-contract/src/contract/run/typed.rs @@ -81,7 +81,10 @@ impl Erased for Typed<'_, '_, C> { } fn take_common(&mut self) -> Common { - std::mem::take(self.comp.get().common_mut(Internal::new())) + let common = std::mem::take(self.comp.get().common_mut(Internal::new())); + // The sizing stays with the component: the layout hooks after step 1 read it through `Component::fills`. + self.comp.get().common_mut(Internal::new()).sizing = common.sizing; + common } fn variants(&self, asked: Option) -> (Variant, Variant) { diff --git a/crates/ui-contract/tests/it/layout/fill.rs b/crates/ui-contract/tests/it/layout/fill.rs new file mode 100644 index 000000000..2ce493d44 --- /dev/null +++ b/crates/ui-contract/tests/it/layout/fill.rs @@ -0,0 +1,33 @@ +//! A leaf's `Sizing::FillWidth`: the leaf takes the room its row leaves after the other members. + +use craft_ui::contract::{Props as _, Show as _, ShowContainer as _, Sizing}; +use craft_ui::layout::BodyLayout; +use craft_ui::testing::{Frames, trial}; +use craft_ui_test_kit::contract::{Panel, Probe, Seen}; +use egui::Rect; +use std::cell::{Cell, RefCell}; + +/// The region, the first probe's rect and the second's, in a full-width row whose first member has `sizing`. +fn row(sizing: Sizing) -> (Rect, Rect, Rect) { + let (first, second) = (RefCell::new(Seen::default()), RefCell::new(Seen::default())); + let region = Cell::new(Rect::NOTHING); + let mut frames = Frames::new(); + frames.idle(5, |ui| { + region.set(ui.available_rect_before_wrap()); + Panel::new().layout(BodyLayout::row()).sizing(Sizing::FillWidth).id_salt("row").show(ui, |ui, _| { + Probe::new(&first).sizing(sizing).id_salt("first").show(ui); + Probe::new(&second).id_salt("second").show(ui); + }); + }); + (region.get(), first.into_inner().rect, second.into_inner().rect) +} + +#[trial] +fn a_fill_width_leaf_takes_the_room_its_row_leaves_and_a_content_leaf_does_not() { + let (region, content, after_content) = row(Sizing::Content); + let (_, fill, after_fill) = row(Sizing::FillWidth); + assert!(after_content.max.x < region.center().x, "a content-sized leaf leaves the row's room empty: {after_content:?} in {region:?}"); + assert!(fill.width() > content.width() * 2.0, "the fill-width leaf takes the room: {fill:?} against {content:?}"); + assert!((after_fill.width() - after_content.width()).abs() < 1.0, "the member after it keeps its size"); + assert!(after_fill.min.x >= fill.max.x && after_fill.min.x > region.center().x, "the next member follows it at the row's end: {after_fill:?}"); +} diff --git a/crates/ui-contract/tests/it/layout/mod.rs b/crates/ui-contract/tests/it/layout/mod.rs index 0d8177296..a1d7e28e2 100644 --- a/crates/ui-contract/tests/it/layout/mod.rs +++ b/crates/ui-contract/tests/it/layout/mod.rs @@ -1,2 +1,3 @@ mod body; +mod fill; mod memory; diff --git a/crates/ui-panels/src/sections/footer.rs b/crates/ui-panels/src/sections/footer.rs index bb1526dd5..82939f022 100644 --- a/crates/ui-panels/src/sections/footer.rs +++ b/crates/ui-panels/src/sections/footer.rs @@ -628,12 +628,11 @@ impl FooterBar { DialogRole::Destructive => Variant::DANGER, DialogRole::Cancel | DialogRole::Other => Variant::SECONDARY, }; - let mut widget = Button::new(button.label.clone()) - .painted(labels[at].clone()) - .variant(variant) - .enabled(button.enabled) - .fill_width(column) - .least_width(least); + let mut widget = + Button::new(button.label.clone()).painted(labels[at].clone()).variant(variant).enabled(button.enabled).least_width(least); + if column { + widget = widget.sizing(Sizing::FillWidth); + } let tip = if button.enabled { button.tooltip.clone() } else { button.disabled_reason.clone().or_else(|| button.tooltip.clone()) }; if let Some(tip) = tip { widget = widget.tooltip(TooltipSpec::new(tip.clone()).disabled_text(tip)); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs b/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs index 8573059d5..fc5f6be20 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs @@ -4,7 +4,7 @@ mod stories; use crate::buttons::Button; -use crate::contract::{Bind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, clicked}; +use crate::contract::{Bind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, Sizing, clicked}; use crate::layout_components::Row; use crate::runtime::env::{Env, Label}; use crate::text::TextField; @@ -68,7 +68,7 @@ impl<'a> PathRow<'a> { let mut edit = EditEvents::new(); let mut browse = false; let shown = Row::new().show(ui, |ui, _| { - let mut field = TextField::new(name.clone(), value.reborrowed()).fill_width(true).id_salt("path"); + let mut field = TextField::new(name.clone(), value.reborrowed()).sizing(Sizing::FillWidth).id_salt("path"); if let Some(placeholder) = placeholder.clone() { field = field.placeholder(placeholder); } diff --git a/crates/ui-test-kit/src/contract.rs b/crates/ui-test-kit/src/contract.rs index e4567dc54..d90cb3609 100644 --- a/crates/ui-test-kit/src/contract.rs +++ b/crates/ui-test-kit/src/contract.rs @@ -4,6 +4,7 @@ use craft_behavior::{Intent, ItemSource, Metrics, PartRef, PressPhase, Selection use craft_ui::contract::{ Collection, CollectionProps, Common, Component, Container, ContainerProps, Cx, Focus as _, MeasureCx, Pointer as _, Props as _, Role, }; +use craft_ui::layout::BodyLayout; use craft_ui::runtime::commands::FireSource; use craft_ui::style::{ComponentStyle, StyleCx}; use egui::{Id, Rect, Response, Vec2}; @@ -150,6 +151,12 @@ impl<'a> Panel<'a> { self } + /// How the panel lays out its body. + pub fn layout(mut self, layout: BodyLayout) -> Self { + self.props = self.props.layout(layout); + self + } + /// Whether the panel's body is an arena. pub fn arena(mut self, on: bool) -> Self { self.props = self.props.arena(on); diff --git a/crates/ui-widgets/src/bars/bar.rs b/crates/ui-widgets/src/bars/bar.rs index 4bb623507..efd200eff 100644 --- a/crates/ui-widgets/src/bars/bar.rs +++ b/crates/ui-widgets/src/bars/bar.rs @@ -78,7 +78,7 @@ impl Outcome for BarOutput { /// 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 -/// caller makes with `Row`. A member that fills (a `Slider::fill_width`, a fill-width `Row`) takes the room the view +/// 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, then scrolls, so a /// member past the edge is reached by Tab and revealed. A member the view shows only in part (a control, or a captioned /// field with its caption) is not shown until a scroll brings it in whole. Under right-to-left the bar is the mirror of diff --git a/crates/ui-widgets/src/buttons/button.rs b/crates/ui-widgets/src/buttons/button.rs index eadc63458..e4ea9fdcd 100644 --- a/crates/ui-widgets/src/buttons/button.rs +++ b/crates/ui-widgets/src/buttons/button.rs @@ -144,10 +144,6 @@ pub struct Button<'a> { #[style_key] #[prop] tint: Option, - /// Takes the width its column offers; in a column sized from its content, the width of the widest member, so a - /// column of buttons shares one width. - #[prop] - fill_width: bool, /// The least width, from a size role (a dialog's footer buttons); a longer label is wider. #[style_key] #[prop] @@ -168,7 +164,6 @@ impl<'a> Button<'a> { loading: false, painted: None, tint: None, - fill_width: false, least_width: None, align: HAlign::Center, } @@ -215,10 +210,6 @@ impl Component for Button<'_> { face::measure(cx, &self.spec(cx.resolved.label)) } - fn fills(&self) -> Option { - self.fill_width.then_some(craft_behavior::Axis::X) - } - fn sense(&self) -> Sense { if self.loading { Sense::FOCUS } else { Sense::CLICK | Sense::FOCUS } } diff --git a/crates/ui-widgets/src/choice/swatch.rs b/crates/ui-widgets/src/choice/swatch.rs index b784fbaad..f65ad8def 100644 --- a/crates/ui-widgets/src/choice/swatch.rs +++ b/crates/ui-widgets/src/choice/swatch.rs @@ -5,7 +5,7 @@ use super::radio::RadioKind; use super::words::ChoiceWords; use crate::contract::{ Access, Activation, Common, Component, Cx, DisabledLook, GroupHandle, MeasureCx, Meta as _, Outcome, PaintUi, Pointer as _, Props as _, Role, - Styled as _, WordSetCx as _, + Sizing, Styled as _, WordSetCx as _, }; use crate::primitives::{ContentPainterCx, Draw, PaintShape, StrokeWidth}; use crate::runtime::requests::ColorRequest; @@ -140,9 +140,6 @@ pub struct Swatch { #[style_key] #[prop(flag)] well: bool, - /// Takes the width the layout offers, at the control height. - #[prop(flag)] - fill: bool, /// A thin edge in the text colour just inside the outline. #[prop(flag)] marked: bool, @@ -162,7 +159,6 @@ impl Swatch<()> { member: None, cell: false, well: false, - fill: false, marked: false, picker: None, checked: false, @@ -181,7 +177,6 @@ impl Swatch { member: Some(value), cell: self.cell, well: self.well, - fill: self.fill, marked: self.marked, picker: self.picker, checked: false, @@ -220,14 +215,14 @@ impl Component for Swatch { fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { let side = cx.style.side; - let width = if self.fill { cx.room.filter(|room| room.is_finite()).map_or(side, |room| room.max(side)) } else { side }; + let width = if cx.resolved.sizing() == Some(Sizing::FillWidth) { + cx.room.filter(|room| room.is_finite()).map_or(side, |room| room.max(side)) + } else { + side + }; Vec2::new(width, side) } - fn fills(&self) -> Option { - self.fill.then_some(craft_behavior::Axis::X) - } - fn sense(&self) -> Sense { Sense::CLICK | Sense::FOCUS } diff --git a/crates/ui-widgets/src/layout_components/mod.rs b/crates/ui-widgets/src/layout_components/mod.rs index f1568bb3c..fafe663e6 100644 --- a/crates/ui-widgets/src/layout_components/mod.rs +++ b/crates/ui-widgets/src/layout_components/mod.rs @@ -226,7 +226,7 @@ impl<'a> Stack<'a> { } /// The footer stands in a column at the end edge, beside the body and at its top, as wide as its widest child; - /// a child that fills the width (`Button::fill_width`) takes that width. Set it after [`footer`](Stack::footer). + /// a child that fills the width (a button with `Sizing::FillWidth`) takes that width. Set it after [`footer`](Stack::footer). #[must_use] pub fn footer_beside(mut self) -> Self { self.props.end = Some(EndRegion::new()); diff --git a/crates/ui-widgets/src/text/text_field.rs b/crates/ui-widgets/src/text/text_field.rs index ccdf788fa..5f9027a09 100644 --- a/crates/ui-widgets/src/text/text_field.rs +++ b/crates/ui-widgets/src/text/text_field.rs @@ -45,10 +45,6 @@ pub struct TextField<'a, C: Codec + Clone + 'static = PlainText> { /// the id the collection is built with (`Props::id`), so a pattern can name a collection it shows after the field. #[prop] drives: Option, - /// Takes the room its row leaves after the other members, instead of its ideal width: a search field before a - /// count. - #[prop] - fill_width: bool, } impl<'a> TextField<'a, PlainText> { @@ -82,7 +78,6 @@ impl<'a, C: Codec + Clone + 'static> TextField<'a, C> { leading: Vec::new(), arrow: false, drives: None, - fill_width: false, } .label(label) } @@ -242,10 +237,6 @@ impl Component for TextField<'_, C> { Sense::CLICK | Sense::FOCUS | Sense::TAKE_FOCUS } - fn fills(&self) -> Option { - self.fill_width.then_some(craft_behavior::Axis::X) - } - /// The text, and the room the adornments take; a search field keeps the room of its clear button while the text is /// empty, so the field does not change width as the button comes and goes. fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { diff --git a/crates/ui-widgets/src/value_drag/slider.rs b/crates/ui-widgets/src/value_drag/slider.rs index 794a0f2e2..e65a3b11a 100644 --- a/crates/ui-widgets/src/value_drag/slider.rs +++ b/crates/ui-widgets/src/value_drag/slider.rs @@ -94,9 +94,6 @@ pub struct Slider<'a> { track_face: Option>, /// The kept part of the range, its ends drawn across the track ([`Slider::trim`]). trim: Option<(f64, f64)>, - /// Takes the width its row offers past its length: a seek track along the rest of a bar. - #[prop] - fill_width: bool, } /// The shape of a slider's thumb. @@ -129,7 +126,6 @@ impl<'a> Slider<'a> { value_text: None, track_face: None, trim: None, - fill_width: false, } } @@ -196,10 +192,6 @@ impl Component for Slider<'_> { } } - fn fills(&self) -> Option { - self.fill_width.then_some(craft_behavior::Axis::X) - } - fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { self.marks.lay_out(&cx.style.mark_text, cx.style.space, |label| cx.env.resolve(label), |run| cx.layout(run).size()); let along = if cx.proposal == Proposal::Min { 0.0 } else { cx.style.length }; diff --git a/crates/ui-widgets/tests/it/bars/overflow.rs b/crates/ui-widgets/tests/it/bars/overflow.rs index a0614dbaa..7e4fee409 100644 --- a/crates/ui-widgets/tests/it/bars/overflow.rs +++ b/crates/ui-widgets/tests/it/bars/overflow.rs @@ -8,7 +8,7 @@ use craft_i18n::Direction; use craft_theme::ControlSize; use craft_ui::bars::{Bar, BarItem, BarItems, BarKind, ConstraintFields, ItemDisplay}; use craft_ui::buttons::{Button, IconButton}; -use craft_ui::contract::{Bind, Entry, Lazy, Props as _, Show as _, ShowContainer as _}; +use craft_ui::contract::{Bind, Entry, Lazy, Props as _, Show as _, ShowContainer as _, Sizing}; use craft_ui::display::{Divider, Text}; use craft_ui::form::Field; use craft_ui::pickers::Select; @@ -90,7 +90,7 @@ fn filled(width: f32) -> (Rect, Rect) { let (mut slider, mut readout) = (Rect::NOTHING, Rect::NOTHING); Bar::new("Media", BarKind::Tool).show(ui, |ui, _| { IconButton::new(IconId::new("play")).label("Play").show(ui); - slider = Slider::new(Bind::given(2.0), 0.0..=10.0).fill_width(true).label("Seek").show(ui).response.rect; + slider = Slider::new(Bind::given(2.0), 0.0..=10.0).sizing(Sizing::FillWidth).label("Seek").show(ui).response.rect; readout = Text::new("0:12.50").show(ui).rect; }); out.set((slider, readout));