slight change to element:removeChild(), commented out ideas for window focusing

This commit is contained in:
Paul Liverman III 2016-04-27 10:53:19 -07:00
parent 47f69d606e
commit d530dfc5e0
5 changed files with 23 additions and 8 deletions

View File

@ -38,8 +38,7 @@ do
else
for k, v in ipairs(self.child) do
if v == child then
remove(self.child, k)
return self
return remove(self.child, k)
end
end
return "Element \"" .. tostring(child) .. "\" is not a child of element \"" .. tostring(self) .. "\". Cannot remove it."

View File

@ -38,8 +38,7 @@ do
else
for k, v in ipairs(self.child) do
if v == child then
remove(self.child, k)
return self
return remove(self.child, k)
end
end
return "Element \"" .. tostring(child) .. "\" is not a child of element \"" .. tostring(self) .. "\". Cannot remove it."

View File

@ -51,7 +51,8 @@ class element
return @
-- remove child by index and return it OR remove child by reference
-- remove child by index OR by reference and return it
--NOTE API CHANGE HERE MIGHT'VE FUCKED A THING
removeChild: (child) =>
if tonumber(child) == child
-- remove indexed child, return it
@ -60,13 +61,16 @@ class element
else
for k,v in ipairs @child
if v == child
remove @child, k
return @
return remove @child, k
return "Element \"#{child}\" is not a child of element \"#{@}\". Cannot remove it."
getChildren: =>
return @child
--focusChild: (child) =>
-- insert @child, 1, @removeChild(child)
-- return @
move: (x, y) =>
if x
@x = @x + x

View File

@ -104,6 +104,10 @@ class window extends element
return true
return false
--@head.focusChild = =>
-- @parent\focusChild @ -- nope
-- return @
debugDraw: =>
graphics.setLineWidth 0.5
graphics.setColor 0, 0, 0, 100
@ -137,6 +141,11 @@ class window extends element
getChildren: =>
return @area.child
--focusChild: =>
-- @parent\focusChild @
-- --NOTE might need to also actually focus the sub-element
-- return @
align: (horizontal, vertical, toPixel) =>
super horizontal, vertical, toPixel

View File

@ -137,7 +137,7 @@ pop.mousepressed = (x, y, button, element) ->
if handled = element\mousepressed x - element.x, y - element.y, button
pop.focused = element
-- have we handled the event?
-- return whether or not we have handled the event
return handled
pop.mousereleased = (x, y, button, element) ->
@ -165,6 +165,10 @@ pop.mousereleased = (x, y, button, element) ->
-- if we clicked, we're focused!
if clickedHandled
pop.focused = element
--NOTE this might cause an error in the above for loop!
-- basically, move focused element to front of its parent's child
--element.parent\focusChild element
--table.insert element.parent, element.parent\removeChild(element),
-- else, default to pop.screen to begin! (and print that we received an event)
else