mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-27 02:23:56 +00:00
Merge pull request #4964 from tsw2k/fix/table-narrow-column-floor
fix(engine): a drag between narrow columns leaves them as they are
This commit is contained in:
@@ -305,12 +305,16 @@ fn share_out(w: &mut [f32], i: usize, dx: f32, share: Share) -> Option<f32> {
|
||||
Share::Proportional if rest > 0.0 && narrowest > 0.0 => Share::Proportional,
|
||||
_ => Share::LeftOnly,
|
||||
};
|
||||
let least = MIN_COL - left;
|
||||
// A column already narrower than `MIN_COL` (a file can give one) is not narrowed further,
|
||||
// nor widened by a drag that has no room for it: forcing it to `MIN_COL` would take its
|
||||
// neighbour below a point, which import reads as no width and gives the whole table equal
|
||||
// columns.
|
||||
let least = (MIN_COL - left).min(0.0);
|
||||
let d = match share {
|
||||
Share::Neighbour => dx.clamp(least, (w.get(i + 1).copied().unwrap_or(0.0) - MIN_COL).max(least)),
|
||||
Share::Neighbour => dx.clamp(least, (w.get(i + 1).copied().unwrap_or(0.0) - MIN_COL).max(0.0)),
|
||||
// As far as the narrowest column on the right, shrunk in proportion, stays `MIN_COL`.
|
||||
Share::Proportional => dx.clamp(least, (rest * (1.0 - (MIN_COL / narrowest).min(1.0))).max(least)),
|
||||
Share::LeftOnly => (left + dx).clamp(MIN_COL, MAX_LEN) - left,
|
||||
Share::Proportional => dx.clamp(least, (rest * (1.0 - (MIN_COL / narrowest).min(1.0))).max(0.0)),
|
||||
Share::LeftOnly => (left + dx).clamp(MIN_COL.min(left), MAX_LEN.max(left)) - left,
|
||||
};
|
||||
if let Some(x) = w.get_mut(i) {
|
||||
*x = left + d;
|
||||
|
||||
@@ -237,6 +237,29 @@ fn ctrl_shares_a_border_drag_among_the_columns_right_of_it() {
|
||||
assert_eq!(share_out(&mut w, 3, 1.0, Share::Proportional), None);
|
||||
}
|
||||
|
||||
/// Columns a file gives narrower than the minimum (3 pt and 4 pt) aren't forced to it by a drag
|
||||
/// between them: that took the right one to 1 pt, which the next import read as no width.
|
||||
#[test]
|
||||
fn a_drag_between_narrow_columns_leaves_them_as_they_are() {
|
||||
for share in [Share::Neighbour, Share::Proportional, Share::LeftOnly] {
|
||||
for dx in [0.0, -2.0, 2.0] {
|
||||
let mut w = [3.0, 4.0, 100.0];
|
||||
share_out(&mut w, 0, dx, share);
|
||||
assert!(w.iter().all(|x| *x > 1.0), "{share:?} by {dx}: {w:?}");
|
||||
if share == Share::Neighbour {
|
||||
assert_eq!(w, [3.0, 4.0, 100.0], "by {dx}: no room on either side");
|
||||
}
|
||||
}
|
||||
}
|
||||
// A narrow column still widens when its neighbour has room.
|
||||
let mut w = [3.0, 100.0];
|
||||
assert_eq!(share_out(&mut w, 0, 10.0, Share::Neighbour), Some(10.0));
|
||||
assert_eq!(w, [13.0, 90.0]);
|
||||
// Nothing moves for no drag.
|
||||
let mut w = [3.0, 100.0];
|
||||
assert_eq!(share_out(&mut w, 0, 0.0, Share::Neighbour), Some(0.0));
|
||||
}
|
||||
|
||||
/// The table's left edge, grabbed from just outside it, moves the table in or out: its
|
||||
/// indent changes and the first column makes up the difference, so the other borders stay.
|
||||
/// A centred or right-aligned table keeps its alignment, as in Word: only the first column
|
||||
|
||||
Reference in New Issue
Block a user