#797: Improves Fl_Tile resize behaviour

- if a tile with a size range is resize smaller than the
minimum size of all children, the children will now no
longer shrink, and expanding will make them work
again as expected.
This commit is contained in:
Matthias Melcher
2024-01-04 01:26:32 +01:00
parent d237d186ae
commit 46c9cf2f10
+49 -9
View File
@@ -565,19 +565,59 @@ void Fl_Tile::drag_intersection(int oldx, int oldy, int newx, int newy) {
void Fl_Tile::resize(int X,int Y,int W,int H) {
if (size_range_) {
int dw = w() - W, dh = h() - H;
Fl_Widget *r = resizable();
if (r) {
int rr = r->x() + r->w(), rb = r->y() + r->h();
move_intersection(rr, rb, rr-dw, rb-dh);
// -- handle size_range style resizing
int dx = X - x();
int dy = Y - y();
int dw = w() - W;
int dh = h() - H;
// -- if the size does not change, Group resize will suffice
if ((dw==0) && (dh==0)) {
Fl_Group::resize(X, Y, W, H);
init_sizes();
redraw();
return;
}
int tr = x() + w(), tb = y() + h();
move_intersection(tr, tb, tr-dw, tb-dh);
// -- if the position changes, move all widgets first
if ((dx!=0) || (dy!=0)) {
for (int i = 0; i < children(); i++) {
Fl_Widget *c = child(i);
c->position(c->x()+dx, c->y()+dy);
}
}
// check the bounding box of all children at minimum size
init_sizes();
Fl_Rect *p = bounds();
int bbr = X, bbb = Y;
for (int i = 0; i < children(); i++) {
// find the current bounding box
bbr = fl_max(bbr, p[i+2].r());
bbb = fl_max(bbb, p[i+2].b());
}
// fix the dw to the maximum difference possible
int r2 = X+W;
request_shrink_r(bbr, r2, NULL);
dw = bbr - r2;
// fix the dh to the maximum difference possible
int b2 = Y+H;
request_shrink_b(bbb, b2, NULL);
dh = bbb - b2;
printf("%d %d %d %d %d %d\n", X, Y, W, H, dw, dh);
// perform the actual resize within a safe range
if ((dw!=0) || (dh!=0)) {
Fl_Widget *r = resizable();
if (r) {
int rr = r->x() + r->w(), rb = r->y() + r->h();
move_intersection(rr, rb, rr-dw, rb-dh);
}
int tr = x() + w(), tb = y() + h();
move_intersection(bbr, bbb, bbr-dw, bbb-dh);
init_sizes();
}
// resize the tile itself
if (Fl_Window::is_a_rescale())
Fl_Group::resize(X,Y,W,H);
Fl_Group::resize(X, Y, W, H);
else
Fl_Widget::resize(X,Y,W,H);
Fl_Widget::resize(X, Y, W, H);
return;
}