mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-27 03:46:50 -06:00
Layout grids: a stretched grid's count takes no Auto
CodeRabbit: typing "Auto" in the count of a stretched grid set 0, which the setter clamped to 1. The count field only takes the word where 0 is Auto (a fixed-size grid); a stretched grid's count is a plain number.
This commit is contained in:
@@ -611,6 +611,9 @@ fn typing_auto_is_zero_only_where_zero_is_the_automatic_value() {
|
||||
assert!(u.ctx.read_response(Id::new(("grid_field", "size", 0usize)).with("field")).is_some(), "the width row is shown");
|
||||
type_at(&mut u, Id::new(("grid_field", "size", 0usize)), "40");
|
||||
assert_eq!(u.app.session.doc().unwrap().node(f).unwrap().grids[0].size, 0.0, "a stretched grid's width isn't set");
|
||||
// Nor its count: a stretched grid has at least one band, so the word commits nothing.
|
||||
type_at(&mut u, Id::new(("grid_field", "count", 0usize)), "Auto");
|
||||
assert_eq!(u.app.session.doc().unwrap().node(f).unwrap().grids[0].count, 3, "a stretched grid keeps its count");
|
||||
|
||||
// The auto layout's gap: its placeholder says Auto, but Auto is a mode, not 0.
|
||||
let mut s = Session::new();
|
||||
|
||||
@@ -2056,7 +2056,13 @@ fn grid_settings(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId], list: &[LayoutGr
|
||||
// 0 is Auto for fixed-size columns (rows); a stretched grid has at least one.
|
||||
let count = (!auto_count(g)).then(|| f64::from(g.count.max(1)));
|
||||
let key = format!("layoutGrids/{i}/count");
|
||||
let e = crate::variable_ui::number_field_auto(app, ui, ids, &key, Id::new(("grid_field", "count", i)), count, col, Lead::None, "");
|
||||
let id = Id::new(("grid_field", "count", i));
|
||||
// A stretched grid has at least one band, so 0 (Auto) isn't a count it can take.
|
||||
let e = if g.align == GridAlign::Stretch {
|
||||
crate::variable_ui::number_field_or(app, ui, ids, &key, id, count, col, "", Lead::None, "")
|
||||
} else {
|
||||
crate::variable_ui::number_field_auto(app, ui, ids, &key, id, count, col, Lead::None, "")
|
||||
};
|
||||
app.field_run(e, "node.set", |v| {
|
||||
set(&|x| x.count = if x.align == GridAlign::Stretch { v.round().clamp(1.0, 1000.0) } else { v.round().clamp(0.0, 1000.0) } as u32)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user