Hello,

With FLTK 1.1.10 or one of 1.3.x snapshot (7677), I can't change the position of widgets Fl_Input and Fl_Output. I found that the problem is with the redefinition of Fl_Widget::position(X,Y) in the class Fl_Input_. To reproduce the behavior, run the simple file in attachment.

In the callback function, widget are casted by default to Fl_Input_ and I try to move using the position(X,Y) function.

- With Fl_Input_ cast and the position function, widgets don't move.
- If I leave the cast to Fl_Input_, I can move the widget using the resize(X,Y,W,H) function instead. Is that a normal behavior? - If we change the cast to Fl_Widget, then they can be moved with the position function.

If we look into Fl_Widget and Fl_Input_, we can see that Fl_Widget::position(X,Y) is a shortcut to resize(X,Y,w(),h()) but in Fl_Input_, the function position(X,Y) is redefined and is more complicated.

If we look into the documentation, it appear that the functions Fl_Input_::position(int,int) and Fl_Widget::position(int,int) don't have the same definition, i.e., Fl_Widget::position(int,int) is to move the widget while Fl_Input_::position(int,int) is for the cursor position (from what I understand).

Since 1.3.x is still under development, should we change the name of the function Fl_Input_::position(int,int) to avoid problem like I have? It's strange to me that the function position(int,int) does 2 things completely different depending of the type of widget.

My suggestion is to rename Fl_Input_::position(int,int) to any name that is significant, lets say Fl_Input_::cursor_position(int,int). And from a grep into the source file, the function Fl_Input_::position(int,int) is used only into Fl_Input_ and Fl_Input class, and into these two class, every call to functions position(), position(int) or position(int, int) is related to the Fl_Input_::position(int,int) function. So a simple find and replace should do the job.

I can commit a patch, but I prefer to have comments first.

Boris
// [path_of_local_fltk]/fltk-config --compile fl_input_output.cxx

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Input_.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Check_Button.H>

Fl_Window *window = 0;
Fl_Check_Button* widgetType = 0;
Fl_Check_Button* moveType = 0;

void up_cb(Fl_Widget*, void* data)
{
   if (widgetType->value())
   {
      Fl_Widget* w = (Fl_Widget*)data;
      if (moveType->value()) { w->resize(w->x(), w->y()-10, w->w(), w->h()); }
      else { w->position(w->x(), w->y()-10); }
   }
   else
   {
      Fl_Input_* w = (Fl_Input_*)data;
      if (moveType->value()) { w->resize(w->x(), w->y()-10, w->w(), w->h()); }
      else { w->position(w->x(), w->y()-10); }
   }
   window->redraw();
}

void down_cb(Fl_Widget*, void* data)
{
   if (widgetType->value())
   {
      Fl_Widget* w = (Fl_Widget*)data;
      if (moveType->value()) { w->resize(w->x(), w->y()+10, w->w(), w->h()); }
      else { w->position(w->x(), w->y()+10); }
   }
   else
   {
      Fl_Input_* w = (Fl_Input_*)data;
      if (moveType->value()) { w->resize(w->x(), w->y()+10, w->w(), w->h()); }
      else { w->position(w->x(), w->y()+10); }
   }
   window->redraw();
}

int main(int argc, char **argv)
{
   window = new Fl_Window(300, 200);

   Fl_Input* input = new Fl_Input(80, 40, 90, 30, "Fl_Input");
   Fl_Button *up_btn1 = new Fl_Button(200, 40, 30, 30, "+");
   up_btn1->callback(up_cb, input);
   Fl_Button *down_btn1 = new Fl_Button(250, 40, 30, 30, "-");
   down_btn1->callback(down_cb, input);

   Fl_Output* output = new Fl_Output(80, 80, 90, 30, "Fl_Output");
   Fl_Button *up_btn2 = new Fl_Button(200, 80, 30, 30, "+");
   up_btn2->callback(up_cb, output);
   Fl_Button *down_btn2 = new Fl_Button(250, 80, 30, 30, "-");
   down_btn2->callback(down_cb, output);

   widgetType = new Fl_Check_Button(30, 130, 260, 30, "Use Fl_Widget instead of Fl_Input_");
   widgetType->clear();
   moveType = new Fl_Check_Button(30, 160, 260, 30, "Use resize() instead of position()");
   moveType->clear();

   window->end();
   window->show(argc, argv);
   return Fl::run();
}

_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to