summaryrefslogtreecommitdiff
path: root/examples/howto-flex-simple.cxx
blob: 15bdde715b776fe1f2e7a5c0f64419f79f629e2d (plain)
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
//
// 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.fixed(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();
}