mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 07:35:02 +00:00
Contract stubs: craft-draw (part 3: shape, shape_presets, paint_bar, paths, pen, bezier)
This commit is contained in:
@@ -34,10 +34,13 @@ pub mod corner;
|
||||
pub mod crop;
|
||||
pub mod gradient;
|
||||
pub mod measure;
|
||||
pub mod paint_bar;
|
||||
pub mod paths;
|
||||
pub mod pattern;
|
||||
pub mod pen;
|
||||
pub mod picture_fill;
|
||||
pub mod shape;
|
||||
pub mod shape_presets;
|
||||
pub mod shape_drag;
|
||||
pub mod slice;
|
||||
pub mod stroke;
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
//! [`PaintBar`]: the options bar members of the Brush, Pencil, Eraser and Mixer Brush tools after the preset picker.
|
||||
|
||||
use craft_behavior::{EditEvents, Value};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::Entry;
|
||||
use craft_ui::text::RangeAlert;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
mod words;
|
||||
|
||||
pub use words::PaintBarWords;
|
||||
|
||||
/// The painting tools the bar serves.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum PaintTool {
|
||||
/// The Brush tool.
|
||||
Brush,
|
||||
/// The Pencil tool.
|
||||
Pencil,
|
||||
/// The Eraser tool.
|
||||
Eraser,
|
||||
/// The Mixer Brush tool.
|
||||
MixerBrush,
|
||||
}
|
||||
|
||||
/// The bar's values.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct PaintValues<M> {
|
||||
/// The brush size.
|
||||
pub size: f64,
|
||||
/// The brush hardness.
|
||||
pub hardness: f64,
|
||||
/// The opacity.
|
||||
pub opacity: f64,
|
||||
/// The flow.
|
||||
pub flow: f64,
|
||||
/// The stroke smoothing.
|
||||
pub smoothing: Smoothing,
|
||||
/// Pressure controls the opacity.
|
||||
pub pressure_opacity: bool,
|
||||
/// Pressure controls the size.
|
||||
pub pressure_size: bool,
|
||||
/// Build-up (airbrush) is on.
|
||||
pub build_up: bool,
|
||||
/// The blend mode, as the app's blend key.
|
||||
pub mode: M,
|
||||
/// The eraser erases to history.
|
||||
pub erase_to_history: bool,
|
||||
/// The pencil erases where it starts on the foreground colour.
|
||||
pub auto_erase: bool,
|
||||
/// The Mixer Brush's values.
|
||||
pub mixer: MixerValues,
|
||||
}
|
||||
|
||||
/// The stroke smoothing options.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct Smoothing {
|
||||
/// The amount, 0 to 1.
|
||||
pub amount: f64,
|
||||
/// Pulled string mode.
|
||||
pub pulled_string: bool,
|
||||
/// The stroke catches up when the pointer pauses.
|
||||
pub catch_up: bool,
|
||||
/// The stroke catches up at the end.
|
||||
pub catch_up_on_end: bool,
|
||||
/// The amount adjusts for zoom.
|
||||
pub adjust_for_zoom: bool,
|
||||
}
|
||||
|
||||
/// The Mixer Brush's values.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct MixerValues {
|
||||
/// Load the brush after each stroke.
|
||||
pub load_after_stroke: bool,
|
||||
/// Clean the brush after each stroke.
|
||||
pub clean_after_stroke: bool,
|
||||
/// The wetness.
|
||||
pub wet: f64,
|
||||
/// The load.
|
||||
pub load: f64,
|
||||
/// The mix.
|
||||
pub mix: f64,
|
||||
/// The flow.
|
||||
pub flow: f64,
|
||||
/// Sample all layers.
|
||||
pub sample_all_layers: bool,
|
||||
/// The index into [`MIXER_COMBINATIONS`].
|
||||
pub combination: usize,
|
||||
/// The colour the brush is loaded with, if any.
|
||||
pub load_color: Option<Srgba>,
|
||||
/// Only solid colours load.
|
||||
pub solid_colors_only: bool,
|
||||
}
|
||||
|
||||
/// What the Eraser tool erases with.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum EraserMode {
|
||||
/// A brush.
|
||||
#[default]
|
||||
Brush,
|
||||
/// A pencil.
|
||||
Pencil,
|
||||
/// A block.
|
||||
Block,
|
||||
}
|
||||
|
||||
/// The mixer combinations as (wet, load, mix); `None` is Custom.
|
||||
pub const MIXER_COMBINATIONS: [Option<(f64, f64, f64)>; 13] = [
|
||||
None,
|
||||
Some((0.0, 25.0, 25.0)),
|
||||
Some((0.0, 50.0, 50.0)),
|
||||
Some((0.0, 75.0, 75.0)),
|
||||
Some((25.0, 25.0, 25.0)),
|
||||
Some((25.0, 50.0, 50.0)),
|
||||
Some((25.0, 75.0, 75.0)),
|
||||
Some((50.0, 25.0, 25.0)),
|
||||
Some((50.0, 50.0, 50.0)),
|
||||
Some((50.0, 75.0, 75.0)),
|
||||
Some((75.0, 25.0, 25.0)),
|
||||
Some((75.0, 50.0, 50.0)),
|
||||
Some((75.0, 75.0, 75.0)),
|
||||
];
|
||||
|
||||
/// The index of the first combination of each group, as fractions 0..1 of the list.
|
||||
pub const MIXER_GROUP_STARTS: [usize; 4] = [0, 1, 4, 7];
|
||||
|
||||
/// The bar's members for one painting tool.
|
||||
#[must_use = "show the bar with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
#[pattern(probe(PaintBar<'static, u32>))]
|
||||
pub struct PaintBar<'a, M: Value> {
|
||||
tool: PaintTool,
|
||||
values: &'a mut PaintValues<M>,
|
||||
eraser_mode: Option<&'a mut EraserMode>,
|
||||
max_size: f64,
|
||||
modes: &'a [Entry<M>],
|
||||
}
|
||||
|
||||
/// What [`PaintBar::show`] reports.
|
||||
#[non_exhaustive]
|
||||
pub struct PaintBarOutput<M> {
|
||||
/// The bar's response.
|
||||
pub response: Response,
|
||||
/// The edits of the values, one gesture each.
|
||||
pub edits: EditEvents<PaintValues<M>>,
|
||||
/// The Load button was pressed.
|
||||
pub mixer_load: bool,
|
||||
/// The Clean button was pressed.
|
||||
pub mixer_clean: bool,
|
||||
/// A value was typed out of range.
|
||||
pub out_of_range: Option<RangeAlert>,
|
||||
}
|
||||
|
||||
impl<'a, M: Value> PaintBar<'a, M> {
|
||||
/// The bar of `tool` over `values`.
|
||||
pub fn new(tool: PaintTool, values: &'a mut PaintValues<M>) -> Self {
|
||||
PaintBar { tool, values, eraser_mode: None, max_size: 5000.0, modes: &[] }
|
||||
}
|
||||
|
||||
/// The Eraser's mode, shown for the Eraser tool.
|
||||
pub fn eraser_mode(mut self, mode: &'a mut EraserMode) -> Self {
|
||||
self.eraser_mode = Some(mode);
|
||||
self
|
||||
}
|
||||
|
||||
/// The largest brush size.
|
||||
pub fn max_size(mut self, max: f64) -> Self {
|
||||
self.max_size = max;
|
||||
self
|
||||
}
|
||||
|
||||
/// The blend modes the Mode list offers.
|
||||
pub fn modes(mut self, modes: &'a [Entry<M>]) -> Self {
|
||||
self.modes = modes;
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the members.
|
||||
pub fn show(self, ui: &mut Ui) -> PaintBarOutput<M> {
|
||||
let PaintBar { tool, values, eraser_mode, max_size, modes } = self;
|
||||
let _ = (ui, tool, values, eraser_mode, max_size, modes);
|
||||
todo!("pn.C18")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//! The words of the paint bar ([`PaintBarWords`]).
|
||||
|
||||
craft_ui::words! {
|
||||
/// The words of [`PaintBar`](super::PaintBar), English by default (Photoshop's).
|
||||
pub struct PaintBarWords {
|
||||
/// The Size field's caption.
|
||||
size: "paintBar.size" = "Size";
|
||||
/// The Hardness field's caption.
|
||||
hardness: "paintBar.hardness" = "Hardness";
|
||||
/// The Opacity field's caption.
|
||||
opacity: "paintBar.opacity" = "Opacity";
|
||||
/// The Flow field's caption.
|
||||
flow: "paintBar.flow" = "Flow";
|
||||
/// The Mode field's caption.
|
||||
mode: "paintBar.mode" = "Mode";
|
||||
/// The Smoothing field's caption.
|
||||
smoothing: "paintBar.smoothing" = "Smoothing";
|
||||
/// The names of the mixer combinations, in [`MIXER_COMBINATIONS`](super::MIXER_COMBINATIONS) order.
|
||||
combinations: array [
|
||||
"paintBar.combination0" = "Custom",
|
||||
"paintBar.combination1" = "Dry, Light Load",
|
||||
"paintBar.combination2" = "Dry, Medium Load",
|
||||
"paintBar.combination3" = "Dry, Heavy Load",
|
||||
"paintBar.combination4" = "Moist, Light Load",
|
||||
"paintBar.combination5" = "Moist, Medium Load",
|
||||
"paintBar.combination6" = "Moist, Heavy Load",
|
||||
"paintBar.combination7" = "Wet, Light Load",
|
||||
"paintBar.combination8" = "Wet, Medium Load",
|
||||
"paintBar.combination9" = "Wet, Heavy Load",
|
||||
"paintBar.combination10" = "Very Wet, Light Load",
|
||||
"paintBar.combination11" = "Very Wet, Medium Load",
|
||||
"paintBar.combination12" = "Very Wet, Heavy Load"
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//! The footer of the Paths panel.
|
||||
|
||||
/// A button of the Paths footer.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum PathsFooterButton {
|
||||
/// Fill the path with the foreground colour; disabled while the document cannot be filled.
|
||||
FillPath,
|
||||
/// Stroke the path.
|
||||
StrokePath,
|
||||
/// Load the path as a selection; a row dropped on it is loaded.
|
||||
LoadSelection,
|
||||
/// Make a work path from the selection.
|
||||
MakeWorkPath,
|
||||
/// Create a new path; a row dropped on it is duplicated.
|
||||
New,
|
||||
/// Delete the path; a row dropped on it is deleted.
|
||||
Delete,
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//! The commands of the Paths panel.
|
||||
|
||||
use super::PathKind;
|
||||
use craft_ui::contract::CommandSet;
|
||||
|
||||
/// The commands of the Paths panel: its panel-menu rows, its row menu and the footer's buttons.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, CommandSet)]
|
||||
#[command(prefix = "pathsPanel", scope = "pathsPanel")]
|
||||
#[non_exhaustive]
|
||||
pub enum PathsCommands {
|
||||
/// Load the path as a selection.
|
||||
#[command(label = "Make Selection…")]
|
||||
MakeSelection,
|
||||
/// Fill the path with the foreground colour.
|
||||
#[command(label = "Fill Path…")]
|
||||
FillPath,
|
||||
/// Stroke the path with the current tool.
|
||||
#[command(label = "Stroke Path…")]
|
||||
StrokePath,
|
||||
/// Save the work path.
|
||||
#[command(label = "Save Path…")]
|
||||
SavePath,
|
||||
/// Duplicate the path.
|
||||
#[command(label = "Duplicate Path…")]
|
||||
DuplicatePath,
|
||||
/// Rename the path in place.
|
||||
#[command(label = "Rename Path…")]
|
||||
RenamePath,
|
||||
/// Delete the path.
|
||||
#[command(label = "Delete Path")]
|
||||
DeletePath,
|
||||
}
|
||||
|
||||
impl PathsCommands {
|
||||
/// Whether the command applies to a targeted row of `kind` (`None`: no row targeted); Fill Path and Stroke Path
|
||||
/// need `can_fill`.
|
||||
pub fn applies_to(self, kind: Option<PathKind>, can_fill: bool) -> bool {
|
||||
let fills = matches!(self, PathsCommands::FillPath | PathsCommands::StrokePath);
|
||||
kind.is_some() && (can_fill || !fills)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//! The Paths panel ([`PathsPanel`]): saved paths, the work path, shape paths and vector masks as a list with a
|
||||
//! footer.
|
||||
|
||||
mod footer;
|
||||
mod menu;
|
||||
mod model;
|
||||
mod panel;
|
||||
mod rows;
|
||||
mod words;
|
||||
|
||||
pub use footer::PathsFooterButton;
|
||||
pub use menu::PathsCommands;
|
||||
pub use model::{PathKind, PathRow, PathsEvent, PathsOutput};
|
||||
pub use panel::PathsPanel;
|
||||
pub use words::PathsWords;
|
||||
@@ -0,0 +1,106 @@
|
||||
//! The data of the Paths panel: its rows, events and output.
|
||||
|
||||
use craft_behavior::geometry::selection_op::SelectionOperation;
|
||||
use craft_ui::contract::{NoValue, Outcome};
|
||||
use egui::Response;
|
||||
|
||||
/// What a path row is.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum PathKind {
|
||||
/// A saved path.
|
||||
Saved,
|
||||
/// The work path: italic, one per document.
|
||||
Work,
|
||||
/// The path of the selected shape layer.
|
||||
ShapePath,
|
||||
/// The path of the selected layer's vector mask.
|
||||
VectorMask,
|
||||
}
|
||||
|
||||
impl PathKind {
|
||||
/// Whether a row of this kind is renamed in place.
|
||||
pub fn renames(self) -> bool {
|
||||
let _ = self;
|
||||
todo!("tl.T34")
|
||||
}
|
||||
|
||||
/// Whether a row of this kind can be dragged.
|
||||
pub fn drags(self) -> bool {
|
||||
let _ = self;
|
||||
todo!("tl.T34")
|
||||
}
|
||||
|
||||
/// Whether a row of this kind is shown in italics: the work path.
|
||||
pub fn italic(self) -> bool {
|
||||
matches!(self, PathKind::Work)
|
||||
}
|
||||
}
|
||||
|
||||
/// One row of the panel.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct PathRow<K> {
|
||||
/// The row's key.
|
||||
pub key: K,
|
||||
/// What the row is.
|
||||
pub kind: PathKind,
|
||||
/// The path's name.
|
||||
pub name: String,
|
||||
/// The outline the thumbnail draws, in document pixels.
|
||||
pub outline: kurbo::BezPath,
|
||||
/// The row is the selected path.
|
||||
pub selected: bool,
|
||||
}
|
||||
|
||||
impl<K> PathRow<K> {
|
||||
/// An unselected row of `kind` named `name` with `outline`.
|
||||
pub fn new(key: K, kind: PathKind, name: impl Into<String>, outline: kurbo::BezPath) -> Self {
|
||||
PathRow { key, kind, name: name.into(), outline, selected: false }
|
||||
}
|
||||
}
|
||||
|
||||
/// What the Paths panel reports, in the order it happened.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum PathsEvent<K> {
|
||||
/// A row was selected.
|
||||
Select(K),
|
||||
/// A rename committed: never empty after trimming, never unchanged.
|
||||
#[non_exhaustive]
|
||||
Rename {
|
||||
/// The path.
|
||||
key: K,
|
||||
/// The new name, trimmed.
|
||||
text: String,
|
||||
},
|
||||
/// A Cmd/Ctrl-click on the thumbnail: load the path as a selection with the operation of Shift and Alt.
|
||||
#[non_exhaustive]
|
||||
LoadSelection {
|
||||
/// The path.
|
||||
key: K,
|
||||
/// New, add, subtract or intersect.
|
||||
operation: SelectionOperation,
|
||||
},
|
||||
/// A command of the panel menu, the row menu or the footer.
|
||||
Command(super::PathsCommands),
|
||||
}
|
||||
|
||||
/// What [`PathsPanel::show`](super::PathsPanel::show) returns.
|
||||
#[derive(Debug)]
|
||||
#[must_use = "the app applies the panel's events"]
|
||||
#[non_exhaustive]
|
||||
pub struct PathsOutput<K> {
|
||||
/// What the user did this pass, in order.
|
||||
pub events: Vec<PathsEvent<K>>,
|
||||
/// The panel.
|
||||
pub response: Response,
|
||||
}
|
||||
|
||||
impl<K> Outcome for PathsOutput<K> {
|
||||
type Value = NoValue;
|
||||
|
||||
fn response(&self) -> &Response {
|
||||
&self.response
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//! [`PathsPanel`]: the Paths panel on a `List` with a footer.
|
||||
|
||||
use super::{PathRow, PathsOutput};
|
||||
use craft_ui::runtime::env::Label;
|
||||
use egui::Ui;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
/// The Paths panel: one row per path with a thumbnail of its outline, rename in place, and the footer's buttons.
|
||||
///
|
||||
/// A Cmd/Ctrl-click on the thumbnail loads the path as a selection. Fill Path and Stroke Path are greyed while
|
||||
/// [`can_fill`](Self::can_fill) is false.
|
||||
#[must_use = "show the panel with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
#[pattern(probe(PathsPanel<'static, u32>))]
|
||||
pub struct PathsPanel<'a, K: Clone + Eq + Hash + Debug + Send + Sync + 'static> {
|
||||
rows: &'a [PathRow<K>],
|
||||
document: kurbo::Size,
|
||||
can_fill: bool,
|
||||
work_name: Option<Label>,
|
||||
rename: Option<K>,
|
||||
}
|
||||
|
||||
impl<'a, K: Clone + Eq + Hash + Debug + Send + Sync + 'static> PathsPanel<'a, K> {
|
||||
/// The panel showing `rows` in their order, thumbnails scaled to the `document`'s size.
|
||||
pub fn new(rows: &'a [PathRow<K>], document: kurbo::Size) -> Self {
|
||||
PathsPanel { rows, document, can_fill: true, work_name: None, rename: None }
|
||||
}
|
||||
|
||||
/// Whether the document can be filled and stroked; true by default.
|
||||
pub fn can_fill(mut self, can_fill: bool) -> Self {
|
||||
self.can_fill = can_fill;
|
||||
self
|
||||
}
|
||||
|
||||
/// The name the work path shows.
|
||||
pub fn work_name(mut self, name: impl Into<Label>) -> Self {
|
||||
self.work_name = Some(name.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Opens the rename field on the row `key`.
|
||||
pub fn start_rename(mut self, key: K) -> Self {
|
||||
self.rename = Some(key);
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the panel.
|
||||
pub fn show(self, ui: &mut Ui) -> PathsOutput<K> {
|
||||
let PathsPanel { rows, document, can_fill, work_name, rename } = self;
|
||||
let _ = (ui, rows, document, can_fill, work_name, rename);
|
||||
todo!("tl.T34")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
//! The rows of the Paths panel: a thumbnail of the outline and the name.
|
||||
@@ -0,0 +1,23 @@
|
||||
//! The words of the Paths panel ([`PathsWords`]).
|
||||
|
||||
craft_ui::words! {
|
||||
/// The words of [`PathsPanel`](super::PathsPanel), English by default (Photoshop's).
|
||||
pub struct PathsWords {
|
||||
/// The panel's accessible name.
|
||||
panel: "paths.panel" = "Paths";
|
||||
/// The default name of the work path.
|
||||
work_path: "paths.workPath" = "Work Path";
|
||||
/// The footer's Fill Path button.
|
||||
fill_path: "paths.fillPath" = "Fill path with foreground color";
|
||||
/// The footer's Stroke Path button.
|
||||
stroke_path: "paths.strokePath" = "Stroke path with brush";
|
||||
/// The footer's Load button.
|
||||
load_selection: "paths.loadSelection" = "Load path as a selection";
|
||||
/// The footer's Make Work Path button.
|
||||
make_work_path: "paths.makeWorkPath" = "Make work path from selection";
|
||||
/// The footer's New button.
|
||||
new_path: "paths.newPath" = "Create new path";
|
||||
/// The footer's Delete button.
|
||||
delete_path: "paths.deletePath" = "Delete current path";
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ use hit_test::{Shown, nearest_on_screen, shown_handles};
|
||||
pub(crate) use mark::paint_mark;
|
||||
pub use mark::{AnchorsShown, HitMark, SegmentMark};
|
||||
use mark::{Fill, paint_handle, segment_path, stroke};
|
||||
pub use model::{EditPath, EditSubpath, HandleSide, Knot, KnotRef, PathEdit, PathSelection};
|
||||
pub use model::{AnchorDelete, EditPath, EditSubpath, HandleSide, Knot, KnotRef, PathEdit, PathSelection};
|
||||
pub use style::BezierStyle;
|
||||
pub use words::BezierWords;
|
||||
|
||||
@@ -167,7 +167,7 @@ struct Report {
|
||||
change: Option<PathEdit>,
|
||||
select: Option<PathSelection>,
|
||||
insert: Option<(u64, KnotRef, f64)>,
|
||||
delete: Option<(u64, Vec<KnotRef>)>,
|
||||
delete: Option<AnchorDelete>,
|
||||
context: Option<(BezierHit, Pos2)>,
|
||||
hover: Option<BezierHit>,
|
||||
}
|
||||
@@ -859,7 +859,7 @@ impl<'a> BezierOverlay<'a> {
|
||||
&& let Some(path) = self.selection.path
|
||||
&& !self.selection.anchors.is_empty()
|
||||
{
|
||||
self.report.delete = Some((path, self.selection.anchors.clone()));
|
||||
self.report.delete = Some(AnchorDelete::new(path, self.selection.anchors.clone(), false)); // P3(tools-w9): tl.T32
|
||||
}
|
||||
if keyed && cx.gesture().is_none() && cx.intents().take(Intent::Cancel) && *self.selection != PathSelection::default() {
|
||||
self.report.select = Some(PathSelection::default());
|
||||
@@ -938,7 +938,10 @@ pub struct BezierOutput {
|
||||
/// anchor tool on a segment, or Insert on a picked anchor (`t` 0.5).
|
||||
pub insert: Option<(u64, KnotRef, f64)>,
|
||||
/// Delete or Backspace: remove these anchors of a path (Delete Anchor Point).
|
||||
pub delete: Option<(u64, Vec<KnotRef>)>,
|
||||
/// Delete or Backspace: remove these anchors of a path (Delete Anchor Point).
|
||||
pub delete: Option<AnchorDelete>,
|
||||
/// A press landed on empty canvas, outside every path.
|
||||
pub pressed_empty: bool,
|
||||
/// A secondary click on a part of a path, with its screen position, for the host's path menu.
|
||||
pub context: Option<(BezierHit, Pos2)>,
|
||||
/// The part under the pointer.
|
||||
@@ -965,6 +968,7 @@ impl Component for BezierOverlay<'_> {
|
||||
.with_moves()
|
||||
.with_deletes()
|
||||
.with_submits()
|
||||
.with_session()
|
||||
.with_chrome_key(false)
|
||||
.with_edits(EditSet::NONE.with(EditCommand::SelectAll))
|
||||
.with_claims(&[INSERT]);
|
||||
@@ -1147,6 +1151,6 @@ impl Component for BezierOverlay<'_> {
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> BezierOutput {
|
||||
let Report { change, select, insert, delete, context, hover } = self.report;
|
||||
BezierOutput { edit: cx.edit_response(), change, select, insert, delete, context, hover }
|
||||
BezierOutput { edit: cx.edit_response(), change, select, insert, delete, pressed_empty: false, context, hover } // P3(tools-w9): tl.T32
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,6 +285,18 @@ pub enum PathEdit {
|
||||
/// The move of the new anchor, in document units.
|
||||
by: Vec2,
|
||||
},
|
||||
/// Add an anchor to the segment leaving `segment` at `t`, then move it by `by`.
|
||||
#[non_exhaustive]
|
||||
InsertAnchor {
|
||||
/// The path's host key.
|
||||
path: u64,
|
||||
/// The anchor the segment leaves.
|
||||
segment: KnotRef,
|
||||
/// Position along the segment, 0..=1.
|
||||
t: f64,
|
||||
/// The move of the new anchor, in document units.
|
||||
by: Vec2,
|
||||
},
|
||||
/// The Curvature tool's double-click or Enter on an anchor: a smooth knot becomes a corner
|
||||
/// with retracted handles and a corner becomes smooth, then the subpath reflows.
|
||||
#[non_exhaustive]
|
||||
@@ -296,6 +308,25 @@ pub enum PathEdit {
|
||||
},
|
||||
}
|
||||
|
||||
/// A request to delete anchors of a path.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct AnchorDelete {
|
||||
/// The path's host key.
|
||||
pub path: u64,
|
||||
/// The selected anchors.
|
||||
pub anchors: Vec<KnotRef>,
|
||||
/// Segments are selected too (the live-shape prompt applies).
|
||||
pub segments: bool,
|
||||
}
|
||||
|
||||
impl AnchorDelete {
|
||||
/// A delete of `anchors` of the path keyed `path`; `segments` is whether segments are selected too.
|
||||
pub fn new(path: u64, anchors: Vec<KnotRef>, segments: bool) -> Self {
|
||||
AnchorDelete { path, anchors, segments }
|
||||
}
|
||||
}
|
||||
|
||||
impl PathEdit {
|
||||
/// Moves `anchors` of the path keyed `path` with their handles by `by`.
|
||||
pub fn move_anchors(path: u64, anchors: Vec<KnotRef>, by: Vec2) -> Self {
|
||||
@@ -327,6 +358,11 @@ impl PathEdit {
|
||||
PathEdit::InsertCurvature { path, segment, t, by }
|
||||
}
|
||||
|
||||
/// The insert of an anchor into the segment leaving `segment` at `t`, moved by `by`.
|
||||
pub fn insert_anchor(path: u64, segment: KnotRef, t: f64, by: Vec2) -> Self {
|
||||
PathEdit::InsertAnchor { path, segment, t, by }
|
||||
}
|
||||
|
||||
/// The Curvature tool's toggle of `knot` between smooth and corner.
|
||||
pub fn toggle_curvature(path: u64, knot: KnotRef) -> Self {
|
||||
PathEdit::ToggleCurvature { path, knot }
|
||||
@@ -341,6 +377,7 @@ impl PathEdit {
|
||||
| PathEdit::Convert { path, .. }
|
||||
| PathEdit::MoveCurvature { path, .. }
|
||||
| PathEdit::InsertCurvature { path, .. }
|
||||
| PathEdit::InsertAnchor { path, .. }
|
||||
| PathEdit::ToggleCurvature { path, .. } => path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,13 @@ impl EditSubpath {
|
||||
/// anchors, with the corner knots (`!smooth`) as corners and `closed` as it is. Corner knots
|
||||
/// keep their own handles.
|
||||
pub fn reflow(&mut self) {
|
||||
self.reflow_kept(0);
|
||||
}
|
||||
|
||||
/// The reflow with the first `kept` knots left as they are.
|
||||
pub fn reflow_kept(&mut self, kept: usize) {
|
||||
let _ = kept;
|
||||
// P3(tools-w9): tl.T32
|
||||
let anchors: Vec<Point> = self.knots.iter().map(|k| k.anchor).collect();
|
||||
let corners: Vec<bool> = self.knots.iter().map(|k| !k.smooth).collect();
|
||||
let fresh = curvature_handles(&anchors, &corners, self.closed);
|
||||
@@ -183,6 +190,7 @@ impl PathEdit {
|
||||
keep_smooth(&mut sp.knots[b], HandleSide::In);
|
||||
}
|
||||
}
|
||||
PathEdit::InsertAnchor { .. } => todo!("tl.T32"),
|
||||
PathEdit::Convert { knot, out, .. } => {
|
||||
if !knot_ok(path, *knot) {
|
||||
return false;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use craft_keymap::Mods;
|
||||
|
||||
use super::{BezierHit, BezierTool, Report};
|
||||
use super::{AnchorDelete, BezierHit, BezierTool, Report};
|
||||
|
||||
impl BezierTool {
|
||||
/// The tool a press acts as: [`BezierTool::AddAnchor`] and [`BezierTool::DeleteAnchor`] swap while ⌥ is held;
|
||||
@@ -70,7 +70,7 @@ pub(super) fn anchor_click(tool: BezierTool, hit: BezierHit, mods: Mods, report:
|
||||
// pc: crates/ui-egui/src/tools/anchor_tools.rs:88-114 `pointer`, `click`; :130-150 `apply`.
|
||||
match (hit, tool.acting(mods)) {
|
||||
(BezierHit::Segment { path, segment, t }, BezierTool::AddAnchor | BezierTool::AutoAddDelete) => report.insert = Some((path, segment, t)),
|
||||
(BezierHit::Anchor { path, knot }, BezierTool::DeleteAnchor | BezierTool::AutoAddDelete) => report.delete = Some((path, vec![knot])),
|
||||
(BezierHit::Anchor { path, knot }, BezierTool::DeleteAnchor | BezierTool::AutoAddDelete) => report.delete = Some(AnchorDelete::new(path, vec![knot], false)), // P3(tools-w9): tl.T32
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ impl PenTool {
|
||||
draft.reflow();
|
||||
self.change(draft);
|
||||
self.commit();
|
||||
self.finish();
|
||||
self.finish(super::tool::PenEnd::Closed); // P3(tools-w9): tl.T31
|
||||
return ToolAction::Done;
|
||||
}
|
||||
let index = match under {
|
||||
|
||||
@@ -13,10 +13,10 @@ mod tool;
|
||||
mod words;
|
||||
|
||||
pub use bezier::{
|
||||
AnchorsShown, BezierHit, BezierOutput, BezierOverlay, BezierStyle, BezierTool, BezierWords, EditPath, EditSubpath, HandleSide, HandlesShown,
|
||||
AnchorDelete, AnchorsShown, BezierHit, BezierOutput, BezierOverlay, BezierStyle, BezierTool, BezierWords, EditPath, EditSubpath, HandleSide, HandlesShown,
|
||||
HitMark, Knot, KnotRef, MAX_ANCHORS, PathEdit, PathSelection, SegmentMark,
|
||||
};
|
||||
pub use mode::{PathMode, PathTool, PenMode};
|
||||
pub use options::{PATH_OPTIONS_COLOR_KEY, PathOptionsOutput, PathOptionsPopover, PathOptionsSettings, PathOptionsWords};
|
||||
pub use tool::{PenEvent, PenStyle, PenTool};
|
||||
pub use tool::{PenEnd, PenEvent, PenStyle, PenTool};
|
||||
pub use words::PenWords;
|
||||
|
||||
@@ -20,6 +20,24 @@ use egui::{CornerRadius, Pos2, Rect, Vec2};
|
||||
/// The side of the box a tool icon is drawn on; an icon's hotspot is in these units.
|
||||
const ICON_BOX: f32 = 24.0;
|
||||
|
||||
/// Why a draft ended.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum PenEnd {
|
||||
/// Enter or a tool switch committed it.
|
||||
Submit,
|
||||
/// Escape ended it.
|
||||
Escape,
|
||||
/// The path was closed.
|
||||
Closed,
|
||||
/// Its only anchor was removed.
|
||||
Removed,
|
||||
/// Something else interrupted it (focus loss, a command).
|
||||
Interrupted,
|
||||
/// The draft was discarded back to the run's start.
|
||||
Discarded,
|
||||
}
|
||||
|
||||
/// What the pen reports to the host, drained with [`PenTool::take_events`].
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
@@ -33,7 +51,7 @@ pub enum PenEvent {
|
||||
Edit(EditEvent<EditSubpath>),
|
||||
/// The pen ended the draft (Enter, Escape, closing it, removing its only anchor, an interruption): the host
|
||||
/// stops handing it in. It follows the draft's `Commit` or `Cancel`.
|
||||
Finished,
|
||||
Finished(PenEnd),
|
||||
/// A press on the end point of an open path while no draft is open: the host makes that path's subpath the draft
|
||||
/// with the knot of that end last (reversing it for its first knot).
|
||||
Resumed(u64, KnotRef),
|
||||
@@ -193,6 +211,24 @@ impl PenTool {
|
||||
self
|
||||
}
|
||||
|
||||
/// Ends the run with `Edit(Cancel)` back to the run's start, then `Finished(Discarded)`; false when no run is
|
||||
/// open.
|
||||
pub fn discard(&mut self) -> bool {
|
||||
todo!("tl.T31")
|
||||
}
|
||||
|
||||
/// The number of leading anchors of the draft that are kept when the draft is rebuilt.
|
||||
pub fn kept(&mut self, kept: usize) -> &mut Self {
|
||||
let _ = kept;
|
||||
todo!("tl.T31")
|
||||
}
|
||||
|
||||
/// Replaces the draft with `draft` while a run is open; false when none is.
|
||||
pub fn replace(&mut self, draft: &EditSubpath) -> bool {
|
||||
let _ = draft;
|
||||
todo!("tl.T31")
|
||||
}
|
||||
|
||||
/// The Pen or the Curvature Pen; [`PenMode::Pen`] by default.
|
||||
pub fn mode(&mut self, mode: PenMode) -> &mut Self {
|
||||
self.mode = mode;
|
||||
@@ -278,7 +314,7 @@ impl PenTool {
|
||||
/// Ends a draft too short to be a path. The gesture's start is what the host holds of the draft: when that is
|
||||
/// empty a cancel leaves nothing behind; when it holds anchors (a resumed path) the empty draft is committed, so
|
||||
/// the host removes them.
|
||||
fn discard(&mut self, reason: CancelReason) {
|
||||
fn discard_short(&mut self, reason: CancelReason) {
|
||||
let Some(run) = self.run.take() else { return };
|
||||
if run.before.knots.is_empty() {
|
||||
self.events.push(PenEvent::Edit(EditEvent::cancel(run.id, reason, Some(Mixed::Same(run.before)))));
|
||||
@@ -290,8 +326,8 @@ impl PenTool {
|
||||
}
|
||||
|
||||
/// The draft is over: reports `Finished` and starts clean.
|
||||
pub(super) fn finish(&mut self) {
|
||||
self.events.push(PenEvent::Finished);
|
||||
pub(super) fn finish(&mut self, end: PenEnd) {
|
||||
self.events.push(PenEvent::Finished(end));
|
||||
self.shown = EditSubpath::default();
|
||||
self.run = None;
|
||||
self.drag = None;
|
||||
@@ -301,17 +337,18 @@ impl PenTool {
|
||||
/// Ends the draft open: a path of two anchors or more is kept, a shorter one discarded.
|
||||
fn end(&mut self, reason: CancelReason) {
|
||||
if self.shown.knots.len() < 2 {
|
||||
self.discard(reason);
|
||||
self.discard_short(reason);
|
||||
} else {
|
||||
self.commit();
|
||||
}
|
||||
self.finish();
|
||||
// P3(tools-w9): tl.T31
|
||||
self.finish(if reason == CancelReason::Escape { PenEnd::Escape } else { PenEnd::Interrupted });
|
||||
}
|
||||
|
||||
fn remove_last_anchor(&mut self, reason: CancelReason) {
|
||||
if self.shown.knots.len() <= 1 {
|
||||
self.discard(reason);
|
||||
self.finish();
|
||||
self.discard_short(reason);
|
||||
self.finish(PenEnd::Removed);
|
||||
return;
|
||||
}
|
||||
let mut draft = self.shown.clone();
|
||||
@@ -491,7 +528,7 @@ impl CanvasTool for PenTool {
|
||||
draft.closed = true;
|
||||
self.change(draft);
|
||||
self.commit();
|
||||
self.finish();
|
||||
self.finish(PenEnd::Closed); // P3(tools-w9): tl.T31
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//! [`ArrowheadsPopover`]: the Line tool's arrowhead settings.
|
||||
|
||||
use super::Arrowheads;
|
||||
use craft_behavior::EditEvent;
|
||||
use craft_ui::contract::Bind;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
/// The arrowhead popover: which ends carry a head and the head's width, length and concavity.
|
||||
#[must_use = "show the popover with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct ArrowheadsPopover<'a> {
|
||||
value: Bind<'a, Arrowheads>,
|
||||
open: Bind<'a, bool>,
|
||||
}
|
||||
|
||||
/// What [`ArrowheadsPopover::show`] reports.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct ArrowheadsOutput {
|
||||
/// The button's response.
|
||||
pub response: Response,
|
||||
/// The edit made this pass, if any.
|
||||
pub edit: Option<EditEvent<Arrowheads>>,
|
||||
}
|
||||
|
||||
impl<'a> ArrowheadsPopover<'a> {
|
||||
/// The popover of `value`, open while `open` is set.
|
||||
pub fn new(value: Bind<'a, Arrowheads>, open: Bind<'a, bool>) -> Self {
|
||||
ArrowheadsPopover { value, open }
|
||||
}
|
||||
|
||||
/// Shows the button and, while open, the popover.
|
||||
pub fn show(self, ui: &mut Ui) -> ArrowheadsOutput {
|
||||
let ArrowheadsPopover { value, open } = self;
|
||||
let _ = (ui, value, open);
|
||||
todo!("tl.T29")
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ use craft_ui::display::Divider;
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::requests::ColorRequest;
|
||||
use craft_ui::text::RangeAlert;
|
||||
use egui::Ui;
|
||||
|
||||
/// What [`ShapeBar::show`] reports.
|
||||
@@ -24,6 +26,10 @@ pub struct ShapeBarOutput {
|
||||
pub events: Vec<EditEvent<ShapeChange>>,
|
||||
/// A chip's screen eyedropper was pressed, as [`ShapePanelOutput::screen_pick`](super::ShapePanelOutput::screen_pick).
|
||||
pub screen_pick: Option<(ShapePaint, ScreenPickGesture)>,
|
||||
/// A chip asked for the app's full colour picker, with the chip it is for.
|
||||
pub pick_color: Option<(ShapePaint, ColorRequest)>,
|
||||
/// The kind cell's (Radius, Sides, Weight) value was typed out of range.
|
||||
pub out_of_range: Option<RangeAlert>,
|
||||
}
|
||||
|
||||
/// The cells a Shape tool adds to the options bar, in PhotoCraft's order: the "Fill" check box and chip, the
|
||||
@@ -47,6 +53,7 @@ pub struct ShapeBar<'a> {
|
||||
fallbacks: (Srgba, Srgba),
|
||||
sampled: Option<(ShapePaint, Srgba)>,
|
||||
pixels_per_inch: f64,
|
||||
paint: bool,
|
||||
}
|
||||
|
||||
impl<'a> ShapeBar<'a> {
|
||||
@@ -62,9 +69,16 @@ impl<'a> ShapeBar<'a> {
|
||||
fallbacks: (Srgba::BLACK, Srgba::WHITE),
|
||||
sampled: None,
|
||||
pixels_per_inch,
|
||||
paint: true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the bar shows the paint cells (the Fill check, both chips and the stroke cells); off in Path mode.
|
||||
pub fn paint(mut self, on: bool) -> Self {
|
||||
self.paint = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// The Stroke style popover's open flag; without it the button is not shown.
|
||||
pub fn stroke_open(mut self, open: Bind<'a, bool>) -> Self {
|
||||
self.stroke_open = Some(open);
|
||||
@@ -91,7 +105,8 @@ impl<'a> ShapeBar<'a> {
|
||||
|
||||
/// Adds the cells to the bar's row `ui`.
|
||||
pub fn show(self, ui: &mut Ui) -> ShapeBarOutput {
|
||||
let ShapeBar { kind, settings, appearance, stroke_open, chips, fallbacks, sampled, pixels_per_inch } = self;
|
||||
let ShapeBar { kind, settings, appearance, stroke_open, chips, fallbacks, sampled, pixels_per_inch, paint } = self;
|
||||
let _ = paint; // P3(tools-w8): tl.T28
|
||||
let env = Env::of(ui);
|
||||
let (words, units) = (env.words::<ShapeWords>(), env.units());
|
||||
let mut pass = Cells::new(&words, &units, pixels_per_inch, appearance, fallbacks, sampled, chips);
|
||||
@@ -122,7 +137,7 @@ impl<'a> ShapeBar<'a> {
|
||||
pass.style_button(ui, kind != ShapeKind::Ellipse);
|
||||
let cell = match kind {
|
||||
ShapeKind::Rectangle | ShapeKind::RoundedRectangle => Some((
|
||||
NumberCell::pixels(&units, pixels_per_inch, "radius", &words.radius, settings.corner_radius, 0.0..=RADIUS_MAX),
|
||||
NumberCell::pixels(&units, pixels_per_inch, "radius", &words.radius, settings.corner_radius, super::RADIUS_RANGE),
|
||||
ShapeChange::CornerRadius as fn(f64) -> ShapeChange,
|
||||
)),
|
||||
ShapeKind::Polygon | ShapeKind::Star => Some((
|
||||
@@ -130,7 +145,7 @@ impl<'a> ShapeBar<'a> {
|
||||
sides_change as fn(f64) -> ShapeChange,
|
||||
)),
|
||||
ShapeKind::Line => Some((
|
||||
NumberCell::pixels(&units, pixels_per_inch, "weight", &words.weight, settings.line_weight, 1.0..=LINE_WEIGHT_MAX),
|
||||
NumberCell::pixels(&units, pixels_per_inch, "weight", &words.weight, settings.line_weight, super::LINE_WEIGHT_RANGE),
|
||||
ShapeChange::Weight as fn(f64) -> ShapeChange,
|
||||
)),
|
||||
_ => None,
|
||||
@@ -143,11 +158,13 @@ impl<'a> ShapeBar<'a> {
|
||||
pass.events.extend(event.unwrap_or_default().map(change));
|
||||
}
|
||||
});
|
||||
ShapeBarOutput { events: pass.events, screen_pick: pass.screen_pick }
|
||||
ShapeBarOutput { events: pass.events, screen_pick: pass.screen_pick, pick_color: None, out_of_range: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// The largest corner radius of the bar's Radius cell, in pixels.
|
||||
#[allow(dead_code)] // P3(tools-w8): tl.T27
|
||||
const RADIUS_MAX: f64 = 10_000.0;
|
||||
/// The largest weight of the bar's Line cell, in pixels.
|
||||
#[allow(dead_code)] // P3(tools-w8): tl.T27
|
||||
const LINE_WEIGHT_MAX: f64 = 1_000.0;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//! The shape layer's Properties sections ([`ShapePanel`]) and the Shape tools' options bar
|
||||
//! ([`ShapeBar`]), each field a gesture-aware [`EditEvent<ShapeChange>`](craft_behavior::EditEvent).
|
||||
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
use craft_color::ui::Paint;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -8,16 +10,77 @@ use crate::stroke::StrokeStyle;
|
||||
|
||||
use super::shape_drag::{ShapeDragOptions, ShapeKind};
|
||||
|
||||
mod arrowheads;
|
||||
mod bar;
|
||||
mod mode_select;
|
||||
mod panel;
|
||||
mod stroke_cells;
|
||||
#[cfg(feature = "screen-testing")]
|
||||
pub(crate) mod stories;
|
||||
mod words;
|
||||
|
||||
pub use arrowheads::{ArrowheadsOutput, ArrowheadsPopover};
|
||||
pub use mode_select::VectorModeSelect;
|
||||
pub use stroke_cells::StrokeCells;
|
||||
pub use bar::{ShapeBar, ShapeBarOutput};
|
||||
pub use panel::{ChipSetup, ShapePaint, ShapePanel, ShapePanelOutput};
|
||||
pub use words::ShapeWords;
|
||||
|
||||
/// The drawing mode of the vector tools.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[non_exhaustive]
|
||||
pub enum VectorMode {
|
||||
/// Draws a shape layer.
|
||||
#[default]
|
||||
Shape,
|
||||
/// Draws a path.
|
||||
Path,
|
||||
/// Draws filled pixels.
|
||||
Pixels,
|
||||
}
|
||||
|
||||
/// A line's arrowheads: which ends carry one and its size.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[non_exhaustive]
|
||||
pub struct Arrowheads {
|
||||
/// An arrowhead at the start.
|
||||
pub start: bool,
|
||||
/// An arrowhead at the end.
|
||||
pub end: bool,
|
||||
/// The head's width as a percentage of the line weight.
|
||||
pub width: f64,
|
||||
/// The head's length as a percentage of the line weight.
|
||||
pub length: f64,
|
||||
/// The head's concavity in percent.
|
||||
pub concavity: f64,
|
||||
}
|
||||
|
||||
impl Arrowheads {
|
||||
/// The range of the width and length fields, in percent.
|
||||
pub const ARROW_SIZE: RangeInclusive<f64> = 10.0..=1000.0;
|
||||
/// The range of the concavity field, in percent.
|
||||
pub const ARROW_CONCAVITY: RangeInclusive<f64> = -50.0..=50.0;
|
||||
|
||||
/// No arrowheads at the default size.
|
||||
pub const fn new() -> Self {
|
||||
Arrowheads { start: false, end: false, width: 5.0, length: 10.0, concavity: 0.0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Arrowheads {
|
||||
/// No arrowheads; width 5, length 10, concavity 0.
|
||||
fn default() -> Self {
|
||||
Arrowheads::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// The range of a radius field, in document pixels.
|
||||
pub const RADIUS_RANGE: RangeInclusive<f64> = 0.0..=150_000.0;
|
||||
/// The range of a line weight field, in document pixels.
|
||||
pub const LINE_WEIGHT_RANGE: RangeInclusive<f64> = 1.0..=10_000.0;
|
||||
|
||||
/// The selected shape layer's live shape, as the Shape section shows it: plain data the app
|
||||
/// converts to and from its document. Sizes in document pixels.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -60,6 +123,8 @@ pub enum LiveShape {
|
||||
Line {
|
||||
/// The line's weight in document pixels.
|
||||
weight: f64,
|
||||
/// The line's arrowheads, or `None` for a plain line.
|
||||
arrows: Option<Arrowheads>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -82,7 +147,12 @@ impl LiveShape {
|
||||
|
||||
/// A line of `weight`.
|
||||
pub fn line(weight: f64) -> Self {
|
||||
LiveShape::Line { weight }
|
||||
LiveShape::Line { weight, arrows: None }
|
||||
}
|
||||
|
||||
/// A line of `weight` with `arrows`.
|
||||
pub fn arrow_line(weight: f64, arrows: Arrowheads) -> Self {
|
||||
LiveShape::Line { weight, arrows: Some(arrows) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +242,8 @@ pub enum ShapeChange {
|
||||
StarRatio(f64),
|
||||
/// A line's weight.
|
||||
Weight(f64),
|
||||
/// A line's arrowheads.
|
||||
Arrowheads(Arrowheads),
|
||||
}
|
||||
|
||||
impl ShapeChange {
|
||||
@@ -198,13 +270,15 @@ pub struct ShapeToolSettings {
|
||||
pub line_weight: f64,
|
||||
/// Stroke width of new shapes, in pixels; 0 is no stroke.
|
||||
pub stroke_width: f64,
|
||||
/// The Line's arrowheads.
|
||||
pub arrowheads: Arrowheads,
|
||||
}
|
||||
|
||||
impl Default for ShapeToolSettings {
|
||||
/// Fill on, square corners, 5 sides, a plain polygon, weight 3, no stroke (PhotoCraft's
|
||||
/// `ToolOptions::default`, `state/tool_options.rs:405-412`).
|
||||
fn default() -> Self {
|
||||
ShapeToolSettings { fill_on: true, corner_radius: 0.0, sides: 5, star_ratio: 1.0, line_weight: 3.0, stroke_width: 0.0 }
|
||||
ShapeToolSettings { fill_on: true, corner_radius: 0.0, sides: 5, star_ratio: 1.0, line_weight: 3.0, stroke_width: 0.0, arrowheads: Arrowheads::default() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//! [`VectorModeSelect`]: the Shape, Path and Pixels mode choice of the vector tools.
|
||||
|
||||
use super::VectorMode;
|
||||
use craft_ui::contract::{Bind, EditResponse};
|
||||
use egui::Ui;
|
||||
|
||||
/// The mode select of the vector tools' bars; a mode in `offered` with `false` shows disabled.
|
||||
#[must_use = "show the select with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct VectorModeSelect<'a> {
|
||||
mode: Bind<'a, VectorMode>,
|
||||
offered: &'a [(VectorMode, bool)],
|
||||
}
|
||||
|
||||
impl<'a> VectorModeSelect<'a> {
|
||||
/// The select of `mode` over the `offered` modes, each with whether it is enabled.
|
||||
pub fn new(mode: Bind<'a, VectorMode>, offered: &'a [(VectorMode, bool)]) -> Self {
|
||||
VectorModeSelect { mode, offered }
|
||||
}
|
||||
|
||||
/// Shows the select and reports the picked mode.
|
||||
pub fn show(self, ui: &mut Ui) -> EditResponse<VectorMode> {
|
||||
let VectorModeSelect { mode, offered } = self;
|
||||
let _ = (ui, mode, offered);
|
||||
todo!("tl.T29")
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
use super::{LiveShape, ShapeAppearance, ShapeChange, ShapeWords};
|
||||
use super::{RADIUS_RANGE, LiveShape, ShapeAppearance, ShapeChange, ShapeWords};
|
||||
use crate::ui::stroke::StrokeButton;
|
||||
use craft_behavior::{EditEvent, EditEvents, NumberCodec};
|
||||
use craft_color::ui::{Paint, PaintChip, PaintChipOutput, ScreenPickGesture};
|
||||
@@ -11,6 +11,7 @@ use craft_theme::Srgba;
|
||||
use craft_ui::contract::{Bind, GlyphLabel, LabelKind, LabelScheme, Props as _, Show as _, ShowContainer as _, SideLabel};
|
||||
use craft_ui::form::{Field, FieldGroup};
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::runtime::requests::ColorRequest;
|
||||
use craft_ui::runtime::env::{Env, Label, LengthUnits, UnitKind, Units, with_env};
|
||||
use craft_ui::sections::Section;
|
||||
use craft_ui::text::NumberField;
|
||||
@@ -46,6 +47,8 @@ pub struct ShapePanelOutput {
|
||||
/// A chip's screen eyedropper was pressed: the host samples the screen and answers with
|
||||
/// [`ShapePanel::sampled`].
|
||||
pub screen_pick: Option<(ShapePaint, ScreenPickGesture)>,
|
||||
/// A chip asked for the app's full colour picker, with the chip it is for.
|
||||
pub pick_color: Option<(ShapePaint, ColorRequest)>,
|
||||
}
|
||||
|
||||
/// A shape layer's Properties sections, as PhotoCraft's `shape_properties`.
|
||||
@@ -73,6 +76,7 @@ pub struct ShapePanel<'a> {
|
||||
sections: (bool, bool),
|
||||
sampled: Option<(ShapePaint, Srgba)>,
|
||||
pixels_per_inch: f64,
|
||||
arrow_default: Option<Bind<'a, bool>>,
|
||||
}
|
||||
|
||||
impl<'a> ShapePanel<'a> {
|
||||
@@ -89,9 +93,16 @@ impl<'a> ShapePanel<'a> {
|
||||
sections: (true, true),
|
||||
sampled: None,
|
||||
pixels_per_inch,
|
||||
arrow_default: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The link that makes the Arrowheads defaults follow the panel's edits.
|
||||
pub fn arrow_default(mut self, linked: Bind<'a, bool>) -> Self {
|
||||
self.arrow_default = Some(linked);
|
||||
self
|
||||
}
|
||||
|
||||
/// The Stroke style popover's open flag, kept by the app between passes. Without it the button is not shown.
|
||||
pub fn stroke_open(mut self, open: Bind<'a, bool>) -> Self {
|
||||
self.stroke_open = Some(open);
|
||||
@@ -125,7 +136,8 @@ impl<'a> ShapePanel<'a> {
|
||||
|
||||
/// Adds the sections to `ui` and reports the changed fields.
|
||||
pub fn show(self, ui: &mut Ui) -> ShapePanelOutput {
|
||||
let ShapePanel { label, shape, appearance, stroke_open, chips, fallbacks, sections, sampled, pixels_per_inch } = self;
|
||||
let ShapePanel { label, shape, appearance, stroke_open, chips, fallbacks, sections, sampled, pixels_per_inch, arrow_default } = self;
|
||||
let _ = arrow_default; // P3(tools-w8): tl.T28
|
||||
let env = Env::of(ui);
|
||||
let (words, units) = (env.words::<ShapeWords>(), env.units());
|
||||
let mut pass = Cells::new(&words, &units, pixels_per_inch, appearance, fallbacks, sampled, chips);
|
||||
@@ -151,7 +163,7 @@ impl<'a> ShapePanel<'a> {
|
||||
} else {
|
||||
body(ui);
|
||||
}
|
||||
ShapePanelOutput { events: pass.events, screen_pick: pass.screen_pick }
|
||||
ShapePanelOutput { events: pass.events, screen_pick: pass.screen_pick, pick_color: None }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,8 +445,8 @@ impl<'p, 'a> Cells<'p, 'a> {
|
||||
let ratio = NumberCell::percent(units, "star-ratio", &words.star_ratio, star_ratio * 100.0, RATIO_PERCENT);
|
||||
self.number_row(ui, ratio, |percent| ShapeChange::StarRatio(percent / 100.0));
|
||||
}
|
||||
LiveShape::Line { weight } => {
|
||||
let cell = NumberCell::pixels(units, ppi, "weight", &words.weight, *weight, 1.0..=10_000.0);
|
||||
LiveShape::Line { weight, .. } => {
|
||||
let cell = NumberCell::pixels(units, ppi, "weight", &words.weight, *weight, super::LINE_WEIGHT_RANGE);
|
||||
self.number_row(ui, cell, ShapeChange::Weight);
|
||||
}
|
||||
}
|
||||
@@ -451,7 +463,8 @@ const STROKE_WIDTH_MAX: f64 = 288.0;
|
||||
/// The range of a shape's width and height in whole pixels.
|
||||
const SIZE_RANGE: RangeInclusive<f64> = 1.0..=300_000.0;
|
||||
/// The range of a corner radius in pixels.
|
||||
const RADIUS_RANGE: RangeInclusive<f64> = 0.0..=100_000.0;
|
||||
#[allow(dead_code)] // P3(tools-w8): tl.T27
|
||||
const RADIUS_RANGE_OLD: RangeInclusive<f64> = 0.0..=100_000.0;
|
||||
/// The number of sides of a polygon or points of a star.
|
||||
pub(super) const SIDES_RANGE: RangeInclusive<f64> = 3.0..=100.0;
|
||||
/// The star ratio in percent.
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//! [`StrokeCells`]: the stroke width cell and the Stroke style button, shared by the Shape bar and the Pen tools'
|
||||
//! Shape mode.
|
||||
|
||||
use super::{ShapeAppearance, ShapeChange};
|
||||
use craft_behavior::EditEvent;
|
||||
use craft_ui::contract::Bind;
|
||||
use egui::Ui;
|
||||
|
||||
/// The stroke width cell and the Stroke style button of a shape's stroke, as one pattern shown as children of a
|
||||
/// `Bar`.
|
||||
#[must_use = "show the cells with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct StrokeCells<'a> {
|
||||
appearance: &'a ShapeAppearance,
|
||||
pixels_per_inch: f64,
|
||||
corners: bool,
|
||||
stroke_open: Option<Bind<'a, bool>>,
|
||||
}
|
||||
|
||||
impl<'a> StrokeCells<'a> {
|
||||
/// The cells for `appearance`, in a document of `pixels_per_inch`.
|
||||
pub fn new(appearance: &'a ShapeAppearance, pixels_per_inch: f64) -> Self {
|
||||
StrokeCells { appearance, pixels_per_inch, corners: true, stroke_open: None }
|
||||
}
|
||||
|
||||
/// Whether the style popover offers corner joins; off for an ellipse.
|
||||
pub fn corners(mut self, on: bool) -> Self {
|
||||
self.corners = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// The Stroke style popover's open flag; without it the button is not shown.
|
||||
pub fn stroke_open(mut self, open: Bind<'a, bool>) -> Self {
|
||||
self.stroke_open = Some(open);
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds the cells to the bar's row `ui` and reports each change.
|
||||
pub fn show(self, ui: &mut Ui) -> Vec<EditEvent<ShapeChange>> {
|
||||
let StrokeCells { appearance, pixels_per_inch, corners, stroke_open } = self;
|
||||
let _ = (ui, appearance, pixels_per_inch, corners, stroke_open);
|
||||
todo!("tl.T29")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
//! The shape menu: the preset glyphs, their words and [`ShapeMenu`].
|
||||
|
||||
use crate::geometry::presets::ShapePreset;
|
||||
use craft_ui::style::UiTokens;
|
||||
use craft_ui::primitives::Glyph;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use egui::{Color32, Painter, Rect, Ui};
|
||||
|
||||
craft_ui::words! {
|
||||
/// The labels of the shape presets, English by default (upstream's).
|
||||
pub struct ShapePresetWords {
|
||||
/// The Rectangle preset's label.
|
||||
rectangle: "shapePreset.rectangle" = "Rectangle";
|
||||
/// The Rounded Rectangle preset's label.
|
||||
rounded_rectangle: "shapePreset.roundedRectangle" = "Rounded Rectangle";
|
||||
/// The Oval preset's label.
|
||||
ellipse: "shapePreset.ellipse" = "Oval";
|
||||
/// The Triangle preset's label.
|
||||
triangle: "shapePreset.triangle" = "Triangle";
|
||||
/// The Diamond preset's label.
|
||||
diamond: "shapePreset.diamond" = "Diamond";
|
||||
/// The Line preset's label.
|
||||
line: "shapePreset.line" = "Line";
|
||||
/// The Arrow preset's label.
|
||||
arrow: "shapePreset.arrow" = "Arrow";
|
||||
/// The Star preset's label.
|
||||
star: "shapePreset.star" = "Star";
|
||||
/// The Heart preset's label.
|
||||
heart: "shapePreset.heart" = "Heart";
|
||||
/// The Text Box preset's label.
|
||||
text_box: "shapePreset.textBox" = "Text Box";
|
||||
/// The Straight Connector preset's label.
|
||||
straight_connector: "shapePreset.straightConnector" = "Straight Connector";
|
||||
/// The Straight Arrow Connector preset's label.
|
||||
straight_arrow_connector: "shapePreset.straightArrowConnector" = "Straight Arrow Connector";
|
||||
/// The Elbow Connector preset's label.
|
||||
elbow_connector: "shapePreset.elbowConnector" = "Elbow Connector";
|
||||
/// The Elbow Arrow Connector preset's label.
|
||||
elbow_arrow_connector: "shapePreset.elbowArrowConnector" = "Elbow Arrow Connector";
|
||||
/// The Curved Connector preset's label.
|
||||
curved_connector: "shapePreset.curvedConnector" = "Curved Connector";
|
||||
/// The Curved Arrow Connector preset's label.
|
||||
curved_arrow_connector: "shapePreset.curvedArrowConnector" = "Curved Arrow Connector";
|
||||
}
|
||||
}
|
||||
|
||||
impl ShapePreset {
|
||||
/// The preset's label in `words`.
|
||||
pub fn label(self, words: &ShapePresetWords) -> &Label {
|
||||
match self {
|
||||
ShapePreset::Rectangle => &words.rectangle,
|
||||
ShapePreset::RoundedRectangle => &words.rounded_rectangle,
|
||||
ShapePreset::Ellipse => &words.ellipse,
|
||||
ShapePreset::Triangle => &words.triangle,
|
||||
ShapePreset::Diamond => &words.diamond,
|
||||
ShapePreset::Line => &words.line,
|
||||
ShapePreset::Arrow => &words.arrow,
|
||||
ShapePreset::Star => &words.star,
|
||||
ShapePreset::Heart => &words.heart,
|
||||
ShapePreset::TextBox => &words.text_box,
|
||||
ShapePreset::StraightConnector => &words.straight_connector,
|
||||
ShapePreset::StraightArrowConnector => &words.straight_arrow_connector,
|
||||
ShapePreset::ElbowConnector => &words.elbow_connector,
|
||||
ShapePreset::ElbowArrowConnector => &words.elbow_arrow_connector,
|
||||
ShapePreset::CurvedConnector => &words.curved_connector,
|
||||
ShapePreset::CurvedArrowConnector => &words.curved_arrow_connector,
|
||||
#[allow(unreachable_patterns)]
|
||||
_ => &words.rectangle,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Glyph for ShapePreset {
|
||||
fn paint(&self, painter: &Painter, tokens: &UiTokens, rect: Rect, color: Color32, mirrored: bool) {
|
||||
let _ = (painter, tokens, rect, color, mirrored);
|
||||
todo!("fx.F57")
|
||||
}
|
||||
}
|
||||
|
||||
/// The shape menu: the supported presets as menu items with the preset glyph as icon, a separator before the first
|
||||
/// connector.
|
||||
#[must_use = "show the menu with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct ShapeMenu<'a> {
|
||||
supported: Box<dyn Fn(ShapePreset) -> bool + 'a>,
|
||||
}
|
||||
|
||||
impl<'a> ShapeMenu<'a> {
|
||||
/// The menu of the presets `supported` accepts.
|
||||
pub fn new(supported: impl Fn(ShapePreset) -> bool + 'a) -> Self {
|
||||
ShapeMenu { supported: Box::new(supported) }
|
||||
}
|
||||
|
||||
/// Shows the menu and reports the picked preset.
|
||||
pub fn show(self, ui: &mut Ui) -> Option<ShapePreset> {
|
||||
let ShapeMenu { supported } = self;
|
||||
let _ = (ui, supported);
|
||||
todo!("fx.F57")
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,8 @@ fn harness_with(paths: Vec<EditPath>, pans: bool) -> Harness {
|
||||
sub.insert_at(segment.knot, t);
|
||||
}
|
||||
}
|
||||
if let Some((path, mut knots)) = output.delete {
|
||||
if let Some(delete) = output.delete {
|
||||
let (path, mut knots) = (delete.path, delete.anchors); // P3(tools-w9): tl.T32
|
||||
st.deletes.push((path, knots.clone()));
|
||||
knots.sort_by(|a, b| b.cmp(a));
|
||||
if let Some(entry) = st.paths.iter_mut().find(|e| e.key == path) {
|
||||
|
||||
@@ -93,7 +93,7 @@ impl Pen {
|
||||
match event {
|
||||
PenEvent::Edit(EditEvent::Update { value, .. }) => now = value.clone(),
|
||||
PenEvent::Edit(EditEvent::Commit { after, .. }) => now = after.clone(),
|
||||
PenEvent::Finished => now = EditSubpath::default(),
|
||||
PenEvent::Finished(_) => now = EditSubpath::default(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ impl Pen {
|
||||
PenEvent::Edit(EditEvent::Commit { .. }) => "commit",
|
||||
PenEvent::Edit(EditEvent::Cancel { .. }) => "cancel",
|
||||
PenEvent::Edit(_) => "other",
|
||||
PenEvent::Finished => "finished",
|
||||
PenEvent::Finished(_) => "finished",
|
||||
PenEvent::Resumed(..) => "resumed",
|
||||
})
|
||||
.collect()
|
||||
|
||||
Reference in New Issue
Block a user