FLTK logo

Re: [fltk.coredev] Fl_Scroll x/yposition and scroll_to confusion

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.coredev  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Fl_Scroll x/yposition and scroll_to confusion Albrecht Schlosser Jan 27, 2023  
 
On 1/26/23 09:51 Mo_Al_ wrote:
It seems Fl_Scroll takes into account the position of the topmost leftmost widget among its children, where the docs state:
```
Fl_Scroll scroll (10,10,200,200);
Fl_Box b1 ( 10, 10,50,50,"b1"); // relative (x,y) = (0,0)
Fl_Box b2 ( 60, 60,50,50,"b2"); // relative (x,y) = (50,50)
Fl_Box b3 ( 60,110,50,50,"b3"); // relative (x,y) = (50,100)
```

It's a fact that the scrollbars of Fl_Scroll consider the bounding box of all children for their positioning. I admit that this can be confusing.

a modified example from the docs:
```
...
void btn_cb(Fl_Widget *w, void *data) {
auto s = (Fl_Scroll*)data;
s->scroll_to(0, 0);
}

int main() {
...
return Fl::run();
}
```

This makes the relative position of b1 (following the docs) be (10, 10), but using s.scroll_to(0, 0), actually appears to scroll to 10, 10, making the the first button appear at position 0, 0 of the window. To get the initial appearance, one would need to s.scroll_to(-10, -10).

I never thought of using s->scroll_to(0, 0); like in your example to position the scrollbars as you did.

The docs state: "The Fl_Scroll widget calculates the bounding box of all its children by using their widget positions and sizes (x, y, w, h). Outside labels are not considered. If you need outside labels of any widgets or free space outside of this bounding box you can add a tiny invisible Fl_Box at the relevant corner(s) of the Fl_Scroll widget,..."

See https://www.fltk.org/doc-1.4/classFl__Scroll.html

I could be misunderstanding the docs, or is the position of the topleft-most widget the reference for the Fl_Scroll?

More or less, yes. The bounding box of all children determines the width and height of the contents, and that's what the scrollbars control. The description cited above gives a hint that you can position an invisible box at the top left (or any other corner) if you want to extend the contents of the widget to include spacing around the widgets.

I'm not sure if we can clarify this even more in the docs without confusing people even more. But maybe we could?

--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkcoredev/f4b3f116-d6c3-6015-5ede-335112a7a7a6%40online.de.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.