FLTK logo

Re: [fltk.general] Re: how to restore position of hidden modeless form

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: Re: how to restore position of hidden modeless form "'Mark' via fltk.general" Dec 14, 2021  
 
The code worked correctly on Windows as is. However, I have now switched to using Window::new() and it works on both Linux and Windows. I've also pushed the change.

Once again, thank you all for your help!

On Monday, December 13, 2021 at 10:36:36 PM UTC may64...@gmail.com wrote:
So the C bindings did call the base class's constructor correctly. It was a mistake in the code example I put. 

It's actually a bug in fltk-rs. Calling the window's ::default constructor:
Window::default().with_size(400, 100)

Actually calls force_position(0), instead of actually just passing 0 for x and y. This causes the window to ignore the x and y when reshown. 
So in fltk-rs, creating a window using Window::new(x, y, w, h, label) doesn't exhibit this behavior. 

Mark, can you pull the latest changes using cargo update then rebuilding. You either have to give your form an initial x and y positions, otherwise you need to call form.force_position(true) before calling set_pos() or resize().

On Tuesday, December 14, 2021 at 12:48:44 AM UTC+3 Albrecht Schlosser wrote:
On 12/13/21 9:57 PM Mo_Al_ wrote:
make_modal() just calls Fl_Window::set_modal and set_non_modal depending on the flag. 

I think Mark's program can be translated into this in C++:

Thanks!

If this is a correct transcription, then only one statement is missing. The virtual resize() method must call the resize() method of the base class (Fl_Window). See below.



#include <FL/Enumerations.H>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
static int last_x = 0;
static int last_y = 0;
struct Form: public Fl_Window {
    Form(int x, int y, int w, int h, const char *label): Fl_Window(x, y, w, h, label) {}
    virtual void resize(int x, int y, int w, int h) override {

    Fl_Window::resize(x, y, w, h); // ADD THIS HERE


        last_x = x;
        last_y = y;
        printf("last pos: %d %d\n", last_x, last_y);
    }
    void show_again() {
        printf("shown again at: %d %d\n", last_x, last_y);
        show();
        resize(last_x, last_y, w(), h());
    }
};
void btn_cb(Fl_Widget *w, void *data) {
    auto form = (Form *)data;
    form->show_again();
}
int main(int argc, char **argv) {
    auto win = new Fl_Window(400, 300, "Main Win");
    auto btn = new Fl_Button(160, 200, 80, 30, "Show");
    win->end();
    win->show();
    auto form = new Form(100, 100, 200, 100, "Form");
    form->show();
    btn->callback(btn_cb, form);
    return Fl::run();
}

I would however suggest to store the current position (only) when the window is actually hidden. The attached file x.cxx shows both ways, the "original" and the one which stores the position when the window is hidden if you

#define USE_HIDE (1)

(instead of 0)

Yet another way might be to use the callback of the Fl_Window class which is called when the user clicks the close button. In that case you'd have to call hide() explicitly after storing the coordinates. Since the callback is not a class method it you require write access to last_x and last_y which is a given for a struct but might not be true for a class unless declared public or using an accessor method.

--
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/a1f77de8-de73-4385-986a-958899cebafcn%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'.