From 38871c5b3192bccd508f3686413d4e56041ab091 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Mon, 16 Oct 2023 22:11:33 +0200 Subject: Add Fl_Grid widget and test and demo programs - FL/Fl_Grid.H: header file - src/Fl_Grid.cxx: implementation - examples/grid-simple.cxx: simple example program - test/cube.cxx: use Fl_Grid for layout - test/grid_alignment.cxx: test cell alignment and other functions - test/grid_buttons.cxx: demo program as discussed in fltk.general - test/grid_login.cxx: like test/flex_login.cxx but with Fl_Grid - test/flex_login.cxx: modified to match test/grid_login.cxx --- test/grid_buttons.cxx | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/grid_buttons.cxx (limited to 'test/grid_buttons.cxx') diff --git a/test/grid_buttons.cxx b/test/grid_buttons.cxx new file mode 100644 index 000000000..a00a69a64 --- /dev/null +++ b/test/grid_buttons.cxx @@ -0,0 +1,75 @@ +// +// Fl_Grid demo program for the Fast Light Tool Kit (FLTK). +// +// Copyright 2021 by Albrecht Schlosser +// Copyright 2022-2023 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 +// + +// Q: How to achieve a spaced out layout? +// https://groups.google.com/g/fltkgeneral/c/haet7hOQR0g + +// A: We use an Fl_Grid with 1 x 7 cells (5 buttons) as requested: +// [New] [Options] [About] [Help] [Quit] + +#include +#include +#include +#include + +int main(int argc, char **argv) { + + Fl_Double_Window *win = new Fl_Double_Window(460, 200, "Fl_Grid Row with 5 Buttons"); + + Fl_Grid *grid = new Fl_Grid(0, 0, win->w(), 50); + grid->layout(1, 7, 10, 10); + + // create the buttons + + Fl_Button *b0 = new Fl_Button(0, 0, 80, 30, "New"); + Fl_Button *b1 = new Fl_Button(0, 0, 80, 30, "Options"); + Fl_Button *b3 = new Fl_Button(0, 0, 80, 30, "About"); + Fl_Button *b4 = new Fl_Button(0, 0, 80, 30, "Help"); + Fl_Button *b6 = new Fl_Button(0, 0, 80, 30, "Quit"); + + grid->end(); + + // assign buttons to grid positions + + grid->widget(b0, 0, 0); + grid->widget(b1, 0, 1); grid->col_gap(1, 0); + grid->widget(b3, 0, 3); + grid->widget(b4, 0, 4); grid->col_gap(4, 0); + grid->widget(b6, 0, 6); + + // set column weights for resizing (only empty columns resize) + + int weight[] = { 0, 0, 50, 0, 0, 50, 0 }; + grid->col_weight(weight, 7); + + grid->end(); + // grid->show_grid(1); // enable to display grid helper lines + + // add content ... + + Fl_Group *g1 = new Fl_Group(0, 50, win->w(), win->h() - 50); + // add more widgets ... + + win->end(); + win->resizable(g1); + win->size_range(win->w(), 100); + win->show(argc, argv); + + int ret = Fl::run(); + delete win; // not necessary but useful to test for memory leaks + return ret; +} -- cgit v1.2.3