mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 22:14:30 +00:00
design-lint: api/non-exhaustive: #[non_exhaustive] on public types and variants, constructors where other crates build them
This commit is contained in:
@@ -192,6 +192,7 @@ impl Finished {
|
||||
}
|
||||
|
||||
/// A screenshot request as the control surface received it.
|
||||
#[non_exhaustive]
|
||||
pub struct ScreenshotRequest {
|
||||
/// The caller's token: one per pending request.
|
||||
pub token: u64,
|
||||
@@ -207,6 +208,13 @@ pub struct ScreenshotRequest {
|
||||
pub settle_ms: f64,
|
||||
}
|
||||
|
||||
impl ScreenshotRequest {
|
||||
/// A request for `viewport` answered on `reply`: no file, no document, no settle delay.
|
||||
pub fn new(token: u64, viewport: ViewportId, reply: Sender<ControlResponse>) -> Self {
|
||||
Self { token, path: None, viewport, reply, document: None, settle_ms: 0.0 }
|
||||
}
|
||||
}
|
||||
|
||||
/// A request not yet queued: it waits while its viewport's geometry is not recorded.
|
||||
struct WaitingAdmit {
|
||||
token: u64,
|
||||
|
||||
@@ -23,6 +23,7 @@ use crate::security::{
|
||||
/// A running control server. Dropping it stops accepting connections and returns once the port is
|
||||
/// free, so a restart on the same port binds it again at once; connections already open end at their
|
||||
/// next request, once the app has dropped the request channel.
|
||||
#[non_exhaustive]
|
||||
pub struct Listening {
|
||||
/// The bound address (with port 0, the port the system picked); the one a client needs.
|
||||
pub addr: SocketAddr,
|
||||
|
||||
@@ -39,7 +39,9 @@ fn admit_for(
|
||||
now: Instant,
|
||||
) -> Result<Receiver<ControlResponse>, String> {
|
||||
let (tx, rx) = channel();
|
||||
captures.admit(ScreenshotRequest { token, path: None, viewport, reply: tx, document, settle_ms: 0.0 }, now).map(|()| rx).map_err(|(_, e)| e)
|
||||
let mut request = ScreenshotRequest::new(token, viewport, tx);
|
||||
request.document = document;
|
||||
captures.admit(request, now).map(|()| rx).map_err(|(_, e)| e)
|
||||
}
|
||||
|
||||
fn admit(captures: &mut Captures, token: u64, now: Instant) -> Result<Receiver<ControlResponse>, String> {
|
||||
|
||||
@@ -33,6 +33,7 @@ const TURN_GRID_MAX: usize = 4096;
|
||||
|
||||
/// What a resize holds about the frame's proportions.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum AspectHold {
|
||||
/// No proportion held.
|
||||
Free,
|
||||
|
||||
@@ -346,6 +346,7 @@ pub fn count_clicks(previous: Option<(Pos2, f64, u32, Mods)>, pos: Pos2, time: f
|
||||
#[non_exhaustive]
|
||||
pub enum PointerEvent {
|
||||
/// The pointer moved, with the pen's reading for the move when the runtime has one.
|
||||
#[non_exhaustive]
|
||||
Moved {
|
||||
/// Where the pointer is.
|
||||
at: Pos2,
|
||||
@@ -377,6 +378,11 @@ pub enum PointerEvent {
|
||||
}
|
||||
|
||||
impl PointerEvent {
|
||||
/// The pointer moved to `at`, with the pen's reading for the move when the runtime has one.
|
||||
pub const fn moved(at: Pos2, sample: Option<PointerSample>) -> Self {
|
||||
PointerEvent::Moved { at, sample }
|
||||
}
|
||||
|
||||
/// The primary button going down at `pos`, `time`, as the `clicks`th press in a row.
|
||||
pub const fn pressed(pos: Pos2, time: f64, clicks: u32) -> Self {
|
||||
PointerEvent::Pressed { button: PointerButton::Primary, pos, time, clicks }
|
||||
|
||||
@@ -53,6 +53,7 @@ craft_ui::words! {
|
||||
|
||||
/// A colour in 8-bit sRGB and CMYK percent.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct InfoColor {
|
||||
/// The colour in 8-bit sRGB.
|
||||
pub rgb: [u8; 3],
|
||||
@@ -61,6 +62,11 @@ pub struct InfoColor {
|
||||
}
|
||||
|
||||
impl InfoColor {
|
||||
/// The colour with the given 8-bit sRGB and CMYK percent values, as an app already holds them.
|
||||
pub const fn from_parts(rgb: [u8; 3], cmyk: [u8; 4]) -> Self {
|
||||
InfoColor { rgb, cmyk }
|
||||
}
|
||||
|
||||
/// `color` through the document's CMYK converter: the one sRGB-and-CMYK conversion, which `SamplerReadout::new` builds
|
||||
/// its `rgb` and `cmyk` through. A channel that is not finite reads as 0 and the rest is clamped.
|
||||
pub fn new(color: Srgba, cmyk: &CmykConverter) -> Self {
|
||||
@@ -75,6 +81,7 @@ impl InfoColor {
|
||||
#[non_exhaustive]
|
||||
pub enum InfoMeasure {
|
||||
/// A plain ruler: its angle and length.
|
||||
#[non_exhaustive]
|
||||
Line {
|
||||
/// The angle.
|
||||
angle: Label,
|
||||
@@ -82,6 +89,7 @@ pub enum InfoMeasure {
|
||||
length: Label,
|
||||
},
|
||||
/// A protractor: the angle between its arms and the arms' lengths.
|
||||
#[non_exhaustive]
|
||||
Protractor {
|
||||
/// The angle between the arms.
|
||||
angle: Label,
|
||||
|
||||
@@ -283,11 +283,13 @@ impl Component for ColorSamplerMarks<'_> {
|
||||
#[non_exhaustive]
|
||||
pub enum SamplerEvent {
|
||||
/// A point was placed at `at`.
|
||||
#[non_exhaustive]
|
||||
Add {
|
||||
/// Where, in document pixels.
|
||||
at: [f64; 2],
|
||||
},
|
||||
/// Point `index` was moved to `to`.
|
||||
#[non_exhaustive]
|
||||
Move {
|
||||
/// The point's index.
|
||||
index: usize,
|
||||
@@ -295,15 +297,34 @@ pub enum SamplerEvent {
|
||||
to: [f64; 2],
|
||||
},
|
||||
/// Point `index` was removed.
|
||||
#[non_exhaustive]
|
||||
Remove {
|
||||
/// The point's index.
|
||||
index: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl SamplerEvent {
|
||||
/// A point placed at `at`.
|
||||
pub fn add(at: [f64; 2]) -> Self {
|
||||
SamplerEvent::Add { at }
|
||||
}
|
||||
|
||||
/// Point `index` moved to `to`.
|
||||
pub fn moved(index: usize, to: [f64; 2]) -> Self {
|
||||
SamplerEvent::Move { index, to }
|
||||
}
|
||||
|
||||
/// Point `index` removed.
|
||||
pub fn removed(index: usize) -> Self {
|
||||
SamplerEvent::Remove { index }
|
||||
}
|
||||
}
|
||||
|
||||
/// A point the tool carries: point `index` draws at `at`, or with `index: None` the next number draws at `at` while
|
||||
/// below [`MAX_SAMPLERS`].
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct SamplerCarry {
|
||||
/// The point carried; `None` for a new one.
|
||||
pub index: Option<usize>,
|
||||
|
||||
@@ -403,6 +403,7 @@ pub(super) fn value_text(color: &SwatchColor, book: &str) -> String {
|
||||
#[non_exhaustive]
|
||||
pub enum SwatchEdit {
|
||||
/// Adds `color` named `name` to `group`, or the first group.
|
||||
#[non_exhaustive]
|
||||
Add {
|
||||
/// The group's name, `None` for the first group.
|
||||
group: Option<String>,
|
||||
@@ -412,11 +413,13 @@ pub enum SwatchEdit {
|
||||
color: SwatchColor,
|
||||
},
|
||||
/// Adds an empty group.
|
||||
#[non_exhaustive]
|
||||
NewGroup {
|
||||
/// The new group's name.
|
||||
name: String,
|
||||
},
|
||||
/// Renames a swatch.
|
||||
#[non_exhaustive]
|
||||
Rename {
|
||||
/// The swatch's current name.
|
||||
swatch: String,
|
||||
@@ -424,6 +427,7 @@ pub enum SwatchEdit {
|
||||
name: String,
|
||||
},
|
||||
/// Renames a group.
|
||||
#[non_exhaustive]
|
||||
RenameGroup {
|
||||
/// The group's current name.
|
||||
group: String,
|
||||
@@ -431,16 +435,19 @@ pub enum SwatchEdit {
|
||||
name: String,
|
||||
},
|
||||
/// Deletes a swatch.
|
||||
#[non_exhaustive]
|
||||
Delete {
|
||||
/// The swatch's name.
|
||||
swatch: String,
|
||||
},
|
||||
/// Deletes a group with its swatches.
|
||||
#[non_exhaustive]
|
||||
DeleteGroup {
|
||||
/// The group's name.
|
||||
group: String,
|
||||
},
|
||||
/// Moves a swatch.
|
||||
#[non_exhaustive]
|
||||
MoveTo {
|
||||
/// The swatch's name.
|
||||
swatch: String,
|
||||
@@ -450,6 +457,7 @@ pub enum SwatchEdit {
|
||||
at: usize,
|
||||
},
|
||||
/// Moves a group.
|
||||
#[non_exhaustive]
|
||||
MoveGroup {
|
||||
/// The group's name.
|
||||
group: String,
|
||||
@@ -459,6 +467,7 @@ pub enum SwatchEdit {
|
||||
/// Puts the default swatches back.
|
||||
Reset,
|
||||
/// Imports `groups`, replacing the library when `replace`.
|
||||
#[non_exhaustive]
|
||||
Import {
|
||||
/// The groups the file holds.
|
||||
groups: Vec<SwatchGroup>,
|
||||
@@ -467,6 +476,18 @@ pub enum SwatchEdit {
|
||||
},
|
||||
}
|
||||
|
||||
impl SwatchEdit {
|
||||
/// Adds `color` named `name` to `group`, or the first group.
|
||||
pub fn add(group: Option<String>, name: String, color: SwatchColor) -> Self {
|
||||
SwatchEdit::Add { group, name, color }
|
||||
}
|
||||
|
||||
/// Deletes the swatch named `swatch`.
|
||||
pub fn delete(swatch: String) -> Self {
|
||||
SwatchEdit::Delete { swatch }
|
||||
}
|
||||
}
|
||||
|
||||
impl SwatchLibrary {
|
||||
/// Runs `edit` on the library: the in-memory host's path (stories, tests). False when the edit names nothing in the
|
||||
/// library.
|
||||
|
||||
@@ -274,7 +274,7 @@ fn swatches_panel_reports_each_edit_and_leaves_the_library() {
|
||||
fixture.click(&row).settle();
|
||||
assert!(edits.borrow().is_empty(), "a click selects and uses, it edits nothing: {:?}", edits.borrow());
|
||||
fixture.key(Key::Delete, Modifiers::NONE).settle();
|
||||
assert_eq!(*edits.borrow(), [SwatchEdit::Delete { swatch: "Red".to_owned() }], "one resolved edit, once");
|
||||
assert_eq!(*edits.borrow(), [SwatchEdit::delete("Red".to_owned())], "one resolved edit, once");
|
||||
|
||||
let (mut fixture, edits) = swatches_rig(groups.clone());
|
||||
let row = fixture.by_label("Red, #ff0000").expect("the Red swatch");
|
||||
@@ -292,7 +292,7 @@ fn swatches_panel_reports_each_edit_and_leaves_the_library() {
|
||||
let made = SwatchesMenu::run_command(&groups, &mut state, SwatchesCommand::NewSwatch, RED, &Default::default());
|
||||
assert_eq!(
|
||||
made.edit,
|
||||
Some(SwatchEdit::Add { group: Some("Basics".to_owned()), name: "Color Swatch 2".to_owned(), color: red }),
|
||||
Some(SwatchEdit::add(Some("Basics".to_owned()), "Color Swatch 2".to_owned(), red)),
|
||||
"the next free number, in the selected swatch's group, with the foreground"
|
||||
);
|
||||
assert_eq!(state.rename, Some(SwatchKey::Swatch("Color Swatch 2".to_owned())), "the new swatch opens for renaming");
|
||||
|
||||
@@ -82,7 +82,7 @@ fn a_new_point_lands_at_the_release_and_a_dragged_point_moves_on_release() {
|
||||
tool.press_at(at);
|
||||
assert!(events(&tool).is_empty(), "a press only starts the carry");
|
||||
tool.release_at(at);
|
||||
assert_eq!(events(&tool), [SamplerEvent::Add { at: [100.0, 50.0] }]);
|
||||
assert_eq!(events(&tool), [SamplerEvent::add([100.0, 50.0])]);
|
||||
let outside = doc_to_screen(&tool, [320.5, 50.5]);
|
||||
tool.press_at(at).release_at(outside);
|
||||
assert!(events(&tool).is_empty(), "released off the canvas places none");
|
||||
@@ -96,18 +96,18 @@ fn a_new_point_lands_at_the_release_and_a_dragged_point_moves_on_release() {
|
||||
tool.press_at(on).release_at(on);
|
||||
assert!(events(&tool).is_empty(), "a click on the point's own pixel moves nothing");
|
||||
tool.press_at(near).release_at(near);
|
||||
assert_eq!(events(&tool), [SamplerEvent::Move { index: 0, to: [102.0, 50.0] }]);
|
||||
assert_eq!(events(&tool), [SamplerEvent::moved(0, [102.0, 50.0])]);
|
||||
let outside = doc_to_screen(&tool, [320.5, 50.5]);
|
||||
tool.drag_from(on, outside - on);
|
||||
assert_eq!(events(&tool), [SamplerEvent::Remove { index: 0 }], "a point dropped off the canvas is removed");
|
||||
assert_eq!(events(&tool), [SamplerEvent::removed(0)], "a point dropped off the canvas is removed");
|
||||
|
||||
// Alt: a click on a point removes it, off a point it adds.
|
||||
tool.fixture().hold(Modifiers::ALT);
|
||||
tool.press_at(on).release_at(on);
|
||||
assert_eq!(events(&tool), [SamplerEvent::Remove { index: 0 }]);
|
||||
assert_eq!(events(&tool), [SamplerEvent::removed(0)]);
|
||||
let empty = doc_to_screen(&tool, [200.5, 150.5]);
|
||||
tool.press_at(empty).release_at(empty);
|
||||
assert_eq!(events(&tool), [SamplerEvent::Add { at: [200.0, 150.0] }]);
|
||||
assert_eq!(events(&tool), [SamplerEvent::add([200.0, 150.0])]);
|
||||
tool.fixture().hold(Modifiers::NONE);
|
||||
|
||||
// At the limit nothing is carried and one notice is set.
|
||||
|
||||
@@ -27,6 +27,7 @@ const CLOSED: &[&str] = &[
|
||||
"SetPosition",
|
||||
"States",
|
||||
"StateMix",
|
||||
"ShowReadouts", // the one Show Transformation Values flag: a bool, fixed by meaning
|
||||
"CollectionEvent", // built or matched in craft-ui-patterns
|
||||
"ColumnAlign", // built or matched in craft-ui-widgets
|
||||
"ColumnEvent", // built or matched in craft-ui-widgets
|
||||
|
||||
@@ -73,6 +73,7 @@ pub enum ArtboardBarTarget<'a> {
|
||||
/// The selected board.
|
||||
Board(&'a ArtboardItem),
|
||||
/// No board is selected: the size and background the next board gets.
|
||||
#[non_exhaustive]
|
||||
Next {
|
||||
/// The size of the next board.
|
||||
size: Size,
|
||||
@@ -81,6 +82,13 @@ pub enum ArtboardBarTarget<'a> {
|
||||
},
|
||||
}
|
||||
|
||||
impl ArtboardBarTarget<'_> {
|
||||
/// No board is selected: the `size` and `background` the next board gets.
|
||||
pub const fn next(size: Size, background: ArtboardBackground) -> Self {
|
||||
ArtboardBarTarget::Next { size, background }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArtboardBar<'a> {
|
||||
/// The members for `target` with the app's `presets`.
|
||||
pub fn new(target: ArtboardBarTarget<'a>, presets: &'a [ArtboardPreset]) -> Self {
|
||||
|
||||
@@ -186,6 +186,7 @@ pub enum ApplyBy {
|
||||
/// A double click inside the box.
|
||||
DoubleClick,
|
||||
/// A click outside the box, at `at` in document units.
|
||||
#[non_exhaustive]
|
||||
ClickOutside {
|
||||
/// Where the click landed.
|
||||
at: Point,
|
||||
@@ -415,10 +416,10 @@ impl<'a> TransformBox<'a> {
|
||||
let (to, lines) = match (snap, grabbed) {
|
||||
(Some(snap), Some(grabbed)) => {
|
||||
let off = grip.from - grabbed;
|
||||
let (at, lines) = snap.point(to - off, mods, GestureSnap { reads_control, ..GestureSnap::default() });
|
||||
let (at, lines) = snap.point(to - off, mods, GestureSnap::default().reads_control(reads_control));
|
||||
(at + off, lines)
|
||||
}
|
||||
(Some(snap), None) => snap.point(to, mods, GestureSnap { reads_control, ..GestureSnap::default() }),
|
||||
(Some(snap), None) => snap.point(to, mods, GestureSnap::default().reads_control(reads_control)),
|
||||
(None, _) => (to, Vec::new()),
|
||||
};
|
||||
let dragged = quad::drag(&grip.start, &grip.last, grip.part, grip.from, to, mods, &self.rules);
|
||||
|
||||
@@ -36,6 +36,7 @@ pub enum EditPhase {
|
||||
|
||||
/// What an adjustment editor shares with its dialog for one pass: the context, the canvas, the dialog's own picker,
|
||||
/// channel and clipping state, and the editor's edit phase.
|
||||
#[non_exhaustive]
|
||||
pub struct AdjustDialogCx<'a> {
|
||||
/// Where the editor is shown.
|
||||
pub context: AdjustContext,
|
||||
@@ -53,6 +54,19 @@ pub struct AdjustDialogCx<'a> {
|
||||
pub edit: Option<(EditPhase, GestureId)>,
|
||||
}
|
||||
|
||||
impl<'a> AdjustDialogCx<'a> {
|
||||
/// The context for an editor shown in `context` over the dialog's own `picker`, `channel` and `clipping` state, with
|
||||
/// no canvas, no curve point to select and no edit phase; the fields set the rest.
|
||||
pub fn new(
|
||||
context: AdjustContext,
|
||||
picker: &'a mut Option<TonePicker>,
|
||||
channel: &'a mut usize,
|
||||
clipping: &'a mut Option<LevelsClip>,
|
||||
) -> Self {
|
||||
Self { context, canvas: None, picker, channel, select_point: None, clipping, edit: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// The clipping display as automation names it: `"shadows"`, `"highlights"` or null (`LevelsClip` has no serde).
|
||||
fn clipping_json(clip: Option<LevelsClip>) -> serde_json::Value {
|
||||
match clip {
|
||||
|
||||
@@ -89,6 +89,7 @@ pub enum SampleSign {
|
||||
|
||||
/// The points the user sampled, in document pixels, and the order they were made in.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct ColorSamples {
|
||||
/// The added samples.
|
||||
pub add: Vec<[f64; 2]>,
|
||||
|
||||
@@ -434,9 +434,9 @@ impl RawDevelopWorkspace {
|
||||
for event in self.sampler_tool.take_events() {
|
||||
// A refused point (the eleventh, one off the picture) is the tool's toast, not a state change.
|
||||
let _ = match event {
|
||||
SamplerEvent::Add { at } => self.samplers.add(at, size).map(|_| ()),
|
||||
SamplerEvent::Move { index, to } => self.samplers.move_point(index, to, size),
|
||||
SamplerEvent::Remove { index } => self.samplers.remove(index),
|
||||
SamplerEvent::Add { at, .. } => self.samplers.add(at, size).map(|_| ()),
|
||||
SamplerEvent::Move { index, to, .. } => self.samplers.move_point(index, to, size),
|
||||
SamplerEvent::Remove { index, .. } => self.samplers.remove(index),
|
||||
_ => Ok(()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,9 +114,15 @@ impl ZoneScale {
|
||||
|
||||
/// The values of the controls the tone zones edit, one per zone in the zones' order, each in its control's units.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct ZoneValues(pub Vec<f32>);
|
||||
|
||||
impl ZoneValues {
|
||||
/// The values of the zones in order, one per zone.
|
||||
pub fn new(values: Vec<f32>) -> Self {
|
||||
Self(values)
|
||||
}
|
||||
|
||||
/// These values with zone `at` set to what `to` makes of its value and scale, held to the zone's range; `None`
|
||||
/// when the zone has no value or no scale.
|
||||
fn with(&self, scales: &[ZoneScale], at: usize, to: impl FnOnce(f32, &ZoneScale) -> f32) -> Option<ZoneValues> {
|
||||
|
||||
@@ -62,6 +62,7 @@ craft_ui::words! {
|
||||
|
||||
/// The cylinder's values: the box, the depths of its top and bottom edges and the wrap.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct CylinderValues {
|
||||
/// The left edge of the box.
|
||||
pub left: f64,
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::rc::Rc;
|
||||
|
||||
/// The zone values the rig starts from: each zone at its index, in -100 to 100.
|
||||
fn start_values() -> ZoneValues {
|
||||
ZoneValues(vec![0.0, 1.0, 2.0, 3.0, 4.0])
|
||||
ZoneValues::new(vec![0.0, 1.0, 2.0, 3.0, 4.0])
|
||||
}
|
||||
|
||||
/// A fixture of the tone zones alone over a 200 by 100 plot at the origin, over values that start at
|
||||
|
||||
@@ -80,6 +80,7 @@ impl Outcome for LayerCompsOutput {
|
||||
/// arrive as [`LayerCompsEvent::Reorder`].
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, CommandSet)]
|
||||
#[command(prefix = "layerCompsPanel")]
|
||||
#[non_exhaustive]
|
||||
pub enum LayerCompsRowCommands {
|
||||
/// Move the comp up.
|
||||
#[command(label = "Move Up")]
|
||||
|
||||
@@ -20,6 +20,7 @@ use egui::Ui;
|
||||
|
||||
/// What a layer comp records of a layer: the options a comp row toggles.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum CompOption {
|
||||
/// Whether the layers are shown.
|
||||
Visibility,
|
||||
|
||||
@@ -22,6 +22,7 @@ pub enum ThemeChoice {
|
||||
/// Follow the system's light or dark mode.
|
||||
System,
|
||||
/// A theme in its light (`dark: false`) or dark mode.
|
||||
#[non_exhaustive]
|
||||
Theme {
|
||||
/// The theme.
|
||||
id: ThemeId,
|
||||
@@ -33,6 +34,11 @@ pub enum ThemeChoice {
|
||||
}
|
||||
|
||||
impl ThemeChoice {
|
||||
/// The theme `id` in its dark mode when `dark`, else its light mode.
|
||||
pub fn theme(id: ThemeId, dark: bool) -> Self {
|
||||
ThemeChoice::Theme { id, dark }
|
||||
}
|
||||
|
||||
/// The choice a command made, `None` for any other command or an unknown parameter.
|
||||
pub fn from_command(command: &CommandRef) -> Option<ThemeChoice> {
|
||||
if command.id != THEME_COMMAND {
|
||||
|
||||
@@ -47,6 +47,7 @@ const MARK_LEN: f32 = 10.0;
|
||||
|
||||
/// Which marks the preview draws.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct PrintMarks {
|
||||
/// Corner crop marks.
|
||||
pub corner_crop: bool,
|
||||
@@ -102,6 +103,7 @@ impl PrintSheet {
|
||||
|
||||
/// One titled section of the app's rows (Color Management, Position and Size, Printing Marks,
|
||||
/// Functions, Save as PDF).
|
||||
#[non_exhaustive]
|
||||
pub struct PrintSection {
|
||||
/// The section's title.
|
||||
pub title: Label,
|
||||
@@ -109,8 +111,16 @@ pub struct PrintSection {
|
||||
pub params: Vec<Param>,
|
||||
}
|
||||
|
||||
impl PrintSection {
|
||||
/// The section titled `title` with its `params` rows.
|
||||
pub fn new(title: impl Into<Label>, params: Vec<Param>) -> Self {
|
||||
Self { title: title.into(), params }
|
||||
}
|
||||
}
|
||||
|
||||
/// How a print dialog finished.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum PrintFinish {
|
||||
/// Print the document.
|
||||
Print,
|
||||
|
||||
@@ -151,6 +151,7 @@ pub enum StyleOptionsChange {
|
||||
/// The style's new name.
|
||||
Rename(String),
|
||||
/// An include check switched.
|
||||
#[non_exhaustive]
|
||||
Include {
|
||||
/// The attribute.
|
||||
attribute: StyleAttribute,
|
||||
@@ -163,6 +164,13 @@ pub enum StyleOptionsChange {
|
||||
Paragraph(ParagraphChange),
|
||||
}
|
||||
|
||||
impl StyleOptionsChange {
|
||||
/// The include check of `attribute` switched to `on`.
|
||||
pub fn include(attribute: StyleAttribute, on: bool) -> Self {
|
||||
StyleOptionsChange::Include { attribute, on }
|
||||
}
|
||||
}
|
||||
|
||||
/// What the options editor did this pass.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
|
||||
@@ -76,6 +76,7 @@ pub trait PathTrack {
|
||||
|
||||
/// The part of the path the text fills: arc lengths of its start and end, and whether it runs against the path.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct PathRange {
|
||||
/// The arc length of the text's start.
|
||||
pub start: f64,
|
||||
@@ -85,6 +86,13 @@ pub struct PathRange {
|
||||
pub flip: bool,
|
||||
}
|
||||
|
||||
impl PathRange {
|
||||
/// The range from arc length `start` to `end`, running against the path when `flip`.
|
||||
pub const fn new(start: f64, end: f64, flip: bool) -> Self {
|
||||
Self { start, end, flip }
|
||||
}
|
||||
}
|
||||
|
||||
/// The part of the markers under the pointer or being dragged.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
|
||||
@@ -72,6 +72,7 @@ impl TextAntiAlias {
|
||||
|
||||
/// The direction the text runs.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum TextOrientation {
|
||||
/// Horizontal lines.
|
||||
Horizontal,
|
||||
|
||||
@@ -207,7 +207,7 @@ fn coincident_markers_pick_their_end_by_the_first_motion() {
|
||||
let lap = TAU * RADIUS;
|
||||
// On a full lap: a press ahead of the markers grabs the start, behind them the end, between them the body.
|
||||
for (offset, grab, direction) in [(3.0, PathGrab::Start, 1.0), (-3.0, PathGrab::End, -1.0), (0.0, PathGrab::Body, 1.0)] {
|
||||
let mut h = harness(Config::circle(PathRange { start: 0.0, end: lap, flip: false }));
|
||||
let mut h = harness(Config::circle(PathRange::new(0.0, lap, false)));
|
||||
let tangent = h.direction(0.0);
|
||||
let from = h.at(0.0) + tangent * offset;
|
||||
h.frame(vec![pointer::moved(from)]);
|
||||
@@ -222,7 +222,7 @@ fn coincident_markers_pick_their_end_by_the_first_motion() {
|
||||
}
|
||||
// Not on a full lap: the first motion picks the end (forward) or the start (backward).
|
||||
for forward in [true, false] {
|
||||
let mut h = harness(Config::circle(PathRange { start: 50.0, end: 50.0, flip: false }));
|
||||
let mut h = harness(Config::circle(PathRange::new(50.0, 50.0, false)));
|
||||
let tangent = h.direction(50.0);
|
||||
let from = h.at(50.0);
|
||||
let sign = if forward { 1.0 } else { -1.0 };
|
||||
@@ -243,7 +243,7 @@ fn a_body_drag_at_an_open_end_keeps_the_paragraph_anchor() {
|
||||
// (anchor, the arc length the pointer is dragged to from 40, the range afterwards)
|
||||
let cases = [(0.0, 100.0, (80.0, 100.0)), (1.0, 100.0, (60.0, 100.0)), (0.5, 90.0, (80.0, 100.0))];
|
||||
for (anchor, to, (start, end)) in cases {
|
||||
let mut config = Config::line(100.0, PathRange { start: 20.0, end: 60.0, flip: false });
|
||||
let mut config = Config::line(100.0, PathRange::new(20.0, 60.0, false));
|
||||
config.anchor = anchor;
|
||||
config.boxes = boxes.clone();
|
||||
let mut h = harness(config);
|
||||
@@ -253,7 +253,7 @@ fn a_body_drag_at_an_open_end_keeps_the_paragraph_anchor() {
|
||||
assert!(close(range.start, start, 1e-6) && close(range.end, end, 1e-6), "anchor {anchor}: {range:?}");
|
||||
}
|
||||
// A click with no drag changes nothing.
|
||||
let mut config = Config::line(100.0, PathRange { start: 20.0, end: 60.0, flip: false });
|
||||
let mut config = Config::line(100.0, PathRange::new(20.0, 60.0, false));
|
||||
config.boxes = boxes;
|
||||
let mut h = harness(config);
|
||||
let at = h.at(40.0);
|
||||
@@ -261,13 +261,13 @@ fn a_body_drag_at_an_open_end_keeps_the_paragraph_anchor() {
|
||||
h.frame(vec![pointer::press(at)]);
|
||||
h.frame(vec![pointer::release(at)]);
|
||||
h.frame(Vec::new());
|
||||
assert_eq!(h.range(), PathRange { start: 20.0, end: 60.0, flip: false });
|
||||
assert_eq!(h.range(), PathRange::new(20.0, 60.0, false));
|
||||
assert!(h.host.borrow().events.is_empty(), "no edit: {:?}", h.host.borrow().events);
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn crossing_the_path_flips_the_text_and_keeps_its_span() {
|
||||
let start = PathRange { start: 20.0, end: 60.0, flip: false };
|
||||
let start = PathRange::new(20.0, 60.0, false);
|
||||
// Within 4 points of the path nothing flips.
|
||||
let mut h = harness(Config::line(120.0, start));
|
||||
let from = h.at(60.0);
|
||||
|
||||
@@ -36,7 +36,7 @@ fn a_row_left_out_of_the_style_takes_no_input_and_its_check_includes_it() {
|
||||
fixture.click(&include).idle(4);
|
||||
assert_eq!(
|
||||
changes(&edits),
|
||||
vec![StyleOptionsChange::Include { attribute: StyleAttribute::Size, on: true }],
|
||||
vec![StyleOptionsChange::include(StyleAttribute::Size, true)],
|
||||
"the check of a row that is not included includes it"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ pub struct Snap {
|
||||
|
||||
/// The gesture's snap options in one argument: whether the gesture reads Control itself, and a kind filter.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct GestureSnap {
|
||||
/// Whether the gesture reads the Control key itself, so Control does not suspend snapping.
|
||||
pub reads_control: bool,
|
||||
@@ -31,6 +32,20 @@ pub struct GestureSnap {
|
||||
pub kinds: craft_behavior::geometry::SnapKinds,
|
||||
}
|
||||
|
||||
impl GestureSnap {
|
||||
/// These options with the gesture reading Control itself when `reads_control`.
|
||||
pub fn reads_control(mut self, reads_control: bool) -> Self {
|
||||
self.reads_control = reads_control;
|
||||
self
|
||||
}
|
||||
|
||||
/// These options snapping to `kinds`.
|
||||
pub fn kinds(mut self, kinds: craft_behavior::geometry::SnapKinds) -> Self {
|
||||
self.kinds = kinds;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Snap {
|
||||
/// The snapping over `targets` with `options`; the tolerance is set by the canvas each pass.
|
||||
pub fn new(targets: Arc<SnapTargets>, options: SnapOptions) -> Self {
|
||||
|
||||
@@ -647,10 +647,10 @@ impl<'m> ToolHost<'m> {
|
||||
let host = WindowHost::of(ctx);
|
||||
match input {
|
||||
ToolInput::Down { button, pos, sample, mods } => {
|
||||
host.inject_pointer(viewport, InjectedPointer::Down { button, at: pos, mods, pen: sample });
|
||||
host.inject_pointer(viewport, InjectedPointer::down(button, pos, mods, sample));
|
||||
}
|
||||
ToolInput::Move { pos, sample, mods } => host.inject_pointer(viewport, InjectedPointer::Move { at: pos, mods, pen: sample }),
|
||||
ToolInput::Up { pos, mods } => host.inject_pointer(viewport, InjectedPointer::Up { at: pos, mods }),
|
||||
ToolInput::Move { pos, sample, mods } => host.inject_pointer(viewport, InjectedPointer::move_to(pos, mods, sample)),
|
||||
ToolInput::Up { pos, mods } => host.inject_pointer(viewport, InjectedPointer::up(pos, mods)),
|
||||
ToolInput::Hold { key } => host.inject_hold(viewport, key),
|
||||
ToolInput::LetGo { key } => host.inject_let_go(viewport, key),
|
||||
}
|
||||
@@ -1100,7 +1100,7 @@ impl<'a, 't: 'a> Run<'a, 't> {
|
||||
pass.events[from..]
|
||||
.iter()
|
||||
.filter_map(|event| match event {
|
||||
PointerEvent::Moved { at, sample } => Some((*at, *sample)),
|
||||
PointerEvent::Moved { at, sample, .. } => Some((*at, *sample)),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -6,6 +6,7 @@ use egui::{Context, Id};
|
||||
|
||||
/// The position and orientation of the guide a drag is moving or creating.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct GuideReading {
|
||||
/// The axis the guide runs along.
|
||||
pub along: Axis,
|
||||
@@ -13,6 +14,13 @@ pub struct GuideReading {
|
||||
pub position: f64,
|
||||
}
|
||||
|
||||
impl GuideReading {
|
||||
/// The reading of a guide running `along` at `position`.
|
||||
pub const fn new(along: Axis, position: f64) -> Self {
|
||||
Self { along, position }
|
||||
}
|
||||
}
|
||||
|
||||
/// The guide a drag is moving or creating on the canvas `canvas`, read from the note the guides set on their running
|
||||
/// gesture, so a panel drawn before or after the canvas reads the same value; `None` when no guide drag runs or the
|
||||
/// dragged guide lies off the canvas.
|
||||
|
||||
@@ -26,6 +26,7 @@ use std::sync::Arc;
|
||||
/// Where the task bar sits: pinned or following its anchor, and where the user moved it. The one owner of the bar's
|
||||
/// place; the serde shape is PhotoCraft's, so saved preferences load unchanged, and a non-finite `at` counts as unset.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct TaskBarPlace {
|
||||
/// The bar keeps its place instead of following the anchor.
|
||||
#[serde(default)]
|
||||
@@ -36,6 +37,11 @@ pub struct TaskBarPlace {
|
||||
}
|
||||
|
||||
impl TaskBarPlace {
|
||||
/// A place that is pinned or follows the anchor, with the top left corner `at` once moved.
|
||||
pub const fn new(pinned: bool, at: Option<[f32; 2]>) -> Self {
|
||||
Self { pinned, at }
|
||||
}
|
||||
|
||||
/// The bar's top left in `area` while it has a place; `None` while it follows its anchor. A non-finite `at`
|
||||
/// counts as unset.
|
||||
fn placed_in(&self, area: Rect) -> Option<Pos2> {
|
||||
|
||||
@@ -95,7 +95,7 @@ fn snap_targets_snap_points_and_boxes_unless_control_suspends() {
|
||||
assert_eq!(snap.apply(Axis::Y, 103.0, Mods::CTRL), 103.0);
|
||||
assert_eq!(snap.apply(Axis::Y, 103.0, Mods::CMD), 100.0);
|
||||
assert_eq!(
|
||||
snap.point(NEAR, Mods::CTRL, GestureSnap { reads_control: true, ..GestureSnap::default() }).0,
|
||||
snap.point(NEAR, Mods::CTRL, GestureSnap::default().reads_control(true)).0,
|
||||
Point::new(100.0, 200.0),
|
||||
"a gesture that reads Control keeps snapping"
|
||||
);
|
||||
|
||||
@@ -110,7 +110,7 @@ fn the_running_guide_reading_follows_the_drag_and_goes_when_it_ends() {
|
||||
});
|
||||
let canvas = fixture.canvas_id();
|
||||
let reading = |fixture: &mut ToolFixture<Recorder>| running(fixture.fixture().ctx(), canvas);
|
||||
let vertical = |position: f64| Some(GuideReading { along: Axis::Y, position });
|
||||
let vertical = |position: f64| Some(GuideReading::new(Axis::Y, position));
|
||||
assert_eq!(reading(&mut fixture), None, "no drag, no reading");
|
||||
|
||||
fixture.fixture().frame(vec![pointer::moved(pos2(200.0, 300.0))]);
|
||||
|
||||
@@ -124,12 +124,12 @@ fn the_task_bar_follows_its_anchor_until_moved_and_stays_inside_the_area() {
|
||||
fixture.settle();
|
||||
assert!((seen(&scene).rect.min - pinned.rect.min).length() < SLACK, "a pinned bar stays while the anchor moves");
|
||||
|
||||
scene.borrow_mut().place = TaskBarPlace { pinned: false, at: Some([f32::NAN, 0.0]) };
|
||||
scene.borrow_mut().place = TaskBarPlace::new(false, Some([f32::NAN, 0.0]));
|
||||
fixture.settle();
|
||||
let unset = seen(&scene);
|
||||
assert!(centred_under_anchor(&unset), "a non-finite place counts as unset: {:?}", unset.rect);
|
||||
|
||||
scene.borrow_mut().place = TaskBarPlace { pinned: false, at: Some([1.0e30, -1.0e30]) };
|
||||
scene.borrow_mut().place = TaskBarPlace::new(false, Some([1.0e30, -1.0e30]));
|
||||
fixture.settle();
|
||||
let far = seen(&scene);
|
||||
assert!(inside_area(&far), "a place far outside comes back inside {:?}: {:?}", far.area, far.rect);
|
||||
|
||||
@@ -101,6 +101,7 @@ impl Thumbnail {
|
||||
/// One layer of a backdrop: where it lies, its reduced picture and the colour that stands in for a missing one.
|
||||
/// Later layers cover earlier ones.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct BackdropLayer<'a> {
|
||||
/// Where the layer lies.
|
||||
pub rect: Rect,
|
||||
@@ -110,6 +111,13 @@ pub struct BackdropLayer<'a> {
|
||||
pub fallback: Color32,
|
||||
}
|
||||
|
||||
impl<'a> BackdropLayer<'a> {
|
||||
/// The layer over `rect` showing `thumbnail`, or `fallback` where it has none.
|
||||
pub const fn new(rect: Rect, thumbnail: Option<&'a Thumbnail>, fallback: Color32) -> Self {
|
||||
Self { rect, thumbnail, fallback }
|
||||
}
|
||||
}
|
||||
|
||||
/// The blurred composition of `layers` over `background` for `area`: an opaque image of cells about four points
|
||||
/// wide, at most [`MAX_SIDE`] per side and [`MAX_TEXELS`] in all, softened by three box passes per axis. Linear
|
||||
/// texture filtering supplies the final upsampling. `None` for an invalid, empty or excessive area; invalid layer
|
||||
|
||||
@@ -10,6 +10,7 @@ include!(concat!(env!("OUT_DIR"), "/icons.rs"));
|
||||
|
||||
/// An app's own icon set: SVG documents drawn beside the built-in catalog in every `IconSet`.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct AppIcons {
|
||||
/// The set's name, for the log line that refuses a clashing registration.
|
||||
pub name: &'static str,
|
||||
@@ -19,6 +20,13 @@ pub struct AppIcons {
|
||||
pub icons: &'static [(&'static str, &'static [u8])],
|
||||
}
|
||||
|
||||
impl AppIcons {
|
||||
/// The set `name` of `icons`, each an icon name and its SVG document, drawn with `stroke_width` when it is `Some`.
|
||||
pub const fn new(name: &'static str, stroke_width: Option<f32>, icons: &'static [(&'static str, &'static [u8])]) -> Self {
|
||||
Self { name, stroke_width, icons }
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers `set` in the process-wide list beside the built-in catalog; runs before the first pass.
|
||||
///
|
||||
/// Registering the same set again is a no-op; a name the built-in catalog or an earlier app set has is refused with a
|
||||
|
||||
@@ -528,6 +528,7 @@ pub(crate) fn inject_release(ctx: &Context, viewport: ViewportId, at: Option<Pos
|
||||
#[non_exhaustive]
|
||||
pub enum InjectedPointer {
|
||||
/// `button` goes down at `at`, after a move there when the injected pointer is elsewhere.
|
||||
#[non_exhaustive]
|
||||
Down {
|
||||
/// The button.
|
||||
button: PointerButton,
|
||||
@@ -539,6 +540,7 @@ pub enum InjectedPointer {
|
||||
pen: Option<PointerSample>,
|
||||
},
|
||||
/// The pointer moves to `at`; a button held by injected input drags.
|
||||
#[non_exhaustive]
|
||||
Move {
|
||||
/// The pointer.
|
||||
at: Pos2,
|
||||
@@ -549,6 +551,7 @@ pub enum InjectedPointer {
|
||||
},
|
||||
/// Every button injected input holds comes up at `at`, after a move there; the modifiers go with them when no
|
||||
/// button or key stays down. Nothing held queues nothing.
|
||||
#[non_exhaustive]
|
||||
Up {
|
||||
/// The pointer.
|
||||
at: Pos2,
|
||||
@@ -557,6 +560,23 @@ pub enum InjectedPointer {
|
||||
},
|
||||
}
|
||||
|
||||
impl InjectedPointer {
|
||||
/// `button` goes down at `at` with `mods` held and the pen's reading `pen`.
|
||||
pub const fn down(button: PointerButton, at: Pos2, mods: Mods, pen: Option<PointerSample>) -> Self {
|
||||
InjectedPointer::Down { button, at, mods, pen }
|
||||
}
|
||||
|
||||
/// The pointer moves to `at` with `mods` held and the pen's reading `pen`.
|
||||
pub const fn move_to(at: Pos2, mods: Mods, pen: Option<PointerSample>) -> Self {
|
||||
InjectedPointer::Move { at, mods, pen }
|
||||
}
|
||||
|
||||
/// Every injected button comes up at `at` with `mods` held.
|
||||
pub const fn up(at: Pos2, mods: Mods) -> Self {
|
||||
InjectedPointer::Up { at, mods }
|
||||
}
|
||||
}
|
||||
|
||||
/// Queues `step` for `viewport`, one pass per event. A button egui has no counterpart, or a non-finite point of a
|
||||
/// press or move, queues nothing; a release at a non-finite point releases where the pointer is.
|
||||
pub(crate) fn inject_pointer(ctx: &Context, viewport: ViewportId, step: InjectedPointer) {
|
||||
|
||||
@@ -314,7 +314,7 @@ pub(crate) fn pointer_read(ctx: &Context) -> PointerRead {
|
||||
Event::PointerMoved(pos) => {
|
||||
stirred = true;
|
||||
moves.push(events.len());
|
||||
events.push(PointerEvent::Moved { at: *pos, sample: None });
|
||||
events.push(PointerEvent::moved(*pos, None));
|
||||
}
|
||||
Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed: true, .. } => {
|
||||
// Only the next press sets the barrel state again, so a missed release never remaps a plain tap.
|
||||
|
||||
+6
@@ -203,6 +203,7 @@ impl UnitKind {
|
||||
|
||||
/// The column size of a document: `n` columns are `n·(width + gutter) − gutter` points.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct ColumnSize {
|
||||
/// The width of one column, in points; a value that is not a finite number above 0 counts as 180.
|
||||
pub width: f64,
|
||||
@@ -211,6 +212,11 @@ pub struct ColumnSize {
|
||||
}
|
||||
|
||||
impl ColumnSize {
|
||||
/// The column size with columns `width` points wide `gutter` points apart.
|
||||
pub const fn new(width: f64, gutter: f64) -> Self {
|
||||
Self { width, gutter }
|
||||
}
|
||||
|
||||
/// The column width used when the given one is not a finite number above 0.
|
||||
const FALLBACK_WIDTH: f64 = 180.0;
|
||||
/// The gutter used when the given one is not finite.
|
||||
|
||||
@@ -46,6 +46,7 @@ pub struct InstallSpec {
|
||||
|
||||
/// The modifiers the mouse wheel zooms and scrolls sideways with.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct WheelModifiers {
|
||||
/// Held with the wheel, the wheel zooms.
|
||||
pub zoom: egui::Modifiers,
|
||||
@@ -53,6 +54,13 @@ pub struct WheelModifiers {
|
||||
pub sideways: egui::Modifiers,
|
||||
}
|
||||
|
||||
impl WheelModifiers {
|
||||
/// The wheel zooms with `zoom` held and scrolls sideways with `sideways` held.
|
||||
pub const fn new(zoom: egui::Modifiers, sideways: egui::Modifiers) -> Self {
|
||||
Self { zoom, sideways }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WheelModifiers {
|
||||
fn default() -> Self {
|
||||
WheelModifiers { zoom: egui::Modifiers::COMMAND, sideways: egui::Modifiers::SHIFT }
|
||||
|
||||
@@ -18,10 +18,10 @@ fn transparent_capture_composites_over_paper_and_missing_capture_uses_fallback()
|
||||
let image = ColorImage::new([2, 2], vec![Color32::TRANSPARENT; 4]);
|
||||
let thumbnail = Thumbnail::from_image(&image, 2, Color32::RED);
|
||||
assert!(thumbnail.is_some());
|
||||
let layers = [BackdropLayer { rect: area(), thumbnail: thumbnail.as_ref(), fallback: Color32::BLUE }];
|
||||
let layers = [BackdropLayer::new(area(), thumbnail.as_ref(), Color32::BLUE)];
|
||||
let image = compose(area(), &layers, Color32::GREEN);
|
||||
assert!(image.as_ref().is_some_and(|image| image.pixels.iter().all(|p| *p == Color32::RED)));
|
||||
let layers = [BackdropLayer { rect: area(), thumbnail: None, fallback: Color32::BLUE }];
|
||||
let layers = [BackdropLayer::new(area(), None, Color32::BLUE)];
|
||||
let image = compose(area(), &layers, Color32::GREEN);
|
||||
assert!(image.as_ref().is_some_and(|image| image.pixels.iter().all(|p| *p == Color32::BLUE)));
|
||||
}
|
||||
@@ -30,7 +30,7 @@ fn transparent_capture_composites_over_paper_and_missing_capture_uses_fallback()
|
||||
fn downsampling_and_softening_mix_neighbours_without_changing_opaque_output() {
|
||||
let image = ColorImage::new([2, 1], vec![Color32::BLACK, Color32::WHITE]);
|
||||
let thumbnail = Thumbnail::from_image(&image, 1, Color32::WHITE);
|
||||
let layers = [BackdropLayer { rect: area(), thumbnail: thumbnail.as_ref(), fallback: Color32::RED }];
|
||||
let layers = [BackdropLayer::new(area(), thumbnail.as_ref(), Color32::RED)];
|
||||
let image = compose(area(), &layers, Color32::GREEN);
|
||||
assert!(image.as_ref().is_some_and(|image| image.pixels.iter().all(|p| p.a() == 255 && p.r() > 0 && p.r() < 255)));
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ fn non_finite_injected_points_queue_nothing_and_a_release_there_lets_go() {
|
||||
host.inject_click(ViewportId::ROOT, nan, PointerButton::Primary, 1, Mods::NONE, false);
|
||||
host.inject_move(ViewportId::ROOT, Pos2::new(f32::INFINITY, 0.0), Mods::NONE, 0.0);
|
||||
host.inject_wheel(ViewportId::ROOT, Pos2::new(20.0, 20.0), Vec2::new(0.0, f32::NAN), Mods::NONE);
|
||||
host.inject_pointer(ViewportId::ROOT, InjectedPointer::Down { button: PointerButton::Primary, at: nan, mods: Mods::NONE, pen: None });
|
||||
host.inject_pointer(ViewportId::ROOT, InjectedPointer::down(PointerButton::Primary, nan, Mods::NONE, None));
|
||||
frames(6);
|
||||
assert_eq!(presses.get(), 0, "no non-finite press reaches egui");
|
||||
assert!(!down.get(), "nothing is held");
|
||||
@@ -460,7 +460,7 @@ fn non_finite_injected_points_queue_nothing_and_a_release_there_lets_go() {
|
||||
host.inject_click(ViewportId::ROOT, Pos2::new(40.0, 40.0), PointerButton::Primary, 1, Mods::NONE, true);
|
||||
frames(4);
|
||||
assert!(down.get(), "the finite press is held");
|
||||
host.inject_pointer(ViewportId::ROOT, InjectedPointer::Up { at: nan, mods: Mods::NONE });
|
||||
host.inject_pointer(ViewportId::ROOT, InjectedPointer::up(nan, Mods::NONE));
|
||||
frames(4);
|
||||
assert!(!down.get(), "a release at a non-finite point lets the button go");
|
||||
assert_eq!(presses.get(), 1);
|
||||
|
||||
@@ -232,6 +232,7 @@ impl WebSlices {
|
||||
|
||||
/// A slice of the document: its number and its rectangle in document pixels.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct WebSlice {
|
||||
/// The slice's number.
|
||||
pub number: u32,
|
||||
@@ -239,6 +240,13 @@ pub struct WebSlice {
|
||||
pub rect: egui::Rect,
|
||||
}
|
||||
|
||||
impl WebSlice {
|
||||
/// The slice numbered `number` over `rect`.
|
||||
pub const fn new(number: u32, rect: egui::Rect) -> Self {
|
||||
Self { number, rect }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SaveForWebOptions {
|
||||
/// The opening values: JPEG quality 60, Selective 128 colours, Diffusion 88 %, transparency, white matte,
|
||||
/// Optimized, Convert to sRGB, Copyright, 100 %.
|
||||
|
||||
@@ -32,6 +32,7 @@ const THUMB_POINTS: f32 = 32.0;
|
||||
|
||||
/// What a history row stands for: a named snapshot or a state of the undo stack, by number.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum HistoryKey {
|
||||
/// The snapshot with this number.
|
||||
Snapshot(u64),
|
||||
@@ -85,6 +86,7 @@ impl HistoryRow {
|
||||
|
||||
/// Which buttons the history footer shows.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct HistoryFooter {
|
||||
/// The Delete button.
|
||||
pub delete: bool,
|
||||
@@ -94,6 +96,26 @@ pub struct HistoryFooter {
|
||||
pub new_document: bool,
|
||||
}
|
||||
|
||||
impl HistoryFooter {
|
||||
/// This footer with the Delete button shown when `shown`.
|
||||
pub const fn delete(mut self, shown: bool) -> Self {
|
||||
self.delete = shown;
|
||||
self
|
||||
}
|
||||
|
||||
/// This footer with the New Snapshot button shown when `shown`.
|
||||
pub const fn new_snapshot(mut self, shown: bool) -> Self {
|
||||
self.new_snapshot = shown;
|
||||
self
|
||||
}
|
||||
|
||||
/// This footer with the New Document button shown when `shown`.
|
||||
pub const fn new_document(mut self, shown: bool) -> Self {
|
||||
self.new_document = shown;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// What the user did in the history panel.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
@@ -103,6 +125,7 @@ pub enum HistoryEvent {
|
||||
/// The user set the row as the source of the history brush.
|
||||
SetSource(HistoryKey),
|
||||
/// The user renamed a snapshot.
|
||||
#[non_exhaustive]
|
||||
Rename {
|
||||
/// The snapshot's number.
|
||||
snapshot: u64,
|
||||
@@ -112,6 +135,7 @@ pub enum HistoryEvent {
|
||||
/// The user deleted the row, or the picked one when `None`.
|
||||
Delete(Option<HistoryKey>),
|
||||
/// The user asked for a new snapshot; `mods` were held.
|
||||
#[non_exhaustive]
|
||||
NewSnapshot {
|
||||
/// The modifiers held with the press.
|
||||
mods: Mods,
|
||||
@@ -121,6 +145,7 @@ pub enum HistoryEvent {
|
||||
}
|
||||
|
||||
/// What [`HistoryPanel`] reports.
|
||||
#[non_exhaustive]
|
||||
pub struct HistoryPanelOutput {
|
||||
/// The panel's response.
|
||||
pub response: Response,
|
||||
|
||||
@@ -58,6 +58,7 @@ impl<G, K> PresetManagerTaken<G, K> {
|
||||
}
|
||||
|
||||
/// What a [`PresetManager`] reports.
|
||||
#[non_exhaustive]
|
||||
pub struct PresetManagerOutput<G, K> {
|
||||
/// The manager's response.
|
||||
pub response: Response,
|
||||
|
||||
@@ -33,7 +33,7 @@ fn texture() -> SizedTexture {
|
||||
fn slices() -> Vec<WebSlice> {
|
||||
[(1, 0.0), (2, 100.0)]
|
||||
.into_iter()
|
||||
.map(|(number, left)| WebSlice { number, rect: Rect::from_min_size(pos2(left, 0.0), vec2(100.0, 100.0)) })
|
||||
.map(|(number, left)| WebSlice::new(number, Rect::from_min_size(pos2(left, 0.0), vec2(100.0, 100.0))))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ fn an_untouched_resolution_outside_the_range_is_not_reported_as_changed() {
|
||||
}
|
||||
|
||||
/// The 180 pt / 12 pt column size of the Units preference.
|
||||
const COLUMNS: ColumnSize = ColumnSize { width: 180.0, gutter: 12.0 };
|
||||
const COLUMNS: ColumnSize = ColumnSize::new(180.0, 12.0);
|
||||
|
||||
fn close(actual: f64, expected: f64) -> bool {
|
||||
(actual - expected).abs() < 1e-9
|
||||
@@ -117,9 +117,9 @@ fn relative_columns() {
|
||||
/// A degenerate or negative column size falls back to 180 pt / 12 pt, a negative gutter counts as none.
|
||||
fn degenerate_column_sizes() {
|
||||
let degenerate = [
|
||||
ColumnSize { width: 0.0, gutter: f64::NAN },
|
||||
ColumnSize { width: f64::NAN, gutter: f64::INFINITY },
|
||||
ColumnSize { width: -5.0, gutter: f64::NAN },
|
||||
ColumnSize::new(0.0, f64::NAN),
|
||||
ColumnSize::new(f64::NAN, f64::INFINITY),
|
||||
ColumnSize::new(-5.0, f64::NAN),
|
||||
];
|
||||
for column_size in degenerate {
|
||||
let mut size = document().column_size(column_size);
|
||||
@@ -128,7 +128,7 @@ fn degenerate_column_sizes() {
|
||||
assert_eq!(pixels(&size).0, 372, "{column_size:?} converts as 180 pt / 12 pt");
|
||||
assert!(size.width().is_finite());
|
||||
}
|
||||
let mut no_gutter = document().column_size(ColumnSize { width: 100.0, gutter: -4.0 });
|
||||
let mut no_gutter = document().column_size(ColumnSize::new(100.0, -4.0));
|
||||
assert!(no_gutter.set_width_unit(UnitKind::Columns));
|
||||
no_gutter.set_width(2.0);
|
||||
assert_eq!(pixels(&no_gutter).0, 200, "a negative gutter counts as none");
|
||||
|
||||
@@ -18,7 +18,7 @@ fn rig(source: Option<HistoryKey>, with_source: bool) -> (Fixture, Seen) {
|
||||
Fixture::new(move |ui| {
|
||||
let mut panel = HistoryPanel::new(&rows, Some(HistoryKey::State(2)))
|
||||
.can_delete(|key| *key != HistoryKey::State(1))
|
||||
.footer(HistoryFooter { delete: true, new_snapshot: false, new_document: false });
|
||||
.footer(HistoryFooter::default().delete(true));
|
||||
if with_source {
|
||||
panel = panel.source(source);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ pub struct ScreenModeButton {
|
||||
|
||||
/// What a [`ScreenModeButton`] reports.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct ScreenModeButtonOutput {
|
||||
/// The button's response.
|
||||
pub response: Response,
|
||||
|
||||
Reference in New Issue
Block a user