1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
//
// Fl_Pack or Fl_Flex test program for the Fast Light Tool Kit (FLTK).
//
// Rather crude test of the Fl_Pack or Fl_Flex class.
// Changing the type() of an Fl_Pack after it is displayed is not supported
// so I have to do a lot of resizing of things before that.
//
// Copyright 1998-2022 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
//
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Light_Button.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl_Pack.H>
#include <FL/Fl_Flex.H>
// This test program can be modified by two #define's below to test Fl_Flex
// as a drop-in replacement of Fl_Pack. The committed code should always use
// the default settings documented below.
//
// Edit the following 2 #define's to modify the test scenario:
#define USE_FLEX 0 // default 0 = use Fl_Pack, 1 = use Fl_Flex
#define USE_SCROLL 1 // default 1 = put Fl_Pack or Fl_Flex inside Fl_Scroll
// Do not edit #define's below
#if USE_FLEX
#define CONTAINER Fl_Flex
#define USE_PACK 0
#else
#define CONTAINER Fl_Pack
#define USE_PACK 1
#endif
CONTAINER *pack; // either Fl_Pack or Fl_Flex
#if USE_SCROLL
Fl_Scroll *scroll;
#endif
void type_cb(Fl_Light_Button *, long v) {
for (int i = 0; i < pack->children(); i++) {
Fl_Widget *o = pack->child(i);
o->resize(0, 0, 25, 25);
}
pack->type(uchar(v));
#if USE_SCROLL
pack->resize(scroll->x(), scroll->y(), scroll->w(), scroll->h());
#endif
#if USE_FLEX
pack->layout();
#else
pack->parent()->redraw();
pack->redraw();
#endif
}
void spacing_cb(Fl_Value_Slider *o, long) {
int s = int(o->value());
pack->spacing(s);
#if USE_FLEX
if (s > 4)
pack->margin(4);
else
pack->margin(s);
pack->layout();
#else
pack->parent()->redraw();
#endif
}
int main(int argc, char **argv) {
Fl_Double_Window *w = new Fl_Double_Window(360, 370);
#if USE_SCROLL
scroll = new Fl_Scroll(10, 10, 340, 285);
#endif
int nbuttons = 24;
pack = new CONTAINER(10, 10, 340, 285);
#if (USE_FLEX)
pack->box(FL_DOWN_BOX);
nbuttons = 12;
#else
pack->box(FL_DOWN_FRAME);
#endif
// create buttons: position (xx, xx) will be "fixed" by Fl_Pack/Fl_Flex
int xx = 35;
for (int i = 0; i < nbuttons; i++) {
char ltxt[8];
snprintf(ltxt, 8, "b%d", i + 1);
Fl_Button *b = new Fl_Button(xx, xx, 25, 25);
b->copy_label(ltxt);
xx += 10;
}
pack->end();
w->resizable(pack);
#if USE_SCROLL
scroll->end();
#endif
{
Fl_Light_Button *o = new Fl_Light_Button(10, 305, 165, 25, "HORIZONTAL");
o->type(FL_RADIO_BUTTON);
o->callback((Fl_Callback *)type_cb, (void *)(CONTAINER::HORIZONTAL));
}
{
Fl_Light_Button *o = new Fl_Light_Button(185, 305, 165, 25, "VERTICAL");
o->type(FL_RADIO_BUTTON);
o->value(1);
o->callback((Fl_Callback *)type_cb, (void *)(CONTAINER::VERTICAL));
}
{
Fl_Value_Slider *o = new Fl_Value_Slider(100, 335, 250, 25, "Spacing: ");
o->align(FL_ALIGN_LEFT);
o->type(FL_HORIZONTAL);
o->range(0, 30);
o->step(1);
o->callback((Fl_Callback *)spacing_cb);
}
w->end();
w->size_range(300, 300);
w->show(argc, argv);
return Fl::run();
}
|