On 19 Jan 2013, at 15:39, Ian MacArthur wrote:

> 
> On 18 Jan 2013, at 23:49, George wrote:
> 
> 
>> Now i have another question I'm kind of a beginner in fltk. I have a window 
>> with some input widgets and a button which is deactiveted initially. I want 
>> to activate the button when i insert text in all the input widgets(the 
>> button can't be pressed if an input is empty). I've read some things and i 
>> know it;s something with events handling and FL_KEYDOWN but it really gives 
>> me a hard time. Any help will be appreciated
> 
> 
> I don't think it would require any messing about with event handling per se; 
> should be enough to have a callback attached to the input widgets that checks 
> whether they are all set or not, and if they are all set, do a 
> button->activate() to "wake up" the button...
> 

So... in a rare quiet moment, I was inspired to throw together a quick demo: I 
think this shows what was being asked...
Though in practice I imagine that some more sophisticated validation of the 
content of the Fl_Inputs would be performed, to make sure the values set were 
valid (and not just non-empty!)


// demo of activating a button...
// fltk-config --compile inactive-button-demo.cxx

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Button.H>

static Fl_Double_Window *main_win=(Fl_Double_Window *)0;
static Fl_Button *done_bt=(Fl_Button *)0;

static unsigned inputs_set = 0;

static void check_inputs_are_ready(Fl_Input* in, unsigned mask) {
  if (strlen(in->value())) {
    inputs_set |= mask;
  }
  else {
    inputs_set &= ~mask;
  }

  if (inputs_set == 7) {
    done_bt->activate();
  }
  else {
    done_bt->deactivate();
  }
}

static void cb_input1(Fl_Input* in, void*) {
  // input 1;
  check_inputs_are_ready(in, 1);
}

static void cb_input2(Fl_Input* in, void*) {
  // input 2;
  check_inputs_are_ready(in, 2);
}

static void cb_input3(Fl_Input* in, void*) {
  // input 3;
  check_inputs_are_ready(in, 4);
}

static void cb_done_bt(Fl_Button*, void*) {
  main_win->hide();
}

int main(int argc, char **argv) {
  main_win = new Fl_Double_Window(348, 367, "Activate Button Demo");
  main_win->begin();

  Fl_Input *input1 = new Fl_Input(130, 37, 200, 33, "Enter Some Text");
  input1->callback((Fl_Callback*)cb_input1);
  input1->when(FL_WHEN_CHANGED);

  Fl_Input *input2 = new Fl_Input(130, 124, 200, 33, "Enter Some Text");
  input2->callback((Fl_Callback*)cb_input2);
  input2->when(FL_WHEN_CHANGED);

  Fl_Input *input3 = new Fl_Input(130, 212, 200, 33, "Enter Some Text");
  input3->callback((Fl_Callback*)cb_input3);
  input3->when(FL_WHEN_CHANGED);

  done_bt = new Fl_Button(215, 285, 115, 65, "Done");
  done_bt->callback((Fl_Callback*)cb_done_bt);
  done_bt->deactivate();

  main_win->end();
  main_win->show(argc, argv);

  return Fl::run();
} // main

// end of file





_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to