nappgui_src
nappgui_src copied to clipboard
Get size and origin for all controls
During my development of drag & drop I am continuously confronted by trying to obtain the correct position of the dropped item. This is possible some, but the inconsistency in being able to set the sizes of controls, but not obtaining the current size and origins is frustrating, necessitating own functions (on the Mac, in Objective-c, or modifying NAppGUI itself).
I propose that the following be added:
S2Df size = guicontrol_size(<control>)
and
V2Df origin = guicontrol_origin(<control>)
This way we would have a consistent way of obtaining these across NAppGUI, and, together with the existing gui_mouse()
function may calculate any drop position accurately. These already exist for windows, and to a lesser degree for views.
For some controls, like listboxes, tables, etc. a similar row and header height function should also be added. For instance, now you can set the row and header height in a table but not obtain the current ones.
Hi @SamSandq. This can be done with
window_control_frame()
window_client_to_screen()
You are right, the following code will obtain the mouse position in a control:
V2Df gui_mouse_pos_in_view(Window *w, void *v) {
V2Df mp = gui_mouse_pos();
R2Df frame = window_control_frame(w, (GuiControl *) v);
V2Df posX = window_client_to_screen(app->window, frame.pos);
V2Df pos = {mp.x - posX.x, mp.y - posX.y};
return pos;
}
Consider this issue partly resolved; we still have to be able to obtain the row and header heights, as applicable, in order to position correctly.
You may close this issue as solved.