mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
Clean Up: Hairline Slivers' widths use the stroke unit in the framework dialog
The parameter dialog on main builds its rows through the craft UI framework, so the unit rule for the Hairline Slivers width rows moves there: `Setting` carries the stroke unit's `LengthUnits` for `object.path.cleanUp` and `select.object.hairlineSlivers`, or points when the stroke unit rounds 0.001 pt to 0.
This commit is contained in:
1 parent
6e117821db
commit
91e54b669e
2 files changed
+33
-2
No files matched your search
@@ -62,7 +62,7 @@ pub(crate) fn units() -> &'static [UnitKind] {
|
||||
}
|
||||
|
||||
/// Lengths stored in points and shown in `unit`, a bare number read as Numbers Without Units Are Points says.
|
||||
fn lengths(app: &VectorcraftApp, unit: Unit) -> LengthUnits {
|
||||
pub(crate) fn lengths(app: &VectorcraftApp, unit: Unit) -> LengthUnits {
|
||||
crate::fields::bare_points(
|
||||
LengthUnits::new(UnitKind::Points, unit_kind(unit), PIXELS_PER_INCH),
|
||||
app.session.prefs.numbers_without_units_are_points,
|
||||
|
||||
@@ -59,6 +59,9 @@ struct Open {
|
||||
struct Setting {
|
||||
cmyk: bool,
|
||||
units: LengthUnits,
|
||||
/// Hairline Slivers' widths: the stroke unit (Preferences › Units › Stroke), or points when
|
||||
/// that unit's field rounds the narrowest width to 0.
|
||||
sliver_units: LengthUnits,
|
||||
}
|
||||
|
||||
impl Setting {
|
||||
@@ -67,8 +70,23 @@ impl Setting {
|
||||
cmyk: app.session.active().is_some_and(|s| s.doc.color_mode == vectorcraft_doc::ColorMode::Cmyk),
|
||||
// PLAN: assumed `canvas::rulers::general_lengths(&VectorcraftApp) -> LengthUnits` (cv.B5)
|
||||
units: crate::canvas::rulers::general_lengths(app),
|
||||
sliver_units: crate::canvas::rulers::lengths(app, sliver_unit(app.session.stroke_unit())),
|
||||
}
|
||||
}
|
||||
|
||||
/// The length units of `command`'s distance rows.
|
||||
fn units_for(self, command: &str) -> LengthUnits {
|
||||
match command {
|
||||
"object.path.cleanUp" | "select.object.hairlineSlivers" => self.sliver_units,
|
||||
_ => self.units,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The unit Hairline Slivers' widths show in for the stroke unit `stroke`: `stroke`, or points
|
||||
/// when `stroke` rounds the narrowest width to 0.
|
||||
fn sliver_unit(stroke: vectorcraft_doc::Unit) -> vectorcraft_doc::Unit {
|
||||
if stroke.number(*vectorcraft_engine::HAIRLINE_SLIVER_WIDTH_RANGE.start()) == "0" { vectorcraft_doc::Unit::Points } else { stroke }
|
||||
}
|
||||
|
||||
/// Opens the parameter dialog of `command`, headed `label`, on `params` (a menu item's own values, `__params` for the
|
||||
@@ -283,7 +301,7 @@ fn row(command: &str, key: &str, value: &Value, setting: Setting) -> Option<Para
|
||||
param = param.bounds(Some(*range.start()), Some(*range.end()));
|
||||
}
|
||||
if lengths(command).contains(&key) {
|
||||
param = param.length(setting.units);
|
||||
param = param.length(setting.units_for(command));
|
||||
if let Some(range) = length_range(command, key) {
|
||||
param = param.bounds(Some(*range.start()), Some(*range.end()));
|
||||
}
|
||||
@@ -1161,4 +1179,17 @@ mod tests {
|
||||
answer_ok(&mut app);
|
||||
assert_eq!(fold_angle(&mut app, a), Some(-180.0));
|
||||
}
|
||||
|
||||
/// Hairline Slivers' widths show in the stroke unit, or in points when that unit rounds the
|
||||
/// narrowest width (0.001 pt) to 0.
|
||||
#[test]
|
||||
fn sliver_widths_show_in_the_stroke_unit_unless_it_rounds_them_to_zero() {
|
||||
use vectorcraft_doc::Unit;
|
||||
assert_eq!(sliver_unit(Unit::Points), Unit::Points);
|
||||
assert_eq!(sliver_unit(Unit::Millimeters), Unit::Millimeters);
|
||||
assert_eq!(sliver_unit(Unit::Inches), Unit::Points);
|
||||
assert!(lengths("object.path.cleanUp").contains(&"sliverWidth"));
|
||||
assert!(lengths("select.object.hairlineSlivers").contains(&"width"));
|
||||
assert_eq!(length_range("object.path.cleanUp", "sliverWidth"), Some(vectorcraft_engine::HAIRLINE_SLIVER_WIDTH_RANGE));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user