diff --git a/crates/text/src/ui/character.rs b/crates/text/src/ui/character.rs index d4254c5b2..1f9ab4751 100644 --- a/crates/text/src/ui/character.rs +++ b/crates/text/src/ui/character.rs @@ -603,7 +603,7 @@ impl<'a> CharacterControls<'a> { } toggles.push(Toggle::new(&words.underline, "text_underline", values.underline, Box::new(CharacterChange::Underline))); toggles.push(Toggle::new(&words.strikethrough, "text_strikethrough", values.strikethrough, Box::new(CharacterChange::Strikethrough))); - edits.extend(toggle_row(ui, toggles)); + edits.extend(toggle_row(ui, None, toggles)); let names = [ &words.standard_ligatures, @@ -623,7 +623,7 @@ impl<'a> CharacterControls<'a> { Toggle::new(name, icon, Some(values.opentype.contains(&tag)), Box::new(move |on| CharacterChange::OpenType { tag, on })) }) .collect(); - edits.extend(toggle_row(ui, features)); + edits.extend(toggle_row(ui, None, features)); if let Some(entries) = &language_entries { edits.extend(select_row(ui, &words.language, mixed(values.language.clone()), entries, CharacterChange::Language)); diff --git a/crates/text/src/ui/character/paragraph.rs b/crates/text/src/ui/character/paragraph.rs index 3ed477b12..bc456d2ae 100644 --- a/crates/text/src/ui/character/paragraph.rs +++ b/crates/text/src/ui/character/paragraph.rs @@ -3,15 +3,15 @@ use std::ops::RangeInclusive; use crate::ui::length::DocUnit; -use craft_behavior::{EditEvent, IconId}; -use craft_ui::choice::{Checkbox, Segmented}; -use craft_ui::contract::{Bind, Entry, GlyphLabel, NoValue, Outcome, Props as _, Show as _, ShowContainer as _}; +use craft_behavior::EditEvent; +use craft_ui::choice::Checkbox; +use craft_ui::contract::{Bind, GlyphLabel, NoValue, Outcome, Props as _, Show as _, ShowContainer as _}; use craft_ui::layout_components::{Grid, Stack}; use craft_ui::runtime::env::{Env, Label}; use egui::{Response, Ui}; use super::TWO_COLUMNS; -use super::rows::{LengthRow, Lengths, mixed, number_change}; +use super::rows::{LengthRow, Lengths, Toggle, mixed, number_change, toggle_row}; craft_ui::words! { /// The Paragraph controls' words, English by default (PhotoCraft's tooltips). @@ -182,7 +182,7 @@ impl<'a> ParagraphControls<'a> { let units = env.units(); let lengths = Lengths { units: &units, unit: self.unit }; - let aligns: Vec> = [ + let aligns: Vec> = [ (TextAlign::Left, "align_left", &words.left), (TextAlign::Center, "align_center", &words.center), (TextAlign::Right, "align_right", &words.right), @@ -193,25 +193,25 @@ impl<'a> ParagraphControls<'a> { ] .into_iter() .map(|(align, icon, name)| { - let entry = Entry::new(align, name.clone()).icon(IconId::new(icon)); - if point_text && align.needs_box() { entry.disabled_reason(words.justify_needs_box.clone()) } else { entry } + let toggle = Toggle::new(name, icon, Some(values.align == Some(align)), Box::new(move |_| ParagraphChange::Align(align))); + if point_text && align.needs_box() { toggle.disabled(&words.justify_needs_box) } else { toggle } }) .collect(); - let directions: Vec> = [ + let directions: Vec> = [ (ParagraphDirection::Automatic, "pilcrow", &words.direction_auto), (ParagraphDirection::LeftToRight, "pilcrow_right", &words.direction_ltr), (ParagraphDirection::RightToLeft, "pilcrow_left", &words.direction_rtl), ] .into_iter() - .map(|(direction, icon, name)| Entry::new(direction, name.clone()).icon(IconId::new(icon))) + .map(|(direction, icon, name)| { + Toggle::new(name, icon, Some(values.direction == Some(direction)), Box::new(move |_| ParagraphChange::Direction(direction))) + }) .collect(); let mut edits: Vec> = Vec::new(); let shown = Stack::new().fill_width().label(self.label).show(ui, |ui, _| { - let out = Segmented::new(words.alignment.clone(), Bind::given(mixed(values.align)), &aligns).show(ui); - edits.extend(out.events.map(ParagraphChange::Align)); - let out = Segmented::new(words.direction.clone(), Bind::given(mixed(values.direction)), &directions).show(ui); - edits.extend(out.events.map(ParagraphChange::Direction)); + edits.extend(toggle_row(ui, Some(&words.alignment), aligns)); + edits.extend(toggle_row(ui, Some(&words.direction), directions)); Grid::new(&TWO_COLUMNS).fill_width().show(ui, |ui, _| { let start = LengthRow { diff --git a/crates/text/src/ui/character/rows.rs b/crates/text/src/ui/character/rows.rs index 8e197a572..b0ffed652 100644 --- a/crates/text/src/ui/character/rows.rs +++ b/crates/text/src/ui/character/rows.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use crate::ui::length::{DocUnit, length_field}; use craft_behavior::{EditEvent, EditEvents, IconId, Mixed, NumberCodec}; use craft_ui::buttons::ToggleButton; -use craft_ui::contract::{Bind, Entry, FieldLayout, GlyphLabel, LabelKind, Show as _, ShowContainer as _, SideLabel}; +use craft_ui::contract::{Bind, Entry, FieldLayout, GlyphLabel, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel, TooltipSpec}; use craft_ui::form::Field; use craft_ui::layout_components::Row; use craft_ui::pickers::Select; @@ -163,21 +163,38 @@ pub(super) struct Toggle { pub(super) icon: &'static str, pub(super) on: Option, pub(super) change: Box C>, + /// Why the button is disabled; `None` while it is enabled. + pub(super) disabled: Option