mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
merge-c: 1.7: LiveShape::triangle; the Shape panel shows a triangle's W, H and one Corner radius (#13360)
This commit is contained in:
@@ -119,6 +119,16 @@ pub enum LiveShape {
|
||||
/// Inner radius over outer radius; 1 for a plain polygon.
|
||||
star_ratio: f64,
|
||||
},
|
||||
/// A triangle: one corner radius for every corner.
|
||||
#[non_exhaustive]
|
||||
Triangle {
|
||||
/// Width in document pixels.
|
||||
width: f64,
|
||||
/// Height in document pixels.
|
||||
height: f64,
|
||||
/// The corner radius in document pixels.
|
||||
corner_radius: f64,
|
||||
},
|
||||
/// A line.
|
||||
#[non_exhaustive]
|
||||
Line {
|
||||
@@ -146,6 +156,11 @@ impl LiveShape {
|
||||
LiveShape::Polygon { width, height, corner_radius, sides, star_ratio }
|
||||
}
|
||||
|
||||
/// A triangle of `width` by `height` with `corner_radius` at every corner.
|
||||
pub fn triangle(width: f64, height: f64, corner_radius: f64) -> Self {
|
||||
LiveShape::Triangle { width, height, corner_radius }
|
||||
}
|
||||
|
||||
/// A line of `weight`.
|
||||
pub fn line(weight: f64) -> Self {
|
||||
LiveShape::Line { weight, arrows: None }
|
||||
|
||||
@@ -65,10 +65,11 @@ pub struct ShapePanelOutput {
|
||||
/// [`stroke_open`](Self::stroke_open)). Stroke width 0 is no stroke; an edit that turns a stroke on at 0 carries
|
||||
/// [`ShapeChange::ENABLED_STROKE_WIDTH`] in the same change; an arrow step that clamps at 0 reports nothing.
|
||||
/// - Shape (a collapsible section), by the [`LiveShape`]: W and H (1 to 300,000 px, whole pixels) for a rect,
|
||||
/// ellipse or polygon; a rect's "Corner radius" (0 to 150,000, sets all four) then Top Left, Top Right, Bottom
|
||||
/// Left, Bottom Right rows (PhotoCraft's row order, mapped to the radii order TL, TR, BR, BL); a polygon's Corner
|
||||
/// radius, Sides (3 to 100) and Star ratio (1 to 100 %, stored 0.01 to 1); a line's Weight (1 to 10,000), and with
|
||||
/// arrowheads its Start and End check boxes, Width, Length and Concavity (-50 to 50 %, whole), then the "Set as default" check box ([`arrow_default`](Self::arrow_default)).
|
||||
/// ellipse, polygon or triangle; a rect's "Corner radius" (0 to 150,000, sets all four) then Top Left, Top Right,
|
||||
/// Bottom Left, Bottom Right rows (PhotoCraft's row order, mapped to the radii order TL, TR, BR, BL); a polygon's
|
||||
/// Corner radius, Sides (3 to 100) and Star ratio (1 to 100 %, stored 0.01 to 1); a triangle's Corner radius; a
|
||||
/// line's Weight (1 to 10,000), and with arrowheads its Start and End check boxes, Width, Length and Concavity
|
||||
/// (-50 to 50 %, whole), then the "Set as default" check box ([`arrow_default`](Self::arrow_default)).
|
||||
/// - A value typed past its field's range is clamped and reported once in [`ShapePanelOutput::out_of_range`].
|
||||
/// - A locked layer ([`ShapeAppearance::locked`]) disables the whole panel.
|
||||
/// - Keyboard: every field and chip is a Tab stop in reading order; sections fold with their title rows. Right to
|
||||
@@ -497,6 +498,11 @@ 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::Triangle { width, height, corner_radius } => {
|
||||
self.size_row(ui, (*width, *height));
|
||||
let radius = NumberCell::pixels(units, ppi, "corner-radius", &words.corner_radius, *corner_radius, RADIUS_RANGE);
|
||||
self.number_row(ui, radius, ShapeChange::CornerRadius);
|
||||
}
|
||||
LiveShape::Line { weight, arrows } => {
|
||||
let cell = NumberCell::pixels(units, ppi, "weight", &words.weight, *weight, LINE_WEIGHT_RANGE);
|
||||
match arrows {
|
||||
|
||||
@@ -41,12 +41,17 @@ fn apply(change: ShapeChange, shape: &mut LiveShape, look: &mut ShapeAppearance)
|
||||
}
|
||||
(
|
||||
ShapeChange::Size { width: w, height: h },
|
||||
LiveShape::Rect { width, height, .. } | LiveShape::Ellipse { width, height } | LiveShape::Polygon { width, height, .. },
|
||||
LiveShape::Rect { width, height, .. }
|
||||
| LiveShape::Ellipse { width, height }
|
||||
| LiveShape::Polygon { width, height, .. }
|
||||
| LiveShape::Triangle { width, height, .. },
|
||||
) => {
|
||||
(*width, *height) = (w, h);
|
||||
}
|
||||
(ShapeChange::Radii(next), LiveShape::Rect { radii, .. }) => *radii = next,
|
||||
(ShapeChange::CornerRadius(next), LiveShape::Polygon { corner_radius, .. }) => *corner_radius = next,
|
||||
(ShapeChange::CornerRadius(next), LiveShape::Polygon { corner_radius, .. } | LiveShape::Triangle { corner_radius, .. }) => {
|
||||
*corner_radius = next
|
||||
}
|
||||
(ShapeChange::Sides(next), LiveShape::Polygon { sides, .. }) => *sides = next,
|
||||
(ShapeChange::StarRatio(next), LiveShape::Polygon { star_ratio, .. }) => *star_ratio = next,
|
||||
(ShapeChange::Weight(next), LiveShape::Line { weight, .. }) => *weight = next,
|
||||
@@ -95,6 +100,11 @@ fn shape_panel_polygon(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
panel(ui, data, polygon())
|
||||
}
|
||||
|
||||
#[story(ShapePanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn shape_panel_triangle(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
panel(ui, data, LiveShape::triangle(240.0, 200.0, 0.0))
|
||||
}
|
||||
|
||||
#[story(ShapePanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn shape_panel_line(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
panel(ui, data, LiveShape::line(3.0))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! The shape cells: the arrowhead rows behind the popover and the Shape panel.
|
||||
//! The shape cells: the arrowhead rows behind the popover and the Shape panel, and the panel's rows by shape.
|
||||
|
||||
use craft_behavior::EditEvent;
|
||||
use craft_color::ui::Paint;
|
||||
@@ -170,3 +170,28 @@ fn a_concavity_typed_past_its_range_keeps_the_end_and_reports_it_once_from_the_p
|
||||
assert_eq!(host.borrow().shape, LiveShape::arrow_line(3.0, kept), "panel: 80 keeps 50");
|
||||
assert_eq!(host.borrow().alerts.len(), 1, "panel: the clamp is reported once");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_triangle_shows_its_size_and_one_corner_radius() {
|
||||
let host = Rc::new(RefCell::new(PanelHost {
|
||||
shape: LiveShape::triangle(240.0, 200.0, 0.0),
|
||||
look: ShapeAppearance::new(Paint::None, Paint::None, 2.0),
|
||||
events: Vec::new(),
|
||||
}));
|
||||
let shown = Rc::clone(&host);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut held = shown.borrow_mut();
|
||||
let PanelHost { shape, look, events } = &mut *held;
|
||||
events.extend(ShapePanel::new("Shape properties", shape, look, 72.0).show(ui).events);
|
||||
});
|
||||
fixture.settle();
|
||||
for shown in ["Width", "Height", "Corner radius"] {
|
||||
assert!(fixture.by_label(shown).is_some(), "a triangle shows {shown}");
|
||||
}
|
||||
for absent in ["Sides", "Star ratio", "Top Left"] {
|
||||
assert!(fixture.by_label(absent).is_none(), "a triangle has no {absent} field");
|
||||
}
|
||||
type_into(&mut fixture, "Corner radius", "12");
|
||||
let radius = host.borrow().events.iter().rev().find_map(|event| event.value().cloned());
|
||||
assert_eq!(radius, Some(ShapeChange::CornerRadius(12.0)), "the radius is one radius for every corner");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user