design-lint: props: derive the setters of draw components (#[prop]) and drop the hand setters

This commit is contained in:
aiongg
2026-11-16 13:27:45 +00:00
parent 6697fc9ebc
commit 305bc92fbd
4 changed files with 15 additions and 36 deletions
+7 -19
View File
@@ -270,8 +270,15 @@ pub struct BrushPresetPicker<'a, K: Value + Eq + Hash> {
#[prop]
resizable: Option<SaveKey>,
opened_at: Option<(Pos2, Bind<'a, bool>)>,
/// The compact form: the popover shows only the head (Size, Hardness for round tips, the tip widget), without the
/// search row, the gear or the browser.
#[prop]
compact: bool,
/// Whether the picker takes input: off disables its field, its head and its popover. It is enabled by default.
#[prop]
enabled: bool,
/// App rows drawn under the head.
#[prop(name = "rows", boxed = "FnOnce(&mut Ui) + 'a")]
app_rows: Option<AppRows<'a>>,
}
@@ -305,25 +312,6 @@ impl<'a, K: Value + Eq + Hash> BrushPresetPicker<'a, K> {
}
}
/// The compact form: the popover shows only the head (Size, Hardness for round tips, the tip widget), without the
/// search row, the gear or the browser.
pub fn compact(mut self, on: bool) -> Self {
self.compact = on;
self
}
/// Whether the picker takes input: off disables its field, its head and its popover. It is enabled by default.
pub fn enabled(mut self, on: bool) -> Self {
self.enabled = on;
self
}
/// App rows drawn under the head.
pub fn rows(mut self, rows: impl FnOnce(&mut Ui) + 'a) -> Self {
self.app_rows = Some(Box::new(rows));
self
}
/// Opens the popover at `at`, a point in the parent's layer space, while `open` is true, and shows no field: the
/// app opens it (a right-click on the canvas) and every close writes `false`.
pub fn open_at(mut self, at: Pos2, open: Bind<'a, bool>) -> Self {
+4 -7
View File
@@ -119,15 +119,12 @@ pub struct RulerOverlay<'a> {
#[common]
common: Common,
line: Bind<'a, Option<RulerLine>>,
/// Whether the overlay only paints: no parts, no Tab stop, no keys.
#[prop]
read_only: bool,
}
impl<'a> RulerOverlay<'a> {
/// An overlay named `label` over the Ruler `line` (document units).
pub fn new(label: impl Into<Label>, line: Bind<'a, Option<RulerLine>>) -> Self {
RulerOverlay { common: Common::new(), line, read_only: false }.label(label)
RulerOverlay { common: Common::new(), line }.label(label)
}
}
@@ -181,7 +178,7 @@ impl Component for RulerOverlay<'_> {
/// The points: drag parts at handle priority in one roving group, in keyboard order; a plain ruler's line: a drag
/// part under them.
fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) {
if self.read_only {
if cx.resolved.read_only {
return;
}
let (Some(space), Some(line)) = (canvas_space(&cx.env), cx.value().copied().flatten()) else { return };
@@ -211,7 +208,7 @@ impl Component for RulerOverlay<'_> {
}
fn update(&mut self, cx: &mut Cx<'_, Self>) {
if self.read_only {
if cx.resolved.read_only {
return;
}
let (Some(space), Some(line)) = (canvas_space(&cx.env), cx.value().copied().flatten()) else { return };
@@ -308,7 +305,7 @@ impl Component for RulerOverlay<'_> {
let units = cx.env.units();
let rulers = space.rulers();
access.value(reading_text(&line, &space, &units, &words));
if self.read_only {
if cx.resolved.read_only {
return;
}
for (part, name) in [(RulerPart::Start, &words.start), (RulerPart::End, &words.end), (RulerPart::Protractor, &words.protractor)] {
+1 -1
View File
@@ -8,7 +8,7 @@ use craft_behavior::kurbo::Point;
use craft_behavior::{CancelReason, Cursor, EditEvent, GestureId, Mixed};
use craft_ui::canvas::{CanvasTool, NUDGE, NUDGE_FAR, ToolAccess, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer};
use craft_ui::canvas_controls::StraightLinePreview;
use craft_ui::contract::{Bind, Show as _};
use craft_ui::contract::{Bind, Props as _, Show as _};
use craft_ui::primitives::Draw;
use egui::{Rect, Ui};
use std::sync::Arc;
@@ -300,7 +300,9 @@ pub struct TransformBox<'a> {
/// that handle does; while it is dragged, the box shows as it scales. No other part is declared.
#[prop]
line: Option<LineLook>,
/// How far outside the frame, in screen points, a plain press moves the box (0: off); set by `TransformOverlay`.
/// A plain press within `points` screen points outside the frame moves the box (0: off). Crate-private: the
/// public entry is `TransformOverlay::move_reach`.
#[prop(quantity = "press reach outside the frame, in screen points")]
move_reach: f32,
/// Whether this pass holds a drag of the reference point, so the hidden point is drawn while it moves.
pivot_held: bool,
@@ -348,14 +350,6 @@ impl<'a> TransformBox<'a> {
Self::new(label, state, start, 0.0).rules(rules).reference_point(false).inside_moves(false).rotate_zone(RotateZone::Band)
}
/// A plain press within `points` screen points outside the frame moves the box (0: off). Crate-private: the
/// public entry is `TransformOverlay::move_reach`.
#[must_use]
pub(crate) fn move_reach(mut self, points: f32) -> Self {
self.move_reach = points;
self
}
/// Whether the middle of the box is a move part: the reference point is hidden, so it does not take that place.
fn declares_centre(&self) -> bool {
!self.reference_point && self.inside_moves && self.rules.allows(BoxPart::Inside)