summaryrefslogtreecommitdiff
path: root/src/Fl_Tile.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2024-01-04 01:26:32 +0100
committerMatthias Melcher <github@matthiasm.com>2024-01-04 01:26:40 +0100
commit46c9cf2f1033b847896e43d5dad6359f6b01decf (patch)
tree8858e64f4dd2adc7aecee1d59ed65a3d397e0633 /src/Fl_Tile.cxx
parentd237d186ae1db050ce07a6e39cc2fb4d455f150a (diff)
#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.
Diffstat (limited to 'src/Fl_Tile.cxx')
-rw-r--r--src/Fl_Tile.cxx58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/Fl_Tile.cxx b/src/Fl_Tile.cxx
index 5fc015e62..a8f24e67e 100644
--- a/src/Fl_Tile.cxx
+++ b/src/Fl_Tile.cxx
@@ -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;
}