Keyslam / Inky

A GUI Framework for LÖVE
MIT License
48 stars 4 forks source link

Consumption of pointer events #5

Closed Keyslam closed 1 year ago

Keyslam commented 1 year ago

If a pointer event is emitted at a point where multiple elements are overlapping, the event will be sent to all of the elements. In some cases, events should be able to be consumed: A window might consume any clicks, such that a window below won't be focused. To enable this, a sense of "depth" is also required.

I propose the following changes:

  1. When drawing an element, a 5th argument can be given to indicate the "depth" of the element can be given. This defaults to 0:
    myElement(x, y, w, h, depth)
  2. The depth is passed into the render function:
    return function(view, depth)
    otherElement(view, depth + 1)
    end
  3. Inky, under the hood, will send events to elements with higher depth first.
  4. Context:onPointer and Context:onPointerEnter can return true to indicate the event was consumed. It will not be passed to other elements then.
Keyslam commented 1 year ago

From a discussion in the LÖVE Discord server:

Simple parent-child relations will be by far the most common pattern when using Inky, so it's a bit silly to constantly have to do depth + 1. Inky should track the current hierarchy's depth, and if no depth is passed to the render function, automatically put in depth + 1.

Keyslam commented 1 year ago

Sometimes a parent element might want to know when a (grand)child element accepted an event: Lets say you have a window thats unfocused with a button in it. When you click the button both should activate, but the window should also take focus.

For this I propose:

context:onPointerInHierarchy(name, function(pointer)
end)

context:onPointerEnterHierarchy(function(pointer)
end)
Keyslam commented 1 year ago

Resolved by https://github.com/Keyslam/Inky/commit/8d236c5c96dbaaebd64c4aa3f0031863c9569dcd