diff --git a/crates/draw/src/ui/crop/bar.rs b/crates/draw/src/ui/crop/bar.rs index 8ffb10527..04b96d8a5 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 c20e76e8d..8a4d5f6cc 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 10da7ca52..8de160b61 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 8574dd792..6610c8458 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 28d3a6673..5c3f9ec28 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 2ea2ac63f..bfeb18ed9 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 7c3256ccf..a8159fea4 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 155d84b24..75d2fd021 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 7209982a9..32a559974 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 eb317656d..90e66c05b 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 4162cec6e..c8c1b00e4 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 73f3953ef..cc986c973 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 52491ba9b..96be78c5e 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 cb6a0fa6d..5f634c2fd 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