Page 1 of 1

[2.0.41] on_gui_leave is raised on sub elements

Posted: Mon Mar 17, 2025 8:09 am
by Kuxynator
I want to create a context menu that closes when the mouse leaves the area

Code: Select all

frame { name = "context_menu", direction = "vertical", raise_hover_events = true,
	flow {
		button {caption="Option 1"},
		button {caption="Option 2 long text"},
		button {caption="Option 3" }
	}

script.on_event(defines.events.on_gui_leave, function(e)
	if element  and e.element.name == "context_menu" then close(e) return end
end)
Problem:
The event is already raised when you move over the content (the buttons) and do not leave the frame at all.

Expected behavior:
as long as the mouse is within the element, on_gui_leave must not be raised.

Using Factorio 2.0.41, but the problem has probably existed for some time.

P.S.:
the forum search does not work as expected.
- seach for "on_gui_leave" shows 10000 irrelevant results.
- seach for "on_gui_leave" in topics only shows less results but none of them with "on_gui_leave".

Re: [2.0.41] on_gui_leave is raised on sub elements

Posted: Mon Mar 17, 2025 12:40 pm
by Rseding91
Thanks for the report however this is unlikely to change as this is how the generic GUI logic works since forever. gui enter/leave is specific to the element the mouse is directly over and it is not called for parents of elements the mouse is over - only the final element itself.