ui-widgets: Radio::detail shows a muted line after the radio's label through the label step; form radio rows use it

This commit is contained in:
bflatastic
2026-11-22 04:57:37 +07:00
parent ecb5efdebd
commit d059b92889
6 changed files with 59 additions and 21 deletions
@@ -504,5 +504,9 @@ pub(crate) fn show_leaf_in_flow<C: Show>(mut child: C, ui: &mut Ui) -> C::Output
let facts = crate::contract::run::TypeFacts::of::<C>();
let id = crate::contract::steps::id(ui, &child.common(crate::contract::Internal::new()).id, false, true, facts.style_key, facts.name);
let side = SideLabel::new().layout(FieldLayout::After);
let side = match child.label_detail() {
Some(detail) => side.detail(detail),
None => side,
};
flow_leaf(ui, (id, id), (env.enabled, env.size), label, side, child, None)
}
+6
View File
@@ -399,6 +399,12 @@ pub trait Component: Meta + Sized {
Self::SHOWS_LABEL
}
/// The muted line a `LABELLED_AFTER` control's label shows after its text (`SideLabel::detail`), as a radio's
/// `detail`; none by default. It reads props only.
fn label_detail(&self) -> Option<crate::runtime::env::Label> {
None
}
/// How far the component paints outside its rect by design, in points (a graph node's ports sit on its edge).
/// Steps 13 and 14 clip to the rect grown by this much; the paint-bounds suite case reads it.
fn paint_outset(_tokens: &crate::style::UiTokens) -> f32 {
@@ -13,8 +13,8 @@ use super::words::ParamWords;
use crate::buttons::{Button, IconButton, ToggleButton};
use crate::choice::{Checkbox, Radio, RadioGroup, Swatch};
use crate::contract::{
Bind, BodyCx, CanvasGesture, Entry, FieldLayout, NoValue, Outcome, Props as _, Remember as _, Sampler as _, Show as _, ShowContainer as _,
SideLabel, Sizing, clicked,
Bind, BodyCx, CanvasGesture, Entry, NoValue, Outcome, Props as _, Remember as _, Sampler as _, Show as _, ShowContainer as _, SideLabel, Sizing,
clicked,
};
use crate::display::Text;
use crate::form::{Field, FieldGroup, SliderField, SliderFieldLayout};
@@ -1017,20 +1017,15 @@ impl<'p> Pass<'p> {
if let Some(tip) = line.param.tooltip_text() {
group = group.tooltip(tip.clone());
}
let group = group.show(ui, |ui, cx| {
let group = group.show(ui, |ui, _| {
let mut radios = |ui: &mut Ui| {
for (at, (id, label)) in options.iter().enumerate() {
let radio = Radio::new(id.clone()).enabled(line.param.option_enabled(id) && line.enabled);
let radio = Radio::new(id.clone()).enabled(line.param.option_enabled(id) && line.enabled).label(label.clone());
match details.get(at) {
// An option with a detail line draws it under its label through the body's label step.
Some(detail) => {
let side = SideLabel::new().layout(FieldLayout::After).detail(detail.clone());
cx.labelled(ui, id, label.clone(), side, radio);
}
None => {
radio.label(label.clone()).show(ui);
}
Some(detail) => radio.detail(detail.clone()),
None => radio,
}
.show(ui);
}
};
if in_row {
+12 -5
View File
@@ -160,19 +160,22 @@ pub struct Radio<T: Value + 'static> {
value: T,
checked: bool,
invalid: bool,
/// The line after the label ([`Radio::detail`]).
detail: Option<crate::runtime::env::Label>,
}
impl<T: Value + 'static> Radio<T> {
/// A radio button standing for `value`.
pub fn new(value: T) -> Self {
Radio { common: Common::new(), value, checked: false, invalid: false }
Radio { common: Common::new(), value, checked: false, invalid: false, detail: None }
}
/// A dimmed line under the label (muted text role, small text token), inside the radio's hit area.
/// A dimmed line after the label (the label's detail: muted text), inside the radio's hit area; it joins the
/// radio's description.
#[must_use]
pub fn detail(self, text: impl Into<crate::runtime::env::Label>) -> Self {
let _ = text;
todo!("co.K26")
pub fn detail(mut self, text: impl Into<crate::runtime::env::Label>) -> Self {
self.detail = Some(text.into());
self
}
}
@@ -195,6 +198,10 @@ impl<T: Value + 'static> Component for Radio<T> {
}
}
fn label_detail(&self) -> Option<crate::runtime::env::Label> {
self.detail.clone()
}
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
Vec2::splat(cx.icon())
}
@@ -111,16 +111,15 @@ fn radio_group_with_icons_and_counts(ui: &mut Ui, data: &mut StoryData) -> Story
.into()
}
/// Rows with a description under the label: the `SideLabel`'s detail joins the radio's accessible description.
/// Rows with a description after the label (`Radio::detail`): it joins the radio's accessible description.
#[story(RadioGroup<'static, u8>, covers = [], drive = Drive::Never)]
fn radio_group_with_descriptions(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let rows =
[(1u8, "Fast", "Lower quality, smaller file"), (2, "Balanced", "The default for most photos"), (3, "Best", "Full quality, largest file")];
RadioGroup::new("Export", data.bind("export", 2u8))
.show(ui, |ui, cx| {
.show(ui, |ui, _| {
for (value, label, description) in rows {
let side = SideLabel::new().layout(FieldLayout::After).detail(description);
cx.labelled(ui, value, label.into(), side, Radio::new(value));
Radio::new(value).label(label).detail(description).show(ui);
}
})
.into()
+27
View File
@@ -81,6 +81,33 @@ fn a_click_on_a_radio_label_picks_it_in_that_pass() {
assert_eq!(picked.get(), 2, "the release on Medium's label picks it in its own pass");
}
/// A radio's detail line follows its label and is part of its hit area: a click on it picks the radio.
#[trial]
fn a_radio_detail_follows_its_label_and_a_click_on_it_picks_the_radio() {
let mut frames = Frames::new();
let picked = Cell::new(1u8);
let mut show = |ui: &mut Ui| {
let mut value = picked.get();
in_region(ui, REGION, |ui| {
RadioGroup::new("Quality", Bind::bound(&mut value)).show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
Radio::new(1u8).label("Fast").detail("Smaller file").show(ui);
Radio::new(2u8).label("Best").detail("Largest file").show(ui);
});
})
});
picked.set(value);
};
frames.frame(vec![], &mut show);
let (label, detail) = (text_rect(&frames, "Best"), text_rect(&frames, "Largest file"));
let follows = detail.left() >= label.right() || detail.top() >= label.bottom();
assert!(follows, "the detail follows the label: {detail:?} after {label:?}");
for event in [moved(detail.center()), press(detail.center()), release(detail.center())] {
frames.frame(vec![event], &mut show);
}
assert_eq!(picked.get(), 2, "a click on the detail picks its radio");
}
#[trial]
fn a_long_label_after_its_box_wraps_with_the_box_on_its_first_line() {
const LONG: &str = "Show the transform controls on the selected layer whenever the move tool is active";