Add option to test Fl_Flex in test/pack.cxx
This new feature demonstrates that Fl_Flex can be used (almost) as a drop-in replacement of Fl_Pack. Add missing file to examples/.gitignore.
This commit is contained in:
parent
e6c2503453
commit
a5b9cc888b
1
examples/.gitignore
vendored
1
examples/.gitignore
vendored
@ -10,6 +10,7 @@ howto-add_fd-and-popen
|
||||
howto-browser-with-icons
|
||||
howto-drag-and-drop
|
||||
howto-draw-an-x
|
||||
howto-flex-simple
|
||||
howto-menu-with-images
|
||||
howto-parse-args
|
||||
howto-remap-numpad-keyboard-keys
|
||||
|
@ -1744,6 +1744,7 @@ pack.o: ../FL/fl_casts.H
|
||||
pack.o: ../FL/fl_config.h
|
||||
pack.o: ../FL/Fl_Double_Window.H
|
||||
pack.o: ../FL/Fl_Export.H
|
||||
pack.o: ../FL/Fl_Flex.H
|
||||
pack.o: ../FL/Fl_Group.H
|
||||
pack.o: ../FL/Fl_Image.H
|
||||
pack.o: ../FL/Fl_Light_Button.H
|
||||
|
173
test/pack.cxx
173
test/pack.cxx
@ -1,11 +1,11 @@
|
||||
//
|
||||
// Fl_Pack test program for the Fast Light Tool Kit (FLTK).
|
||||
// Fl_Pack or Fl_Flex test program for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
// Rather crude test of the Fl_Pack object.
|
||||
// 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-2010 by Bill Spitzak and others.
|
||||
// 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
|
||||
@ -25,81 +25,118 @@
|
||||
#include <FL/Fl_Scroll.H>
|
||||
#include <FL/Fl_Value_Slider.H>
|
||||
#include <FL/Fl_Pack.H>
|
||||
#include <FL/Fl_Flex.H>
|
||||
|
||||
Fl_Pack *pack;
|
||||
// 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) {
|
||||
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);
|
||||
Fl_Widget *o = pack->child(i);
|
||||
o->resize(0, 0, 25, 25);
|
||||
}
|
||||
pack->resize(scroll->x(),scroll->y(),scroll->w(),scroll->h());
|
||||
pack->parent()->redraw();
|
||||
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) {
|
||||
pack->spacing(int(o->value()));
|
||||
scroll->redraw();
|
||||
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;
|
||||
{Fl_Double_Window* o = new Fl_Double_Window(360, 370);
|
||||
w = o;
|
||||
scroll = new Fl_Scroll(10,10,340,285);
|
||||
{Fl_Pack* o = new Fl_Pack(10, 10, 340, 285);
|
||||
pack = o;
|
||||
o->box(FL_DOWN_FRAME);
|
||||
//o->box(FL_ENGRAVED_FRAME);
|
||||
new Fl_Button(35, 35, 25, 25, "b1");
|
||||
new Fl_Button(45, 45, 25, 25, "b2");
|
||||
new Fl_Button(55, 55, 25, 25, "b3");
|
||||
new Fl_Button(65, 65, 25, 25, "b4");
|
||||
new Fl_Button(75, 75, 25, 25, "b5");
|
||||
new Fl_Button(85, 85, 25, 25, "b6");
|
||||
new Fl_Button(95, 95, 25, 25, "b7");
|
||||
new Fl_Button(105, 105, 25, 25, "b8");
|
||||
new Fl_Button(115, 115, 25, 25, "b9");
|
||||
new Fl_Button(125, 125, 25, 25, "b10");
|
||||
new Fl_Button(135, 135, 25, 25, "b11");
|
||||
new Fl_Button(145, 145, 25, 25, "b12");
|
||||
new Fl_Button(155, 155, 25, 25, "b13");
|
||||
new Fl_Button(165, 165, 25, 25, "b14");
|
||||
new Fl_Button(175, 175, 25, 25, "b15");
|
||||
new Fl_Button(185, 185, 25, 25, "b16");
|
||||
new Fl_Button(195, 195, 25, 25, "b17");
|
||||
new Fl_Button(205, 205, 25, 25, "b18");
|
||||
new Fl_Button(215, 215, 25, 25, "b19");
|
||||
new Fl_Button(225, 225, 25, 25, "b20");
|
||||
new Fl_Button(235, 235, 25, 25, "b21");
|
||||
new Fl_Button(245, 245, 25, 25, "b22");
|
||||
new Fl_Button(255, 255, 25, 25, "b23");
|
||||
new Fl_Button(265, 265, 25, 25, "b24");
|
||||
o->end();
|
||||
w->resizable(o);
|
||||
}
|
||||
scroll->end();
|
||||
{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*)(Fl_Pack::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*)(Fl_Pack::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->show(argc, argv);
|
||||
return Fl::run();
|
||||
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];
|
||||
sprintf(ltxt, "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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user