|
|
commit 47cd9a11a0d68fa511cb6c593b62b25af1550e19
Author: Greg Ercolano <erco@seriss.com>
AuthorDate: Thu Jan 13 07:28:00 2022 -0800
Commit: Greg Ercolano <erco@seriss.com>
CommitDate: Thu Jan 13 07:28:00 2022 -0800
Fixes issue #361.
FL/Fl_Input_Choice.H | 36 +++++++++++++++++++++++++++---------
src/Fl_Input_Choice.cxx | 38 +++++++++++++++++++++++++++++++++++---
2 files changed, 62 insertions(+), 12 deletions(-)
diff --git FL/Fl_Input_Choice.H FL/Fl_Input_Choice.H
index 71bc76e..56fdd10 100644
--- FL/Fl_Input_Choice.H
+++ FL/Fl_Input_Choice.H
@@ -58,16 +58,34 @@ class FL_EXPORT Fl_Input_Choice : public Fl_Group {
// note: this is used by the Fl_Input_Choice ctor.
static void inp_cb(Fl_Widget*, void *data);
+protected:
// Custom resize behavior -- input stretches, menu button doesn't
- inline int inp_x() { return(x() + Fl::box_dx(box())); }
- inline int inp_y() { return(y() + Fl::box_dy(box())); }
- inline int inp_w() { return(w() - Fl::box_dw(box()) - 20); }
- inline int inp_h() { return(h() - Fl::box_dh(box())); }
-
- inline int menu_x() { return(x() + w() - 20 - Fl::box_dx(box())); }
- inline int menu_y() { return(y() + Fl::box_dy(box())); }
- inline int menu_w() { return(20); }
- inline int menu_h() { return(h() - Fl::box_dh(box())); }
+
+ /** The methods inp_x(), inp_y(), inp_w() and inp_h() return the
+ desired position and size of the internal Fl_Input widget.
+ These can be overridden by a subclass to redefine positioning.
+ See code example in the Description for subclassing details.
+ */
+ virtual int inp_x() const { return(x() + Fl::box_dx(box())); }
+ /** See inp_x() for info. */
+ virtual int inp_y() const { return(y() + Fl::box_dy(box())); }
+ /** See inp_x() for info. */
+ virtual int inp_w() const { return(w() - Fl::box_dw(box()) - 20); }
+ /** See inp_x() for info. */
+ virtual int inp_h() const { return(h() - Fl::box_dh(box())); }
+
+ /** The methods menu_x(), menu_y(), menu_w() and menu_h() return the
+ desired position and size of the internal Fl_Menu_Button widget.
+ These can be overridden by a subclass to redefine positioning.
+ See code example in the Description for subclassing details.
+ */
+ virtual int menu_x() const { return(x() + w() - 20 - Fl::box_dx(box())); }
+ /** See menu_x() for info. */
+ virtual int menu_y() const { return(y() + Fl::box_dy(box())); }
+ /** See menu_x() for info. */
+ virtual int menu_w() const { return(20); }
+ /** See menu_x() for info. */
+ virtual int menu_h() const { return(h() - Fl::box_dh(box())); }
public:
diff --git src/Fl_Input_Choice.cxx src/Fl_Input_Choice.cxx
index 765b965..bf52360 100644
--- src/Fl_Input_Choice.cxx
+++ src/Fl_Input_Choice.cxx
@@ -54,19 +54,18 @@
- 1: the user picked a different item in the choice menu
- 0: the user typed or pasted directly into the input field
- Example use:
+ \par Example Use of Fl_Input_Choice
\code
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Input_Choice.H>
+ // Fl_Input_Choice callback()
void choice_cb(Fl_Widget *w, void *userdata) {
-
// Show info about the picked item
Fl_Input_Choice *choice = (Fl_Input_Choice*)w;
printf("*** Choice Callback:\n");
printf(" widget's text value='%s'\n", choice->value()); // normally all you need
-
// Access the menu via menubutton()..
const Fl_Menu_Item *item = choice->menubutton()->mvalue();
printf(" item label()='%s'\n", item ? item->label() : "(No item)");
@@ -90,6 +89,39 @@
return Fl::run();
}
\endcode
+
+ \par Subclassing Example
+ One can subclass Fl_Input_Choice to override the virtual methods inp_x/y/w/h()
+ and menu_x/y/w/h() to take control of the internal Fl_Input and Fl_Menu_Button widget
+ positioning. In this example, input and menubutton's positions are swapped:
+ \code
+ #include <FL/Fl.H>
+ #include <FL/Fl_Window.H>
+ #include <FL/Fl_Input_Choice.H>
+
+ class MyInputChoice : public Fl_Input_Choice {
+ protected:
+ virtual int inp_x() const { return x() + Fl::box_dx(box()) + menu_w(); } // override to reposition
+ virtual int menu_x() const { return x() + Fl::box_dx(box()); } // override to reposition
+ public:
+ MyInputChoice(int X,int Y,int W,int H,const char*L=0) : Fl_Input_Choice(X,Y,W,H,L) {
+ resize(X,Y,W,H); // necessary for ctor to trigger our overrides
+ }
+ };
+
+ int main(int argc, char **argv) {
+ Fl_Window *win = new Fl_Window(400,300);
+ MyInputChoice *mychoice = new MyInputChoice(150,40,150,25,"Right Align Input");
+ mychoice->add("Aaa");
+ mychoice->add("Bbb");
+ mychoice->add("Ccc");
+ win->end();
+ win->resizable(win);
+ win->show();
+ return Fl::run();
+ }
+ \endcode
+
*/
/** Constructor for private menu button. */
[ Direct Link to Message ] | |
|
| |