layout editor: column drag follows the pointer through the cell floor

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Martino FerrariandClaude Opus 4.6 committed 2026-11-03 19:18:18 +01:00
1 parent 2183317953
commit 4fab14949c
5 files changed
+127 -52

No files matched your search

+80 -36
View File
@@ -3826,20 +3826,15 @@ gboolean layout_probe_step(gpointer user) {
// Each step changes the arrangement of cells, re-points the area at the new figure, and lets the
// next step (250 ms on) read what a frame was actually laid out with.
void split_probe_report(App& a, const char* tag) {
/// 1 when every row's cells fill its rect edge to edge, share its y and height, and are one `col_gap`
/// apart (and the layout has the cells it should); the readout both the state lines and `col-drag` use.
int split_probe_tile(App& a) {
RowSet& rs = *a.rows;
const double scale = (a.area != nullptr && a.area->device_scale() > 0.0f)
? static_cast<double>(a.area->device_scale()) : 1.0;
const plot::FigureLayout& fl = rs.figure().layout();
const int frows = rs.figure_row_count();
// tile: every row's cells fill its rect edge to edge, share its y and height, and are one
// `col_gap` apart.
int tile = fl.cells.size() == static_cast<std::size_t>(rs.row_count()) &&
fl.rows.size() == static_cast<std::size_t>(frows)
? 1 : 0;
std::string cells_s;
std::string widths_s;
std::string weights_s;
for (int fr = 0; fr < frows && tile; ++fr) {
const int first = rs.first_plot_of_row(fr);
const int n = rs.cells_in_row(fr);
@@ -3857,6 +3852,19 @@ void split_probe_report(App& a, const char* tag) {
}
}
}
return tile;
}
void split_probe_report(App& a, const char* tag) {
RowSet& rs = *a.rows;
const double scale = (a.area != nullptr && a.area->device_scale() > 0.0f)
? static_cast<double>(a.area->device_scale()) : 1.0;
const plot::FigureLayout& fl = rs.figure().layout();
const int frows = rs.figure_row_count();
const int tile = split_probe_tile(a);
std::string cells_s;
std::string widths_s;
std::string weights_s;
for (int fr = 0; fr < frows; ++fr) {
const int first = rs.first_plot_of_row(fr);
const int n = rs.cells_in_row(fr);
@@ -4176,37 +4184,73 @@ gboolean split_probe_step(gpointer user) {
}
case 12: {
split_probe_report(*a, "cell-assigned");
// Column drag: apply a +80 px offset, verify widths shifted, clamp to extremes.
// Column drag, through the real begin/apply pair: every drag is relative to the state it began
// from, and the divider must follow the pointer (the cell is not proportional to its weight --
// the plotter floors it -- so the weights are solved for the width).
if (rs.cells_in_row(0) >= 2) {
const plot::FigureLayout& fl2 = rs.figure().layout();
const double scale2 = (a->area != nullptr && a->area->device_scale() > 0.0f)
? static_cast<double>(a->area->device_scale()) : 1.0;
a->layout_col_drag_plot = rs.first_plot_of_row(0) + 1;
a->layout_col_drag_left0 = static_cast<double>(fl2.cells[0].w) / scale2;
a->layout_col_drag_right0 = static_cast<double>(fl2.cells[1].w) / scale2;
a->layout_col_drag_start = rs.cell_weights(0);
a->layout_col_drag_start.resize(static_cast<std::size_t>(rs.cells_in_row(0)), 1.0f);
layout_col_apply(*a, rs.first_plot_of_row(0) + 1, 80.0);
// Read back widths.
const plot::FigureLayout& fl3 = rs.figure().layout();
const double w0 = static_cast<double>(fl3.cells[0].w) / scale2;
const double w1 = static_cast<double>(fl3.cells[1].w) / scale2;
const int left_gt = w0 > w1 ? 1 : 0;
// Extreme clamp test: +10000 px and -10000 px.
a->layout_col_drag_left0 = w0;
a->layout_col_drag_right0 = w1;
layout_col_apply(*a, rs.first_plot_of_row(0) + 1, 10000.0);
const double w0_max = static_cast<double>(rs.figure().layout().cells[0].w) / scale2;
const double w1_min = static_cast<double>(rs.figure().layout().cells[1].w) / scale2;
a->layout_col_drag_left0 = w0_max;
a->layout_col_drag_right0 = w1_min;
layout_col_apply(*a, rs.first_plot_of_row(0) + 1, -10000.0);
const double w0_min = static_cast<double>(rs.figure().layout().cells[0].w) / scale2;
const double w1_max = static_cast<double>(rs.figure().layout().cells[1].w) / scale2;
const int both_above_min = (w0_min >= kMinCellPx - 1.0 && w1_min >= kMinCellPx - 1.0) ? 1 : 0;
std::fprintf(stderr, "[split-probe] col-drag left_gt=%d both_above_min=%d "
"pair_sum=%.0f left_gt_right=%d tile=1\n",
left_gt, both_above_min, w0_min + w1_max, left_gt);
const int plot1 = rs.first_plot_of_row(0) + 1;
const auto width = [&](int cell) {
return static_cast<double>(rs.figure().layout().cells[static_cast<std::size_t>(cell)].w) / scale2;
};
// One drag of `dx` logical px from the arrangement the figure is in now, then the widths read
// back from the layout (the figure re-lays out on the weights, not on a frame).
struct Pair { double l0, r0, l, r; };
const auto drag = [&](double dx) {
Pair p{};
layout_col_drag_begin(*a, plot1);
p.l0 = width(0);
p.r0 = width(1);
layout_col_apply(*a, plot1, dx * scale2);
p.l = width(0);
p.r = width(1);
return p;
};
// A drag of +80 from the start: the left cell grows by 80 and the pair keeps its total.
const Pair d80 = drag(80.0);
const int left_gt = d80.l > d80.r ? 1 : 0;
const int left_grew = d80.l > d80.l0 ? 1 : 0;
const int follows_80 = std::fabs(d80.l - (d80.l0 + 80.0)) <= 1.0 ? 1 : 0;
const int sum_80 = std::fabs((d80.l + d80.r) - (d80.l0 + d80.r0)) <= 1.0 ? 1 : 0;
// The same drag, again: it is relative to its start, so this +80 must land where the last did
// (a drag that read the live weights would compound).
layout_col_drag_begin(*a, plot1);
const double l_start = width(0);
const double r_start = width(1);
layout_col_apply(*a, plot1, 30.0 * scale2);
layout_col_apply(*a, plot1, 60.0 * scale2);
layout_col_apply(*a, plot1, 80.0 * scale2);
const int relative = std::fabs(width(0) - (l_start + 80.0)) <= 1.0 &&
std::fabs(width(1) - (r_start - 80.0)) <= 1.0 ? 1 : 0;
layout_col_apply(*a, plot1, 0.0);
// Extreme drags, each from the settled start: the shrinking cell reads the 96 px floor.
layout_col_drag_begin(*a, plot1);
const double pair0 = width(0) + width(1);
layout_col_apply(*a, plot1, 10000.0 * scale2);
const double w0_max = width(0);
const double w1_min = width(1);
layout_col_apply(*a, plot1, -10000.0 * scale2);
const double w0_min = width(0);
const double w1_max = width(1);
const int right_floor = std::fabs(w1_min - kMinCellPx) <= 1.0 ? 1 : 0;
const int left_floor = std::fabs(w0_min - kMinCellPx) <= 1.0 ? 1 : 0;
const int sum_ext = std::fabs((w0_max + w1_min) - pair0) <= 1.0 &&
std::fabs((w0_min + w1_max) - pair0) <= 1.0 ? 1 : 0;
const int both_above_min = (w0_min >= kMinCellPx - 1.0 && w1_min >= kMinCellPx - 1.0 &&
w0_max >= kMinCellPx - 1.0 && w1_max >= kMinCellPx - 1.0) ? 1 : 0;
const int ok = left_gt && left_grew && follows_80 && sum_80 && relative && right_floor &&
left_floor && sum_ext && both_above_min ? 1 : 0;
// Leave the drag ended, as the gesture's end does.
a->layout_col_drag_plot = -1;
a->layout_col_drag_start.clear();
std::fprintf(stderr,
"[split-probe] col-drag ok=%d left_gt_right=%d follows_80=%d relative=%d "
"sum_80=%d right_floor=%d left_floor=%d sum_ext=%d both_above_min=%d "
"tile=%d d80=[%.1f,%.1f]->[%.1f,%.1f] ext=[%.1f,%.1f|%.1f,%.1f]\n",
ok, left_gt, follows_80, relative, sum_80, right_floor, left_floor, sum_ext,
both_above_min, split_probe_tile(*a), d80.l0, d80.r0, d80.l, d80.r, w0_max,
w1_min, w0_min, w1_max);
}
split_probe_next(*a);
break;