panels-w13: review fixes (review-1)

This commit is contained in:
aiongg
2026-11-14 17:56:01 +00:00
parent 2fa69d40d8
commit 552da163a2
6 changed files with 123 additions and 97 deletions
+26 -12
View File
@@ -42,8 +42,8 @@ pub use paragraph_dialog::{
SpacingKind, SpecialIndent,
};
use rows::{
LengthRow, Lengths, PlainRow, Toggle, family_field, hidden_side, leading_menu, leading_row, mark, mixed, number_change, number_presets,
picked_event, plain, select_row, size_menu, string_entries, toggle_row,
LengthRow, Lengths, PlainRow, Toggle, agree, family_field, hidden_side, leading_menu, leading_row, mark, mixed, number_change, number_presets,
plain, select_row, size_menu, string_entries, toggle_row,
};
pub use style_options::{
STYLE_COLOR_KEY, StyleAttribute, StyleOptionValues, StyleOptionsChange, TextStyleOptions, TextStyleOptionsOutput, TextStyleOptionsWords,
@@ -345,10 +345,28 @@ pub struct CharacterValues {
impl CharacterValues {
/// The values of two selections together: each field stays where both are equal and becomes `None` where they
/// differ.
// P3(panels-w13): tools-w24 decision, `CharacterValues::mixed_with`
pub fn mixed_with(&self, other: &Self) -> Self {
let _ = other;
todo!("panels-w13")
CharacterValues {
family: agree(&self.family, &other.family),
style: agree(&self.style, &other.style),
size: agree(&self.size, &other.size),
leading: agree(&self.leading, &other.leading),
kerning: agree(&self.kerning, &other.kerning),
tracking: agree(&self.tracking, &other.tracking),
vertical_scale: agree(&self.vertical_scale, &other.vertical_scale),
horizontal_scale: agree(&self.horizontal_scale, &other.horizontal_scale),
baseline_shift: agree(&self.baseline_shift, &other.baseline_shift),
color: agree(&self.color, &other.color),
faux_bold: agree(&self.faux_bold, &other.faux_bold),
faux_italic: agree(&self.faux_italic, &other.faux_italic),
caps: agree(&self.caps, &other.caps),
position: agree(&self.position, &other.position),
underline: agree(&self.underline, &other.underline),
strikethrough: agree(&self.strikethrough, &other.strikethrough),
opentype: self.opentype.iter().copied().filter(|tag| other.opentype.contains(tag)).collect(),
language: agree(&self.language, &other.language),
axes: agree(&self.axes, &other.axes),
}
}
}
@@ -531,7 +549,6 @@ impl<'a> CharacterControls<'a> {
.chain(KERNING_PRESETS.iter().map(|&p| Entry::new(NumberPick::Number(f64::from(p)), units.number(f64::from(p), 0..=PRESET_DECIMALS))))
.collect();
let family_entries = string_entries(families.iter().map(|name| (name.clone(), name.clone())));
let style_entries = string_entries(styles.iter().map(|name| (name.clone(), name.clone())));
let language_entries = languages.map(|languages| string_entries(languages.iter().cloned()));
@@ -548,15 +565,12 @@ impl<'a> CharacterControls<'a> {
let shown = Stack::new().label(self.label).show(ui, |ui, _| {
#[cfg(feature = "font-picker")]
let family = family_field(ui, &words.family, mixed(values.family.clone()), &family_entries, picker.as_mut());
let family = family_field(ui, &words, values, families, picker.as_mut());
#[cfg(not(feature = "font-picker"))]
let family = family_field(ui, &words.family, mixed(values.family.clone()), &family_entries);
let family = family_field(ui, &words, values, families);
preview_family = family.preview;
rested_family = family.rested;
edits.extend(family.edits.into_iter().map(|event| event.map(CharacterChange::Family)));
if let Some(style) = family.picked_style {
edits.push(picked_event(CharacterChange::Style(style), words.style.as_str()));
}
edits.extend(family.edits);
edits.extend(select_row(ui, &words.style, hidden_side(), mixed(values.style.clone()), &style_entries, CharacterChange::Style));
#[cfg(feature = "font-picker")]
if let Some(axes) = axes {
+11 -4
View File
@@ -11,7 +11,7 @@ use craft_ui::runtime::env::{Env, Label};
use egui::{Response, Ui};
use super::TWO_COLUMNS;
use super::rows::{LengthRow, Lengths, Toggle, mark, mixed, number_change, toggle_row};
use super::rows::{LengthRow, Lengths, Toggle, agree, mark, mixed, number_change, toggle_row};
craft_ui::words! {
/// The Paragraph controls' words, English by default (PhotoCraft's tooltips).
@@ -114,10 +114,17 @@ pub struct ParagraphValues {
impl ParagraphValues {
/// The values of two selections together: each field stays where both are equal and becomes `None` where they
/// differ.
// P3(panels-w13): tools-w24 decision, `ParagraphValues::mixed_with`
pub fn mixed_with(&self, other: &Self) -> Self {
let _ = other;
todo!("panels-w13")
ParagraphValues {
align: agree(&self.align, &other.align),
direction: agree(&self.direction, &other.direction),
start_indent: agree(&self.start_indent, &other.start_indent),
end_indent: agree(&self.end_indent, &other.end_indent),
first_line_indent: agree(&self.first_line_indent, &other.first_line_indent),
space_before: agree(&self.space_before, &other.space_before),
space_after: agree(&self.space_after, &other.space_after),
hyphenate: agree(&self.hyphenate, &other.hyphenate),
}
}
}
+45 -63
View File
@@ -19,7 +19,8 @@ use egui::Ui;
#[cfg(feature = "font-picker")]
use super::FontPickerSource;
use super::{
AUTO_LEADING, AUTO_ROW, CharacterChange, CharacterWords, KerningName, LEADING_RANGE, Leading, PRESET_DECIMALS, SIZE_PRESETS, TRACKING_RANGE,
AUTO_LEADING, AUTO_ROW, CharacterChange, CharacterValues, CharacterWords, KerningName, LEADING_RANGE, Leading, PRESET_DECIMALS, SIZE_PRESETS,
TRACKING_RANGE,
};
#[cfg(feature = "font-picker")]
use craft_font_manager::picker::FontPicker;
@@ -211,55 +212,6 @@ pub(crate) fn select_row<C>(
shown.inner.unwrap_or_default().map(&change)
}
/// What the family field did this pass.
#[derive(Default)]
pub(crate) struct FamilyOutput {
/// The family edits: a pick commits; a hovered row is not one.
pub(crate) edits: Vec<EditEvent<String>>,
/// The style picked in an expanded family's rows of the font picker.
pub(crate) picked_style: Option<String>,
/// The family under the pointer or keyboard row in the open list.
pub(crate) preview: Option<String>,
/// The family the pointer or keyboard rested on in the open list.
pub(crate) rested: Option<String>,
}
/// The family as a select over `entries`.
fn family_select(ui: &mut Ui, label: &Label, value: Mixed<String>, entries: &[Entry<String>]) -> FamilyOutput {
FamilyOutput { edits: select_row(ui, label, hidden_side(), value, entries, |name| name).into_iter().collect(), ..FamilyOutput::default() }
}
/// The family field: the font picker over `picker`, or a select over `entries` when there is none.
#[cfg(feature = "font-picker")]
pub(crate) fn family_field(
ui: &mut Ui,
label: &Label,
value: Mixed<String>,
entries: &[Entry<String>],
picker: Option<&mut FontPickerSource<'_>>,
) -> FamilyOutput {
let Some(source) = picker else { return family_select(ui, label, value, entries) };
let shown = Field::new(label.clone()).side(hidden_side()).show(ui, |ui, _| {
let mut field = FontPicker::new(label.clone(), Bind::given(value.clone()), source.catalog)
.settings(source.settings.reborrowed())
.filters(source.filters.reborrowed())
.served(source.served);
if let Some(text) = source.preview_text {
field = field.preview_text(text);
}
field.show(ui)
});
let Some(out) = shown.inner else { return FamilyOutput::default() };
let edits = out.edit.events.into_iter().filter(|event| matches!(event, EditEvent::Commit { .. } | EditEvent::Set { .. })).collect();
FamilyOutput { edits, picked_style: out.picked_style, preview: out.preview, rested: out.rested }
}
/// The family field: a select over `entries`.
#[cfg(not(feature = "font-picker"))]
pub(crate) fn family_field(ui: &mut Ui, label: &Label, value: Mixed<String>, entries: &[Entry<String>]) -> FamilyOutput {
family_select(ui, label, value, entries)
}
/// One toggle button of a row: its name, icon, state (`None` while the selection mixes) and the change it makes.
pub(crate) struct Toggle<C> {
pub(crate) name: Label,
@@ -305,27 +257,57 @@ pub(crate) fn toggle_row<C>(ui: &mut Ui, label: Option<&Label>, toggles: &[Toggl
}
/// What [`family_field`] reports: the family edits, and the family the picker previews and rests on.
// P3(panels-w13): tools-w5 decision, `FamilyField`
#[allow(dead_code)] // P3(panels-w13): FamilyField
#[derive(Default)]
pub(crate) struct FamilyField {
pub edits: Vec<EditEvent<super::CharacterChange>>,
/// The family edit, and the style edit of a style picked in an expanded family's rows; a hovered row is not one.
pub edits: Vec<EditEvent<CharacterChange>>,
/// The family under the pointer or keyboard row in the open list.
pub preview: Option<String>,
/// The family the pointer or keyboard rested on in the open list.
pub rested: Option<String>,
}
/// The family field of the character controls and the type bar: the font picker in a hidden-label field when a
/// `picker` source is given, else a select over `families`.
// P3(panels-w13): tools-w5 decision, `family_field`
#[allow(dead_code)] // P3(panels-w13): family_field
/// The family field of the character controls, the style options and the type bar: the font picker in a
/// hidden-label field when a `picker` source is given, else a select over `families`.
pub(crate) fn family_field(
ui: &mut Ui,
words: &super::CharacterWords,
values: &super::CharacterValues,
words: &CharacterWords,
values: &CharacterValues,
families: &[String],
#[cfg(feature = "font-picker")] picker: Option<&mut super::FontPickerSource<'_>>,
#[cfg(feature = "font-picker")] picker: Option<&mut FontPickerSource<'_>>,
) -> FamilyField {
let _ = (ui, words, values, families);
let value = mixed(values.family.clone());
#[cfg(feature = "font-picker")]
let _ = picker;
todo!("panels-w13")
if let Some(source) = picker {
let shown = Field::new(words.family.clone()).side(hidden_side()).show(ui, |ui, _| {
let mut field = FontPicker::new(words.family.clone(), Bind::given(value.clone()), source.catalog)
.settings(source.settings.reborrowed())
.filters(source.filters.reborrowed())
.served(source.served);
if let Some(text) = source.preview_text {
field = field.preview_text(text);
}
field.show(ui)
});
let Some(out) = shown.inner else { return FamilyField::default() };
let mut edits: Vec<EditEvent<CharacterChange>> = out
.edit
.events
.into_iter()
.filter(|event| matches!(event, EditEvent::Commit { .. } | EditEvent::Set { .. }))
.map(|event| event.map(CharacterChange::Family))
.collect();
if let Some(style) = out.picked_style {
edits.push(picked_event(CharacterChange::Style(style), words.style.as_str()));
}
return FamilyField { edits, preview: out.preview, rested: out.rested };
}
let entries = string_entries(families.iter().map(|name| (name.clone(), name.clone())));
let edits = select_row(ui, &words.family, hidden_side(), value, &entries, CharacterChange::Family).into_iter().collect();
FamilyField { edits, ..FamilyField::default() }
}
/// Where two selections' optional values agree: that value, else `None` (mixed).
pub(crate) fn agree<T: Clone + PartialEq>(a: &Option<T>, b: &Option<T>) -> Option<T> {
if a == b { a.clone() } else { None }
}
+39 -16
View File
@@ -12,14 +12,14 @@ use craft_ui::display::Text;
use craft_ui::form::Field;
use craft_ui::layout_components::{Grid, Row, Stack};
use craft_ui::patterns::form_dialogs::HostRequests;
use craft_ui::runtime::env::{Env, Label};
use craft_ui::runtime::env::{Env, Label, WordTemplate};
use craft_ui::text::{NumberPick, TextField};
use egui::{Response, Ui};
use super::paragraph::{INDENT_RANGE, SPACE_RANGE};
use super::rows::{
LengthRow, Lengths, PlainRow, Toggle, family_field, hidden_side, leading_menu, leading_row, mark, mixed, number_change, number_presets,
picked_event, plain, select_row, size_menu, string_entries, toggle_row,
plain, select_row, size_menu, string_entries, toggle_row,
};
use super::{
CharacterChange, CharacterValues, CharacterWords, ParagraphChange, ParagraphValues, ParagraphWords, SHIFT_RANGE, SIZE_RANGE, TRACKING_PRESETS,
@@ -34,16 +34,16 @@ use super::FontPickerSource;
mod stories;
craft_ui::words! {
/// The words of the style options editor, English by default: the three short alignment names its rows show, the
/// name field, the include checks and the close button. The other labels come from the Character and Paragraph words.
/// The words of the style options editor, English by default: the three short alignment names its rows show. The
/// name field, the include checks and the close button are words the contract row does not list but the editor
/// needs. The other labels come from the Character and Paragraph words.
#[non_exhaustive]
pub struct TextStyleOptionsWords {
left: "styleOptions.left" = "Left";
center: "styleOptions.center" = "Center";
right: "styleOptions.right" = "Right";
// PLAN: the sheet lists these three words (note 3); the contract row names only the alignment names
name: "styleOptions.name" = "Style name";
include: "styleOptions.include" = "Include";
include: template "styleOptions.include" = "Include {attribute}";
close: "styleOptions.close" = "Close";
}
}
@@ -262,7 +262,7 @@ impl<'a> TextStyleOptions<'a> {
let size_presets = size_menu(&units, unit);
let leading_presets = leading_menu(&cw, values.character.leading, &size_presets);
let tracking_presets = number_presets(&units, TRACKING_PRESETS.iter().copied());
let family_entries = string_entries(families.iter().map(|name| (name.clone(), name.clone())));
let style_entries = string_entries(styles.iter().map(|name| (name.clone(), name.clone())));
let align_entries: Vec<Entry<String>> = ALIGNS
.iter()
@@ -305,13 +305,10 @@ impl<'a> TextStyleOptions<'a> {
let found = match attribute {
StyleAttribute::Font => include_row(ui, &words.include, attribute, on, |ui| {
#[cfg(feature = "font-picker")]
let family = family_field(ui, &cw.family, mixed(c.family.clone()), &family_entries, picker.as_mut());
let family = family_field(ui, &cw, c, families, picker.as_mut());
#[cfg(not(feature = "font-picker"))]
let family = family_field(ui, &cw.family, mixed(c.family.clone()), &family_entries);
let mut found = character(family.edits.into_iter().map(|event| event.map(CharacterChange::Family)));
if let Some(style) = family.picked_style {
found.extend(character([picked_event(CharacterChange::Style(style), cw.style.as_str())]));
}
let family = family_field(ui, &cw, c, families);
let mut found = character(family.edits);
found.extend(character(select_row(
ui,
&cw.style,
@@ -456,15 +453,41 @@ fn text_side(label: &Label) -> SideLabel {
mark(GlyphLabel::text(label.clone()), None, FieldLayout::Beside)
}
/// One row: the include check, then the row's `field`. A row that is not included shows the inherited value and takes
/// no input; its check still does.
/// The name of the row of `attribute`, which the include check's accessible name carries.
fn attribute_name(attribute: StyleAttribute, cw: &CharacterWords, pw: &ParagraphWords) -> Label {
match attribute {
StyleAttribute::Font => cw.family.clone(),
StyleAttribute::Size => cw.size.clone(),
StyleAttribute::Leading => cw.leading.clone(),
StyleAttribute::Tracking => cw.tracking.clone(),
StyleAttribute::BaselineShift => cw.baseline_shift.clone(),
StyleAttribute::Color => cw.text_color.clone(),
StyleAttribute::FauxBold => cw.faux_bold.clone(),
StyleAttribute::FauxItalic => cw.faux_italic.clone(),
StyleAttribute::Underline => cw.underline.clone(),
StyleAttribute::Strikethrough => cw.strikethrough.clone(),
StyleAttribute::Align => pw.alignment.clone(),
StyleAttribute::FirstLineIndent => pw.first_line_indent.clone(),
StyleAttribute::StartIndent => pw.start_indent.clone(),
StyleAttribute::EndIndent => pw.end_indent.clone(),
StyleAttribute::SpaceBefore => pw.space_before.clone(),
StyleAttribute::SpaceAfter => pw.space_after.clone(),
StyleAttribute::Hyphenate => pw.hyphenate.clone(),
}
}
/// One row: the include check, named by the `include` template filled with the row's name, then the row's `field`. A
/// row that is not included shows the inherited value and takes no input; its check still does.
fn include_row(
ui: &mut Ui,
include: &Label,
include: &WordTemplate,
attribute: StyleAttribute,
on: bool,
field: impl FnOnce(&mut Ui) -> Vec<EditEvent<StyleOptionsChange>>,
) -> Vec<EditEvent<StyleOptionsChange>> {
let env = Env::of(ui);
let name = attribute_name(attribute, &env.words::<CharacterWords>(), &env.words::<ParagraphWords>());
let include = Label::from(include.fill(&[("attribute", name.as_str())]));
let mut found = Vec::new();
Grid::new(&TWO_COLUMNS).fill_width().show(ui, |ui, _| {
let check = Field::new(include.clone()).side(hidden_side()).show(ui, |ui, _| Checkbox::new(Bind::given(Mixed::Same(on))).show(ui).events);
+1 -1
View File
@@ -4,7 +4,7 @@
mod editor;
mod notes;
// PLAN: `mod path_text;` belongs here once tools-w4's `tests/it/path_text.rs` exists. It is not in this tree, so the declaration fails to compile.
mod ruler;
mod style_options;
mod style_panel;
+1 -1
View File
@@ -33,7 +33,7 @@ fn a_row_left_out_of_the_style_takes_no_input_and_its_check_includes_it() {
fixture.idle(4);
assert!(changes(&edits).is_empty(), "a row that is not included takes no input: {:?}", changes(&edits));
let include = fixture.by_label("Include").expect("the include check is shown");
let include = fixture.by_label("Include Font size").expect("the include check is shown");
fixture.click(&include).idle(4);
assert_eq!(
changes(&edits),