frang75 / nappgui_src

SDK for building cross-platform desktop apps in ANSI-C
https://www.nappgui.com
MIT License
442 stars 43 forks source link

OnDown event for controls enhancement #93

Closed SamSandq closed 3 months ago

SamSandq commented 4 months ago

If I use a listbox or table (any control with OnSelect), I sometimes wish to use a popup menu with a right click. This is not currently possible.

I propose a new ...OnDown event which gives access to the button pressed, and thus one may check for ekGUI_MOUSE_RIGHT and take appropriate action.

Furthermore, in that case it is necessary to know the index clicked as well. So something like

EvMouse *p = event_params(e, EvMouse); uint32_t button = p->button; uint32_t line = p->index;

in addition to the x and y coordinates.

frang75 commented 3 months ago

listbox_OnDown(): https://github.com/frang75/nappgui_src/commit/711ea786b8d5dabede70180b57e2414fc8b3533c Review doc for details: https://nappgui.com/en/gui/listbox.html#f2

SamSandq commented 3 months ago

This works well, but a little confusing with a new variable p->tag instead of p->index like in the OnSelecthandler.

I also uncovered a small effect: when selecting a line programmatically with listbox_select(lb, index, TRUE) it does not repaint it immediately, only after having moved the mouse however little. Could be only in the OnDown handler, have not checked. This does not happen if you return TRUE from the handler -- but the compiler complains about about pointer comparison if you change the handler's signature from void to bool_t. It works well in either case, though.

frang75 commented 3 months ago

tag is a generic name (like guicontrol_tag). Is an extra field in EvMouse that can be used in high-level controls for diferent purposes. It can contain a index, color, hash, bitfield, etc. In the particular case of ListBox, tag is the row index.

listbox_select() refresh fix: https://github.com/frang75/nappgui_src/commit/418ef8c72e04c45d31971d39380e92d0d823f91e

frang75 commented 3 months ago

I close this issue. Feel free reopen if detect any issue.