diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2022-07-28 18:26:07 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2022-08-01 15:33:20 +0200 |
| commit | f37aca15e9786a7192e36ea4b0295ab4dc12819f (patch) | |
| tree | 549680fc1da3b72de9a38ed24d9ce1521b97cf71 /test/flex_login.cxx | |
| parent | de8e6de25b33a3bf6c00da603d1332042ae51cf2 (diff) | |
Add Fl_Flex widget from Karsten Pedersen (issue #255)
This work is based on the repository and latest commit:
https://github.com/osen/FL_Flex.git
commit 36e4ed75a00daac825b87e81295818b4650991f5
Author: Karsten Pedersen <...>
Date: Fri Apr 23 12:06:16 2021 +0000
Added Fltk (LGPL) license.
This widget is similar to Fl_Pack and supports either one row or one
column of widgets but has some more features. Test and demo programs
are included:
test/flex_login.cxx: simple "login window" demo program
test/flex_demo.cxx: slightly more complex demo program
The original demo programs can still be compiled and built with
the new widget provided you '#include <FL/Fl_Flex.H>'.
Backwards compatible methods are included (except debug()).
The original widget has been modified to match FLTK standards and
enhanced in several ways, including:
- support box frames
- add HORIZONTAL and VERTICAL enum values (as in Fl_Pack)
- add horizontal() method (as in Fl_Pack)
- use type() rather than internal 'direction' variable
- add standard widget constructor (x, y, w, h, label)
- add margin and gap accessors rather than hard coding constants
- improve test and demo programs
- add documentation
- replace <vector> with array as required by FLTK CMP
- rename camelCase method names, keeping old names for compatibility:
- change 'setSize(Fl_Widget*, int)' to 'set_size(Fl_Widget*, int)'
- change 'bool isSetSize(Fl_Widget*)' to 'int set_size(Fl_Widget*)'
- remove debug() method
- add a way to "unset" fixed size: set_size(Fl_Widget *, 0)
- add layout() method to force recalculation of children
- unify resizeRow() and resizeCol() methods to avoid code duplication
- improve widget size calculation.
Diffstat (limited to 'test/flex_login.cxx')
| -rw-r--r-- | test/flex_login.cxx | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/test/flex_login.cxx b/test/flex_login.cxx new file mode 100644 index 000000000..3923bcde3 --- /dev/null +++ b/test/flex_login.cxx @@ -0,0 +1,131 @@ +// +// Fl_Flex demo program for the Fast Light Tool Kit (FLTK). +// +// Copyright 2020 by Karsten Pedersen +// 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_Input.H> + +Fl_Button *createButton(const char *caption) { + Fl_Button *rtn = new Fl_Button(0, 0, 100, 25, caption); + rtn->color(fl_rgb_color(225, 225, 225)); + return rtn; +} + +void buttonsPanel(Fl_Flex *parent) { + new Fl_Box(0, 0, 0, 0, ""); + Fl_Box *w = new Fl_Box(0, 0, 0, 0, "Welcome to Flex Login"); + + Fl_Flex *urow = new Fl_Flex(Fl_Flex::ROW); + { + Fl_Box *b = new Fl_Box(0, 0, 0, 0, "Username:"); + b->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT); + Fl_Input *username = new Fl_Input(0, 0, 0, 0, ""); + + urow->set_size(username, 180); + urow->end(); + } + + Fl_Flex *prow = new Fl_Flex(Fl_Flex::ROW); + { + Fl_Box *b = new Fl_Box(0, 0, 0, 0, "Password:"); + b->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT); + Fl_Input *password = new Fl_Input(0, 0, 0, 0, ""); + + prow->set_size(password, 180); + prow->end(); + } + + Fl_Box *pad = new Fl_Box(0, 0, 0, 0, ""); + + Fl_Flex *brow = new Fl_Flex(Fl_Flex::ROW); + { + new Fl_Box(0, 0, 0, 0, ""); + Fl_Button *reg = createButton("Register"); + Fl_Button *login = createButton("Login"); + + brow->set_size(reg, 80); + brow->set_size(login, 80); + brow->gap(20); + + brow->end(); + } + + Fl_Box *b = new Fl_Box(0, 0, 0, 0, ""); + + parent->set_size(w, 60); + parent->set_size(urow, 30); + parent->set_size(prow, 30); + parent->set_size(pad, 1); + parent->set_size(brow, 30); + parent->set_size(b, 30); +} + +void middlePanel(Fl_Flex *parent) { + new Fl_Box(0, 0, 0, 0, ""); + + Fl_Box *box = new Fl_Box(0, 0, 0, 0, "Image"); + box->box(FL_BORDER_BOX); + box->color(fl_rgb_color(0, 200, 0)); + Fl_Box *spacer = new Fl_Box(0, 0, 0, 0, ""); + + Fl_Flex *bp = new Fl_Flex(Fl_Flex::COLUMN); + buttonsPanel(bp); + bp->end(); + + new Fl_Box(0, 0, 0, 0, ""); + + parent->set_size(box, 200); + parent->set_size(spacer, 10); + parent->set_size(bp, 300); +} + +void mainPanel(Fl_Flex *parent) { + new Fl_Box(0, 0, 0, 0, ""); + + Fl_Flex *mp = new Fl_Flex(Fl_Flex::ROW); + middlePanel(mp); + mp->end(); + + new Fl_Box(0, 0, 0, 0, ""); + + parent->set_size(mp, 200); +} + +int main(int argc, char **argv) { + + Fl_Window *window = new Fl_Double_Window(100, 100, "Simple GUI Example"); + { + Fl_Flex *col = new Fl_Flex(5, 5, 90, 90, Fl_Flex::COLUMN); + mainPanel(col); + col->end(); + + window->resizable(col); + window->color(fl_rgb_color(250, 250, 250)); + window->end(); + } + + window->resize(0, 0, 640, 480); + window->size_range(550, 250); + window->show(argc, argv); + + int ret = Fl::run(); + delete window; + return ret; +} |
