Skip to content

Commit 02c03c7

Browse files
committed
fix(gui): root widget is missing hover and active status
1 parent bc7710a commit 02c03c7

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

src/gui/widget_event.c

+15-31
Original file line numberDiff line numberDiff line change
@@ -666,13 +666,12 @@ int Widget_StopEventPropagation(LCUI_Widget widget)
666666
static LCUI_Widget GetSameParent(LCUI_Widget a, LCUI_Widget b)
667667
{
668668
int depth = 0, i;
669-
LCUI_Widget w, root;
669+
LCUI_Widget w;
670670

671-
root = LCUIWidget_GetRoot();
672-
for (w = a; w != root && w; w = w->parent) {
671+
for (w = a; w; w = w->parent) {
673672
++depth;
674673
}
675-
for (w = b; w != root && w; w = w->parent) {
674+
for (w = b; w; w = w->parent) {
676675
--depth;
677676
}
678677
if (depth > 0) {
@@ -688,7 +687,7 @@ static LCUI_Widget GetSameParent(LCUI_Widget a, LCUI_Widget b)
688687
a = a->parent;
689688
b = b->parent;
690689
}
691-
if (a && a == b && a != root) {
690+
if (a && a == b) {
692691
return a;
693692
}
694693
return NULL;
@@ -762,9 +761,7 @@ static void Widget_OnMouseOverEvent(LCUI_Widget widget)
762761
if (self.targets[WST_HOVER] == widget) {
763762
return;
764763
}
765-
if (widget && self.targets[WST_HOVER]) {
766-
parent = GetSameParent(widget, self.targets[WST_HOVER]);
767-
}
764+
parent = GetSameParent(widget, self.targets[WST_HOVER]);
768765
if (widget) {
769766
Widget_TriggerMouseOverEvent(widget, parent);
770767
}
@@ -776,13 +773,14 @@ static void Widget_OnMouseOverEvent(LCUI_Widget widget)
776773

777774
static void Widget_OnMouseDownEvent(LCUI_Widget widget)
778775
{
779-
LCUI_Widget w, parent;
776+
LCUI_Widget parent;
777+
LCUI_Widget w = self.targets[WST_ACTIVE];
780778

781-
if (self.targets[WST_ACTIVE] == widget) {
779+
if (w == widget) {
782780
return;
783781
}
784-
parent = GetSameParent(widget, self.targets[WST_ACTIVE]);
785-
for (w = self.targets[WST_ACTIVE]; w && w != parent; w = w->parent) {
782+
parent = GetSameParent(widget, w);
783+
for (; w && w != parent; w = w->parent) {
786784
Widget_RemoveStatus(w, "active");
787785
}
788786
for (w = widget; w && w != parent; w = w->parent) {
@@ -911,42 +909,28 @@ static void OnMouseEvent(LCUI_SysEvent sys_ev, void *arg)
911909
{
912910
float scale;
913911
LCUI_Pos pos;
912+
LCUI_Widget root;
914913
LCUI_Widget target, w;
915914
LCUI_WidgetEventRec ev = { 0 };
916915

917-
w = LCUIWidget_GetRoot();
916+
root = LCUIWidget_GetRoot();
918917
LCUICursor_GetPos(&pos);
919918
scale = LCUIMetrics_GetScale();
920919
pos.x = iround(pos.x / scale);
921920
pos.y = iround(pos.y / scale);
922921
if (self.mouse_capturer) {
923922
target = self.mouse_capturer;
924923
} else {
925-
target = Widget_GetEventTarget(w, (float)pos.x, (float)pos.y,
924+
target = Widget_GetEventTarget(root, 1.f * pos.x, 1.f * pos.y,
926925
SV_AUTO);
927926
}
928927
for (w = target; w; w = w->parent) {
929928
if (w->event_blocked) {
930929
return;
931930
}
932931
}
933-
if (!target || target == LCUIWidget_GetRoot()) {
934-
Widget_OnMouseOverEvent(NULL);
935-
switch (sys_ev->type) {
936-
case LCUI_MOUSEDOWN:
937-
LCUIWidget_SetFocus(NULL);
938-
break;
939-
case LCUI_MOUSEUP:
940-
if (sys_ev->button.button == LCUI_KEY_LEFTBUTTON) {
941-
self.click.x = 0;
942-
self.click.y = 0;
943-
self.click.time = 0;
944-
self.click.widget = NULL;
945-
Widget_OnMouseDownEvent(NULL);
946-
break;
947-
}
948-
}
949-
return;
932+
if (!target) {
933+
target = root;
950934
}
951935
ev.target = target;
952936
ev.cancel_bubble = FALSE;

0 commit comments

Comments
 (0)