Sizing::FillWidth makes a leaf fill its row's leftover room

Component::fills defaults to the width when the caller set Sizing::FillWidth,
and the sizing stays on the component after step 1 so the layout hooks read
it. Button, TextField and Slider lose their fill_width props and Swatch and
GradientSwatch their fill flags; callers set Sizing::FillWidth. The blend
select in BlendRows takes the room before Opacity, as in PhotoCraft.

A contract trial checks that a FillWidth leaf takes the row's room and a
Content leaf does not.
This commit is contained in:
aiongg
2026-11-12 15:12:10 +00:00
parent 5468aa82ac
commit f7f75c178f
24 changed files with 99 additions and 85 deletions
+2 -2
View File
@@ -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());
}
+1 -1
View File
@@ -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()));
+3 -3
View File
@@ -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);
+2 -2
View File
@@ -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());
+13 -15
View File
@@ -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<craft_ui::runtime::env::Label>, 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<Axis> {
self.fill.then_some(Axis::X)
}
fn sense(&self) -> Sense {
Sense::CLICK | Sense::FOCUS
}
@@ -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 {
+4 -2
View File
@@ -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);
+2 -2
View File
@@ -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);
}
+3 -2
View File
@@ -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);
}
+3 -2
View File
@@ -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<craft_behavior::Axis> {
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
+2 -2
View File
@@ -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
+4 -1
View File
@@ -81,7 +81,10 @@ impl<C: Component> 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, Variant) {
@@ -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:?}");
}
@@ -1,2 +1,3 @@
mod body;
mod fill;
mod memory;
+5 -6
View File
@@ -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));
@@ -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);
}
+7
View File
@@ -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);
+1 -1
View File
@@ -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
-9
View File
@@ -144,10 +144,6 @@ pub struct Button<'a> {
#[style_key]
#[prop]
tint: Option<Rgba>,
/// 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<craft_behavior::Axis> {
self.fill_width.then_some(craft_behavior::Axis::X)
}
fn sense(&self) -> Sense {
if self.loading { Sense::FOCUS } else { Sense::CLICK | Sense::FOCUS }
}
+6 -11
View File
@@ -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<T: Value + 'static = ()> {
#[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<T: Value + 'static> Swatch<T> {
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<T: Value + 'static> Component for Swatch<T> {
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<craft_behavior::Axis> {
self.fill.then_some(craft_behavior::Axis::X)
}
fn sense(&self) -> Sense {
Sense::CLICK | Sense::FOCUS
}
@@ -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());
-9
View File
@@ -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<Id>,
/// 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<C: Codec + Clone + 'static> Component for TextField<'_, C> {
Sense::CLICK | Sense::FOCUS | Sense::TAKE_FOCUS
}
fn fills(&self) -> Option<craft_behavior::Axis> {
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 {
@@ -94,9 +94,6 @@ pub struct Slider<'a> {
track_face: Option<TrackFace<'a>>,
/// 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<craft_behavior::Axis> {
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 };
+2 -2
View File
@@ -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));