mirror of
https://github.com/fltk/fltk.git
synced 2026-05-09 21:06:51 +08:00
Fl_Tree: make automatic resizing of children optional (STR 3030)
- add getter and setter methods: - int Fl_Tree::auto_resize_children() - void Fl_Tree::auto_resize_children(int mode) Note: the default in 1.5.0 is "OFF", i.e. no automatic resizing. The methods above can be used to switch it on if required. This is a behavioral change to fix a bug in 1.4 and lower. It will not be backported because it would break the ABI.
This commit is contained in:
+70
-19
@@ -1,4 +1,19 @@
|
||||
//
|
||||
// Fl_Tree.H -- This file is part of the Fl_Tree widget for FLTK
|
||||
//
|
||||
// Copyright 2009-2010 by Greg Ercolano.
|
||||
// Copyright 2011-2026 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software. Distribution and use rights are outlined in
|
||||
// the file "COPYING" which should have been included with this file. If this
|
||||
// file is missing or damaged, see the license at:
|
||||
//
|
||||
// https://www.fltk.org/COPYING.php
|
||||
//
|
||||
// Please see the following page on how to report bugs and issues:
|
||||
//
|
||||
// https://www.fltk.org/bugs.php
|
||||
//
|
||||
|
||||
#ifndef FL_TREE_H
|
||||
#define FL_TREE_H
|
||||
@@ -11,24 +26,6 @@
|
||||
#include <FL/Fl_Tree_Item.H>
|
||||
#include <FL/Fl_Tree_Prefs.H>
|
||||
|
||||
//////////////////////
|
||||
// FL/Fl_Tree.H
|
||||
//////////////////////
|
||||
//
|
||||
// Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
|
||||
// Copyright (C) 2009-2010 by Greg Ercolano.
|
||||
//
|
||||
// This library is free software. Distribution and use rights are outlined in
|
||||
// the file "COPYING" which should have been included with this file. If this
|
||||
// file is missing or damaged, see the license at:
|
||||
//
|
||||
// https://www.fltk.org/COPYING.php
|
||||
//
|
||||
// Please see the following page on how to report bugs and issues:
|
||||
//
|
||||
// https://www.fltk.org/bugs.php
|
||||
//
|
||||
|
||||
///
|
||||
/// \file
|
||||
/// \brief This file contains the definitions of the Fl_Tree class
|
||||
@@ -293,7 +290,9 @@ class FL_EXPORT Fl_Tree : public Fl_Group {
|
||||
int _scrollbar_size; // size of scrollbar trough
|
||||
Fl_Tree_Item *_lastselect; // last selected item
|
||||
char _lastpushed; // FL_PUSH occurred on: 0=nothing, 1=open/close, 2=usericon, 3=label
|
||||
void fix_scrollbar_order();
|
||||
int _auto_resize_children; // if true: resize children when the Fl_Tree container is resized
|
||||
|
||||
void fix_scrollbar_order(); // internal: rearrange scrollbars in list of children
|
||||
|
||||
protected:
|
||||
Fl_Scrollbar *_vscroll; ///< Vertical scrollbar
|
||||
@@ -321,6 +320,58 @@ public:
|
||||
void show_self();
|
||||
void resize(int,int,int,int) override;
|
||||
|
||||
/**
|
||||
Set mode to resize children when the Fl_Tree container widget is resized.
|
||||
|
||||
The default value is \c false, meaning that child widgets within Fl_Tree
|
||||
widgets are not automatically resized.
|
||||
|
||||
This default behavior was changed in version 1.5.0 because resizing children
|
||||
automatically led to unpredictable behavior depending on their positions and
|
||||
sizes. This was caused by using the default resizing mechanism, Fl_Group::resize(),
|
||||
and was fixed in version 1.5.0 by disabling automatic resizing of children.
|
||||
|
||||
This method can be used to restore the 1.4.x behavior to resize children
|
||||
automatically for backwards compatibility by calling
|
||||
Fl_Tree::auto_resize_children(1). See example below.
|
||||
|
||||
\b Note: use with care and only if required for strict backwards compatibility.
|
||||
The resulting resize behavior can be \e surprising. If your development
|
||||
target is FLTK 1.4 or lower you can't use this method (you may include
|
||||
it inside conditional compilation for FLTK 1.5 and higher).
|
||||
|
||||
Example code for strict backwards compatibility to 1.4.x or lower:
|
||||
|
||||
\code
|
||||
#include <FL/Fl_Tree.H>
|
||||
Fl_Tree *tree = new Fl_Tree(0, 0, 400, 400);
|
||||
#if FL_API_VERSION >= 10500
|
||||
tree->auto_resize_children(1);
|
||||
#endif
|
||||
\endcode
|
||||
|
||||
\param[in] mode enable auto resizing if true (non-zero)
|
||||
|
||||
\since 1.5.0
|
||||
\see int auto_resize_children()
|
||||
*/
|
||||
void auto_resize_children(int mode) {
|
||||
_auto_resize_children = (mode) ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns whether auto resizing of children is active.
|
||||
|
||||
\returns 0 (auto resizing \b off) or 1 ( \b on)
|
||||
|
||||
\since 1.5.0
|
||||
|
||||
\see void auto_resize_children(int mode) for details
|
||||
*/
|
||||
int auto_resize_children() {
|
||||
return _auto_resize_children;
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
// root methods
|
||||
///////////////////////
|
||||
|
||||
+24
-22
@@ -1,19 +1,8 @@
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <FL/Fl_Tree.H>
|
||||
#include <FL/Fl_Preferences.H>
|
||||
#include <FL/fl_string_functions.h>
|
||||
|
||||
//////////////////////
|
||||
// Fl_Tree.cxx
|
||||
//////////////////////
|
||||
// Fl_Tree.cxx -- This file is part of the Fl_Tree widget for FLTK
|
||||
//
|
||||
// Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
|
||||
// Copyright (C) 2009-2010 by Greg Ercolano.
|
||||
// Copyright 2009-2010 by Greg Ercolano.
|
||||
// Copyright 2011-2026 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software. Distribution and use rights are outlined in
|
||||
// the file "COPYING" which should have been included with this file. If this
|
||||
@@ -26,6 +15,14 @@
|
||||
// https://www.fltk.org/bugs.php
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <FL/Fl_Tree.H>
|
||||
#include <FL/Fl_Preferences.H>
|
||||
#include <FL/fl_string_functions.h>
|
||||
|
||||
// INTERNAL: scroller callback (hor+vert scroll)
|
||||
static void scroll_cb(Fl_Widget*,void *data) {
|
||||
((Fl_Tree*)data)->redraw();
|
||||
@@ -79,12 +76,13 @@ Fl_Tree::Fl_Tree(int X, int Y, int W, int H, const char *L) : Fl_Group(X,Y,W,H,L
|
||||
_root = new Fl_Tree_Item(this);
|
||||
_root->parent(0); // we are root of tree
|
||||
_root->label("ROOT");
|
||||
_item_focus = 0;
|
||||
_callback_item = 0;
|
||||
_callback_reason = FL_TREE_REASON_NONE;
|
||||
_scrollbar_size = 0; // 0: uses Fl::scrollbar_size()
|
||||
|
||||
_lastselect = 0;
|
||||
_item_focus = 0;
|
||||
_callback_item = 0;
|
||||
_callback_reason = FL_TREE_REASON_NONE;
|
||||
_scrollbar_size = 0; // 0: uses Fl::scrollbar_size()
|
||||
_lastselect = nullptr;
|
||||
_lastpushed = 0;
|
||||
_auto_resize_children = 0; // don't resize children automatically
|
||||
|
||||
box(FL_DOWN_BOX);
|
||||
color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR);
|
||||
@@ -691,9 +689,13 @@ void Fl_Tree::calc_tree() {
|
||||
|
||||
void Fl_Tree::resize(int X,int Y,int W, int H) {
|
||||
fix_scrollbar_order();
|
||||
Fl_Group::resize(X,Y,W,H);
|
||||
if (auto_resize_children()) { // backwards compatibility to 1.4.x
|
||||
Fl_Group::resize(X, Y, W, H);
|
||||
init_sizes(); // remove stored sizes
|
||||
} else {
|
||||
Fl_Widget::resize(X, Y, W, H);
|
||||
}
|
||||
calc_dimensions();
|
||||
init_sizes();
|
||||
}
|
||||
|
||||
/// Standard FLTK draw() method, handles drawing the tree widget.
|
||||
|
||||
Reference in New Issue
Block a user