rxi / microui

A tiny immediate-mode UI library
MIT License
3.29k stars 239 forks source link

Mouse down event not registered properly when there is no mouse motion #20

Open uberyoji opened 4 years ago

uberyoji commented 4 years ago

I recently ported the code to a project I am working on the nintendo switch. Since I am using touchscreen, there are no motion message being sent (unless when dragging). Motion occurs only when a touch is inputed.

Seems controls need to be hovered first thru motion before mouse down is processed properly. I tried to debug it a little. I believe the problem occurs in mu_update_control when the context hover id is set.

To reproduce the issue just disable the processing of motion in the sdl message handler. You'll notice you need to click several time to get a proper mouse down.

I'll continue to investigate, let me know if you have some ideas.

uberyoji commented 4 years ago

I think I have a better understanding now. ctx->hover_root is not set on mousedown and the mu_mouse_over called from mu_update_control fails because in_hover_root returns false. Not sure how to fix it yet though.

uberyoji commented 4 years ago

Ok I think I found the issue. The problem lies with ctx->last_hover_root. Since it is null at the beginning, the first move and click will be lost. This never happens when we send down mouse moves every frame as ctx->last_hover_root will be quickly set to something valid. I think I will fix my problem by sending fake mouse moves at the window header coordinates. I wonder if this behavior could also affect focus state.

uberyoji commented 4 years ago

Got the fix! Touchscreen now works perfectly.

In microui.c changed line 654:
if (mouseover /*&& !ctx->mouse_down*/) { ctx->hover = id; }

In microui.c added a new line at 1042:
if( ctx->last_hover_root == 0 ) ctx->last_hover_root = cnt;

ericoporto commented 3 years ago

@uberyoji do you still have the modified microui.c somewhere? I think the lines changed or I am not sure if I am looking in the right place. Do you remember if this solved in Switch but broke the mouse?

pythonmcpi commented 1 year ago

@ericoporto The most recently commit available when uberyoji wrote their comment is c988730f1b744ce3c7169da8794e4d8dbd4ee777 (Committed on Oct 6, 2019).

If you have a local copy of the repository (from git clone), you can run git checkout c988730 to visit that commit. You can run git checkout - to go back to the current commit. (If you've made any local commits after running the first command, check this stackoverflow answer before you go back or you may lose your changes.)