summaryrefslogtreecommitdiff
path: root/examples/howto-flex-simple.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'examples/howto-flex-simple.cxx')
-rw-r--r--examples/howto-flex-simple.cxx63
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/howto-flex-simple.cxx b/examples/howto-flex-simple.cxx
new file mode 100644
index 000000000..329fe9351
--- /dev/null
+++ b/examples/howto-flex-simple.cxx
@@ -0,0 +1,63 @@
+//
+// Very simple Fl_Flex demo program for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 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_Double_Window.H>
+#include <FL/Fl_Flex.H>
+#include <FL/Fl_Box.H>
+#include <FL/Fl_Button.H>
+#include <FL/fl_ask.H>
+
+// the 'Exit' button callback closes the window and terminates the program
+void exit_cb(Fl_Widget *w, void *) {
+ fl_message("The '%s' button closes the window\nand terminates the program.", w->label());
+ w->window()->hide();
+}
+
+// common callback for all other buttons
+void button_cb(Fl_Widget *w, void *) {
+ fl_message("The '%s' button does nothing.", w->label());
+}
+
+int main(int argc, char **argv) {
+ Fl_Double_Window window(410, 40, "Simple Fl_Flex Demo");
+ Fl_Flex flex(5, 5, window.w() - 10, window.h() - 10, Fl_Flex::HORIZONTAL);
+ Fl_Button b1(0, 0, 0, 0, "File");
+ Fl_Button b2(0, 0, 0, 0, "New");
+ Fl_Button b3(0, 0, 0, 0, "Save");
+ Fl_Box bx(0, 0, 0, 0); // empty space
+ Fl_Button eb(0, 0, 0, 0, "Exit");
+
+ // assign callbacks to buttons
+ b1.callback(button_cb);
+ b2.callback(button_cb);
+ b3.callback(button_cb);
+ eb.callback(exit_cb);
+
+ // set gap between adjacent buttons and extra spacing (invisible box size)
+ flex.gap(10);
+ flex.set_size(bx, 30); // total 50: 2 * gap + 30
+
+ // end() groups
+ flex.end();
+ window.end();
+
+ // set resizable, minimal window size, show() window, and execute event loop
+ window.resizable(flex);
+ window.size_range(300, 30);
+ window.show(argc, argv);
+ return Fl::run();
+}