FLTK logo

Re: [fltk.general] Syntax Variations (My original post seemed to disappear

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 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Syntax Variations (My original post seemed to disappear "lifeatt... Sep 17, 2022  
 
I am wondering then what would be the use cases for each particular syntactical version. ie.

When and why would i use this code....
        Fl_Button fltkButton(25, 20, 70, 50, "button1");
             noting it requires fltkButton.labelsize(12);
as opposed to this code....
        Fl_Button *fluidButton = new Fl_Button(25, 80, 70, 50, "button2"); 
            noting it requires fltkButton->labelsize(12);
I use the second form frequently because I'm often working with control interactions. E.g. if I have a button in my GUI which impacts 
other controls (such as a 'Reset' button). As alluded to in erco's first reply: "unless the pointer is saved somewhere else." - pointers to 
the impacted controls need to be kept around so (in this case) the button callback can "talk" to them. So a simple, contrived example:

// Kept pointers
Fl_Int_Input *inpDollarAmount;
Fl_Int_Input *inpOther;
...
// GUI construction
inpDollarAmount = new Fl_Int_Input(25, 20, 75, 25, "Amount:");
Fl_Button *btnReset = new Fl_Button(25, 50, 75, 25, "Reset");
btnReset->callback(onReset);
...
// Reset button callback: clears all input controls
void onReset(Fl_Widget *w, void *d)
{  
    inpDollarAmount->value(0);   // callback can't access the control without the pointer
    inpOther->value(0);
}

 

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/2bb5a185-47d9-4e96-82b0-e7335ac25a6cn%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

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 'erco@seriss.com'.