STR #2494

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]

Return to Bugs & Features | Post Text | Post File | SVN ⇄ GIT | Prev | Next ]

STR #2494

Application:FLTK Library
Status:5 - New
Priority:1 - Request for Enhancement, e.g. asking for a feature
Scope:3 - Applies to all machines and operating systems
Summary:Patch that adds some macros to the extra code lines
Created By:mingodad
Assigned To:Unassigned
Fix Version:Unassigned
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:

Post File ]
Name/Time/Date Filename/Size top right image
#1 mingodad
11:27 Dec 21, 2010
#2 mingodad
02:58 Dec 22, 2010
#3 mingodad
07:55 Dec 22, 2010
#4 mingodad
07:58 Dec 22, 2010
bottom left image   bottom right image

Trouble Report Comments:

Post Text ]
Name/Time/Date Text top right image
#1 mingodad
11:27 Dec 21, 2010
This patch adds simple macro capability to the extra code lines in fluid:

=db_vat_rates.@class.user_data = @name;

If an extra code line starts with "=" then the "=" will be removed and any occurrence of "@name" will be replaced by the widget name entered and every occurrence of "@class" will be replaced by the classname (default or user entered).

Supposing the above line on an "Fl_Input" with a name of "age" will be converted to:

db_vat_rates.Fl_Input.user_data = age;
#2 mingodad
03:13 Dec 22, 2010
This second version of simple macros for fluid also include the memory leaks patch from a previous STR.

This version adds a $(dirty_name) macro that is the supplied widget name without any cleanup, the resulting name used on code generation have all "@" replaced by "_" except the first one if it is at position 0 (see bellow) in this case it's removed.

And a new code generation option when the widget name starts with "@", with this option instead of fluid generate code to create a new widget it instead generate code to reuse an already existing widget (probably existing on a base class or created elsewhere).

This option allow to have more than one Skin/Layout to the same widgets, we create a class with all widgets that are necessary to show/edit a set of fields with the code to mange load/validation/save/..., and we create on fluid one or more dialogs/widget classes derived from this class, lets suppose one for big monitors, another for pdas, another for touch screens, ...

example code with and without this option:

//widget name = @dbf_id
//extra line = =o->user_data((void*)"$(dirty_name)");
  { Fl_Output* o = dbf_id;
    dbf_id->resize(15, 240, 82, 26);
  } // Fl_Output* dbf_id

//widget name = dbf_id
//extra line = =o->user_data((void*)"$(dirty_name)");
  { Fl_Output* o = dbf_id = new Fl_Output(15, 240, 82, 26, _tr("ID"));
  } // Fl_Output* dbf_id
#3 mingodad
08:14 Dec 22, 2010
Here there is some code corrections and a simple project as example.

For this to work with stack/auto widgets we need a new flag:
Fl_Widget.H -> ON_GROUP_ONLY_REMOVE  = 1<<25,  ///< Fl_Group should only remove this widget without apply free on it

And a modification to Fl_Group.cxx on method Fl_Group::clear()
  while (children_) { // delete all children
    int idx = children_-1; // last child's index
    Fl_Widget* w = child(idx); // last child widget
    if (w->parent()==this) { // should always be true
      if (children_>2) { // optimized removal
        w->parent_ = 0; // reset child's parent
        children_--; // update counter
      } else { // slow removal
      if(!w->flags() & ON_GROUP_ONLY_REMOVE)
        delete w; // delete the child
    } else { // should never happen
      remove(idx); // remove it anyway

This modifications are invisible to existing applications but if we want touse automatic/stack widgets with dynamic allocated Windows/Groups then we need to set this flag on our automatic/stack widgets to prevent double free (one on the dynamig window/group release and another by the compiler at the end of the local scope).

Also to use automatic/stack variables on fluid we need to inform it when supplying widget names:

widget name : age //an widget that fluid will generate code to create it
widget name : @age //a pointer to a widget that fluid will reuse
widget name : @&age //an automatic/stack widget that fluid will reuse

On the example attached I use automatic/stack widgets, to ease of use I derived then, using a macro, where I have a constructor that don't need any arguments and sets the flag ON_GROUP_ONLY_REMOVE.

On the dialog created on fluid I have an automatic/stack instance of AddressEdit (wich supply most of the widgets used) and reuse it's widgets with fluid.
#5 matt
05:29 Dec 25, 2010
We have to check if this is of general use and which parts of it to implement.  
bottom left image   bottom right image

Return to Bugs & Features | Post Text | Post File ]


Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to ''.