framework: public enums and records the port added are #[non_exhaustive]; HoldSetting, PopupRegion, ParamPresets, CardSource::preset and WebDocument::vector take constructors for the crates that build them

This commit is contained in:
bflatastic committed 2026-11-22 20:01:00 +07:00
1 parent ff6ba8b216
commit eaa3433662
20 files changed
+68 -14

No files matched your search

+3
View File
@@ -268,10 +268,12 @@ pub enum HarmonyMenuAction {
/// Where a Color Guide cell lies.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum GuideCellAt {
/// The harmony strip's cell at this index.
Strip(usize),
/// The variation grid's cell at this row and column.
#[non_exhaustive]
Grid {
/// The grid row.
row: usize,
@@ -282,6 +284,7 @@ pub enum GuideCellAt {
/// A Color Guide cell: where it lies and the colour it shows.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct GuideCell {
/// Where the cell lies.
pub at: GuideCellAt,
+2
View File
@@ -17,6 +17,7 @@ use egui::{Color32, CornerRadius, Ui, Vec2};
/// How a channel's value steps and settles: a channel's or the alpha's.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ChannelRule {
/// The values the channel takes, from its least to its greatest.
pub range: RangeInclusive<f64>,
@@ -38,6 +39,7 @@ impl ChannelRule {
/// What a channel's number counts.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ChannelUnit {
/// No unit.
None,
+1
View File
@@ -118,6 +118,7 @@ impl GlyphsWords {
/// A grid cell: a character the face maps, or a glyph no character maps (unencoded, positional forms).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum GlyphCell {
/// A character the face maps.
Char(char),
@@ -111,6 +111,7 @@ pub enum FilterGalleryEvent {
PickColor(ColorRequest),
/// A Browse button was pressed on the layer `layer`: the app opens its file picker and answers with
/// `set_layer_fields`, which follows the layer if it moved meanwhile.
#[non_exhaustive]
PickPath {
/// The layer whose parameter asked.
layer: LayerId,
+8
View File
@@ -387,6 +387,7 @@ impl craft_ui::contract::Outcome for ShortcutsOutput {
/// The Hold Shortcuts setting the dialog shows and edits.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct HoldSetting {
/// Whether hold shortcuts are on.
pub on: bool,
@@ -396,6 +397,13 @@ pub struct HoldSetting {
pub range: RangeInclusive<f64>,
}
impl HoldSetting {
/// Hold shortcuts `on`, holding after `delay` seconds, with the field accepting `range`.
pub fn new(on: bool, delay: f64, range: RangeInclusive<f64>) -> Self {
HoldSetting { on, delay, range }
}
}
/// The dialog for one pass: what it edits, borrowed, and how it behaves.
#[must_use = "show the dialog with `show`"]
#[derive(Pattern)]
+1 -1
View File
@@ -10,7 +10,7 @@ use super::fixture::{self, Rig};
/// The setting a trial starts from, at a delay inside its range.
fn setting(on: bool) -> HoldSetting {
HoldSetting { on, delay: 0.5, range: 0.2..=2.0 }
HoldSetting::new(on, 0.5, 0.2..=2.0)
}
/// The hold texts the keymap's overrides hold for the command `key`.
+1 -1
View File
@@ -67,7 +67,7 @@ fn the_summary_lists_hold_bindings() {
let mut km = fixture::keymap(Platform::Mac);
km.set_holds(true);
km.assign(&CommandRef::from("file.save"), Binding::parse("Hold K").expect("a hold"), Policy::Keep).expect("assigns");
let mut rig = Rig::with_holds(km, fixture::options(), HoldSetting { on: true, delay: 0.5, range: 0.2..=2.0 });
let mut rig = Rig::with_holds(km, fixture::options(), HoldSetting::new(true, 0.5, 0.2..=2.0));
let summarize = |rig: &mut Rig| {
rig.click("Summarize…");
rig.outcomes()
+1
View File
@@ -40,6 +40,7 @@ pub enum MomentaryCommands {
/// What a held Shift does to the momentary Hand.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum MomentaryShift {
/// Shift changes nothing: the Hand stays the Hand.
#[default]
@@ -86,8 +86,16 @@ fn stored_opening(ctx: &Context, id: Id) -> Option<Opening> {
/// bar stay below the bar ([`OverlayUi::contain_popups_below`](super::OverlayUi::contain_popups_below)). `None`, the
/// root's, lets popups take the whole safe rect.
#[derive(Clone, Copy, Debug, Default, PartialEq, crate::contract::MemoProps)]
#[non_exhaustive]
pub struct PopupRegion(pub Option<Rect>);
impl PopupRegion {
/// Popups contained in `region`; `None` lets them take the whole safe rect.
pub fn new(region: Option<Rect>) -> Self {
PopupRegion(region)
}
}
impl crate::runtime::env::EnvValue for PopupRegion {
fn root() -> Self {
PopupRegion(None)
@@ -297,6 +297,7 @@ type BelowRowsFn<'a> = Box<dyn Fn(&mut Ui, &DialogFields) + 'a>;
/// The named presets a [`ParamDialog`] offers above its rows: the preset rows, the values each applies, and the names
/// the user cannot rename or delete.
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct ParamPresets<'a> {
/// The listed presets, by name.
pub rows: &'a [PresetRow<String>],
@@ -306,6 +307,13 @@ pub struct ParamPresets<'a> {
pub built_in: &'a [String],
}
impl<'a> ParamPresets<'a> {
/// The presets `rows`, applying `values`, of which `built_in` cannot be renamed or deleted.
pub fn new(rows: &'a [PresetRow<String>], values: &'a [(String, DialogFields)], built_in: &'a [String]) -> Self {
ParamPresets { rows, values, built_in }
}
}
/// What `ParamDialog::below` draws under the rows.
pub struct BelowRows<'a>(BelowRowsFn<'a>);
@@ -1313,7 +1321,7 @@ impl StackDialog for HostedParamDialog {
dialog = dialog.ok_enabled(false).ok_reason(reason.clone());
}
if let Some(presets) = &self.presets {
dialog = dialog.presets(ParamPresets { rows: &presets.rows, values: &presets.values, built_in: &presets.built_in });
dialog = dialog.presets(ParamPresets::new(&presets.rows, &presets.values, &presets.built_in));
}
// The held answer also carries a refusal the host keeps on a dialog without a held OK: its notice shows the reason
// under the rows, and OK is off meanwhile, so nothing is filed.
@@ -142,7 +142,7 @@ fn param_dialog_with_presets(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let built_in = ["soft".to_owned()];
ParamDialog::new("blur", "Blur", Param::parse_list(SPEC))
.opened(Bind::bound(opener(ui, data)))
.presets(ParamPresets { rows: &rows, values: &values, built_in: &built_in })
.presets(ParamPresets::new(&rows, &values, &built_in))
.show(ui)
.into()
}
@@ -91,6 +91,7 @@ impl<S> DocumentCard<S> {
#[non_exhaustive]
pub enum CardSource {
/// A built-in preset; `artboard` is whether it turns Artboards on (`None`: it leaves them).
#[non_exhaustive]
Preset {
/// Whether the card turns Artboards on.
artboard: Option<bool>,
@@ -103,6 +104,13 @@ pub enum CardSource {
Clipboard,
}
impl CardSource {
/// A built-in preset that turns Artboards on or off, or leaves them (`None`).
pub fn preset(artboard: Option<bool>) -> Self {
CardSource::Preset { artboard }
}
}
/// What a card is built from.
#[non_exhaustive]
pub struct CardCx<'a, S: DocumentSettings> {
@@ -101,7 +101,7 @@ impl DocumentSettings for StorySettings {
}
fn preset_card(_preset: &(), _cx: &CardCx<'_, Self>) -> DocumentCard<Self> {
DocumentCard::new("Preset".to_owned(), String::new(), StorySettings::default(), CardSource::Preset { artboard: None })
DocumentCard::new("Preset".to_owned(), String::new(), StorySettings::default(), CardSource::preset(None))
}
fn recent_cards(_cx: &CardCx<'_, Self>) -> Vec<DocumentCard<Self>> {
@@ -66,6 +66,7 @@ pub enum PdfExportMode {
/// The name and description a preset editor edits.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct PresetDraft {
/// The preset's name.
pub name: String,
@@ -34,6 +34,7 @@ const PERCENT: RangeInclusive<f64> = 0.0..=100.0;
/// The artboards to write: all, or the typed range ("1-3, 5").
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct ArtboardChoice {
/// Only the typed range is written.
pub range_only: bool,
@@ -43,6 +44,7 @@ pub struct ArtboardChoice {
/// The two check boxes that turn a password on. A password that is set keeps its box checked.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct PasswordSwitches {
/// The check box of the open password.
pub open: bool,
@@ -220,6 +220,7 @@ pub enum TableOrder {
/// A table edit and the colours it applies to.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ColorTableEvent {
/// The edit.
pub edit: ColorTableEdit,
@@ -229,6 +230,7 @@ pub struct ColorTableEvent {
/// What the host's table says, for the cell marks (web-safe is computed).
#[derive(Clone, Debug, Default, PartialEq)]
#[non_exhaustive]
pub struct TableMarks {
/// The locked colours.
pub locked: Vec<[u8; 3]>,
@@ -247,12 +249,20 @@ pub enum WebDocument {
Raster,
/// A vector document: Image Size shows Anti-aliasing, Clip to Artboard and the Artboard select in place of
/// Resample; an Output row follows Metadata; Slices has no HTML check.
#[non_exhaustive]
Vector {
/// The artboards' names.
artboards: Vec<String>,
},
}
impl WebDocument {
/// A vector document with the artboards `artboards`.
pub fn vector(artboards: Vec<String>) -> Self {
WebDocument::Vector { artboards }
}
}
/// The search Optimize to File Size… asks the host to run.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
@@ -150,7 +150,7 @@ fn save_for_web_vector(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let start = SaveForWebOptions { format: WebFormat::Png24, clip_to_artboard: true, artboard: Some(1), ..SaveForWebOptions::default() };
let flags = extras(data, false, false);
let ((options, open), options_open_at) = data.value_at("web-vector", (start, true));
let document = WebDocument::Vector { artboards: vec!["Artboard 1".to_owned(), "Artboard 2".to_owned()] };
let document = WebDocument::vector(vec!["Artboard 1".to_owned(), "Artboard 2".to_owned()]);
let dialog =
SaveForWebDialog::new("logo.vcr", size(), pictures, options_open_at.bind(options)).opened(options_open_at.bind(open)).document(document);
with_extras(dialog, flags).show(ui).into()
@@ -84,7 +84,7 @@ impl DocumentSettings for Counted {
}
fn preset_card(_preset: &(), _cx: &CardCx<'_, Self>) -> DocumentCard<Self> {
DocumentCard::new("Preset".to_owned(), String::new(), Counted::default(), CardSource::Preset { artboard: None })
DocumentCard::new("Preset".to_owned(), String::new(), Counted::default(), CardSource::preset(None))
}
fn recent_cards(_cx: &CardCx<'_, Self>) -> Vec<DocumentCard<Self>> {
@@ -183,8 +183,9 @@ fn show_palette(host: &Rc<RefCell<DialogHost>>, fixture: &mut Fixture) {
}
/// The colour table events the dialog filed since the last call.
fn table_events(host: &Rc<RefCell<DialogHost>>) -> Vec<ColorTableEvent> {
host.borrow_mut().get_mut::<HostedSaveForWeb>().map(HostedSaveForWeb::take_table_events).expect("the dialog is open")
fn table_events(host: &Rc<RefCell<DialogHost>>) -> Vec<(ColorTableEdit, Vec<[u8; 3]>)> {
let events = host.borrow_mut().get_mut::<HostedSaveForWeb>().map(HostedSaveForWeb::take_table_events).expect("the dialog is open");
events.into_iter().map(|event: ColorTableEvent| (event.edit, event.colors)).collect()
}
#[trial]
@@ -237,7 +238,7 @@ fn slices_and_palette_edits_follow_the_settings() {
assert_eq!(request.key, PALETTE_COLOR_KEY);
host.borrow_mut().answer_color(id, PALETTE_COLOR_KEY, Srgba::rgb(1.0, 0.0, 1.0));
fixture.idle(4);
let shift = ColorTableEvent { edit: ColorTableEdit::Shift([255, 0, 255]), colors: vec![[0, 255, 0]] };
let shift = (ColorTableEdit::Shift([255, 0, 255]), vec![[0, 255, 0]]);
assert_eq!(table_events(&host), vec![shift], "the answer shifts the opened entry's colour");
let interlaced = fixture.by_label("Interlaced").expect("the Interlaced check box");
@@ -246,7 +247,7 @@ fn slices_and_palette_edits_follow_the_settings() {
let colors = fixture.by_label("Colors").expect("the Colors field");
fixture.click(&colors).key(Key::ArrowUp, Modifiers::NONE).idle(4);
assert_eq!(current(&host).colors, 9, "the colour count changed");
let restore = ColorTableEvent { edit: ColorTableEdit::Restore, colors: Vec::new() };
let restore = (ColorTableEdit::Restore, Vec::new());
assert_eq!(table_events(&host), vec![restore], "a colour-count change restores the generated table");
// A preset pick keeps the slices.
@@ -285,10 +286,10 @@ fn table_edits_carry_the_selected_colors() {
let lock = fixture.by_label("Lock Colors").expect("the Lock button");
fixture.click(&lock).idle(4);
let selected = vec![[255, 0, 0], [0, 0, 255]];
assert_eq!(table_events(&host), vec![ColorTableEvent { edit: ColorTableEdit::Lock, colors: selected.clone() }]);
assert_eq!(table_events(&host), vec![(ColorTableEdit::Lock, selected.clone())]);
let delete = fixture.by_label("Delete Color").expect("the Delete button");
fixture.click(&delete).idle(4);
assert_eq!(table_events(&host), vec![ColorTableEvent { edit: ColorTableEdit::Delete, colors: selected }]);
assert_eq!(table_events(&host), vec![(ColorTableEdit::Delete, selected)]);
}
#[trial]
+1 -1
View File
@@ -177,7 +177,7 @@ impl Component for ShellRegion {
fn content_env(&self, _: &Cx<'_, Self>, values: &mut AppValues) {
if let Some((shell, popups)) = &self.shell {
shell.put(values);
values.set(PopupRegion(*popups));
values.set(PopupRegion::new(*popups));
}
if let Some(set) = self.mode_set {
values.set(set);