Merge branch 'rework-dialogs-b' into rework-dialogs

This commit is contained in:
aiongg committed 2026-11-21 02:18:12 +00:00
commit b56b17f63e
12 files changed
+147 -54

No files matched your search

+4 -4
View File
@@ -97,10 +97,10 @@ pub use theme::{
pub use token_group::{GroupValues, TokenGroup};
pub use tokens::{
AccentColors, BarSizes, CaptionColors, ColorToken, ColorTokens, ControlSizes, DataColors, DialogSizes, DockColumnSizes, Edge, EdgeColors,
ElevationTokens, FloatSizes, FontSlot, Gaps, HandleSizes, HitSizes, IconSizes, Insets, KnobShape, LengthSizes, LineColors, Motion, MotionTokens,
OverlayColors, Pads, PaneSizes, PlotSizes, RadiusSet, RailSizes, RampSizes, RowSizes, ShapeTokens, SizeTokens, SpaceTokens, StateColors, Status,
StatusColors, StatusKind, StrokeTokens, SurfaceColors, TextColors, ThumbSamples, ThumbSizes, Tokens, TypeRole, TypeStyle, TypeTokens, WellShape,
WindowSizes,
ElevationTokens, FloatSizes, FontSlot, Gaps, HandleSizes, HitSizes, IconSizes, Insets, KnobShape, LengthSizes, LetterCase, LineColors, Motion,
MotionTokens, OverlayColors, Pads, PaneSizes, PlotSizes, RadiusSet, RailSizes, RampSizes, RowSizes, ShapeTokens, SizeTokens, SpaceTokens,
StateColors, Status, StatusColors, StatusKind, StrokeTokens, SurfaceColors, TextColors, ThumbSamples, ThumbSizes, Tokens, TypeRole, TypeStyle,
TypeTokens, WellShape, WindowSizes,
};
pub use values::ColorSource;
pub use variant::{CustomVariant, Emphasis, RadiusStep, Variant, VariantLook};
+23 -1
View File
@@ -30,6 +30,8 @@ pub struct TypeStyle {
pub enum TypeRole {
/// Small print, badges.
Caption,
/// A heading over a group of fields or cards: the caption's size and font, set in capitals.
SectionCaption,
/// Control labels.
Label,
/// Body text.
@@ -48,6 +50,26 @@ pub enum TypeRole {
Display,
}
/// How a type role sets its letters.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum LetterCase {
/// As written.
#[default]
AsWritten,
/// In capitals; the stored text stays as written.
Upper,
}
impl TypeRole {
/// How the role sets its letters.
pub fn letter_case(self) -> LetterCase {
match self {
TypeRole::SectionCaption => LetterCase::Upper,
_ => LetterCase::AsWritten,
}
}
}
/// Every type role.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct TypeTokens {
@@ -75,7 +97,7 @@ impl TypeTokens {
/// The style of `role`.
pub fn get(&self, role: TypeRole) -> TypeStyle {
match role {
TypeRole::Caption => self.caption,
TypeRole::Caption | TypeRole::SectionCaption => self.caption,
TypeRole::Label => self.label,
TypeRole::Body => self.body,
TypeRole::BodyStrong => self.body_strong,
+6 -1
View File
@@ -5,7 +5,7 @@ use crate::runtime::egui::memory;
use crate::runtime::egui::text_layout;
pub use crate::style::Span;
use crate::style::text_measure::{paragraph_job, span_format};
use crate::style::{StyleColor, TypeRole, UiTokens};
use crate::style::{LetterCase, StyleColor, TypeRole, UiTokens};
use craft_i18n::Direction;
use egui::epaint::text::FontCacheRevision;
use egui::text::{LayoutJob, TextWrapping};
@@ -118,6 +118,11 @@ impl<'a> TextRun<'a> {
/// Sets the type role.
pub fn role(mut self, role: TypeRole) -> Self {
self.role = role;
if role.letter_case() == LetterCase::Upper {
for span in &mut self.spans {
span.text = Cow::Owned(span.text.to_uppercase());
}
}
self
}
+1
View File
@@ -18,6 +18,7 @@ pub use cache::{Accepted, accepted_variant};
pub use craft_behavior::{ControlMetrics, Insets, Metrics};
#[doc(hidden)]
pub use craft_theme::GroupValues;
pub use craft_theme::LetterCase;
pub use craft_theme::{FlagMask, Flags, Mix, Resolve, State, StateMix, Stateful, States, TokenGroup, Tokens, TypeRole, Variant};
pub use craft_ui_macros::{ComponentStyle, TokenGroup};
pub(crate) use cx::control_metrics;
@@ -388,7 +388,7 @@ const MIN_SIDE: f64 = 1.0;
impl ExportOptions {
/// The options as the controls can hold them for a document of size `source`: a format the list has (the first
/// when not), a resample method of `methods` (the first when not; any method when `methods` is empty), a quality
/// when not), a resample method of `methods` (Automatic when listed, else the first; any method when `methods` is empty), a quality
/// of 1 to 100, and a size the document can take. A linked pixel width keeps its width and
/// takes the height from this document (the last export's proportions would stretch another shape); unlinked
/// pixels stay as asked when in range; anything out of range becomes 100 percent.
@@ -399,10 +399,8 @@ impl ExportOptions {
{
self.format = first.id.to_owned();
}
if let Some(first) = Resample::ALL.iter().find(|method| methods.contains(method))
&& !methods.contains(&self.resample)
{
self.resample = *first;
if !methods.is_empty() && !methods.contains(&self.resample) {
self.resample = if methods.contains(&default_resample()) { default_resample() } else { methods[0] };
}
self.quality = self.quality.clamp(*QUALITY.start(), *QUALITY.end());
let in_range = |side: u32| (MIN_SIDE..=MAX_DOCUMENT_SIDE).contains(&f64::from(side));
@@ -140,8 +140,8 @@ pub struct ExportAsDialog<'a> {
/// The formats the list offers.
#[prop(into)]
formats: Vec<ExportFormat>,
/// The resample methods the list offers, in the order of [`Resample::ALL`]; all of them when empty. A method the
/// list lacks, remembered or from a preset, opens as the first listed one.
/// The resample methods the list offers, in the order given; all of them when empty. A method the list lacks,
/// remembered or from a preset, opens as Automatic when listed, else as the first listed one.
#[prop]
methods: Vec<Resample>,
/// The dialog's title in place of "Export As" ("Export As: Layer 1").
@@ -451,7 +451,7 @@ impl HostedExportAs {
self
}
/// The resample methods the list offers, in the order of [`Resample::ALL`]; all of them when empty
/// The resample methods the list offers, in the order given; all of them when empty
/// ([`ExportAsDialog::methods`]).
#[must_use]
pub fn methods(mut self, methods: Vec<Resample>) -> Self {
@@ -8,7 +8,7 @@ use crate::display::{Shade, Text};
use crate::list::{List, ListRow, ThumbAspect};
use crate::patterns::presets::PresetId;
use crate::primitives::{ContentPainterCx, StrokeWidth};
use crate::runtime::env::{Env, Label, UnitKind};
use crate::runtime::env::{Label, UnitKind};
use crate::style::TypeRole;
use crate::tabs::{Tab, TabKind, TabStrip};
use crate::tile_grid::{Tile, TileGrid};
@@ -171,7 +171,7 @@ pub(super) fn show(ui: &mut Ui, session: &Session, values: &DocumentOptions, rea
} else {
let count = read.units.number(cards.len() as f64, 0..=0);
let heading = Label::from(words.presets_heading.fill(&[("n", &count)]));
Text::new(Env::of(ui).view().resolve(&heading).as_str().to_uppercase()).role(TypeRole::Caption).shade(Shade::Muted).show(ui);
Text::new(heading).role(TypeRole::SectionCaption).shade(Shade::Muted).show(ui);
let shown = TileGrid::<usize>::new(words.cards.clone())
.card_columns(CARD_COLUMNS)
.card()
@@ -123,16 +123,28 @@ pub(super) fn show(ui: &mut Ui, session: &mut Session, values: &mut DocumentOpti
PIXEL_ASPECTS.iter().map(|(id, _)| Entry::new((*id).to_owned(), pixel_aspect_label(words, id).clone())).collect();
pixel_aspects.extend(setup.custom_pixel_aspects.iter().map(|(id, name)| Entry::new(id.clone(), name.clone())));
Text::new(Env::of(ui).view().resolve(&words.preset_details).as_str().to_uppercase()).role(TypeRole::Caption).shade(Shade::Muted).show(ui);
Text::new(words.preset_details.clone()).role(TypeRole::SectionCaption).shade(Shade::Muted).show(ui);
FieldGroup::new(words.preset_details.clone()).gap(Gap::Tight).show(ui, |ui, _| {
Field::new(words.name.clone()).layout(FieldLayout::Above).id_salt("name").show(ui, |ui, _| {
let shown = TextField::new(words.name.clone(), Bind::given(values.name.clone())).limit(MAX_NAME).select_on_focus().show(ui);
if let Some(name) = shown.value().cloned() {
values.name = name;
}
if std::mem::take(&mut session.focus_name) {
focus::request(ui.ctx(), FocusTarget::Id(shown.response.id));
}
Row::new().show(ui, |ui, _| {
let shown = TextField::new(words.name.clone(), Bind::given(values.name.clone()))
.limit(MAX_NAME)
.select_on_focus()
.sizing(Sizing::FillWidth)
.show(ui);
if let Some(name) = shown.value().cloned() {
values.name = name;
}
if std::mem::take(&mut session.focus_name) {
focus::request(ui.ctx(), FocusTarget::Id(shown.response.id));
}
let save = Button::new(words.save_preset_title.clone()).painted(words.save_preset.clone()).id_salt("save-preset").show(ui);
if clicked(&save) {
session.naming = Some(proposed_name(read));
session.name_tried = false;
session.focus_preset_name = true;
}
});
});
let dimension = |ui: &mut Ui, session: &mut Session, side: Side| {
@@ -229,22 +241,6 @@ pub(super) fn show(ui: &mut Ui, session: &mut Session, values: &mut DocumentOpti
}
});
});
Field::new(words.profile.clone()).layout(FieldLayout::Above).id_salt("profile").show(ui, |ui, _| {
let current = values.profile.clone().filter(|profile| others.contains(&profile));
let shown = Select::new(words.profile.clone(), Bind::given(current), &profiles).sizing(Sizing::FillWidth).show(ui);
if let Some(profile) = shown.value().cloned() {
values.profile = profile;
}
});
Field::new(words.pixel_aspect.clone()).layout(FieldLayout::Above).id_salt("pixel-aspect").show(ui, |ui, _| {
let listed = pixel_aspects.iter().any(|entry| entry.value() == Some(&values.pixel_aspect));
let current = if listed { values.pixel_aspect.clone() } else { SQUARE_PIXELS.to_owned() };
let shown = Select::new(words.pixel_aspect.clone(), Bind::given(current), &pixel_aspects).sizing(Sizing::FillWidth).show(ui);
if let Some(id) = shown.value().cloned() {
values.pixel_aspect = id;
}
});
Field::new(words.background.clone()).layout(FieldLayout::Above).id_salt("background").show(ui, |ui, _| {
Row::new().show(ui, |ui, _| {
let kind = BackgroundKind::of(values.background);
@@ -265,15 +261,23 @@ pub(super) fn show(ui: &mut Ui, session: &mut Session, values: &mut DocumentOpti
}
});
});
Field::new(words.profile.clone()).layout(FieldLayout::Above).id_salt("profile").show(ui, |ui, _| {
let current = values.profile.clone().filter(|profile| others.contains(&profile));
let shown = Select::new(words.profile.clone(), Bind::given(current), &profiles).sizing(Sizing::FillWidth).show(ui);
if let Some(profile) = shown.value().cloned() {
values.profile = profile;
}
});
Field::new(words.pixel_aspect.clone()).layout(FieldLayout::Above).id_salt("pixel-aspect").show(ui, |ui, _| {
let listed = pixel_aspects.iter().any(|entry| entry.value() == Some(&values.pixel_aspect));
let current = if listed { values.pixel_aspect.clone() } else { SQUARE_PIXELS.to_owned() };
let shown = Select::new(words.pixel_aspect.clone(), Bind::given(current), &pixel_aspects).sizing(Sizing::FillWidth).show(ui);
if let Some(id) = shown.value().cloned() {
values.pixel_aspect = id;
}
});
});
let save = Button::new(words.save_preset_title.clone()).painted(words.save_preset.clone()).id_salt("save-preset").show(ui);
if clicked(&save) {
session.naming = Some(proposed_name(read));
session.name_tried = false;
session.focus_preset_name = true;
}
let fitted = values.clone().fitted();
if fitted != *values {
*values = fitted;
@@ -138,11 +138,11 @@ impl Resample {
}
}
/// The list entries of the methods in `allowed`, in the order of [`Resample::ALL`]; all of them when `allowed` names
/// none.
/// The list entries of the methods in `allowed`, in the order given; all of them in the order of
/// [`Resample::ALL`] when `allowed` names none.
pub fn entries(words: &SizingWords, allowed: &[Resample]) -> Vec<Entry<Resample>> {
let listed = |method: &Resample| allowed.is_empty() || allowed.contains(method);
Resample::ALL.iter().copied().filter(listed).map(|method| Entry::new(method, method.label(words))).collect()
let methods = if allowed.is_empty() { &Resample::ALL[..] } else { allowed };
methods.iter().map(|&method| Entry::new(method, method.label(words))).collect()
}
}
@@ -155,7 +155,7 @@ pub struct ImageSize<'a> {
/// Binds the open state to `open`.
#[prop(name = "opened")]
open: Option<Bind<'a, bool>>,
/// The methods the list offers, in the order of [`Resample::ALL`]; all of them when empty.
/// The methods the list offers, in the order given; all of them when empty.
#[prop]
methods: Vec<Resample>,
/// The bytes one pixel of the flat image takes, for the file size readout: the mode's colour channels at the
@@ -8,6 +8,7 @@ use craft_ui::patterns::form_dialogs::{
HostedFormatOptions, JpegOptions, OutputPathRow, Resample, ScaleRow, ScaleSize, SizeEstimate,
};
use craft_ui::runtime::requests::PathRequest;
use craft_ui::testing::focus::AccessActionKind;
use craft_ui::testing::{Fixture, trial};
use egui::{Key, Modifiers, Vec2};
use std::cell::RefCell;
@@ -281,6 +282,36 @@ fn export_as_starts_from_its_remembered_options_and_stores_the_confirmed_ones()
assert_eq!(again.scale_all, jpeg.scale_all, "and their Scale All rows");
}
/// Export As lists the app's resample methods in the order it gives, and an unlisted opening method opens as Automatic
/// when listed, else as the first listed one.
#[trial]
fn export_as_lists_resample_methods_in_the_hosts_order() {
let methods = vec![Resample::Bicubic, Resample::BicubicSmoother, Resample::NearestNeighbor, Resample::PreserveDetails];
let host = Rc::new(RefCell::new(DialogHost::new()));
let shown = Rc::clone(&host);
let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui));
fixture.room(Vec2::new(1400.0, 1000.0));
let mut start = ExportOptions::default();
start.resample = Resample::Lanczos;
host.borrow_mut().open(HostedExportAs::new("Poster", document(), start).methods(methods.clone()));
fixture.idle(10);
let opened = host.borrow_mut().get_mut::<HostedExportAs>().map(|dialog| dialog.options().resample).expect("the dialog is open");
assert_eq!(opened, Resample::Bicubic, "without Automatic in the list, the first listed method opens");
let select = fixture.by_label("Resample").expect("the resample select");
fixture.access(AccessActionKind::Focus, &select).idle(2);
fixture.key(Key::Space, Modifiers::NONE).idle(3);
let mut options = fixture.by_role(Role::LIST_BOX_OPTION);
options.sort_by(|a, b| a.center().y.total_cmp(&b.center().y));
let names: Vec<String> = options.iter().map(|option| fixture.tree().name_of(option.node).expect("the option has a name").to_owned()).collect();
assert_eq!(names.len(), methods.len(), "the list offers the listed methods only");
assert_eq!(
names,
["Bicubic (smooth gradients)", "Bicubic Smoother (enlargement)", "Nearest Neighbor (hard edges)", "Preserve Details"],
"the list keeps the host's order"
);
}
/// Export As with the app's resample methods offers no other: an unlisted opening method opens as the first listed
/// one, and automation cannot set an unlisted one.
#[trial]
@@ -10,7 +10,7 @@ use egui::{Key, Modifiers, Vec2};
use std::cell::RefCell;
use std::rc::Rc;
/// Opens the Save Document Preset pane with the button below the fields, types `name` over the proposed one and saves.
/// Opens the Save Document Preset pane with the icon on the Name row, types `name` over the proposed one and saves.
fn save_preset(fixture: &mut Fixture, name: &str) {
let save = fixture.by_label("Save Document Preset").expect("the Save Document Preset button");
fixture.click(&save).idle(10);
@@ -266,5 +266,37 @@ fn the_new_document_layout_places_presets_and_details_below_the_tabs() {
assert!(recent.bottom() <= mode.top(), "tabs go above the details");
assert!((mode.top() - depth.top()).abs() < 1.0, "color mode and depth share a row");
assert!(mode.right() <= depth.left(), "depth follows color mode");
assert!(mode.bottom() <= save.top() && save.bottom() <= create.top(), "Save Preset is between the fields and the footer");
assert!(save.bottom() <= create.top(), "Save Preset is above the footer");
}
/// The fields run Name, size, Color Mode, Background Contents, then the advanced Color Profile and Pixel Aspect Ratio; the
/// save icon sits at the end of the Name row.
#[trial]
fn the_new_document_fields_run_background_before_the_advanced_ones_and_save_sits_on_the_name_row() {
let mut options = DocumentOptions::default();
let mut fixture = Fixture::new(move |ui| {
let _ = NewDocumentDialog::new(Bind::bound(&mut options)).show(ui);
});
fixture.room(Vec2::new(1400.0, 1000.0)).idle(30);
let top = |fixture: &Fixture, label: &str| fixture.by_label(label).unwrap_or_else(|| panic!("the {label} field")).rect.top();
let (mode, background) = (top(&fixture, "Color Mode"), top(&fixture, "Background Contents"));
let (profile, aspect) = (top(&fixture, "Color Profile"), top(&fixture, "Pixel Aspect Ratio"));
assert!(mode < background && background < profile && profile < aspect, "Background Contents comes before the advanced fields");
let name = fixture.by_label("Name").expect("the Name field").rect;
let save = fixture.by_label("Save Document Preset").expect("the save action").rect;
assert!(save.top() < name.bottom() && name.top() < save.bottom(), "the save icon shares the Name row");
assert!(name.right() <= save.left(), "the save icon is at the end of the Name field");
}
/// The caption role sets its text in capitals when it paints; the label stays as written.
#[trial]
fn section_captions_paint_in_capitals_and_keep_their_text() {
let mut options = DocumentOptions::default();
let mut fixture = Fixture::new(move |ui| {
let _ = NewDocumentDialog::new(Bind::bound(&mut options)).show(ui);
});
fixture.room(Vec2::new(1400.0, 1000.0)).idle(30);
assert!(shows(&fixture, "PRESET DETAILS"), "the caption paints in capitals");
assert!(fixture.by_label("Preset Details").is_some(), "the accessible name keeps the text as written");
}