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
|
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)
|
delete = function(self)
|
||||||
for i = #self.child, 1, -1 do
|
for i = #self.child, 1, -1 do
|
||||||
self.child[i]:delete()
|
self.child[i]:delete()
|
||||||
|
@ -218,6 +218,11 @@ class element
|
|||||||
if @child[i] == element
|
if @child[i] == element
|
||||||
return i
|
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.
|
--- Deletes references to this element and then deletes it.
|
||||||
delete: =>
|
delete: =>
|
||||||
for i=#@child, 1, -1
|
for i=#@child, 1, -1
|
||||||
|
@ -6,8 +6,6 @@ do
|
|||||||
end
|
end
|
||||||
local path = (...):sub(1, -7)
|
local path = (...):sub(1, -7)
|
||||||
local element = require(tostring(path) .. "/element")
|
local element = require(tostring(path) .. "/element")
|
||||||
local box = require(tostring(path) .. "/box")
|
|
||||||
local text = require(tostring(path) .. "/text")
|
|
||||||
path = path:sub(1, -11)
|
path = path:sub(1, -11)
|
||||||
local maximizeImage = graphics.newImage(tostring(path) .. "/images/maximize.png")
|
local maximizeImage = graphics.newImage(tostring(path) .. "/images/maximize.png")
|
||||||
local minimizeImage = graphics.newImage(tostring(path) .. "/images/minimize.png")
|
local minimizeImage = graphics.newImage(tostring(path) .. "/images/minimize.png")
|
||||||
@ -85,6 +83,13 @@ do
|
|||||||
getPadding = function(self)
|
getPadding = function(self)
|
||||||
return self.window_area:getPadding()
|
return self.window_area:getPadding()
|
||||||
end,
|
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)
|
maximize = function(self)
|
||||||
if self.data.maximized then
|
if self.data.maximized then
|
||||||
self.data.x = self.data.previous.x
|
self.data.x = self.data.previous.x
|
||||||
|
@ -11,8 +11,6 @@ import graphics, mouse from love
|
|||||||
|
|
||||||
path = (...)\sub 1, -7
|
path = (...)\sub 1, -7
|
||||||
element = require "#{path}/element"
|
element = require "#{path}/element"
|
||||||
box = require "#{path}/box"
|
|
||||||
text = require "#{path}/text"
|
|
||||||
|
|
||||||
path = path\sub 1, -11
|
path = path\sub 1, -11
|
||||||
maximizeImage = graphics.newImage "#{path}/images/maximize.png"
|
maximizeImage = graphics.newImage "#{path}/images/maximize.png"
|
||||||
@ -124,21 +122,15 @@ class window extends element
|
|||||||
@header.mousereleased = (x, y, button) =>
|
@header.mousereleased = (x, y, button) =>
|
||||||
if button == pop.constants.left_mouse
|
if button == pop.constants.left_mouse
|
||||||
selected = false
|
selected = false
|
||||||
--pop.focused = false -- we have to manually clear our focus
|
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
-- unsure if needed or how needed
|
|
||||||
--@setSize @data.w, @data.h -- or 100, 80
|
|
||||||
@align!
|
@align!
|
||||||
|
|
||||||
align: (...) =>
|
align: (...) =>
|
||||||
unless @data.align return @
|
unless @data.align return @
|
||||||
super ...
|
super ...
|
||||||
|
|
||||||
-- don't know if this is needed or why
|
|
||||||
--for i = 1, #@child
|
|
||||||
-- @child[i]\align!
|
|
||||||
@header\align!
|
@header\align!
|
||||||
@title\align!
|
@title\align!
|
||||||
@window_area\align!
|
@window_area\align!
|
||||||
@ -164,8 +156,6 @@ class window extends element
|
|||||||
when "right"
|
when "right"
|
||||||
x -= w - @data.w
|
x -= w - @data.w
|
||||||
|
|
||||||
-- close button stuff
|
|
||||||
|
|
||||||
@header\setWidth w - @data.header_width_reduction
|
@header\setWidth w - @data.header_width_reduction
|
||||||
@window_area\setWidth w
|
@window_area\setWidth w
|
||||||
@data.w = w
|
@data.w = w
|
||||||
@ -173,8 +163,6 @@ class window extends element
|
|||||||
|
|
||||||
@title\align!
|
@title\align!
|
||||||
|
|
||||||
-- close button stuff 2 ?
|
|
||||||
|
|
||||||
if h
|
if h
|
||||||
switch @data.vertical
|
switch @data.vertical
|
||||||
when "center"
|
when "center"
|
||||||
@ -205,6 +193,13 @@ class window extends element
|
|||||||
getPadding: =>
|
getPadding: =>
|
||||||
return @window_area\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: =>
|
maximize: =>
|
||||||
if @data.maximized
|
if @data.maximized
|
||||||
@data.x = @data.previous.x
|
@data.x = @data.previous.x
|
||||||
|
27
init.lua
27
init.lua
@ -162,6 +162,7 @@ pop.create = function(element, parent, data, ...)
|
|||||||
end
|
end
|
||||||
insert(parent.child, element)
|
insert(parent.child, element)
|
||||||
insert(parent.data.child, element.data)
|
insert(parent.data.child, element.data)
|
||||||
|
element.parent = parent
|
||||||
element.data.parent = parent.data
|
element.data.parent = parent.data
|
||||||
elseif parent == false then
|
elseif parent == false then
|
||||||
if type(data) == "table" then
|
if type(data) == "table" then
|
||||||
@ -179,7 +180,12 @@ pop.create = function(element, parent, data, ...)
|
|||||||
end
|
end
|
||||||
insert(pop.screen.child, element)
|
insert(pop.screen.child, element)
|
||||||
insert(pop.screen.data.child, element.data)
|
insert(pop.screen.data.child, element.data)
|
||||||
|
element.parent = pop.screen
|
||||||
element.data.parent = pop.screen.data
|
element.data.parent = pop.screen.data
|
||||||
|
if element.parent and element.parent.childAdded then
|
||||||
|
print("working?")
|
||||||
|
element.parent:childAdded(element)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return element
|
return element
|
||||||
end
|
end
|
||||||
@ -368,16 +374,31 @@ pop.debugDraw = function(element)
|
|||||||
pop.debugDraw(element.child[i])
|
pop.debugDraw(element.child[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
pop.printElementTree = function(element, depth)
|
pop.printElementTree = function(element, fn, depth)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = pop.screen
|
element = pop.screen
|
||||||
end
|
end
|
||||||
if depth == nil then
|
if depth == nil then
|
||||||
depth = 0
|
depth = 0
|
||||||
end
|
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
|
local cls = element.__class.__name
|
||||||
if element.debugInfo then
|
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
|
end
|
||||||
if depth > 0 then
|
if depth > 0 then
|
||||||
log(string.rep("-", depth) .. " " .. tostring(cls))
|
log(string.rep("-", depth) .. " " .. tostring(cls))
|
||||||
@ -385,7 +406,7 @@ pop.printElementTree = function(element, depth)
|
|||||||
log(cls)
|
log(cls)
|
||||||
end
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
pop.printElementTree(element.child[i], depth + 1)
|
pop.printElementTree(element.child[i], fn, depth + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
pop.load()
|
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, ...)
|
element = pop.elements[element](parent, {}, data, ...)
|
||||||
insert parent.child, element
|
insert parent.child, element
|
||||||
insert parent.data.child, element.data
|
insert parent.data.child, element.data
|
||||||
--element.parent = parent
|
element.parent = parent
|
||||||
element.data.parent = parent.data
|
element.data.parent = parent.data
|
||||||
-- if explicitly no parent, just create the element
|
-- if explicitly no parent, just create the element
|
||||||
elseif parent == false
|
elseif parent == false
|
||||||
@ -210,15 +210,15 @@ pop.create = (element, parent=pop.screen, data, ...) ->
|
|||||||
element = pop.elements[element](pop.screen, parent, data, ...)
|
element = pop.elements[element](pop.screen, parent, data, ...)
|
||||||
else -- parent must be an argument
|
else -- parent must be an argument
|
||||||
element = pop.elements[element](pop.screen, {}, parent, data, ...)
|
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.child, element
|
||||||
insert pop.screen.data.child, element.data
|
insert pop.screen.data.child, element.data
|
||||||
--element.parent = pop.screen
|
element.parent = pop.screen
|
||||||
element.data.parent = pop.screen.data
|
element.data.parent = pop.screen.data
|
||||||
|
|
||||||
|
if element.parent and element.parent.childAdded
|
||||||
|
print "working?"
|
||||||
|
element.parent\childAdded element
|
||||||
|
|
||||||
return element
|
return element
|
||||||
|
|
||||||
|
|
||||||
@ -513,12 +513,25 @@ pop.debugDraw = (element=pop.screen) ->
|
|||||||
--- `pop.screen`.
|
--- `pop.screen`.
|
||||||
--- @see Element
|
--- @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.
|
--- @todo Write debugInfo things for elements.
|
||||||
cls = element.__class.__name
|
cls = element.__class.__name
|
||||||
|
|
||||||
if element.debugInfo
|
if element.debugInfo
|
||||||
cls = "#{cls} (#{element\debugInfo!})"
|
cls ..= " (#{element\debugInfo!})"
|
||||||
|
|
||||||
|
if fn
|
||||||
|
cls ..= " #{fn element}"
|
||||||
|
|
||||||
if depth > 0
|
if depth > 0
|
||||||
log string.rep("-", depth) .. " #{cls}"
|
log string.rep("-", depth) .. " #{cls}"
|
||||||
@ -526,7 +539,7 @@ pop.printElementTree = (element=pop.screen, depth=0) ->
|
|||||||
log cls
|
log cls
|
||||||
|
|
||||||
for i = 1, #element.child
|
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