FLTK 1.4.4: Fl_Flex.H Source File

FLTK 1.4.4

Loading...
Searching...
No Matches
Fl_Flex.H
1//
2// Fl_Flex widget header file for the Fast Light Tool Kit (FLTK).
3//
4// Copyright 2020 by Karsten Pedersen
5// Copyright 2022-2024 by Bill Spitzak and others.
6//
7// This library is free software. Distribution and use rights are outlined in
8// the file "COPYING" which should have been included with this file. If this
9// file is missing or damaged, see the license at:
10//
11// https://www.fltk.org/COPYING.php
12//
13// Please see the following page on how to report bugs and issues:
14//
15// https://www.fltk.org/bugs.php
16//
17
18#ifndef Fl_Flex_H
19#define Fl_Flex_H
20
21#include <FL/Fl_Group.H>
22
114 class FL_EXPORT Fl_Flex : public Fl_Group {
115
116 int margin_left_; // left margin
117 int margin_top_; // top margin
118 int margin_right_; // right margin
119 int margin_bottom_; // bottom margin
120 int gap_; // gap between widgets
121 int fixed_size_size_; // number of fixed size widgets in array
122 int fixed_size_alloc_; // allocated size of fixed size array
123 Fl_Widget **fixed_size_; // array of fixed size widgets
124 bool need_layout_; // true if layout needs to be calculated
125
126public:
127
128 enum { // values for type(int)
129 VERTICAL = 0,
130 HORIZONTAL = 1,
131 COLUMN = 0,
132 ROW = 1
133 };
134
135 // FLTK standard constructor
136 Fl_Flex(int X, int Y, int W, int H, const char *L = 0);
137
138 // original Fl_Flex constructors:
139 // backwards compatible if direction enums { ROW | COLUMN } are used
140
141 Fl_Flex(int direction);
142 Fl_Flex(int w, int h, int direction);
143 Fl_Flex(int x, int y, int w, int h, int direction);
144
145 virtual ~Fl_Flex();
146
147 virtual void end();
148 void resize(int x, int y, int w, int h) FL_OVERRIDE;
149
158 void fixed(Fl_Widget &w, int size) {
159 fixed(&w, size);
160 }
161
162 void fixed(Fl_Widget *w, int size);
163 int fixed(Fl_Widget *w) const;
164
165protected:
166
167 void init(int t = VERTICAL);
168
169 virtual int alloc_size(int size) const;
170
171 void on_remove(int) FL_OVERRIDE;
172 void draw() FL_OVERRIDE;
173
174public:
175
189 void need_layout(int set) {
190 if (set) need_layout_ = true;
191 else need_layout_ = false;
192 }
193
199 bool need_layout() const {
200 return need_layout_;
201 }
202
214 int margin() const { return margin_left_; }
215
230 int margin(int *left, int *top, int *right, int *bottom) const {
231 if (left) *left = margin_left_;
232 if (top) *top = margin_top_;
233 if (right) *right = margin_right_;
234 if (bottom) *bottom = margin_bottom_;
235 if (margin_left_ == margin_top_ && margin_top_ == margin_right_ && margin_right_ == margin_bottom_)
236 return 1;
237 return 0;
238 }
239
258
259 void margin(int m, int g = -1) {
260 if (m < 0)
261 m = 0;
262 margin_left_ = margin_top_ = margin_right_ = margin_bottom_ = m;
263 if (g >= 0)
264 gap_ = g;
265 need_layout(1);
266 }
267
282 void margin(int left, int top, int right, int bottom) {
283 margin_left_ = left < 0 ? 0 : left;
284 margin_top_ = top < 0 ? 0 : top;
285 margin_right_ = right < 0 ? 0 : right;
286 margin_bottom_ = bottom < 0 ? 0 : bottom;
287 need_layout(1);
288 }
289
293 int gap() const {
294 return gap_;
295 }
296
305 void gap(int g) {
306 gap_ = g < 0 ? 0 : g;
307 need_layout(1);
308 }
309
318 int horizontal() const {
319 return type() == Fl_Flex::HORIZONTAL ? 1 : 0;
320 }
321
322 // Calculate the layout of the widget and redraw it.
323 void layout();
324
334 int spacing() const {
335 return gap_;
336 }
337
347 void spacing(int i) {
348 gap(i);
349 need_layout(1);
350 }
351
352};
353
354#endif // Fl_Flex_H
Fl_Group.H
Fl_Group and Fl_End classes.
Fl_Flex
Fl_Flex is a container (layout) widget for one row or one column of widgets.
Definition Fl_Flex.H:114
Fl_Flex::gap
int gap() const
Return the gap size of the widget.
Definition Fl_Flex.H:293
Fl_Flex::need_layout
bool need_layout() const
Returns whether layout calculation is required.
Definition Fl_Flex.H:199
Fl_Flex::gap
void gap(int g)
Set the gap size of the widget.
Definition Fl_Flex.H:305
Fl_Flex::margin
void margin(int m, int g=-1)
Set the margin and optionally the gap size of the widget.
Definition Fl_Flex.H:259
Fl_Flex::margin
int margin() const
Returns the left margin size of the widget.
Definition Fl_Flex.H:214
Fl_Flex::ROW
@ ROW
alias for HORIZONTAL
Definition Fl_Flex.H:132
Fl_Flex::VERTICAL
@ VERTICAL
vertical layout (one column)
Definition Fl_Flex.H:129
Fl_Flex::HORIZONTAL
@ HORIZONTAL
horizontal layout (one row)
Definition Fl_Flex.H:130
Fl_Flex::COLUMN
@ COLUMN
alias for VERTICAL
Definition Fl_Flex.H:131
Fl_Flex::horizontal
int horizontal() const
Returns non-zero (true) if Fl_Flex alignment is horizontal (row mode).
Definition Fl_Flex.H:318
Fl_Flex::fixed
void fixed(Fl_Widget &w, int size)
Set the horizontal or vertical size of a child widget.
Definition Fl_Flex.H:158
Fl_Flex::Fl_Flex
Fl_Flex(int X, int Y, int W, int H, const char *L=0)
Construct a new Fl_Flex widget with the given position, size, and label.
Definition Fl_Flex.cxx:40
Fl_Flex::spacing
void spacing(int i)
Sets the number of extra pixels of blank space that are added between the children.
Definition Fl_Flex.H:347
Fl_Flex::margin
void margin(int left, int top, int right, int bottom)
Set the margin sizes at all four edges of the Fl_Flex widget.
Definition Fl_Flex.H:282
Fl_Flex::spacing
int spacing() const
Gets the number of extra pixels of blank space that are added between the children.
Definition Fl_Flex.H:334
Fl_Flex::margin
int margin(int *left, int *top, int *right, int *bottom) const
Returns all (four) margin sizes of the widget.
Definition Fl_Flex.H:230
Fl_Flex::need_layout
void need_layout(int set)
Set or reset the request to calculate the layout of children.
Definition Fl_Flex.H:189
Fl_Group::on_remove
virtual void on_remove(int)
Allow derived groups to act when a child widget is removed from the group.
Definition Fl_Group.cxx:571
Fl_Group::end
void end()
Exactly the same as current(this->parent()).
Definition Fl_Group.cxx:73
Fl_Group::resize
void resize(int, int, int, int) FL_OVERRIDE
Resizes the Fl_Group widget and all of its children.
Definition Fl_Group.cxx:825
Fl_Group::draw
void draw() FL_OVERRIDE
Draws the widget.
Definition Fl_Group.cxx:943
Fl_Widget
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:112
Fl_Widget::w
void w(int v)
Internal use only.
Definition Fl_Widget.H:154
Fl_Widget::type
uchar type() const
Gets the widget type.
Definition Fl_Widget.H:351
Fl_Widget::size
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:418
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46