excessive / DOMy

A DOM-like GUI framework for the *awesome* LÖVE framework
Other
32 stars 2 forks source link

Draw Stack #19

Closed karai17 closed 9 years ago

karai17 commented 9 years ago

After discussing the idea of ordering, buffering, and drawing elements, I think the following system may be wise:

  1. A draw stack within the GUI instance is created using root elements as a base
  2. Elements will have a bring_forward() and send_behind() function set that re-positions them within the draw stack
  3. the aforementioned functions will take a single argument that allows you to determine the offset where you want to place the element within the stack
    • send_back(1) places the element after the first item in the stack
    • bring_forward(1) places the element before the last item in the stack
    • This will allow people to have "always behind" and "always on top" elements such as quest trackers and action bars, respectively
  4. If the element in which the function is called is not a root element (and therefore has a parent), it will push the request up the family hierarchy until the root is reached
  5. Detaching an element from a family makes the element a root element, therefore it is put into the draw stack (at the end, so it is drawn on top)
  6. Attaching an element to a family will do the opposite--remove the element from the draw stack

Some example uses:

local frame = gui:new_element("frame")
function frame:on_focus()
    self:bring_forward() -- no arg defaults to draw on top
    -- do frame stuff
end
local frame = gui:new_element("frame")
local button = gui:new_element("button", frame)
function button:on_focus()
    self:bring_forward(1) -- never draw over top of the action bar!
                          -- also pushes the command up to frame
    -- do button stuff
end

I think this could work pretty well and give designers enough control without forcing them to manage their own z-index table. Thoughts?

slime73 commented 9 years ago
  • Elements will have a bring_forward() and send_behind() function set that re-positions them within the draw stack
  • the aforementioned functions will take a single argument that allows you to determine the offset where you want to place the element within the stack
    • send_back(1) places the element after the first item in the stack
    • bring_forward(1) places the element before the last item in the stack

Functionality that behaves something like "bring to front", "send to back", "set index", and "exchange with" makes more sense to me, I think (where "bring to front" and "send to back" wouldn't take any arguments.)

karai17 commented 9 years ago

That might make it less confusing, yeah.

karai17 commented 9 years ago

It should also be noted that when moving an element from root to parent, the spritebatch which is now empty should be destroyed.

karai17 commented 9 years ago

I've gone ahead and added @slime73's methods.