mirror of https://github.com/fltk/fltk
Solves STR #2681.
Added ABI-breaking Fl_Table::scrollbar_size() with new ABI #ifdefs. tests/unittests program modified to test this feature if enabled. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9345 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
db2cca57f1
commit
3cf006f5c3
|
@ -19,7 +19,7 @@
|
|||
|
||||
//
|
||||
// TODO:
|
||||
// o Auto scroll during dragged selection
|
||||
// o Auto scroll during dragged selection (done)
|
||||
// o Keyboard navigation (up/down/left/right arrow)
|
||||
// o Add scrollbar_size() method and integer [breaks ABI]
|
||||
//
|
||||
|
@ -214,7 +214,9 @@ private:
|
|||
|
||||
int _auto_drag;
|
||||
int _selecting;
|
||||
//int _scrollbar_size; // TODO: BREAKS ABI
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
int _scrollbar_size;
|
||||
#endif
|
||||
|
||||
// An STL-ish vector without templates
|
||||
class FL_EXPORT IntVector {
|
||||
|
@ -1074,8 +1076,44 @@ public:
|
|||
*/
|
||||
void callback(Fl_Widget*, void*);
|
||||
#endif
|
||||
//int scrollbar_size() const { // TODO: BREAKS ABI
|
||||
//void scrollbar_size(int size) { // TODO: BREAKS ABI
|
||||
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
// NEW
|
||||
/**
|
||||
Gets the current size of the scrollbars' troughs, in pixels.
|
||||
|
||||
If this value is zero (default), this widget will use the
|
||||
Fl::scrollbar_size() value as the scrollbar's width.
|
||||
|
||||
\returns Scrollbar size in pixels, or 0 if the global Fl::scrollsize() is being used.
|
||||
\see Fl::scrollbar_size(int)
|
||||
*/
|
||||
int scrollbar_size() const {
|
||||
return(_scrollbar_size);
|
||||
}
|
||||
/**
|
||||
Sets the pixel size of the scrollbars' troughs to \p newSize, in pixels.
|
||||
|
||||
Normally you should not need this method, and should use
|
||||
Fl::scrollbar_size(int) instead to manage the size of ALL your
|
||||
widgets' scrollbars. This ensures your application has a consistent
|
||||
UI, is the default behavior, and is normally what you want.
|
||||
|
||||
Only use THIS method if you really need to override the global
|
||||
scrollbar size. The need for this should be rare.
|
||||
|
||||
Setting \p newSize to the special value of 0 causes the widget to
|
||||
track the global Fl::scrollbar_size(), which is the default.
|
||||
|
||||
\param[in] newSize Sets the scrollbar size in pixels.\n
|
||||
If 0 (default), scrollbar size tracks the global Fl::scrollbar_size()
|
||||
\see Fl::scrollbar_size()
|
||||
*/
|
||||
void scrollbar_size(int newSize) {
|
||||
if ( newSize != _scrollbar_size ) redraw();
|
||||
_scrollbar_size = newSize;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /*_FL_TABLE_H*/
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include <FL/fl_utf8.H> // currently only Windows and Linux
|
||||
#endif
|
||||
|
||||
#define SCROLLBAR_SIZE (Fl::scrollbar_size())
|
||||
|
||||
// Scroll display so 'row' is at top
|
||||
void Fl_Table::row_position(int row) {
|
||||
if ( _row_position == row ) return; // OPTIMIZATION: no change? avoid redraw
|
||||
|
@ -126,20 +124,22 @@ Fl_Table::Fl_Table(int X, int Y, int W, int H, const char *l) : Fl_Group(X,Y,W,H
|
|||
_dragging_y = -1;
|
||||
_last_row = -1;
|
||||
_auto_drag = 0;
|
||||
current_col = -1;
|
||||
current_col = -1;
|
||||
current_row = -1;
|
||||
select_row = -1;
|
||||
select_col = -1;
|
||||
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
_scrollbar_size = 0;
|
||||
#endif
|
||||
box(FL_THIN_DOWN_FRAME);
|
||||
|
||||
vscrollbar = new Fl_Scrollbar(x()+w()-SCROLLBAR_SIZE, y(),
|
||||
SCROLLBAR_SIZE, h()-SCROLLBAR_SIZE);
|
||||
vscrollbar = new Fl_Scrollbar(x()+w()-Fl::scrollbar_size(), y(),
|
||||
Fl::scrollbar_size(), h()-Fl::scrollbar_size());
|
||||
vscrollbar->type(FL_VERTICAL);
|
||||
vscrollbar->callback(scroll_cb, (void*)this);
|
||||
|
||||
hscrollbar = new Fl_Scrollbar(x(), y()+h()-SCROLLBAR_SIZE,
|
||||
w(), SCROLLBAR_SIZE);
|
||||
hscrollbar = new Fl_Scrollbar(x(), y()+h()-Fl::scrollbar_size(),
|
||||
w(), Fl::scrollbar_size());
|
||||
hscrollbar->type(FL_HORIZONTAL);
|
||||
hscrollbar->callback(scroll_cb, (void*)this);
|
||||
|
||||
|
@ -480,14 +480,21 @@ void Fl_Table::recalc_dimensions() {
|
|||
// First pass: can hide via window size?
|
||||
int hidev = (table_h <= tih);
|
||||
int hideh = (table_w <= tiw);
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
// NEW
|
||||
int scrollsize = _scrollbar_size ? _scrollbar_size : Fl::scrollbar_size();
|
||||
#else
|
||||
// OLD
|
||||
int scrollsize = Fl::scrollbar_size();
|
||||
#endif
|
||||
// Second pass: Check for interference
|
||||
if ( !hideh & hidev ) { hidev = (( table_h - tih + SCROLLBAR_SIZE ) <= 0 ); }
|
||||
if ( !hidev & hideh ) { hideh = (( table_w - tiw + SCROLLBAR_SIZE ) <= 0 ); }
|
||||
if ( !hideh & hidev ) { hidev = (( table_h - tih + scrollsize ) <= 0 ); }
|
||||
if ( !hidev & hideh ) { hideh = (( table_w - tiw + scrollsize ) <= 0 ); }
|
||||
// Determine scrollbar visibility, trim ti[xywh]/to[xywh]
|
||||
if ( hidev ) { vscrollbar->hide(); }
|
||||
else { vscrollbar->show(); tiw -= SCROLLBAR_SIZE; tow -= SCROLLBAR_SIZE; }
|
||||
else { vscrollbar->show(); tiw -= scrollsize; tow -= scrollsize; }
|
||||
if ( hideh ) { hscrollbar->hide(); }
|
||||
else { hscrollbar->show(); tih -= SCROLLBAR_SIZE; toh -= SCROLLBAR_SIZE; }
|
||||
else { hscrollbar->show(); tih -= scrollsize; toh -= scrollsize; }
|
||||
}
|
||||
// Resize the child table
|
||||
table->resize(tox, toy, tow, toh);
|
||||
|
@ -554,20 +561,27 @@ void Fl_Table::table_resized() {
|
|||
// Vertical scrollbar
|
||||
float vscrolltab = ( table_h == 0 || tih > table_h ) ? 1 : (float)tih / table_h;
|
||||
float hscrolltab = ( table_w == 0 || tiw > table_w ) ? 1 : (float)tiw / table_w;
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
// NEW
|
||||
int scrollsize = _scrollbar_size ? _scrollbar_size : Fl::scrollbar_size();
|
||||
#else
|
||||
// OLD
|
||||
int scrollsize = Fl::scrollbar_size();
|
||||
#endif
|
||||
vscrollbar->bounds(0, table_h-tih);
|
||||
vscrollbar->precision(10);
|
||||
vscrollbar->slider_size(vscrolltab);
|
||||
vscrollbar->resize(wix+wiw-SCROLLBAR_SIZE, wiy,
|
||||
SCROLLBAR_SIZE,
|
||||
wih - ((hscrollbar->visible())?SCROLLBAR_SIZE:0));
|
||||
vscrollbar->resize(wix+wiw-scrollsize, wiy,
|
||||
scrollsize,
|
||||
wih - ((hscrollbar->visible())?scrollsize:0));
|
||||
vscrollbar->Fl_Valuator::value(vscrollbar->clamp(vscrollbar->value()));
|
||||
// Horizontal scrollbar
|
||||
hscrollbar->bounds(0, table_w-tiw);
|
||||
hscrollbar->precision(10);
|
||||
hscrollbar->slider_size(hscrolltab);
|
||||
hscrollbar->resize(wix, wiy+wih-SCROLLBAR_SIZE,
|
||||
wiw - ((vscrollbar->visible())?SCROLLBAR_SIZE:0),
|
||||
SCROLLBAR_SIZE);
|
||||
hscrollbar->resize(wix, wiy+wih-scrollsize,
|
||||
wiw - ((vscrollbar->visible())?scrollsize:0),
|
||||
scrollsize);
|
||||
hscrollbar->Fl_Valuator::value(hscrollbar->clamp(hscrollbar->value()));
|
||||
}
|
||||
|
||||
|
@ -1133,9 +1147,16 @@ void Fl_Table::set_selection(int row_top, int col_left, int row_bot, int col_rig
|
|||
// Then tell the group to draw over us.
|
||||
//
|
||||
void Fl_Table::draw() {
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
// NEW
|
||||
int scrollsize = _scrollbar_size ? _scrollbar_size : Fl::scrollbar_size();
|
||||
#else
|
||||
// OLD
|
||||
int scrollsize = Fl::scrollbar_size();
|
||||
#endif
|
||||
// Check if scrollbar size changed
|
||||
if ( ( vscrollbar && (SCROLLBAR_SIZE != vscrollbar->w()) ) ||
|
||||
( hscrollbar && (SCROLLBAR_SIZE != hscrollbar->h()) ) ) {
|
||||
if ( ( vscrollbar && (scrollsize != vscrollbar->w()) ) ||
|
||||
( hscrollbar && (scrollsize != hscrollbar->h()) ) ) {
|
||||
// handle size change, min/max, table dim's, etc
|
||||
table_resized();
|
||||
}
|
||||
|
@ -1253,7 +1274,7 @@ void Fl_Table::draw() {
|
|||
//
|
||||
fl_rectf(wix, tiy + table_h, row_header_width(),
|
||||
(wiy+wih) - (tiy+table_h) -
|
||||
( hscrollbar->visible() ? SCROLLBAR_SIZE : 0),
|
||||
( hscrollbar->visible() ? scrollsize : 0),
|
||||
color());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,10 @@ class ScrollBarSizeTest : public Fl_Group {
|
|||
if ( strcmp(label,"A: Scroll Size") == 0 ) {
|
||||
brow_a->scrollbar_size(val);
|
||||
tree_a->scrollbar_size(val);
|
||||
//table_a->scrollbar_size(val); // awaiting method (ABI)
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
// NEW
|
||||
table_a->scrollbar_size(val);
|
||||
#endif
|
||||
} else {
|
||||
Fl::scrollbar_size(val);
|
||||
}
|
||||
|
@ -191,7 +194,7 @@ public:
|
|||
slide_glob->callback(slide_cb, (void*)this);
|
||||
slide_glob->labelsize(12);
|
||||
Fl_Value_Slider *slide_browa = new Fl_Value_Slider(X+350,Y,100,18,"A: Scroll Size");
|
||||
slide_browa->value(16);
|
||||
slide_browa->value(0);
|
||||
slide_browa->type(FL_HORIZONTAL);
|
||||
slide_browa->align(FL_ALIGN_LEFT);
|
||||
slide_browa->range(0.0, 30.0);
|
||||
|
@ -203,7 +206,11 @@ public:
|
|||
"Scrollbar's size should change interactively as size sliders are changed.\n"
|
||||
"Changing 'Global Scroll Size' should affect all three browser's scrollbars UNLESS\n"
|
||||
"the 'A: Scroll Size' slider is changed, in which case its value will take precedence\n"
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
"for the 'A' group of widgets.");
|
||||
#else
|
||||
"for the 'A' group of widgets. (NOTE: 'table_a' does not currently support this)");
|
||||
#endif
|
||||
labelsize(10);
|
||||
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue