Merge pull request #9863 from dotCooCoo/fix/corner-radius-labels-start

Transform: the corner radius labels start their column
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-27 21:53:47 -08:00
commit a27235c85c
2 files changed
+50 -16

No files matched your search

+28 -16
View File
@@ -64,7 +64,9 @@ use craft::theme::Srgba;
use craft::theme::variant::Tone;
use craft::ui::buttons::{IconButton, Link, PopupMark};
use craft::ui::choice::{Radio, RadioGroup, SwatchSpacing};
use craft::ui::contract::{Bind, CommandSet as _, Entry, ListDrag, PopupKind, Props as _, Show as _, ShowContainer as _, Sizing, Trigger};
use craft::ui::contract::{
Bind, CaptionColumn, CommandSet as _, Entry, LabelScheme, ListDrag, PopupKind, Props as _, Show as _, ShowContainer as _, Sizing, Trigger,
};
use craft::ui::display::{Divider, Shade, Text};
use craft::ui::form::{Field, FieldGroup};
use craft::ui::layout_components::{Row, Stack};
@@ -74,7 +76,7 @@ use craft::ui::pickers::Select;
use craft::ui::popover::Popover;
use craft::ui::primitives::IconSpec;
use craft::ui::runtime::commands::CommandStates;
use craft::ui::runtime::env::Label;
use craft::ui::runtime::env::{Label, with_env};
use craft::ui::sections::{HeaderStrength, Section};
use craft::ui::text::{NumberField, link_toggle};
use egui::Ui;
@@ -213,27 +215,37 @@ fn rectangle_corners() -> [(usize, &'static str, &'static str); 4] {
}
/// One Corner Radius field and one Corner select per corner of a live rectangle, each pair on its
/// own row after the corner's label, the labels in one column; in a panel too narrow for that,
/// each select wraps under its field. A value typed or a kind picked is set on that corner alone,
/// of each selected live rectangle ([`set_rectangle_corners`]).
/// own row after the corner's label, the labels in one column at its start; in a panel too narrow
/// for that, each select wraps under its field. A value typed or a kind picked is set on that
/// corner alone, of each selected live rectangle ([`set_rectangle_corners`]).
fn corner_fields(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) {
let Some(lc) = LiveCorners::of(n) else { return };
let lengths = general_lengths(app);
let entries = corner_entries();
let mut radii = Vec::new();
let mut kinds = Vec::new();
FieldGroup::new(tl!("Corners")).show(ui, |ui, _| {
for (k, label, corner) in rectangle_corners() {
Field::new(label).show(ui, |ui, _| {
Row::new().wrap(true).show(ui, |ui, _| {
radii.push((k, NumberField::length(label, Bind::given(Some(corner_length(&lc, k))), lengths).show(ui).edit));
if let Some(kind) = corner_select(ui, corner, Some(lc.kind(k)), &entries) {
kinds.push((k, kind));
}
});
// An inline form whose captions share one column: each label starts the column and the fields
// after the labels line up.
with_env(
ui,
|scope| {
scope.values.set(CaptionColumn::SHARED);
},
|ui| {
FieldGroup::new(tl!("Corners")).labels(LabelScheme::Inline).show(ui, |ui, _| {
for (k, label, corner) in rectangle_corners() {
Field::new(label).show(ui, |ui, _| {
Row::new().wrap(true).show(ui, |ui, _| {
radii.push((k, NumberField::length(label, Bind::given(Some(corner_length(&lc, k))), lengths).show(ui).edit));
if let Some(kind) = corner_select(ui, corner, Some(lc.kind(k)), &entries) {
kinds.push((k, kind));
}
});
});
}
});
}
});
},
);
for (k, edit) in &radii {
apply_edits(app, edit, EditPath::Scope, |app, v: &Option<f64>, _| {
// A negative radius typed in rounds nothing: the command takes 0 or more.
@@ -158,6 +158,28 @@ fn a_rectangle_shows_linked_and_unlinked_corner_types() {
assert!(!p.shows("Corner") && p.shows("Top Left Corner") && p.shows("Bottom Left Corner"));
}
/// The four corner labels of an unlinked Corner Radius, in the Transform panel and in the
/// Properties panel, start at one edge of their column whatever their widths, and the radius
/// fields after them line up.
#[test]
fn unlinked_corner_labels_start_in_one_column() {
use craft::ui::contract::Role;
let corners = ["Top Left", "Top Right", "Bottom Right", "Bottom Left"];
for draw in [show as fn(&mut VectorcraftApp, &mut Ui), crate::panels::properties::transform_section] {
let mut app = new_app();
app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 120, "height": 80, "radius": 10})).unwrap();
set_pref(&mut app, "singleCornerRadius", false);
let p = Panel::new(app, draw);
let labels = corners.map(|name| p.rect_role(name, Role::LABEL));
let fields = corners.map(|name| p.rect_role(name, Role::SPIN_BUTTON));
assert!(labels[2].width() > labels[0].width() + 1.0, "Bottom Right {:?} is wider than Top Left {:?}", labels[2], labels[0]);
for (name, (label, field)) in corners.iter().zip(labels.iter().zip(&fields)) {
assert!((label.left() - labels[0].left()).abs() < 0.5, "{name} starts at {}, Top Left at {}", label.left(), labels[0].left());
assert!((field.left() - fields[0].left()).abs() < 0.5, "{name}'s field starts at {}, Top Left's at {}", field.left(), fields[0].left());
}
}
}
/// A corner kind set with no live rectangle selected leaves the selected polygon, the document and
/// its undo history as they are.
#[test]