mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
work in progress attempts at fixing weird problems and improvements
This commit is contained in:
parent
91fc418ae2
commit
d0394c596a
@ -169,6 +169,13 @@ do
|
||||
end
|
||||
end
|
||||
end,
|
||||
dataIndexOf = function(self, data)
|
||||
for i = 1, #self.data.child do
|
||||
if self.data.child[i] == data then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end,
|
||||
delete = function(self)
|
||||
for i = #self.child, 1, -1 do
|
||||
self.child[i]:delete()
|
||||
|
@ -218,6 +218,11 @@ class element
|
||||
if @child[i] == element
|
||||
return i
|
||||
|
||||
dataIndexOf: (data) =>
|
||||
for i = 1, #@data.child
|
||||
if @data.child[i] == data
|
||||
return i
|
||||
|
||||
--- Deletes references to this element and then deletes it.
|
||||
delete: =>
|
||||
for i=#@child, 1, -1
|
||||
|
@ -6,8 +6,6 @@ do
|
||||
end
|
||||
local path = (...):sub(1, -7)
|
||||
local element = require(tostring(path) .. "/element")
|
||||
local box = require(tostring(path) .. "/box")
|
||||
local text = require(tostring(path) .. "/text")
|
||||
path = path:sub(1, -11)
|
||||
local maximizeImage = graphics.newImage(tostring(path) .. "/images/maximize.png")
|
||||
local minimizeImage = graphics.newImage(tostring(path) .. "/images/minimize.png")
|
||||
@ -85,6 +83,13 @@ do
|
||||
getPadding = function(self)
|
||||
return self.window_area:getPadding()
|
||||
end,
|
||||
childAdded = function(self, element)
|
||||
table.insert(self.window_area.data, table.remove(self.data.child, self:dataIndexOf(element.data)))
|
||||
table.insert(self.window_area, table.remove(self.child, self:indexOf(element)))
|
||||
element:align()
|
||||
print("worked?")
|
||||
return self
|
||||
end,
|
||||
maximize = function(self)
|
||||
if self.data.maximized then
|
||||
self.data.x = self.data.previous.x
|
||||
|
@ -11,8 +11,6 @@ import graphics, mouse from love
|
||||
|
||||
path = (...)\sub 1, -7
|
||||
element = require "#{path}/element"
|
||||
box = require "#{path}/box"
|
||||
text = require "#{path}/text"
|
||||
|
||||
path = path\sub 1, -11
|
||||
maximizeImage = graphics.newImage "#{path}/images/maximize.png"
|
||||
@ -124,21 +122,15 @@ class window extends element
|
||||
@header.mousereleased = (x, y, button) =>
|
||||
if button == pop.constants.left_mouse
|
||||
selected = false
|
||||
--pop.focused = false -- we have to manually clear our focus
|
||||
return true
|
||||
return false
|
||||
|
||||
-- unsure if needed or how needed
|
||||
--@setSize @data.w, @data.h -- or 100, 80
|
||||
@align!
|
||||
|
||||
align: (...) =>
|
||||
unless @data.align return @
|
||||
super ...
|
||||
|
||||
-- don't know if this is needed or why
|
||||
--for i = 1, #@child
|
||||
-- @child[i]\align!
|
||||
@header\align!
|
||||
@title\align!
|
||||
@window_area\align!
|
||||
@ -164,8 +156,6 @@ class window extends element
|
||||
when "right"
|
||||
x -= w - @data.w
|
||||
|
||||
-- close button stuff
|
||||
|
||||
@header\setWidth w - @data.header_width_reduction
|
||||
@window_area\setWidth w
|
||||
@data.w = w
|
||||
@ -173,8 +163,6 @@ class window extends element
|
||||
|
||||
@title\align!
|
||||
|
||||
-- close button stuff 2 ?
|
||||
|
||||
if h
|
||||
switch @data.vertical
|
||||
when "center"
|
||||
@ -205,6 +193,13 @@ class window extends element
|
||||
getPadding: =>
|
||||
return @window_area\getPadding!
|
||||
|
||||
childAdded: (element) =>
|
||||
table.insert @window_area.data, table.remove @data.child, @dataIndexOf element.data
|
||||
table.insert @window_area, table.remove @child, @indexOf element
|
||||
element\align!
|
||||
print "worked?"
|
||||
return @
|
||||
|
||||
maximize: =>
|
||||
if @data.maximized
|
||||
@data.x = @data.previous.x
|
||||
|
27
init.lua
27
init.lua
@ -162,6 +162,7 @@ pop.create = function(element, parent, data, ...)
|
||||
end
|
||||
insert(parent.child, element)
|
||||
insert(parent.data.child, element.data)
|
||||
element.parent = parent
|
||||
element.data.parent = parent.data
|
||||
elseif parent == false then
|
||||
if type(data) == "table" then
|
||||
@ -179,7 +180,12 @@ pop.create = function(element, parent, data, ...)
|
||||
end
|
||||
insert(pop.screen.child, element)
|
||||
insert(pop.screen.data.child, element.data)
|
||||
element.parent = pop.screen
|
||||
element.data.parent = pop.screen.data
|
||||
if element.parent and element.parent.childAdded then
|
||||
print("working?")
|
||||
element.parent:childAdded(element)
|
||||
end
|
||||
end
|
||||
return element
|
||||
end
|
||||
@ -368,16 +374,31 @@ pop.debugDraw = function(element)
|
||||
pop.debugDraw(element.child[i])
|
||||
end
|
||||
end
|
||||
pop.printElementTree = function(element, depth)
|
||||
pop.printElementTree = function(element, fn, depth)
|
||||
if element == nil then
|
||||
element = pop.screen
|
||||
end
|
||||
if depth == nil then
|
||||
depth = 0
|
||||
end
|
||||
if "table" ~= type(element) then
|
||||
depth = fn
|
||||
fn = element
|
||||
element = pop.screen
|
||||
end
|
||||
if "number" == type(fn) then
|
||||
depth = fn
|
||||
fn = nil
|
||||
end
|
||||
if not (depth) then
|
||||
depth = 0
|
||||
end
|
||||
local cls = element.__class.__name
|
||||
if element.debugInfo then
|
||||
cls = tostring(cls) .. " (" .. tostring(element:debugInfo()) .. ")"
|
||||
cls = cls .. " (" .. tostring(element:debugInfo()) .. ")"
|
||||
end
|
||||
if fn then
|
||||
cls = cls .. " " .. tostring(fn(element))
|
||||
end
|
||||
if depth > 0 then
|
||||
log(string.rep("-", depth) .. " " .. tostring(cls))
|
||||
@ -385,7 +406,7 @@ pop.printElementTree = function(element, depth)
|
||||
log(cls)
|
||||
end
|
||||
for i = 1, #element.child do
|
||||
pop.printElementTree(element.child[i], depth + 1)
|
||||
pop.printElementTree(element.child[i], fn, depth + 1)
|
||||
end
|
||||
end
|
||||
pop.load()
|
||||
|
31
init.moon
31
init.moon
@ -194,7 +194,7 @@ pop.create = (element, parent=pop.screen, data, ...) ->
|
||||
element = pop.elements[element](parent, {}, data, ...)
|
||||
insert parent.child, element
|
||||
insert parent.data.child, element.data
|
||||
--element.parent = parent
|
||||
element.parent = parent
|
||||
element.data.parent = parent.data
|
||||
-- if explicitly no parent, just create the element
|
||||
elseif parent == false
|
||||
@ -210,15 +210,15 @@ pop.create = (element, parent=pop.screen, data, ...) ->
|
||||
element = pop.elements[element](pop.screen, parent, data, ...)
|
||||
else -- parent must be an argument
|
||||
element = pop.elements[element](pop.screen, {}, parent, data, ...)
|
||||
--if type(data) == "table"
|
||||
-- element = pop.elements[element](pop.screen, parent, data, ...)
|
||||
--else
|
||||
-- element = pop.elements[element](pop.screen, parent, {}, data, ...)
|
||||
insert pop.screen.child, element
|
||||
insert pop.screen.data.child, element.data
|
||||
--element.parent = pop.screen
|
||||
element.parent = pop.screen
|
||||
element.data.parent = pop.screen.data
|
||||
|
||||
if element.parent and element.parent.childAdded
|
||||
print "working?"
|
||||
element.parent\childAdded element
|
||||
|
||||
return element
|
||||
|
||||
|
||||
@ -513,12 +513,25 @@ pop.debugDraw = (element=pop.screen) ->
|
||||
--- `pop.screen`.
|
||||
--- @see Element
|
||||
|
||||
pop.printElementTree = (element=pop.screen, depth=0) ->
|
||||
pop.printElementTree = (element=pop.screen, fn, depth=0) ->
|
||||
if "table" != type element
|
||||
depth = fn
|
||||
fn = element
|
||||
element = pop.screen
|
||||
if "number" == type fn
|
||||
depth = fn
|
||||
fn = nil
|
||||
unless depth
|
||||
depth=0
|
||||
|
||||
--- @todo Write debugInfo things for elements.
|
||||
cls = element.__class.__name
|
||||
|
||||
if element.debugInfo
|
||||
cls = "#{cls} (#{element\debugInfo!})"
|
||||
cls ..= " (#{element\debugInfo!})"
|
||||
|
||||
if fn
|
||||
cls ..= " #{fn element}"
|
||||
|
||||
if depth > 0
|
||||
log string.rep("-", depth) .. " #{cls}"
|
||||
@ -526,7 +539,7 @@ pop.printElementTree = (element=pop.screen, depth=0) ->
|
||||
log cls
|
||||
|
||||
for i = 1, #element.child
|
||||
pop.printElementTree element.child[i], depth + 1
|
||||
pop.printElementTree element.child[i], fn, depth + 1
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user