|
|
commit 3ee8864bfc2badfc6f5dfcd09616eff9c7b2e708
Author: Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Wed Oct 6 18:35:00 2021 +0200
Commit: Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Wed Oct 6 18:35:00 2021 +0200
Simplify and fix the code of Fl_Scroll::bbox()
Declare Fl_Scroll::bbox() and Fl_Scroll::recalc_scrollbars() 'const'.
These methods don't change the Fl_Scroll widget.
Use Fl_Scroll::recalc_scrollbars() in Fl_Scroll::bbox() to simplify
the code and to avoid code duplication.
bbox() can now be called at any time and returns the correct values,
no matter if draw() has been called before.
FL/Fl_Scroll.H | 4 ++--
src/Fl_Scroll.cxx | 56 ++++++++++++++++++++++++++++++-------------------------
2 files changed, 33 insertions(+), 27 deletions(-)
diff --git FL/Fl_Scroll.H FL/Fl_Scroll.H
index 35fcf9a..ce2ff14 100644
--- FL/Fl_Scroll.H
+++ FL/Fl_Scroll.H
@@ -130,11 +130,11 @@ protected: // (STR#1895)
Fl_Scrollbar_Data hscroll; ///< horizontal scrollbar region + values
Fl_Scrollbar_Data vscroll; ///< vertical scrollbar region + values
} ScrollInfo;
- void recalc_scrollbars(ScrollInfo &si);
+ void recalc_scrollbars(ScrollInfo &si) const;
protected:
- void bbox(int&,int&,int&,int&);
+ void bbox(int&,int&,int&,int&) const;
void draw();
public:
diff --git src/Fl_Scroll.cxx src/Fl_Scroll.cxx
index f0dab47..5f87cb3 100644
--- src/Fl_Scroll.cxx
+++ src/Fl_Scroll.cxx
@@ -121,16 +121,25 @@ void Fl_Scroll::draw_clip(void* v,int X, int Y, int W, int H) {
Derived classes can make use of this call to figure out the scrolling area
eg. during resize() handling.
- \param[in] si -- ScrollInfo structure
+ This method does not change the scrollbars or their visibility. It calculates
+ the scrollbar positions and visibility as they \b should be, according to the
+ positions and sizes of the children.
+
+ You may need to call redraw() to make sure the widget gets updated.
+
+ \param[inout] si -- ScrollInfo structure, filled with data
+
\returns Structure containing the calculated info.
+
+ \see bbox()
*/
-void Fl_Scroll::recalc_scrollbars(ScrollInfo &si) {
+void Fl_Scroll::recalc_scrollbars(ScrollInfo &si) const {
// inner box of widget (excluding scrollbars)
- si.innerbox.x = x()+Fl::box_dx(box());
- si.innerbox.y = y()+Fl::box_dy(box());
- si.innerbox.w = w()-Fl::box_dw(box());
- si.innerbox.h = h()-Fl::box_dh(box());
+ si.innerbox.x = x() + Fl::box_dx(box());
+ si.innerbox.y = y() + Fl::box_dy(box());
+ si.innerbox.w = w() - Fl::box_dw(box());
+ si.innerbox.h = h() - Fl::box_dh(box());
// accumulate a bounding box for all the children
si.child.l = si.innerbox.x;
@@ -238,28 +247,25 @@ void Fl_Scroll::recalc_scrollbars(ScrollInfo &si) {
}
/**
- Returns the bounding box for the interior of the scrolling area, inside
- the scrollbars.
+ Returns the bounding box for the interior of the scrolling area,
+ inside the scrollbars.
- Currently this is only reliable after draw(), and before any resizing of
- the Fl_Scroll or any child widgets occur.
+ This method does not change the scrollbars or their visibility. First the
+ the scrollbar positions and visibility are calculated as they \b should be,
+ according to the positions and sizes of the children. Then the bounding
+ box is calculated.
- \todo The visibility of the scrollbars ought to be checked/calculated
- outside of the draw() method (STR #1895).
+ You may need to call redraw() to make sure the widget gets updated.
+
+ \see recalc_scrollbars()
*/
-void Fl_Scroll::bbox(int& X, int& Y, int& W, int& H) {
- X = x()+Fl::box_dx(box());
- Y = y()+Fl::box_dy(box());
- W = w()-Fl::box_dw(box());
- H = h()-Fl::box_dh(box());
- if (scrollbar.visible()) {
- W -= scrollbar.w();
- if (scrollbar.align() & FL_ALIGN_LEFT) X += scrollbar.w();
- }
- if (hscrollbar.visible()) {
- H -= hscrollbar.h();
- if (scrollbar.align() & FL_ALIGN_TOP) Y += hscrollbar.h();
- }
+void Fl_Scroll::bbox(int& X, int& Y, int& W, int& H) const {
+ ScrollInfo si;
+ recalc_scrollbars(si);
+ X = si.innerchild.x;
+ Y = si.innerchild.y;
+ W = si.innerchild.w;
+ H = si.innerchild.h;
}
void Fl_Scroll::draw() {
[ Direct Link to Message ] | |
|
| |