mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
merge-fwa: FW4: one tool-icon cursor with a crosshair or arrow pointer (PointerTool replaces CrosshairTool), protractor drawing
This commit is contained in:
@@ -205,9 +205,12 @@ pub enum PaintedCursor {
|
||||
/// The end of the path can be grabbed.
|
||||
end: bool,
|
||||
},
|
||||
/// A crosshair with the tool's icon below and right of it.
|
||||
/// A pointer with the tool's icon below and right of it: a crosshair (Perspective Crop), or an arrow with its tip
|
||||
/// on the hotspot (Paint Bucket, Ruler).
|
||||
#[non_exhaustive]
|
||||
CrosshairTool {
|
||||
PointerTool {
|
||||
/// The pointer the icon rides beside.
|
||||
pointer: PointerGlyph,
|
||||
/// The icon.
|
||||
icon: IconId,
|
||||
},
|
||||
@@ -280,9 +283,9 @@ impl PaintedCursor {
|
||||
PaintedCursor::PathText { start, end }
|
||||
}
|
||||
|
||||
/// A crosshair with the tool's icon at (+10, +10).
|
||||
pub const fn crosshair_tool(icon: IconId) -> Self {
|
||||
PaintedCursor::CrosshairTool { icon }
|
||||
/// `pointer` with the tool's icon below and right of it.
|
||||
pub const fn pointer_tool(pointer: PointerGlyph, icon: IconId) -> Self {
|
||||
PaintedCursor::PointerTool { pointer, icon }
|
||||
}
|
||||
|
||||
/// A system cursor with a mark.
|
||||
@@ -291,6 +294,16 @@ impl PaintedCursor {
|
||||
}
|
||||
}
|
||||
|
||||
/// The pointer of a [`PaintedCursor::PointerTool`].
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum PointerGlyph {
|
||||
/// A crosshair centred on the hotspot.
|
||||
Crosshair,
|
||||
/// The solid arrow with its tip on the hotspot.
|
||||
Arrow,
|
||||
}
|
||||
|
||||
/// What a cursor request names.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
|
||||
@@ -71,7 +71,7 @@ pub use kurbo;
|
||||
pub use codec::{Caret, Codec, NotAValue, NumberCodec, ParseNote, PlainText, decimals_for_step};
|
||||
pub use columns::{ColumnKey, ColumnWidth, GridSection, GridView, sub_row_cells};
|
||||
pub use command::{CommandFlags, pick_instance, resolve_flags};
|
||||
pub use cursor::{CountMark, Cursor, CursorBadge, CursorIcon, CursorPriority, IconId, PaintedCursor};
|
||||
pub use cursor::{CountMark, Cursor, CursorBadge, CursorIcon, CursorPriority, IconId, PaintedCursor, PointerGlyph};
|
||||
pub use digit_keys::{DigitEntry, DigitKeys};
|
||||
pub use doc_key::DocKey;
|
||||
pub use dock::DockSide;
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::sync::Arc;
|
||||
|
||||
use craft_behavior::geometry::Constraint;
|
||||
use craft_behavior::kurbo::Point;
|
||||
use craft_behavior::{CancelReason, Cursor, CursorIcon, EditEvent, GestureId, IconId, Mixed, PaintedCursor};
|
||||
use craft_behavior::{CancelReason, Cursor, CursorIcon, EditEvent, GestureId, IconId, Mixed, PaintedCursor, PointerGlyph};
|
||||
use craft_theme::variant::Tone;
|
||||
use craft_ui::canvas::{CanvasTool, CropShield, ToolAction, ToolContext, ToolKey, ToolPath, ToolPointer};
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
@@ -292,7 +292,7 @@ impl CanvasTool for PerspectiveCropPass<'_> {
|
||||
|
||||
fn cursor(&self, _: &ToolContext<'_>) -> Cursor {
|
||||
if self.tool.quad.is_none() {
|
||||
PaintedCursor::crosshair_tool(IconId::new("perspective_crop")).into()
|
||||
PaintedCursor::pointer_tool(PointerGlyph::Crosshair, IconId::new("perspective_crop")).into()
|
||||
} else {
|
||||
Cursor::System(CursorIcon::Default)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ Every set folder's files come from the npm package of the version in the table (
|
||||
- `distribute-*`, `symmetry-*`, `painting-symmetry` (the symmetry glyphs follow PhotoCraft's axis icons)
|
||||
- `lasso`, `lasso-magnetic`, `lasso-select`, `adjustment-layer`, `layer-mask`, `lollipop`, `marquee-column`, `marquee-row`, `pen-add-anchor`, `pen-curvature`, `pen-delete-anchor`, `pen-freeform`, `quick-selection` (the pen nib and the quick-selection brush follow Lucide's `pen-tool` and `paintbrush`, ISC)
|
||||
- `gradient-linear`, `gradient-radial`, `gradient-angle`, `gradient-reflected`, `gradient-diamond`, `fx` (the layer-style button)
|
||||
- `protractor` (the Ruler tool's pointer over an end point with Alt, which starts the protractor arm)
|
||||
- `stroke-align-*`, `stroke-cap-*`, `stroke-join-*`, `route-straight`, `route-elbow`, `route-curved` (the stroke editor's and connector bar's segments; the other packs have no matching glyph and draw these)
|
||||
- `sync-lock`, `mark-in`, `mark-out`, `insert-clip`, `overwrite-clip`, `lift-clip`, `extract-clip` (the timeline's lock and edit glyphs, after Premiere Pro's), `keyframe-linear`, `keyframe-bezier`, `keyframe-auto-bezier`, `keyframe-hold`, `keyframe-ease-in`, `keyframe-ease-out` (keyframe nodes after After Effects' shapes: diamond, square for Bezier, circle for Auto Bezier)
|
||||
- `key-linear`, `key-linear-filled`, `key-hold`, `key-bezier`, `key-auto-bezier`, `key-continuous-bezier`, `key-ease-in`, `key-ease-out`, `keyframe-easy-ease` (the timeline's single keyframe marks and the graph editor's Easy Ease button, after FilmCraft's diamond, square and circle and After Effects' keys; solid shapes except the outline diamond and the rings)
|
||||
|
||||
@@ -41,7 +41,7 @@ stroke_drawings = [
|
||||
"keyframe-bezier", "keyframe-ease-in", "keyframe-ease-out", "keyframe-easy-ease", "keyframe-hold",
|
||||
"keyframe-linear", "lasso", "lasso-magnetic", "lasso-select", "layer-mask", "lift-clip", "lollipop", "mark-in",
|
||||
"mark-out", "marquee-column", "marquee-row", "overwrite-clip", "painting-symmetry", "pen-add-anchor",
|
||||
"pen-curvature", "pen-delete-anchor", "pen-freeform", "quick-selection", "route-curved", "route-elbow",
|
||||
"pen-curvature", "pen-delete-anchor", "pen-freeform", "protractor", "quick-selection", "route-curved", "route-elbow",
|
||||
"route-straight", "stroke-align-center", "stroke-align-inside", "stroke-align-outside", "stroke-cap-butt",
|
||||
"stroke-cap-round", "stroke-cap-square", "stroke-join-bevel", "stroke-join-miter", "stroke-join-round",
|
||||
"symmetry-diagonal", "symmetry-dual", "symmetry-horizontal", "symmetry-vertical", "sync-lock",
|
||||
@@ -1419,6 +1419,11 @@ name = "gradient_angle"
|
||||
directional = false
|
||||
phosphor = "gradient-angle" # drawn in Phosphor's style: no match in any set
|
||||
|
||||
[[icon]]
|
||||
name = "protractor"
|
||||
directional = false
|
||||
phosphor = "protractor" # drawn in Phosphor's style: no match in any set
|
||||
|
||||
[[icon]]
|
||||
name = "gradient_reflected"
|
||||
directional = false
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><g transform="scale(10.6667)" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 21a10 10 0 0 1 20 0Z"/><path d="M7.5 21a4.5 4.5 0 0 1 9 0M12 11v2.5M19.1 13.9 17.3 15.7M4.9 13.9 6.7 15.7"/></g></svg>
|
||||
|
After Width: | Height: | Size: 323 B |
@@ -60,7 +60,7 @@ fn paint_pointer(ctx: &Context, env: &Env, painter: &egui::Painter) {
|
||||
/// The art of `cursor`: the hand as a fist while `closed`; with `marks_only`, a brush tip's centre cross and badge
|
||||
/// without its ring.
|
||||
fn pointer_art(env: &Env, cursor: &craft_behavior::PaintedCursor, closed: bool, marks_only: bool) -> Art {
|
||||
use craft_behavior::PaintedCursor;
|
||||
use craft_behavior::{PaintedCursor, PointerGlyph};
|
||||
let overlay = &env.tokens.color.overlay;
|
||||
let pen = pointers::Pen {
|
||||
art: RefCell::new(Art::default()),
|
||||
@@ -100,10 +100,11 @@ fn pointer_art(env: &Env, cursor: &craft_behavior::PaintedCursor, closed: bool,
|
||||
PaintedCursor::Locator => pointers::locator(&pen),
|
||||
PaintedCursor::Arrow { hollow, .. } => pointers::arrow(&pen, *hollow),
|
||||
PaintedCursor::PathText { start, end, .. } => pointers::path_text(&pen, *start, *end),
|
||||
PaintedCursor::CrosshairTool { icon, .. } => {
|
||||
let side = env.tokens.size.icon.sm;
|
||||
PaintedCursor::PointerTool { pointer, icon, .. } => {
|
||||
// The arrow's icon sits under its body, so it takes the larger size to show past the arrow.
|
||||
let side = if *pointer == PointerGlyph::Arrow { env.tokens.size.icon.md } else { env.tokens.size.icon.sm };
|
||||
let icon = SvgIcon::of(&env.tokens, env.direction, side, icon, IconSet::default(), Mirror::Auto);
|
||||
pointers::crosshair_tool(&pen, icon, side, edge, ink);
|
||||
pointers::pointer_tool(&pen, *pointer, icon, side, edge, ink);
|
||||
}
|
||||
// `Hidden` has no marks.
|
||||
_ => {}
|
||||
|
||||
@@ -9,7 +9,7 @@ use super::SvgIcon;
|
||||
use crate::style::UiTokens;
|
||||
pub(crate) use art::Art;
|
||||
use art::Mark;
|
||||
use craft_behavior::{CountMark, CursorBadge, PaintedCursor};
|
||||
use craft_behavior::{CountMark, CursorBadge, PaintedCursor, PointerGlyph};
|
||||
use craft_i18n::Direction;
|
||||
use egui::{Color32, Pos2, Rect, Stroke, Vec2};
|
||||
use std::cell::RefCell;
|
||||
@@ -61,6 +61,8 @@ const ARROW_TRIANGLES: [[usize; 3]; 5] = [[0, 1, 2], [0, 2, 5], [0, 5, 6], [2, 3
|
||||
const GRAB_TRIANGLE: [[f32; 2]; 3] = [[3.0, -4.0], [8.0, 0.0], [3.0, 4.0]];
|
||||
/// The top-left corner of the tool icon beside a crosshair.
|
||||
const CROSSHAIR_ICON: [f32; 2] = [10.0, 10.0];
|
||||
/// The top-left corner of the tool icon beside an arrow: under the arrow's body, which is drawn over it.
|
||||
const ARROW_ICON: [f32; 2] = [6.0, 6.0];
|
||||
/// The rotate pointer: radius of its arc, half its sweep in radians, and its segment count.
|
||||
const TURN_RADIUS: f32 = 12.0;
|
||||
const HALF_SWEEP: f32 = 0.75;
|
||||
@@ -356,13 +358,20 @@ pub(crate) fn path_text(pen: &Pen, start: bool, end: bool) {
|
||||
}
|
||||
}
|
||||
|
||||
/// A crosshair with arms of `side` points in a line of `width` in `color`, as the plain crosshair pointer, with the tool's
|
||||
/// `icon` of `side` points below and right of it. An icon the catalog lacks leaves only the crosshair.
|
||||
// A missing icon still shows the crosshair.
|
||||
pub(crate) fn crosshair_tool(pen: &Pen, icon: Option<SvgIcon>, side: f32, width: f32, color: Color32) {
|
||||
crosshair(pen, side, width, color);
|
||||
/// `pointer` with the tool's `icon` of `side` points below and right of it: a crosshair with arms of `side` points in a
|
||||
/// line of `width` in `color`, as the plain crosshair pointer, beside the icon; or the solid arrow, as the plain arrow
|
||||
/// pointer, over the icon's top-left corner. An icon the catalog lacks leaves only the pointer.
|
||||
pub(crate) fn pointer_tool(pen: &Pen, pointer: PointerGlyph, icon: Option<SvgIcon>, side: f32, width: f32, color: Color32) {
|
||||
let corner = match pointer {
|
||||
PointerGlyph::Arrow => ARROW_ICON,
|
||||
_ => CROSSHAIR_ICON,
|
||||
};
|
||||
if let Some(icon) = icon {
|
||||
icon_on_halo(pen, Rect::from_min_size(v(CROSSHAIR_ICON).to_pos2(), Vec2::splat(side)), icon);
|
||||
icon_on_halo(pen, Rect::from_min_size(v(corner).to_pos2(), Vec2::splat(side)), icon);
|
||||
}
|
||||
match pointer {
|
||||
PointerGlyph::Arrow => arrow(pen, false),
|
||||
_ => crosshair(pen, side, width, color),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The cursor service's images (8.5): a painted pointer reaches the window as its cursor image where the window takes
|
||||
//! one at its size, and is painted at the pointer otherwise.
|
||||
|
||||
use craft_behavior::{CountMark, Cursor, CursorBadge, CursorIcon, CursorPriority, IconId, PaintedCursor};
|
||||
use craft_behavior::{CountMark, Cursor, CursorBadge, CursorIcon, CursorPriority, IconId, PaintedCursor, PointerGlyph};
|
||||
use craft_host::target::{Backend, Os, Runtime, ShellInfo};
|
||||
use craft_ui::runtime::cursor;
|
||||
use craft_ui::testing::pointer::moved;
|
||||
@@ -133,7 +133,8 @@ fn a_painted_pointer_is_the_window_cursor_image_where_the_window_takes_one() {
|
||||
PaintedCursor::arrow(false),
|
||||
PaintedCursor::arrow(true),
|
||||
PaintedCursor::path_text(true, false),
|
||||
PaintedCursor::crosshair_tool(IconId::new("crop")),
|
||||
PaintedCursor::pointer_tool(PointerGlyph::Crosshair, IconId::new("crop")),
|
||||
PaintedCursor::pointer_tool(PointerGlyph::Arrow, IconId::new("paint_bucket")),
|
||||
] {
|
||||
let seen = painted(&mut frames, cursor.clone());
|
||||
assert!(seen.image.is_some() && seen.shapes == 0, "{cursor:?}");
|
||||
@@ -158,6 +159,36 @@ fn a_painted_pointer_is_the_window_cursor_image_where_the_window_takes_one() {
|
||||
assert!(hidden.image.is_none() && hidden.shapes == 0 && hidden.icon == egui::CursorIcon::None);
|
||||
}
|
||||
|
||||
/// A tool icon rides below and right of its pointer: beside the plain pointer, the image's marks reach as far left and up
|
||||
/// from the hotspot (the arrow's tip, the crosshair's centre) and farther right and down; an icon the catalog lacks
|
||||
/// leaves the plain pointer.
|
||||
#[trial]
|
||||
fn a_tool_icon_rides_below_right_of_its_pointer() {
|
||||
// How far the opaque pixels reach from the hotspot: left, up, right, down.
|
||||
fn reach(image: &CustomCursorImage) -> [i32; 4] {
|
||||
let (side, [hx, hy]) = (i32::from(image.size[0]), image.hotspot.map(i32::from));
|
||||
let mut reach = [0; 4];
|
||||
for (i, px) in image.rgba.chunks(4).enumerate() {
|
||||
if px[3] > 0 {
|
||||
let (dx, dy) = (i as i32 % side - hx, i as i32 / side - hy);
|
||||
reach = [reach[0].max(-dx), reach[1].max(-dy), reach[2].max(dx), reach[3].max(dy)];
|
||||
}
|
||||
}
|
||||
reach
|
||||
}
|
||||
let mut frames = frames(linux(), 1.0);
|
||||
for (plain, pointer) in [(PaintedCursor::arrow(false), PointerGlyph::Arrow), (PaintedCursor::Crosshair, PointerGlyph::Crosshair)] {
|
||||
let plain = reach(&painted(&mut frames, plain).image.unwrap());
|
||||
for icon in ["paint_bucket", "ruler", "protractor"] {
|
||||
let with = reach(&painted(&mut frames, PaintedCursor::pointer_tool(pointer, IconId::new(icon))).image.unwrap());
|
||||
assert_eq!(with[..2], plain[..2], "{pointer:?} {icon}: nothing reaches farther left or up");
|
||||
assert!(with[2] > plain[2] && with[3] > plain[3], "{pointer:?} {icon}: the icon lies below right");
|
||||
}
|
||||
let missing = reach(&painted(&mut frames, PaintedCursor::pointer_tool(pointer, IconId::new("no_such_icon"))).image.unwrap());
|
||||
assert_eq!(missing, plain, "{pointer:?}: only the pointer");
|
||||
}
|
||||
}
|
||||
|
||||
/// An unchanged pointer hands the window the same image, so the integration uploads it to the OS once; a new size or
|
||||
/// scale makes a new one; a frame whose winner is a system cursor, or that asks for nothing, clears it (egui keeps an
|
||||
/// image until it is replaced).
|
||||
|
||||
Reference in New Issue
Block a user