mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 22:14:30 +00:00
panels-w13: written from its sheet
This commit is contained in:
@@ -8,12 +8,14 @@
|
||||
#[cfg(feature = "font-picker")]
|
||||
use craft_font_manager::Catalog;
|
||||
#[cfg(feature = "font-picker")]
|
||||
use craft_font_manager::picker::{FontFilters, FontPicker, FontPickerSettings};
|
||||
use craft_font_manager::axes::AxisSliders;
|
||||
#[cfg(feature = "font-picker")]
|
||||
use craft_font_manager::picker::{FontFilters, FontPickerSettings};
|
||||
use std::ops::RangeInclusive;
|
||||
#[cfg(feature = "font-picker")]
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::ui::length::{DocUnit, shown};
|
||||
use crate::ui::length::DocUnit;
|
||||
use craft_behavior::{ColumnWidth, EditEvent, IconId};
|
||||
use craft_theme::{Rgba, Srgba};
|
||||
use craft_ui::choice::Swatch;
|
||||
@@ -40,8 +42,8 @@ pub use paragraph_dialog::{
|
||||
SpacingKind, SpecialIndent,
|
||||
};
|
||||
use rows::{
|
||||
LengthRow, Lengths, PlainRow, Toggle, hidden_side, mark, mixed, number_change, number_presets, picked_event, plain, select_row, string_entries,
|
||||
toggle_row,
|
||||
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,
|
||||
};
|
||||
pub use style_options::{
|
||||
STYLE_COLOR_KEY, StyleAttribute, StyleOptionValues, StyleOptionsChange, TextStyleOptions, TextStyleOptionsOutput, TextStyleOptionsWords,
|
||||
@@ -465,9 +467,8 @@ pub struct CharacterControls<'a> {
|
||||
#[prop]
|
||||
languages: Option<&'a [(String, String)]>,
|
||||
#[cfg(feature = "font-picker")]
|
||||
picker: Option<(&'a Arc<Catalog>, Bind<'a, FontPickerSettings>, Bind<'a, FontFilters>)>,
|
||||
picker: Option<FontPickerSource<'a>>,
|
||||
#[cfg(feature = "font-picker")]
|
||||
#[allow(dead_code)] // P3(panels-w13): tl.R6
|
||||
axes: Option<FaceAxes<'a>>,
|
||||
}
|
||||
|
||||
@@ -489,12 +490,11 @@ impl<'a> CharacterControls<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The family field is craft-font-manager's font picker over `catalog`, with the app's stars, recents and
|
||||
/// filters.
|
||||
/// The family field is craft-font-manager's font picker over `source`: the catalog, the app's stars, recents and
|
||||
/// filters, the preview text and the served families.
|
||||
#[cfg(feature = "font-picker")]
|
||||
pub fn font_picker(mut self, source: FontPickerSource<'a>) -> Self {
|
||||
// P3(panels-w13): tl.R6 (preview_text and served are unread)
|
||||
self.picker = Some((source.catalog, source.settings, source.filters));
|
||||
self.picker = Some(source);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -512,20 +512,15 @@ impl<'a> CharacterControls<'a> {
|
||||
let (unit, superscript) = (self.unit, self.superscript);
|
||||
#[cfg(feature = "font-picker")]
|
||||
let mut picker = self.picker;
|
||||
#[cfg(feature = "font-picker")]
|
||||
let axes = self.axes;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<CharacterWords>();
|
||||
let units = env.units();
|
||||
let lengths = Lengths { units: &units, unit };
|
||||
|
||||
let size_presets: Vec<Entry<NumberPick>> = SIZE_PRESETS
|
||||
.iter()
|
||||
.map(|&p| {
|
||||
let points = f64::from(p);
|
||||
Entry::new(NumberPick::Number(points), units.text(unit.kind, shown(&units, unit, points), 0..=PRESET_DECIMALS))
|
||||
})
|
||||
.collect();
|
||||
let auto_row = Entry::new(NumberPick::Choice(AUTO_ROW), words.auto.clone()).checked(values.leading == Some(Leading::Auto));
|
||||
let leading_presets: Vec<Entry<NumberPick>> = [auto_row, Entry::separator()].into_iter().chain(size_presets.iter().cloned()).collect();
|
||||
let size_presets = size_menu(&units, unit);
|
||||
let leading_presets = leading_menu(&words, values.leading, &size_presets);
|
||||
let tracking_presets = number_presets(&units, TRACKING_PRESETS.iter().copied());
|
||||
let kerning_presets: Vec<Entry<NumberPick>> = [
|
||||
Entry::new(NumberPick::Choice(METRICS_ROW), words.metrics.clone()).checked(values.kerning == Some(Kerning::Metrics)),
|
||||
@@ -539,11 +534,7 @@ impl<'a> CharacterControls<'a> {
|
||||
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()));
|
||||
let leading_value = match values.leading {
|
||||
Some(Leading::Fixed(points)) => Some(points),
|
||||
Some(Leading::Auto) => values.size.map(|size| size * AUTO_LEADING),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let kerning_shown = values.kerning.map(|kerning| match kerning {
|
||||
Kerning::Manual(value) => NamedOr::Number(f64::from(value)),
|
||||
Kerning::Metrics => NamedOr::Named(KerningName::Metrics),
|
||||
@@ -551,39 +542,31 @@ impl<'a> CharacterControls<'a> {
|
||||
});
|
||||
|
||||
let mut edits: Vec<EditEvent<CharacterChange>> = Vec::new();
|
||||
#[cfg(feature = "font-picker")]
|
||||
let mut preview_family = None;
|
||||
#[cfg(not(feature = "font-picker"))]
|
||||
let preview_family = None;
|
||||
let mut rested_family = None;
|
||||
let mut requests = HostRequests::new();
|
||||
|
||||
let shown = Stack::new().label(self.label).show(ui, |ui, _| {
|
||||
#[cfg(feature = "font-picker")]
|
||||
let by_picker = if let Some((catalog, settings, filters)) = picker.as_mut() {
|
||||
let family = mixed(values.family.clone());
|
||||
let side = SideLabel::new().kind(LabelKind::Hidden);
|
||||
let shown = Field::new(words.family.clone()).side(side).show(ui, |ui, _| {
|
||||
let out = FontPicker::new(words.family.clone(), Bind::given(family.clone()), catalog)
|
||||
.settings(settings.reborrowed())
|
||||
.filters(filters.reborrowed())
|
||||
.show(ui);
|
||||
(out.preview, out.edit.events)
|
||||
});
|
||||
if let Some((preview, events)) = shown.inner {
|
||||
preview_family = preview;
|
||||
let kept = events.into_iter().filter(|event| matches!(event, EditEvent::Commit { .. } | EditEvent::Set { .. }));
|
||||
edits.extend(kept.map(|event| event.map(CharacterChange::Family)));
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let family = family_field(ui, &words.family, mixed(values.family.clone()), &family_entries, picker.as_mut());
|
||||
#[cfg(not(feature = "font-picker"))]
|
||||
let by_picker = false;
|
||||
if !by_picker {
|
||||
edits.extend(select_row(ui, &words.family, hidden_side(), mixed(values.family.clone()), &family_entries, CharacterChange::Family));
|
||||
let family = family_field(ui, &words.family, mixed(values.family.clone()), &family_entries);
|
||||
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(select_row(ui, &words.style, hidden_side(), mixed(values.style.clone()), &style_entries, CharacterChange::Style));
|
||||
#[cfg(feature = "font-picker")]
|
||||
if let Some(axes) = axes {
|
||||
let held = values.axes.clone().unwrap_or_default();
|
||||
let mut sliders = AxisSliders::new(words.axes.clone(), axes.axes, Bind::given(held)).instances(axes.instances).italic(axes.italic);
|
||||
if let Some(weight) = axes.weight {
|
||||
sliders = sliders.weight(weight);
|
||||
}
|
||||
edits.extend(sliders.show(ui).edit.into_iter().map(|event| event.map(CharacterChange::Axes)));
|
||||
}
|
||||
|
||||
Grid::new(&TWO_COLUMNS).fill_width().show(ui, |ui, _| {
|
||||
let size = LengthRow {
|
||||
@@ -595,18 +578,8 @@ impl<'a> CharacterControls<'a> {
|
||||
};
|
||||
let (event, _) = lengths.row(ui, size);
|
||||
edits.extend(number_change(event, CharacterChange::Size));
|
||||
let leading = LengthRow {
|
||||
label: words.leading.clone(),
|
||||
side: mark(GlyphLabel::text("A↕"), Some(words.leading_hint.clone()), FieldLayout::Inside),
|
||||
value: leading_value,
|
||||
range: LEADING_RANGE,
|
||||
presets: &leading_presets,
|
||||
};
|
||||
let (event, picked) = lengths.row(ui, leading);
|
||||
edits.extend(number_change(event, |points| CharacterChange::Leading(Leading::Fixed(points))));
|
||||
if picked == Some(NumberPick::Choice(AUTO_ROW)) {
|
||||
edits.push(picked_event(CharacterChange::Leading(Leading::Auto), words.leading.as_str()));
|
||||
}
|
||||
let side = mark(GlyphLabel::text("A↕"), Some(words.leading_hint.clone()), FieldLayout::Inside);
|
||||
edits.extend(leading_row(&lengths, ui, &words, side, values.leading, values.size, &leading_presets));
|
||||
});
|
||||
Grid::new(&TWO_COLUMNS).fill_width().show(ui, |ui, _| {
|
||||
let event = lengths.kerning(
|
||||
@@ -731,7 +704,7 @@ impl<'a> CharacterControls<'a> {
|
||||
edits.extend(select_row(ui, &words.language, hidden_side(), mixed(values.language.clone()), entries, CharacterChange::Language));
|
||||
}
|
||||
});
|
||||
CharacterControlsOutput { response: shown.output, edits, preview_family, rested_family: None, requests }
|
||||
CharacterControlsOutput { response: shown.output, edits, preview_family, rested_family, requests }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,9 +44,9 @@ craft_ui::words! {
|
||||
}
|
||||
|
||||
/// The range of the indent fields, points.
|
||||
const INDENT_RANGE: RangeInclusive<f64> = -1296.0..=1296.0;
|
||||
pub(super) const INDENT_RANGE: RangeInclusive<f64> = -1296.0..=1296.0;
|
||||
/// The range of the space fields, points.
|
||||
const SPACE_RANGE: RangeInclusive<f64> = 0.0..=1296.0;
|
||||
pub(super) const SPACE_RANGE: RangeInclusive<f64> = 0.0..=1296.0;
|
||||
|
||||
/// Paragraph alignment, in Photoshop's button order.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
@@ -196,38 +196,16 @@ impl<'a> ParagraphControls<'a> {
|
||||
pub fn show(self, ui: &mut Ui) -> ParagraphControlsOutput {
|
||||
let values = self.values;
|
||||
let point_text = self.point_text;
|
||||
let _ = self.vertical; // P3(panels-w13): tl.R6
|
||||
let vertical = self.vertical;
|
||||
let show_hyphenate = self.hyphenate;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<ParagraphWords>();
|
||||
let units = env.units();
|
||||
let lengths = Lengths { units: &units, unit: self.unit };
|
||||
|
||||
let aligns: Vec<Toggle<ParagraphChange>> = [
|
||||
(TextAlign::Left, "align_left", &words.left),
|
||||
(TextAlign::Center, "align_center", &words.center),
|
||||
(TextAlign::Right, "align_right", &words.right),
|
||||
(TextAlign::JustifyLeft, "align_justify", &words.justify_left),
|
||||
(TextAlign::JustifyCenter, "align_justify", &words.justify_center),
|
||||
(TextAlign::JustifyRight, "align_justify", &words.justify_right),
|
||||
(TextAlign::JustifyAll, "align_justify", &words.justify_all),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(align, icon, name)| {
|
||||
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<Toggle<ParagraphChange>> = [
|
||||
(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)| {
|
||||
Toggle::new(name, icon, Some(values.direction == Some(direction)), Box::new(move |_| ParagraphChange::Direction(direction)))
|
||||
})
|
||||
.collect();
|
||||
let aligns: Vec<Toggle<ParagraphChange>> =
|
||||
align_toggles(values, &words, vertical).into_iter().chain(justify_toggles(values, &words, point_text)).collect();
|
||||
let directions = direction_toggles(values, &words);
|
||||
|
||||
let mut edits: Vec<EditEvent<ParagraphChange>> = Vec::new();
|
||||
let shown = Stack::new().label(self.label).show(ui, |ui, _| {
|
||||
@@ -291,3 +269,55 @@ impl<'a> ParagraphControls<'a> {
|
||||
ParagraphControlsOutput { response: shown.output, edits }
|
||||
}
|
||||
}
|
||||
|
||||
/// The Left, Center and Right toggles; with `vertical` they are the Top, Middle and Bottom ones, which set the same
|
||||
/// [`TextAlign`] values.
|
||||
pub(crate) fn align_toggles(values: &ParagraphValues, words: &ParagraphWords, vertical: bool) -> Vec<Toggle<ParagraphChange>> {
|
||||
let marks: [(TextAlign, &'static str, &Label); 3] = if vertical {
|
||||
[
|
||||
(TextAlign::Left, "text_align_top", &words.top),
|
||||
(TextAlign::Center, "text_align_middle", &words.middle),
|
||||
(TextAlign::Right, "text_align_bottom", &words.bottom),
|
||||
]
|
||||
} else {
|
||||
[
|
||||
(TextAlign::Left, "align_left", &words.left),
|
||||
(TextAlign::Center, "align_center", &words.center),
|
||||
(TextAlign::Right, "align_right", &words.right),
|
||||
]
|
||||
};
|
||||
marks
|
||||
.into_iter()
|
||||
.map(|(align, icon, name)| Toggle::new(name, icon, Some(values.align == Some(align)), Box::new(move |_| ParagraphChange::Align(align))))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The four justify toggles; in point text, which has no box to fill, they are disabled.
|
||||
pub(crate) fn justify_toggles(values: &ParagraphValues, words: &ParagraphWords, point_text: bool) -> Vec<Toggle<ParagraphChange>> {
|
||||
[
|
||||
(TextAlign::JustifyLeft, &words.justify_left),
|
||||
(TextAlign::JustifyCenter, &words.justify_center),
|
||||
(TextAlign::JustifyRight, &words.justify_right),
|
||||
(TextAlign::JustifyAll, &words.justify_all),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(align, name)| {
|
||||
let toggle = Toggle::new(name, "align_justify", 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()
|
||||
}
|
||||
|
||||
/// The three direction toggles.
|
||||
pub(crate) fn direction_toggles(values: &ParagraphValues, words: &ParagraphWords) -> Vec<Toggle<ParagraphChange>> {
|
||||
[
|
||||
(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)| {
|
||||
Toggle::new(name, icon, Some(values.direction == Some(direction)), Box::new(move |_| ParagraphChange::Direction(direction)))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
use std::ops::RangeInclusive;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::ui::length::{DocUnit, length_field};
|
||||
use crate::ui::length::{DocUnit, length_field, shown};
|
||||
use craft_behavior::{EditEvent, EditEvents, IconId, Mixed, NumberCodec};
|
||||
use craft_ui::buttons::ToggleButton;
|
||||
use craft_ui::contract::{Bind, Entry, FieldLayout, GlyphLabel, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel, TooltipSpec};
|
||||
use craft_ui::contract::{
|
||||
Bind, Entry, FieldLayout, GlyphLabel, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, TooltipSpec,
|
||||
};
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::pickers::Select;
|
||||
@@ -14,47 +16,54 @@ use craft_ui::runtime::env::{Label, UnitKind, Units};
|
||||
use craft_ui::text::{NamedOr, NumberField, NumberPick};
|
||||
use egui::Ui;
|
||||
|
||||
use super::{KerningName, PRESET_DECIMALS, TRACKING_RANGE};
|
||||
#[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,
|
||||
};
|
||||
#[cfg(feature = "font-picker")]
|
||||
use craft_font_manager::picker::FontPicker;
|
||||
|
||||
/// The unit the length fields of a pattern show their numbers in.
|
||||
pub(super) struct Lengths<'u> {
|
||||
pub(super) units: &'u Units,
|
||||
pub(super) unit: DocUnit,
|
||||
pub(crate) struct Lengths<'u> {
|
||||
pub(crate) units: &'u Units,
|
||||
pub(crate) unit: DocUnit,
|
||||
}
|
||||
|
||||
/// A length field of a row: its label, side label, the mark's hint, value in points and range in points.
|
||||
pub(super) struct LengthRow<'p> {
|
||||
pub(super) label: Label,
|
||||
pub(super) side: SideLabel,
|
||||
pub(super) value: Option<f32>,
|
||||
pub(super) range: RangeInclusive<f64>,
|
||||
pub(super) presets: &'p [Entry<NumberPick>],
|
||||
/// A length field of a row: its label, side label, value in points and range in points.
|
||||
pub(crate) struct LengthRow<'p> {
|
||||
pub(crate) label: Label,
|
||||
pub(crate) side: SideLabel,
|
||||
pub(crate) value: Option<f32>,
|
||||
pub(crate) range: RangeInclusive<f64>,
|
||||
pub(crate) presets: &'p [Entry<NumberPick>],
|
||||
}
|
||||
|
||||
/// A plain number field of a row: a count, a percentage, or a value in thousandths.
|
||||
pub(super) struct PlainRow<'p> {
|
||||
pub(super) label: Label,
|
||||
pub(super) side: SideLabel,
|
||||
pub(super) value: Mixed<Option<f64>>,
|
||||
pub(super) range: RangeInclusive<f64>,
|
||||
pub(super) percent: bool,
|
||||
pub(super) presets: &'p [Entry<NumberPick>],
|
||||
pub(crate) struct PlainRow<'p> {
|
||||
pub(crate) label: Label,
|
||||
pub(crate) side: SideLabel,
|
||||
pub(crate) value: Mixed<Option<f64>>,
|
||||
pub(crate) range: RangeInclusive<f64>,
|
||||
pub(crate) percent: bool,
|
||||
pub(crate) presets: &'p [Entry<NumberPick>],
|
||||
}
|
||||
|
||||
impl Lengths<'_> {
|
||||
/// A field over a length in points, shown in the unit: its event in points and the preset row picked.
|
||||
pub(super) fn row(&self, ui: &mut Ui, spec: LengthRow<'_>) -> (EditEvents<Option<f64>>, Option<NumberPick>) {
|
||||
/// A field over a length in points, shown in the unit: its event in points and the preset row picked. The field
|
||||
/// fills its grid cell.
|
||||
pub(crate) fn row(&self, ui: &mut Ui, spec: LengthRow<'_>) -> (EditEvents<Option<f64>>, Option<NumberPick>) {
|
||||
let LengthRow { label, side, value, range, presets } = spec;
|
||||
let points = value.map_or(Mixed::Mixed, |value| Mixed::Same(Some(f64::from(value))));
|
||||
let field = Field::new(label.clone()).side(side).show(ui, |ui, _| {
|
||||
let out = length_field(self.unit, label.clone(), points, range.clone()).presets(presets).scrub_by_label().show(ui);
|
||||
let out = length_field(self.unit, label.clone(), points, range.clone()).presets(presets).scrub_by_label().sizing(Sizing::FillWidth).show(ui);
|
||||
(out.edit.events, out.preset)
|
||||
});
|
||||
field.inner.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The kerning field: a number or the name of a presets row (Metrics, Optical).
|
||||
pub(super) fn kerning(
|
||||
pub(crate) fn kerning(
|
||||
&self,
|
||||
ui: &mut Ui,
|
||||
label: Label,
|
||||
@@ -72,7 +81,7 @@ impl Lengths<'_> {
|
||||
}
|
||||
|
||||
/// A field over a number that is not a length: its event and the preset row picked.
|
||||
pub(super) fn plain(&self, ui: &mut Ui, spec: PlainRow<'_>) -> (EditEvents<Option<f64>>, Option<NumberPick>) {
|
||||
pub(crate) fn plain(&self, ui: &mut Ui, spec: PlainRow<'_>) -> (EditEvents<Option<f64>>, Option<NumberPick>) {
|
||||
let PlainRow { label, side, value, range, percent, presets } = spec;
|
||||
let units = self.units;
|
||||
let shown = Field::new(label.clone()).side(side).show(ui, |ui, _| {
|
||||
@@ -91,7 +100,7 @@ impl Lengths<'_> {
|
||||
|
||||
/// A label shown as a mark at `layout`, whose drag scrubs the field; `hint`, when given, is its tooltip in place of the
|
||||
/// label.
|
||||
pub(super) fn mark(glyph: GlyphLabel, hint: Option<Label>, layout: FieldLayout) -> SideLabel {
|
||||
pub(crate) fn mark(glyph: GlyphLabel, hint: Option<Label>, layout: FieldLayout) -> SideLabel {
|
||||
let side = SideLabel::new().kind(LabelKind::Glyph(glyph)).layout(layout).scrub(true);
|
||||
match hint {
|
||||
Some(hint) => side.tooltip(hint),
|
||||
@@ -100,22 +109,22 @@ pub(super) fn mark(glyph: GlyphLabel, hint: Option<Label>, layout: FieldLayout)
|
||||
}
|
||||
|
||||
/// The side label of a row that shows none (a select).
|
||||
pub(super) fn hidden_side() -> SideLabel {
|
||||
pub(crate) fn hidden_side() -> SideLabel {
|
||||
SideLabel::new().kind(LabelKind::Hidden)
|
||||
}
|
||||
|
||||
/// `value` as a field's value: a missing one is mixed.
|
||||
pub(super) fn mixed<T>(value: Option<T>) -> Mixed<T> {
|
||||
pub(crate) fn mixed<T>(value: Option<T>) -> Mixed<T> {
|
||||
value.map_or(Mixed::Mixed, Mixed::Same)
|
||||
}
|
||||
|
||||
/// `value` as a plain number field's value: a missing one is mixed.
|
||||
pub(super) fn plain(value: Option<f32>) -> Mixed<Option<f64>> {
|
||||
pub(crate) fn plain(value: Option<f32>) -> Mixed<Option<f64>> {
|
||||
value.map_or(Mixed::Mixed, |value| Mixed::Same(Some(f64::from(value))))
|
||||
}
|
||||
|
||||
/// A number field's event as a change; a cleared field is not one.
|
||||
pub(super) fn number_change<C>(events: EditEvents<Option<f64>>, change: impl Fn(f32) -> C) -> EditEvents<C> {
|
||||
pub(crate) fn number_change<C>(events: EditEvents<Option<f64>>, change: impl Fn(f32) -> C) -> EditEvents<C> {
|
||||
events
|
||||
.into_iter()
|
||||
.filter(|event| !matches!(event.value(), Some(None)))
|
||||
@@ -124,12 +133,12 @@ pub(super) fn number_change<C>(events: EditEvents<Option<f64>>, change: impl Fn(
|
||||
}
|
||||
|
||||
/// A menu row that is not a number, as the one-step change it makes.
|
||||
pub(super) fn picked_event<C>(change: C, name: &str) -> EditEvent<C> {
|
||||
pub(crate) fn picked_event<C>(change: C, name: &str) -> EditEvent<C> {
|
||||
EditEvent::set(Mixed::Mixed, change, Arc::from(name), None)
|
||||
}
|
||||
|
||||
/// The rows of a presets menu over groups of numbers, a separator between the groups.
|
||||
pub(super) fn number_presets<'g>(units: &Units, groups: impl Iterator<Item = &'g [f32]>) -> Vec<Entry<NumberPick>> {
|
||||
pub(crate) fn number_presets<'g>(units: &Units, groups: impl Iterator<Item = &'g [f32]>) -> Vec<Entry<NumberPick>> {
|
||||
let mut rows = Vec::new();
|
||||
for (at, group) in groups.enumerate() {
|
||||
if at > 0 {
|
||||
@@ -140,13 +149,54 @@ pub(super) fn number_presets<'g>(units: &Units, groups: impl Iterator<Item = &'g
|
||||
rows
|
||||
}
|
||||
|
||||
/// The size menu's rows: the point presets in the type unit.
|
||||
pub(crate) fn size_menu(units: &Units, unit: DocUnit) -> Vec<Entry<NumberPick>> {
|
||||
SIZE_PRESETS
|
||||
.iter()
|
||||
.map(|&p| {
|
||||
let points = f64::from(p);
|
||||
Entry::new(NumberPick::Number(points), units.text(unit.kind, shown(units, unit, points), 0..=PRESET_DECIMALS))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The leading menu's rows: the Auto row (checked while `leading` is Auto), a separator, then the size rows.
|
||||
pub(crate) fn leading_menu(words: &CharacterWords, leading: Option<Leading>, sizes: &[Entry<NumberPick>]) -> Vec<Entry<NumberPick>> {
|
||||
let auto = Entry::new(NumberPick::Choice(AUTO_ROW), words.auto.clone()).checked(leading == Some(Leading::Auto));
|
||||
[auto, Entry::separator()].into_iter().chain(sizes.iter().cloned()).collect()
|
||||
}
|
||||
|
||||
/// The leading field: a number in points, or Auto, which shows the font size times the auto-leading.
|
||||
pub(crate) fn leading_row(
|
||||
lengths: &Lengths<'_>,
|
||||
ui: &mut Ui,
|
||||
words: &CharacterWords,
|
||||
side: SideLabel,
|
||||
leading: Option<Leading>,
|
||||
size: Option<f32>,
|
||||
presets: &[Entry<NumberPick>],
|
||||
) -> Vec<EditEvent<CharacterChange>> {
|
||||
let value = match leading {
|
||||
Some(Leading::Fixed(points)) => Some(points),
|
||||
Some(Leading::Auto) => size.map(|size| size * AUTO_LEADING),
|
||||
None => None,
|
||||
};
|
||||
let row = LengthRow { label: words.leading.clone(), side, value, range: LEADING_RANGE, presets };
|
||||
let (event, picked) = lengths.row(ui, row);
|
||||
let mut edits: Vec<_> = number_change(event, |points| CharacterChange::Leading(Leading::Fixed(points))).into_iter().collect();
|
||||
if picked == Some(NumberPick::Choice(AUTO_ROW)) {
|
||||
edits.push(picked_event(CharacterChange::Leading(Leading::Auto), words.leading.as_str()));
|
||||
}
|
||||
edits
|
||||
}
|
||||
|
||||
/// Select entries over `(value, text)` pairs.
|
||||
pub(super) fn string_entries(pairs: impl Iterator<Item = (String, String)>) -> Vec<Entry<String>> {
|
||||
pub(crate) fn string_entries(pairs: impl Iterator<Item = (String, String)>) -> Vec<Entry<String>> {
|
||||
pairs.map(|(value, text)| Entry::new(value, text)).collect()
|
||||
}
|
||||
|
||||
/// A row with a select over `entries`; its pick as a change.
|
||||
pub(super) fn select_row<C>(
|
||||
pub(crate) fn select_row<C>(
|
||||
ui: &mut Ui,
|
||||
label: &Label,
|
||||
side: SideLabel,
|
||||
@@ -160,23 +210,72 @@ pub(super) 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(super) struct Toggle<C> {
|
||||
pub(super) name: Label,
|
||||
pub(super) icon: &'static str,
|
||||
pub(super) on: Option<bool>,
|
||||
pub(super) change: Box<dyn Fn(bool) -> C>,
|
||||
pub(crate) struct Toggle<C> {
|
||||
pub(crate) name: Label,
|
||||
pub(crate) icon: &'static str,
|
||||
pub(crate) on: Option<bool>,
|
||||
pub(crate) change: Box<dyn Fn(bool) -> C>,
|
||||
/// Why the button is disabled; `None` while it is enabled.
|
||||
pub(super) disabled: Option<Label>,
|
||||
pub(crate) disabled: Option<Label>,
|
||||
}
|
||||
|
||||
impl<C> Toggle<C> {
|
||||
pub(super) fn new(name: &Label, icon: &'static str, on: Option<bool>, change: Box<dyn Fn(bool) -> C>) -> Self {
|
||||
pub(crate) fn new(name: &Label, icon: &'static str, on: Option<bool>, change: Box<dyn Fn(bool) -> C>) -> Self {
|
||||
Toggle { name: name.clone(), icon, on, change, disabled: None }
|
||||
}
|
||||
|
||||
/// The button is disabled for `reason`, which its tooltip shows.
|
||||
pub(super) fn disabled(mut self, reason: &Label) -> Self {
|
||||
pub(crate) fn disabled(mut self, reason: &Label) -> Self {
|
||||
self.disabled = Some(reason.clone());
|
||||
self
|
||||
}
|
||||
@@ -184,7 +283,7 @@ impl<C> Toggle<C> {
|
||||
|
||||
/// A row of icon toggle buttons, each its own Tab stop; a clicked one reports its change. `label` names the row as a
|
||||
/// group (Alignment).
|
||||
pub(super) fn toggle_row<C>(ui: &mut Ui, label: Option<&Label>, toggles: &[Toggle<C>]) -> Vec<EditEvent<C>> {
|
||||
pub(crate) fn toggle_row<C>(ui: &mut Ui, label: Option<&Label>, toggles: &[Toggle<C>]) -> Vec<EditEvent<C>> {
|
||||
let mut edits = Vec::new();
|
||||
let row = match label {
|
||||
Some(label) => Row::new().label(label.clone()),
|
||||
|
||||
@@ -4,6 +4,8 @@ use super::{
|
||||
BaselinePosition, Caps, CharacterControls, CharacterValues, Kerning, Leading, LineSpacing, ParagraphAlign, ParagraphControls, ParagraphDialog,
|
||||
ParagraphFormat, ParagraphPreview, ParagraphValues, SpacingKind, SpecialIndent, TextAlign,
|
||||
};
|
||||
#[cfg(feature = "font-picker")]
|
||||
use super::FaceAxes;
|
||||
use craft_theme::Rgba;
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::dialog::{DialogStack, StackDialog as _};
|
||||
@@ -43,7 +45,7 @@ fn single_values(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
strikethrough: Some(false),
|
||||
opentype: vec!["liga", "frac"],
|
||||
language: Some("en-US".to_owned()),
|
||||
axes: None, // P3(panels-w13): tl.R6
|
||||
..CharacterValues::default()
|
||||
};
|
||||
let (families, styles, languages) = (families(), styles(), languages());
|
||||
CharacterControls::new("Character", &values, &families, &styles).superscript(true).languages(&languages).show(ui).into()
|
||||
@@ -71,6 +73,32 @@ fn paragraph_text(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
ParagraphControls::new("Paragraph", &values).show(ui).into()
|
||||
}
|
||||
|
||||
// No variable face ships with the stories, so the sliders have no axis to list; the state shows the slot is taken.
|
||||
#[cfg(feature = "font-picker")]
|
||||
#[story(CharacterControls<'static>, covers = [], drive = Drive::Never)]
|
||||
fn with_axes(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let values = CharacterValues {
|
||||
family: Some("Ubuntu".to_owned()),
|
||||
style: Some("Bold".to_owned()),
|
||||
axes: Some(vec![(*b"wght", 700.0)]),
|
||||
..CharacterValues::default()
|
||||
};
|
||||
let (families, styles) = (families(), styles());
|
||||
CharacterControls::new("Character", &values, &families, &styles).axes(FaceAxes::new(&[], &[])).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ParagraphControls<'static>, covers = [], drive = Drive::Never)]
|
||||
fn vertical(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let values = ParagraphValues { align: Some(TextAlign::Center), space_after: Some(6.0), ..ParagraphValues::default() };
|
||||
ParagraphControls::new("Paragraph", &values).vertical(true).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ParagraphControls<'static>, covers = [], drive = Drive::Never)]
|
||||
fn no_hyphenate(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let values = ParagraphValues { align: Some(TextAlign::Left), hyphenate: Some(true), ..ParagraphValues::default() };
|
||||
ParagraphControls::new("Paragraph", &values).hyphenate(false).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ParagraphControls<'static>, covers = [], drive = Drive::Never)]
|
||||
fn point_text(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let values = ParagraphValues { align: Some(TextAlign::Center), space_after: Some(6.0), ..ParagraphValues::default() };
|
||||
|
||||
@@ -1,25 +1,50 @@
|
||||
//! `TextStyleOptions`: the body of the Character Style and Paragraph Style options dialogs, a name and one include
|
||||
//! check with a field per row.
|
||||
|
||||
use craft_behavior::EditEvent;
|
||||
use craft_ui::contract::{NoValue, Outcome};
|
||||
use craft_behavior::{EditEvent, IconId, Mixed};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::buttons::IconButton;
|
||||
use craft_ui::choice::{Checkbox, Swatch};
|
||||
use craft_ui::contract::{
|
||||
Bind, Entry, FieldLayout, GlyphLabel, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked,
|
||||
};
|
||||
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::Label;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::text::{NumberPick, TextField};
|
||||
use egui::{Response, Ui};
|
||||
|
||||
use super::{CharacterChange, CharacterValues, ParagraphChange, ParagraphValues};
|
||||
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,
|
||||
};
|
||||
use super::{
|
||||
CharacterChange, CharacterValues, CharacterWords, ParagraphChange, ParagraphValues, ParagraphWords, SHIFT_RANGE, SIZE_RANGE, TRACKING_PRESETS,
|
||||
TRACKING_RANGE, TWO_COLUMNS, TextAlign,
|
||||
};
|
||||
use crate::ui::length::DocUnit;
|
||||
|
||||
#[cfg(feature = "font-picker")]
|
||||
use super::FontPickerSource;
|
||||
|
||||
#[cfg(feature = "screen-testing")]
|
||||
mod stories;
|
||||
|
||||
craft_ui::words! {
|
||||
/// The words of the style options editor, English by default: the three short alignment names its rows show.
|
||||
/// 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.
|
||||
#[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";
|
||||
close: "styleOptions.close" = "Close";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,11 +185,21 @@ impl Outcome for TextStyleOptionsOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// The alignment select's rows: each alignment and the key its entry carries.
|
||||
const ALIGNS: [(TextAlign, &str); 7] = [
|
||||
(TextAlign::Left, "left"),
|
||||
(TextAlign::Center, "center"),
|
||||
(TextAlign::Right, "right"),
|
||||
(TextAlign::JustifyLeft, "justify-left"),
|
||||
(TextAlign::JustifyCenter, "justify-center"),
|
||||
(TextAlign::JustifyRight, "justify-right"),
|
||||
(TextAlign::JustifyAll, "justify-all"),
|
||||
];
|
||||
|
||||
/// The options of a character or paragraph style: a name field, then one include check and field per row of `rows`.
|
||||
/// A row that is not included shows the inherited value and takes no input; every length row is in the type unit.
|
||||
#[must_use = "show the editor with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern, craft_ui::contract::Props)]
|
||||
#[allow(dead_code)] // P3(panels-w13): pn.C52
|
||||
pub struct TextStyleOptions<'a> {
|
||||
label: Label,
|
||||
values: &'a StyleOptionValues,
|
||||
@@ -212,7 +247,249 @@ impl<'a> TextStyleOptions<'a> {
|
||||
}
|
||||
|
||||
/// Shows the editor and returns the changes the user made.
|
||||
pub fn show(self, _ui: &mut Ui) -> TextStyleOptionsOutput {
|
||||
todo!("pn.C52")
|
||||
pub fn show(self, ui: &mut Ui) -> TextStyleOptionsOutput {
|
||||
let (label, values, rows) = (self.label, self.values, self.rows);
|
||||
let (families, styles, unit, renamable) = (self.families, self.styles, self.unit, self.renamable);
|
||||
#[cfg(feature = "font-picker")]
|
||||
let mut picker = self.picker;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<TextStyleOptionsWords>();
|
||||
let cw = env.words::<CharacterWords>();
|
||||
let pw = env.words::<ParagraphWords>();
|
||||
let units = env.units();
|
||||
let lengths = Lengths { units: &units, unit };
|
||||
|
||||
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()
|
||||
.map(|&(align, key)| {
|
||||
let name = match align {
|
||||
TextAlign::Left => &words.left,
|
||||
TextAlign::Center => &words.center,
|
||||
TextAlign::Right => &words.right,
|
||||
TextAlign::JustifyLeft => &pw.justify_left,
|
||||
TextAlign::JustifyCenter => &pw.justify_center,
|
||||
TextAlign::JustifyRight => &pw.justify_right,
|
||||
TextAlign::JustifyAll => &pw.justify_all,
|
||||
};
|
||||
Entry::new(key.to_owned(), name.as_str().to_owned())
|
||||
})
|
||||
.collect();
|
||||
let has_paragraph = values.paragraph.is_some();
|
||||
let paragraph = values.paragraph.clone().unwrap_or_default();
|
||||
let c = &values.character;
|
||||
|
||||
let mut edits: Vec<EditEvent<StyleOptionsChange>> = Vec::new();
|
||||
let mut requests = HostRequests::new();
|
||||
let mut closed = false;
|
||||
|
||||
let shown = Stack::new().label(label.clone()).show(ui, |ui, _| {
|
||||
Row::new().fill_width().show(ui, |ui, _| {
|
||||
Text::new(label.clone()).show(ui);
|
||||
let close = IconButton::new(IconId::new("close")).label(words.close.clone()).show(ui);
|
||||
closed = clicked(&close);
|
||||
});
|
||||
let renamed = Field::new(words.name.clone())
|
||||
.show(ui, |ui, _| TextField::new(words.name.clone(), Bind::given(values.name.clone())).enabled(renamable).show(ui).events);
|
||||
edits.extend(renamed.inner.unwrap_or_default().map(StyleOptionsChange::Rename));
|
||||
|
||||
for &attribute in rows {
|
||||
if !has_paragraph && StyleAttribute::PARAGRAPH.contains(&attribute) {
|
||||
continue;
|
||||
}
|
||||
let on = values.includes(attribute);
|
||||
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());
|
||||
#[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())]));
|
||||
}
|
||||
found.extend(character(select_row(
|
||||
ui,
|
||||
&cw.style,
|
||||
hidden_side(),
|
||||
mixed(c.style.clone()),
|
||||
&style_entries,
|
||||
CharacterChange::Style,
|
||||
)));
|
||||
found
|
||||
}),
|
||||
StyleAttribute::Size => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let row = LengthRow { label: cw.size.clone(), side: text_side(&cw.size), value: c.size, range: SIZE_RANGE, presets: &size_presets };
|
||||
let (event, _) = lengths.row(ui, row);
|
||||
character(number_change(event, CharacterChange::Size))
|
||||
}),
|
||||
StyleAttribute::Leading => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
character(leading_row(&lengths, ui, &cw, text_side(&cw.leading), c.leading, c.size, &leading_presets))
|
||||
}),
|
||||
StyleAttribute::Tracking => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let row = PlainRow {
|
||||
label: cw.tracking.clone(),
|
||||
side: text_side(&cw.tracking),
|
||||
value: plain(c.tracking),
|
||||
range: TRACKING_RANGE,
|
||||
percent: false,
|
||||
presets: &tracking_presets,
|
||||
};
|
||||
let (event, _) = lengths.plain(ui, row);
|
||||
character(number_change(event, CharacterChange::Tracking))
|
||||
}),
|
||||
StyleAttribute::BaselineShift => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let row = LengthRow {
|
||||
label: cw.baseline_shift.clone(),
|
||||
side: text_side(&cw.baseline_shift),
|
||||
value: c.baseline_shift,
|
||||
range: SHIFT_RANGE,
|
||||
presets: &[],
|
||||
};
|
||||
let (event, _) = lengths.row(ui, row);
|
||||
character(number_change(event, CharacterChange::BaselineShift))
|
||||
}),
|
||||
StyleAttribute::Color => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let color = mixed(c.color.map(Srgba::from));
|
||||
let well = Field::new(cw.text_color.clone()).side(hidden_side()).show(ui, |ui, _| {
|
||||
Swatch::new(cw.text_color.clone(), color).picker(STYLE_COLOR_KEY).sizing(Sizing::FillWidth).show(ui).pick_color
|
||||
});
|
||||
if let Some(request) = well.inner.flatten() {
|
||||
requests.request_color(request);
|
||||
}
|
||||
Vec::new()
|
||||
}),
|
||||
StyleAttribute::FauxBold => {
|
||||
include_row(ui, &words.include, attribute, on, |ui| toggle_field(ui, &cw.faux_bold, "text_bold", c.faux_bold, CharacterChange::FauxBold))
|
||||
}
|
||||
StyleAttribute::FauxItalic => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
toggle_field(ui, &cw.faux_italic, "text_italic", c.faux_italic, CharacterChange::FauxItalic)
|
||||
}),
|
||||
StyleAttribute::Underline => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
toggle_field(ui, &cw.underline, "text_underline", c.underline, CharacterChange::Underline)
|
||||
}),
|
||||
StyleAttribute::Strikethrough => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
toggle_field(ui, &cw.strikethrough, "text_strikethrough", c.strikethrough, CharacterChange::Strikethrough)
|
||||
}),
|
||||
StyleAttribute::Align => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let key = paragraph.align.and_then(|align| ALIGNS.iter().find(|(a, _)| *a == align)).map(|(_, key)| (*key).to_owned());
|
||||
// The entries come from ALIGNS, so every key is found.
|
||||
let align_of = |key: String| {
|
||||
ParagraphChange::Align(ALIGNS.iter().find(|(_, k)| *k == key).map_or_else(TextAlign::default, |(align, _)| *align))
|
||||
};
|
||||
paragraph_changes(select_row(ui, &pw.alignment, hidden_side(), mixed(key), &align_entries, align_of))
|
||||
}),
|
||||
StyleAttribute::FirstLineIndent => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let row = LengthRow {
|
||||
label: pw.first_line_indent.clone(),
|
||||
side: text_side(&pw.first_line_indent),
|
||||
value: paragraph.first_line_indent,
|
||||
range: INDENT_RANGE,
|
||||
presets: &[],
|
||||
};
|
||||
let (event, _) = lengths.row(ui, row);
|
||||
paragraph_changes(number_change(event, ParagraphChange::FirstLineIndent))
|
||||
}),
|
||||
StyleAttribute::StartIndent => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let row = LengthRow {
|
||||
label: pw.start_indent.clone(),
|
||||
side: text_side(&pw.start_indent),
|
||||
value: paragraph.start_indent,
|
||||
range: INDENT_RANGE,
|
||||
presets: &[],
|
||||
};
|
||||
let (event, _) = lengths.row(ui, row);
|
||||
paragraph_changes(number_change(event, ParagraphChange::StartIndent))
|
||||
}),
|
||||
StyleAttribute::EndIndent => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let row = LengthRow {
|
||||
label: pw.end_indent.clone(),
|
||||
side: text_side(&pw.end_indent),
|
||||
value: paragraph.end_indent,
|
||||
range: INDENT_RANGE,
|
||||
presets: &[],
|
||||
};
|
||||
let (event, _) = lengths.row(ui, row);
|
||||
paragraph_changes(number_change(event, ParagraphChange::EndIndent))
|
||||
}),
|
||||
StyleAttribute::SpaceBefore => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let row = LengthRow {
|
||||
label: pw.space_before.clone(),
|
||||
side: text_side(&pw.space_before),
|
||||
value: paragraph.space_before,
|
||||
range: SPACE_RANGE,
|
||||
presets: &[],
|
||||
};
|
||||
let (event, _) = lengths.row(ui, row);
|
||||
paragraph_changes(number_change(event, ParagraphChange::SpaceBefore))
|
||||
}),
|
||||
StyleAttribute::SpaceAfter => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let row = LengthRow {
|
||||
label: pw.space_after.clone(),
|
||||
side: text_side(&pw.space_after),
|
||||
value: paragraph.space_after,
|
||||
range: SPACE_RANGE,
|
||||
presets: &[],
|
||||
};
|
||||
let (event, _) = lengths.row(ui, row);
|
||||
paragraph_changes(number_change(event, ParagraphChange::SpaceAfter))
|
||||
}),
|
||||
StyleAttribute::Hyphenate => include_row(ui, &words.include, attribute, on, |ui| {
|
||||
let out = Checkbox::new(Bind::given(mixed(paragraph.hyphenate))).label(pw.hyphenate.clone()).show(ui);
|
||||
paragraph_changes(out.events.map(ParagraphChange::Hyphenate))
|
||||
}),
|
||||
};
|
||||
edits.extend(found);
|
||||
}
|
||||
});
|
||||
TextStyleOptionsOutput { response: shown.output, edits, requests, closed }
|
||||
}
|
||||
}
|
||||
|
||||
/// A row's side label: its name as text beside the field.
|
||||
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.
|
||||
fn include_row(
|
||||
ui: &mut Ui,
|
||||
include: &Label,
|
||||
attribute: StyleAttribute,
|
||||
on: bool,
|
||||
field: impl FnOnce(&mut Ui) -> Vec<EditEvent<StyleOptionsChange>>,
|
||||
) -> Vec<EditEvent<StyleOptionsChange>> {
|
||||
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);
|
||||
found.extend(check.inner.unwrap_or_default().map(move |on| StyleOptionsChange::Include { attribute, on }));
|
||||
Stack::new().enabled(on).show(ui, |ui, _| found.extend(field(ui)));
|
||||
});
|
||||
found
|
||||
}
|
||||
|
||||
/// A single toggle button as a row's field.
|
||||
fn toggle_field(
|
||||
ui: &mut Ui,
|
||||
name: &Label,
|
||||
icon: &'static str,
|
||||
on: Option<bool>,
|
||||
change: fn(bool) -> CharacterChange,
|
||||
) -> Vec<EditEvent<StyleOptionsChange>> {
|
||||
character(toggle_row(ui, None, &[Toggle::new(name, icon, on, Box::new(change))]))
|
||||
}
|
||||
|
||||
/// Character edits as the editor's changes.
|
||||
fn character(events: impl IntoIterator<Item = EditEvent<CharacterChange>>) -> Vec<EditEvent<StyleOptionsChange>> {
|
||||
events.into_iter().map(|event| event.map(StyleOptionsChange::Character)).collect()
|
||||
}
|
||||
|
||||
/// Paragraph edits as the editor's changes.
|
||||
fn paragraph_changes(events: impl IntoIterator<Item = EditEvent<ParagraphChange>>) -> Vec<EditEvent<StyleOptionsChange>> {
|
||||
events.into_iter().map(|event| event.map(StyleOptionsChange::Paragraph)).collect()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
//! Stories of `TextStyleOptions`: a character style with some rows included, a paragraph style and the Basic Paragraph.
|
||||
|
||||
use super::{StyleAttribute, StyleOptionValues, TextStyleOptions};
|
||||
use crate::ui::character::{CharacterValues, Kerning, Leading, ParagraphValues, TextAlign};
|
||||
use craft_theme::Rgba;
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
fn families() -> Vec<String> {
|
||||
["Hack", "Ubuntu", "Noto Serif"].map(str::to_owned).to_vec()
|
||||
}
|
||||
|
||||
fn styles() -> Vec<String> {
|
||||
["Regular", "Bold", "Italic"].map(str::to_owned).to_vec()
|
||||
}
|
||||
|
||||
fn character_values() -> CharacterValues {
|
||||
CharacterValues {
|
||||
family: Some("Ubuntu".to_owned()),
|
||||
style: Some("Bold".to_owned()),
|
||||
size: Some(24.0),
|
||||
leading: Some(Leading::Auto),
|
||||
kerning: Some(Kerning::Metrics),
|
||||
tracking: Some(25.0),
|
||||
baseline_shift: Some(0.0),
|
||||
color: Some(Rgba([200, 60, 40, 255])),
|
||||
faux_bold: Some(false),
|
||||
faux_italic: Some(true),
|
||||
underline: Some(false),
|
||||
strikethrough: Some(false),
|
||||
..CharacterValues::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn paragraph_values() -> ParagraphValues {
|
||||
ParagraphValues {
|
||||
align: Some(TextAlign::JustifyLeft),
|
||||
first_line_indent: Some(12.0),
|
||||
start_indent: Some(0.0),
|
||||
end_indent: Some(0.0),
|
||||
space_before: Some(0.0),
|
||||
space_after: Some(6.0),
|
||||
hyphenate: Some(true),
|
||||
..ParagraphValues::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[story(TextStyleOptions<'static>, covers = [], drive = Drive::Never)]
|
||||
fn character_style_with_some_rows_included(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let mut values = StyleOptionValues::new("Emphasis", character_values());
|
||||
values.included = vec![StyleAttribute::Font, StyleAttribute::Size, StyleAttribute::Color];
|
||||
let (families, styles) = (families(), styles());
|
||||
TextStyleOptions::new("Character Style Options", &values, &StyleAttribute::CHARACTER, &families, &styles).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(TextStyleOptions<'static>, covers = [], drive = Drive::Never)]
|
||||
fn paragraph_style(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let mut values = StyleOptionValues::new("Heading", character_values());
|
||||
values.paragraph = Some(paragraph_values());
|
||||
values.included = vec![StyleAttribute::Align, StyleAttribute::SpaceAfter, StyleAttribute::Hyphenate];
|
||||
let rows: Vec<StyleAttribute> = StyleAttribute::PARAGRAPH.to_vec();
|
||||
let (families, styles) = (families(), styles());
|
||||
TextStyleOptions::new("Paragraph Style Options", &values, &rows, &families, &styles).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(TextStyleOptions<'static>, covers = [], drive = Drive::Never)]
|
||||
fn basic_paragraph_not_renamable(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let mut values = StyleOptionValues::new("Basic Paragraph", character_values());
|
||||
values.paragraph = Some(paragraph_values());
|
||||
values.included = StyleAttribute::PARAGRAPH.to_vec();
|
||||
let rows: Vec<StyleAttribute> = StyleAttribute::PARAGRAPH.to_vec();
|
||||
let (families, styles) = (families(), styles());
|
||||
TextStyleOptions::new("Paragraph Style Options", &values, &rows, &families, &styles).renamable(false).show(ui).into()
|
||||
}
|
||||
@@ -39,6 +39,7 @@ use craft_ui::style::SurfaceKind;
|
||||
use craft_ui::text::TextField;
|
||||
use egui::{Context, Response, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
#[cfg(feature = "screen-testing")]
|
||||
mod stories;
|
||||
@@ -72,8 +73,8 @@ enum Press {
|
||||
Change,
|
||||
ChangeAll,
|
||||
Add,
|
||||
/// Check All Layers changed.
|
||||
Relist,
|
||||
/// Check All Layers changed to this.
|
||||
Relist(bool),
|
||||
}
|
||||
|
||||
/// The user's dictionary, saved under `[spelling]`. Words are kept as added; read them through
|
||||
@@ -168,7 +169,9 @@ impl Outcome for SpellingOutput {
|
||||
/// - Enter is Done unless Change To has focus; Escape and the close action are Done too (nothing to undo: every
|
||||
/// change was made as it was asked for). Tab walks Change To, the suggestions (one stop, arrows inside), the check
|
||||
/// box and the buttons.
|
||||
/// - Result: `()`; the dialog always ends with [`DialogResult::Ok`] or, closed from outside, `Cancel`.
|
||||
/// - Result: `()`; every close from inside (Done, Escape, the close action, automation's confirm) is
|
||||
/// [`DialogResult::Ok`], and a close from outside is `Cancel`.
|
||||
/// - Automation fields: `word` and `count` (read only), `changeTo` and `allLayers`.
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui::contract::Pattern)]
|
||||
pub struct CheckSpellingDialog {
|
||||
items: Vec<SpellingItem>,
|
||||
@@ -219,6 +222,16 @@ impl CheckSpellingDialog {
|
||||
self.all_layers
|
||||
}
|
||||
|
||||
/// Sets Check All Layers to `on`. A change starts the list again and asks the app to find the misspellings anew;
|
||||
/// the check box and automation both come here.
|
||||
fn relist_all_layers(&mut self, on: bool) {
|
||||
if self.all_layers != on {
|
||||
self.all_layers = on;
|
||||
self.index = 0;
|
||||
self.action = Some(SpellingAction::Relist);
|
||||
}
|
||||
}
|
||||
|
||||
/// The words Ignore All added during this check, for the app's next search to skip.
|
||||
pub fn ignored(&self) -> &[String] {
|
||||
&self.ignored
|
||||
@@ -278,10 +291,10 @@ impl CheckSpellingDialog {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let before = *all_layers;
|
||||
Checkbox::new(Bind::bound(&mut *all_layers)).label(words.all_layers.clone()).show(ui);
|
||||
if *all_layers != before {
|
||||
body_press.set(Some(Press::Relist));
|
||||
let mut checked = *all_layers;
|
||||
Checkbox::new(Bind::bound(&mut checked)).label(words.all_layers.clone()).show(ui);
|
||||
if checked != *all_layers {
|
||||
body_press.set(Some(Press::Relist(checked)));
|
||||
}
|
||||
if !has_item {
|
||||
Notice::new(Tone::Neutral, words.complete.clone()).layout(NoticeLayout::Centred).show(ui);
|
||||
@@ -316,10 +329,7 @@ impl CheckSpellingDialog {
|
||||
self.action = Some(SpellingAction::Add(item.word));
|
||||
}
|
||||
}
|
||||
Some(Press::Relist) => {
|
||||
self.index = 0;
|
||||
self.action = Some(SpellingAction::Relist);
|
||||
}
|
||||
Some(Press::Relist(on)) => self.relist_all_layers(on),
|
||||
None => {}
|
||||
}
|
||||
SpellingOutput { response, closed }
|
||||
@@ -338,15 +348,32 @@ impl StackDialog for CheckSpellingDialog {
|
||||
shown.closed.map(|_| DialogResult::Ok(()))
|
||||
}
|
||||
|
||||
fn json_fields(&self) -> Option<serde_json::Value> {
|
||||
todo!("pn.C54")
|
||||
fn json_fields(&self) -> Option<Value> {
|
||||
let word = self.items.get(self.index).map(|item| item.word.as_str());
|
||||
Some(json!({ "word": word, "changeTo": self.change_to, "allLayers": self.all_layers, "count": self.items.len() }))
|
||||
}
|
||||
|
||||
fn set_json_field(&mut self, _: &Context, _field: &str, _value: serde_json::Value) -> Result<(), String> {
|
||||
todo!("pn.C54")
|
||||
fn set_json_field(&mut self, _: &Context, field: &str, value: Value) -> Result<(), String> {
|
||||
match field {
|
||||
"changeTo" => {
|
||||
if self.items.is_empty() {
|
||||
return Err("`changeTo` takes no input: the list of misspellings is empty".to_owned());
|
||||
}
|
||||
let text = value.as_str().ok_or_else(|| "`changeTo` takes a string".to_owned())?;
|
||||
self.change_to = text.to_owned();
|
||||
Ok(())
|
||||
}
|
||||
"allLayers" => {
|
||||
let on = value.as_bool().ok_or_else(|| "`allLayers` takes true or false".to_owned())?;
|
||||
self.relist_all_layers(on);
|
||||
Ok(())
|
||||
}
|
||||
"word" | "count" => Err(format!("`{field}` is read only")),
|
||||
_ => Err(format!("unknown field `{field}`: this dialog has `word`, `changeTo`, `allLayers` and `count`")),
|
||||
}
|
||||
}
|
||||
|
||||
fn confirm(&mut self, _: &Context) -> Option<()> {
|
||||
todo!("pn.C54")
|
||||
Some(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,6 @@ pub struct TextStylesPanel<'a> {
|
||||
/// Several rows select together: the footer's Duplicate and Delete act on all of them.
|
||||
#[prop]
|
||||
highlighting: bool,
|
||||
#[allow(dead_code)] // P3(panels-w13): pn.C55
|
||||
empty: Option<Label>,
|
||||
}
|
||||
|
||||
@@ -306,7 +305,7 @@ impl<'a> TextStylesPanel<'a> {
|
||||
|
||||
/// Shows the panel and returns what the user asked for.
|
||||
pub fn show(self, ui: &mut Ui) -> TextStylesPanelOutput {
|
||||
let TextStylesPanel { label, kind, rows, mut selection, current, overridden, target, text_selected, highlighting, empty: _ } = self;
|
||||
let TextStylesPanel { label, kind, rows, mut selection, current, overridden, target, text_selected, highlighting, empty } = self;
|
||||
let words = Env::of(ui).words::<TextStylesWords>();
|
||||
let paragraph = kind == TextStyleKind::Paragraph;
|
||||
let action = Cell::new(None::<TextStyleAction>);
|
||||
@@ -383,7 +382,7 @@ impl<'a> TextStylesPanel<'a> {
|
||||
|
||||
let source = keyed(rows, |row: &TextStyleRow| row.id);
|
||||
let mode = if highlighting { SelectMode::Multi } else { SelectMode::Single };
|
||||
let shown_rows = List::new(label.clone())
|
||||
let list = List::new(label.clone())
|
||||
.id(list_id)
|
||||
.select(mode)
|
||||
.activate(ActivateOn::Click)
|
||||
@@ -392,8 +391,12 @@ impl<'a> TextStylesPanel<'a> {
|
||||
.max_rows(8)
|
||||
.can_drag(move |_| highlighting)
|
||||
.drag_payload(|drag: &ListDrag<u64>| Some(drag.clone()))
|
||||
.selection(selection.reborrowed())
|
||||
.show_items(ui, &source, &mut |id, _| {
|
||||
.selection(selection.reborrowed());
|
||||
let list = match &empty {
|
||||
Some(text) => list.empty(text.clone()),
|
||||
None => list,
|
||||
};
|
||||
let shown_rows = list.show_items(ui, &source, &mut |id, _| {
|
||||
let Some(row) = rows.iter().find(|row| row.id == *id) else { return ListRow::new(Label::Empty) };
|
||||
let is_current = target && current == Some(*id);
|
||||
let marked = is_current && overridden;
|
||||
|
||||
@@ -38,6 +38,13 @@ fn character_styles_with_highlighted_rows(ui: &mut Ui, data: &mut StoryData) ->
|
||||
.into()
|
||||
}
|
||||
|
||||
#[story(TextStylesPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
fn no_rows_with_empty_text(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rows: Vec<TextStyleRow> = Vec::new();
|
||||
let selection = data.value("empty", Selection::<u64>::default());
|
||||
TextStylesPanel::new("Character Styles", TextStyleKind::Character, &rows, Bind::bound(selection)).empty("No document").show(ui).into()
|
||||
}
|
||||
|
||||
fn picker_styles() -> Vec<NamedStyleRow> {
|
||||
vec![
|
||||
NamedStyleRow::new(1, "Primary", StylePreview::Icon(IconId::new("palette"))).meta("#1473E6"),
|
||||
|
||||
@@ -4,5 +4,8 @@
|
||||
|
||||
mod editor;
|
||||
mod notes;
|
||||
mod path_text;
|
||||
mod ruler;
|
||||
mod style_options;
|
||||
mod style_panel;
|
||||
mod tabs;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
//! The style options editor: a row left out of the style takes no input, and its check includes it.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use craft_behavior::EditEvent;
|
||||
use craft_text::ui::character::{CharacterValues, StyleAttribute, StyleOptionValues, StyleOptionsChange, TextStyleOptions};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
/// The changes the edits carry, in order.
|
||||
fn changes(edits: &RefCell<Vec<EditEvent<StyleOptionsChange>>>) -> Vec<StyleOptionsChange> {
|
||||
edits.borrow().iter().filter_map(|edit| edit.value().cloned()).collect()
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_row_left_out_of_the_style_takes_no_input_and_its_check_includes_it() {
|
||||
let mut character = CharacterValues::default();
|
||||
character.size = Some(12.0);
|
||||
let values = StyleOptionValues::new("Emphasis", character);
|
||||
let edits = Rc::new(RefCell::new(Vec::new()));
|
||||
let sink = edits.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let out = TextStyleOptions::new("Style Options", &values, &[StyleAttribute::Size], &[], &[]).show(ui);
|
||||
sink.borrow_mut().extend(out.edits);
|
||||
});
|
||||
fixture.idle(10);
|
||||
|
||||
let size = fixture.by_label("Font size").expect("the Size field is shown");
|
||||
fixture.click(&size).idle(2);
|
||||
fixture.type_text("20");
|
||||
fixture.key(Key::Enter, Modifiers::NONE);
|
||||
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");
|
||||
fixture.click(&include).idle(4);
|
||||
assert_eq!(
|
||||
changes(&edits),
|
||||
vec![StyleOptionsChange::Include { attribute: StyleAttribute::Size, on: true }],
|
||||
"the check of a row that is not included includes it"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//! The styles panel's click rules: a click applies, Alt-click clears overrides, a double click opens Options, except on
|
||||
//! the character style None.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use craft_behavior::Selection;
|
||||
use craft_text::ui::style_panel::{TextStyleAction, TextStyleKind, TextStyleRow, TextStylesPanel};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::Modifiers;
|
||||
|
||||
#[trial]
|
||||
fn a_click_applies_alt_clears_overrides_and_a_double_click_opens_options_except_on_none() {
|
||||
let state = Rc::new(RefCell::new((Selection::<u64>::default(), Vec::<TextStyleAction>::new())));
|
||||
let shared = state.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let rows = [TextStyleRow::new(0, "None"), TextStyleRow::new(1, "Emphasis"), TextStyleRow::new(2, "Strong")];
|
||||
let mut guard = shared.borrow_mut();
|
||||
let (selection, actions) = &mut *guard;
|
||||
let out = TextStylesPanel::new("Character Styles", TextStyleKind::Character, &rows, Bind::bound(selection)).target(true).show(ui);
|
||||
actions.extend(out.action);
|
||||
});
|
||||
fixture.idle(10);
|
||||
let taken = |state: &Rc<RefCell<(Selection<u64>, Vec<TextStyleAction>)>>| std::mem::take(&mut state.borrow_mut().1);
|
||||
|
||||
let emphasis = fixture.by_label("Emphasis").expect("the Emphasis row is shown");
|
||||
fixture.click(&emphasis).idle(4);
|
||||
assert_eq!(taken(&state), vec![TextStyleAction::apply(1, false)], "a click applies the style");
|
||||
|
||||
let strong = fixture.by_label("Strong").expect("the Strong row is shown");
|
||||
fixture.hold(Modifiers::ALT);
|
||||
fixture.click(&strong).idle(4);
|
||||
fixture.hold(Modifiers::NONE);
|
||||
assert_eq!(taken(&state), vec![TextStyleAction::apply(2, true)], "an Alt-click applies and clears the overrides");
|
||||
|
||||
fixture.click(&strong).click(&strong).idle(4);
|
||||
assert!(taken(&state).contains(&TextStyleAction::Options(2)), "a double click opens Style Options");
|
||||
|
||||
let none = fixture.by_label("None").expect("the None row is shown");
|
||||
fixture.click(&none).click(&none).idle(4);
|
||||
assert!(!taken(&state).contains(&TextStyleAction::Options(0)), "a double click on None opens nothing");
|
||||
}
|
||||
@@ -159,7 +159,7 @@ note = "Words come from the scope."
|
||||
[[setter]]
|
||||
type = "CharacterControls"
|
||||
old = "font_picker(&Arc<Catalog>, &mut FontPickerSettings, &mut FontFilters)"
|
||||
new = "font_picker(&Arc<Catalog>, Bind<FontPickerSettings>, Bind<FontFilters>)"
|
||||
new = "font_picker(FontPickerSource)"
|
||||
note = "Behind feature `font-picker`. The picker records a pick as recent itself."
|
||||
|
||||
[[setter]]
|
||||
|
||||
@@ -29,7 +29,7 @@ name = "TextEditorResponse"
|
||||
old = "craft_text::ui::editor::TextEditorResponse"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "Replaced by `TextEditorOutput` (response, changed, selection_changed, edit)."
|
||||
note = "Replaced by `TextEditorOutput` (response, changed, selection_changed, edit, character_panel)."
|
||||
|
||||
[[type]]
|
||||
name = "TextEditorOutput"
|
||||
|
||||
Reference in New Issue
Block a user