Thankyou very much. I'd moved the callback outside of the loop as a
hitting-the-wall why won't it work perhaps-it's-counter-intuitive
measure. The thing I really couldn't figure out was how to keep track
of stuff. Really appreciate the fast and clear response, thanks also
for your cheat page, it's a great help.
Jonathan.
Greg Ercolano <[EMAIL PROTECTED]> writes:
> Jonathan Murphy wrote:
>> What I would like is a single
>> callback that will put the value of each input into output.
>
> You were close, see below.
>
> I'd say the main thing you were missing is setting the
> callback inside the loop. The way you had it, only the
> last instance got the callback.
>
> The other thing was keeping track of the Fl_Widget*
> between the static and non-static callback, so that you
> can get the Fl_Float_Input instance.
>
> I added the option when(FL_WHEN_CHANGED), so that whenever
> any input is being changed, the output is updated as you type.
> Commenting that out will go back to what you had, where you
> have to hit Enter for the output to update.
>
> -------------------------------------------- snip
> #include <FL/Fl.H>
> #include <FL/Fl_Double_Window.H>
> #include <FL/Fl_Scroll.H>
> #include <FL/Fl_Output.H>
> #include <FL/Fl_Float_Input.H>
>
> #define COLS 8
> #define ROWS 16
>
> class Table : public Fl_Scroll
> {
> public:
> Table(int X, int Y, int W, int H, const char*L);
> ~Table();
> Fl_Float_Input *in;
> int r, c;
> private:
> static void in_cb(Fl_Widget*, void*);
> inline void in_cb_i(Fl_Widget*); // CHANGED.
> };
>
> Fl_Double_Window *win;
> Fl_Output *out;
> Table::Table *table;
>
> Table::Table(int X, int Y, int W, int H, const char*L) : Fl_Scroll(X,Y,W,H,L)
> {
> int cellw = 60;
> int cellh = 20;
> int xx = X, yy = Y;
> for (r=0; r<ROWS; r++ )
> {
> for (c=0; c<COLS; c++ )
> {
> {
> in = new Fl_Float_Input(xx,yy,cellw,cellh);
> in->box(FL_PLASTIC_UP_BOX);
> in->value("0.00");
> in->when(FL_WHEN_CHANGED); // ADDED
> (OPTIONAL).
> in->callback(in_cb, this); // MOVED
> HERE..
> }
> xx += cellw;
> }
> xx = X;
> yy += cellh;
> }
> //// in->callback(in_cb, this); // ..FROM
> HERE.
>
> end();
> }
>
> Table::~Table(){}
>
> void Table::in_cb(Fl_Widget* o, void* v)
> {
> ((Table*)v)->in_cb_i(o); // CHANGED.
> }
>
> void Table::in_cb_i(Fl_Widget*o) // CHANGED.
> {
> Fl_Float_Input *in = (Fl_Float_Input*)o; // ADDED.
> out->value(in->value());
> }
>
> int main()
> {
> Fl::scheme("plastic");
> win = new Fl_Double_Window(480, 380);
> table = new Table(0, 0, 480, 320, "");
> out = new Fl_Output(200, 340, 80, 20, "");
> win->resizable();
> win->show();
> return(Fl::run());
> }
>
> -------------------------------------------- snip
> _______________________________________________
> fltk mailing list
> [EMAIL PROTECTED]
> http://lists.easysw.com/mailman/listinfo/fltk
_______________________________________________
fltk mailing list
[EMAIL PROTECTED]
http://lists.easysw.com/mailman/listinfo/fltk