mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
Code cleanup
This commit is contained in:
parent
ac5818b102
commit
e4c518e2f0
@ -45,31 +45,26 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
if not self.visible then
|
||||
if not self.alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local cwidth, cheight = self.parent:GetColumnSize()
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
if parent ~= loveframes.base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
for k, v in ipairs(self.children) do
|
||||
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
|
||||
if col then
|
||||
v:update(dt)
|
||||
@ -95,9 +90,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -113,10 +106,6 @@ function newobject:draw()
|
||||
local drawfunc = skin.DrawColumnListArea or skins[defaultskin].DrawColumnListArea
|
||||
local drawoverfunc = skin.DrawOverColumnListArea or skins[defaultskin].DrawOverColumnListArea
|
||||
local draw = self.Draw
|
||||
local drawcount = loveframes.drawcount
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
local swidth = width
|
||||
local sheight = height
|
||||
|
||||
@ -141,7 +130,7 @@ function newobject:draw()
|
||||
|
||||
love.graphics.setStencil(stencilfunc)
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
for k, v in ipairs(self.children) do
|
||||
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, width, v.width, height, v.height)
|
||||
if col then
|
||||
v:draw()
|
||||
@ -150,7 +139,7 @@ function newobject:draw()
|
||||
|
||||
love.graphics.setStencil()
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
@ -166,10 +155,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local toplist = self:IsTopList()
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
if self.hover and button == "l" then
|
||||
local baseparent = self:GetBaseParent()
|
||||
@ -178,10 +164,9 @@ function newobject:mousepressed(x, y, button)
|
||||
end
|
||||
end
|
||||
|
||||
if self.bar and toplist then
|
||||
if self.bar and self:IsTopList() then
|
||||
local bar = self:GetScrollBar()
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
if self.dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
if button == "wu" then
|
||||
bar:Scroll(-scrollamount * dt)
|
||||
@ -197,11 +182,11 @@ function newobject:mousepressed(x, y, button)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
for k, v in ipairs(self.children) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
@ -232,21 +217,17 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:CalculateSize()
|
||||
|
||||
local columnheight = self.parent.columnheight
|
||||
local numitems = #self.children
|
||||
local height = self.height
|
||||
local width = self.width
|
||||
local itemheight = columnheight
|
||||
local itemwidth = 0
|
||||
local bar = self.bar
|
||||
local children = self.children
|
||||
local parent = self.parent
|
||||
local itemheight = parent.columnheight
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
for k, v in ipairs(self.children) do
|
||||
itemheight = itemheight + v.height
|
||||
end
|
||||
|
||||
self.itemheight = itemheight
|
||||
self.itemwidth = self.parent:GetTotalColumnWidth()
|
||||
self.itemwidth = parent:GetTotalColumnWidth()
|
||||
|
||||
local hbarheight = 0
|
||||
local hbar = self:GetHorizontalScrollBar()
|
||||
@ -262,7 +243,7 @@ function newobject:CalculateSize()
|
||||
if not self.vbar then
|
||||
table.insert(self.internals, loveframes.objects["scrollbody"]:new(self, "vertical"))
|
||||
self.vbar = true
|
||||
self:GetVerticalScrollBar().autoscroll = self.parent.autoscroll
|
||||
self:GetVerticalScrollBar().autoscroll = parent.autoscroll
|
||||
end
|
||||
else
|
||||
if self.vbar then
|
||||
@ -278,15 +259,15 @@ function newobject:CalculateSize()
|
||||
vbarwidth = vbar.width
|
||||
end
|
||||
|
||||
if self.itemwidth > (self.width - vbarwidth) then
|
||||
if self.itemwidth > (width - vbarwidth) then
|
||||
if vbar then
|
||||
self.itemwidth = self.itemwidth + vbarwidth
|
||||
end
|
||||
self.extrawidth = self.itemwidth - self.width
|
||||
self.extrawidth = self.itemwidth - width
|
||||
if not self.hbar then
|
||||
table.insert(self.internals, loveframes.objects["scrollbody"]:new(self, "horizontal"))
|
||||
self.hbar = true
|
||||
self:GetHorizontalScrollBar().autoscroll = self.parent.autoscroll
|
||||
self:GetHorizontalScrollBar().autoscroll = parent.autoscroll
|
||||
end
|
||||
else
|
||||
if self.hbar then
|
||||
@ -304,51 +285,38 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:RedoLayout()
|
||||
|
||||
local children = self.children
|
||||
local starty = 0
|
||||
local startx = 0
|
||||
local bar = self.bar
|
||||
local display = self.display
|
||||
self.rowcolorindex = 1
|
||||
|
||||
if #children > 0 then
|
||||
self.rowcolorindex = 1
|
||||
for k, v in ipairs(children) do
|
||||
v:SetWidth(self.parent:GetTotalColumnWidth())
|
||||
local height = v.height
|
||||
v.staticx = startx
|
||||
v.staticy = starty
|
||||
if self.vbar then
|
||||
local vbar = self:GetVerticalScrollBar()
|
||||
--v:SetWidth(self.width - vbar.width)
|
||||
vbar.staticx = self.width - vbar.width
|
||||
if self.hbar then
|
||||
vbar.height = self.height - self:GetHorizontalScrollBar().height
|
||||
else
|
||||
vbar.height = self.height
|
||||
end
|
||||
else
|
||||
--v:SetWidth(self.width)
|
||||
end
|
||||
for k, v in ipairs(self.children) do
|
||||
v:SetWidth(self.parent:GetTotalColumnWidth())
|
||||
v.staticx = 0
|
||||
v.staticy = starty
|
||||
if self.vbar then
|
||||
local vbar = self:GetVerticalScrollBar()
|
||||
vbar.staticx = self.width - vbar.width
|
||||
if self.hbar then
|
||||
local hbar = self:GetHorizontalScrollBar()
|
||||
--self:SetHeight(self.parent.height - hbar.height)
|
||||
if self.vbar then
|
||||
hbar.width = self.width - self:GetVerticalScrollBar().width
|
||||
else
|
||||
hbar.width = self.width
|
||||
end
|
||||
vbar.height = self.height - self:GetHorizontalScrollBar().height
|
||||
else
|
||||
--self:SetHeight(self.parent.height)
|
||||
vbar.height = self.height
|
||||
end
|
||||
starty = starty + v.height
|
||||
v.lastheight = v.height
|
||||
v.colorindex = self.rowcolorindex
|
||||
if self.rowcolorindex == self.rowcolorindexmax then
|
||||
self.rowcolorindex = 1
|
||||
end
|
||||
if self.hbar then
|
||||
local hbar = self:GetHorizontalScrollBar()
|
||||
if self.vbar then
|
||||
hbar.width = self.width - self:GetVerticalScrollBar().width
|
||||
else
|
||||
self.rowcolorindex = self.rowcolorindex + 1
|
||||
hbar.width = self.width
|
||||
end
|
||||
end
|
||||
starty = starty + v.height
|
||||
v.lastheight = v.height
|
||||
v.colorindex = self.rowcolorindex
|
||||
if self.rowcolorindex == self.rowcolorindexmax then
|
||||
self.rowcolorindex = 1
|
||||
else
|
||||
self.rowcolorindex = self.rowcolorindex + 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@ -359,17 +327,15 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:AddRow(data)
|
||||
|
||||
local row = loveframes.objects["columnlistrow"]:new(self, data)
|
||||
local colorindex = self.rowcolorindex
|
||||
local colorindexmax = self.rowcolorindexmax
|
||||
|
||||
if colorindex == colorindexmax then
|
||||
if colorindex == self.rowcolorindexmax then
|
||||
self.rowcolorindex = 1
|
||||
else
|
||||
self.rowcolorindex = colorindex + 1
|
||||
end
|
||||
|
||||
table.insert(self.children, row)
|
||||
table.insert(self.children, loveframes.objects["columnlistrow"]:new(self, data))
|
||||
self:CalculateSize()
|
||||
self:RedoLayout()
|
||||
self.parent:AdjustColumns()
|
||||
@ -381,14 +347,9 @@ end
|
||||
- desc: gets the object's scroll bar
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetScrollBar()
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
if self.bar then
|
||||
local scrollbody = internals[1]
|
||||
local scrollarea = scrollbody.internals[1]
|
||||
local scrollbar = scrollarea.internals[1]
|
||||
return scrollbar
|
||||
return self.internals[1].internals[1].internals[1]
|
||||
else
|
||||
return false
|
||||
end
|
||||
@ -401,10 +362,8 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:Sort(column, desc)
|
||||
|
||||
self.rowcolorindex = 1
|
||||
|
||||
local colorindexmax = self.rowcolorindexmax
|
||||
local children = self.children
|
||||
self.rowcolorindex = 1
|
||||
|
||||
table.sort(children, function(a, b)
|
||||
if desc then
|
||||
@ -417,7 +376,7 @@ function newobject:Sort(column, desc)
|
||||
for k, v in ipairs(children) do
|
||||
local colorindex = self.rowcolorindex
|
||||
v.colorindex = colorindex
|
||||
if colorindex == colorindexmax then
|
||||
if colorindex == self.rowcolorindexmax then
|
||||
self.rowcolorindex = 1
|
||||
else
|
||||
self.rowcolorindex = colorindex + 1
|
||||
|
@ -17,7 +17,7 @@ function newobject:initialize(name, parent)
|
||||
self.name = name
|
||||
self.state = parent.state
|
||||
self.width = 80
|
||||
self.height = self.parent.columnheight
|
||||
self.height = parent.columnheight
|
||||
self.columnid = 0
|
||||
self.hover = false
|
||||
self.down = false
|
||||
@ -61,20 +61,15 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
if not self.visible then
|
||||
if not self.alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
local list = self.parent.internals[1]
|
||||
local parent = self.parent
|
||||
local list = parent.internals[1]
|
||||
local vbar = list:GetVerticalScrollBar()
|
||||
local width = list.width
|
||||
if vbar then
|
||||
@ -93,23 +88,26 @@ function newobject:update(dt)
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = (parent.x + self.staticx) - self.parent.internals[1].offsetx
|
||||
if parent ~= loveframes.base then
|
||||
self.x = (parent.x + self.staticx) - parent.internals[1].offsetx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.parent.resizecolumn and self.parent.resizecolumn == self then
|
||||
local resizecolumn = parent.resizecolumn
|
||||
|
||||
if resizecolumn and resizecolumn == self then
|
||||
local x, y = love.mouse.getPosition()
|
||||
local start = false
|
||||
self.width = x - self.x
|
||||
if self.width < 20 then
|
||||
self.width = 20
|
||||
end
|
||||
self.parent.startadjustment = true
|
||||
self.parent.internals[1]:CalculateSize()
|
||||
self.parent.internals[1]:RedoLayout()
|
||||
elseif self.parent.resizecolumn and self.parent.startadjustment then
|
||||
self.staticx = self.parent.children[self.columnid - 1].staticx + self.parent.children[self.columnid - 1].width
|
||||
parent.startadjustment = true
|
||||
parent.internals[1]:CalculateSize()
|
||||
parent.internals[1]:RedoLayout()
|
||||
elseif resizecolumn and parent.startadjustment then
|
||||
local header = parent.children[self.columnid - 1]
|
||||
self.staticx = header.staticx + header.width
|
||||
end
|
||||
|
||||
self.resizebox = {x = self.x + (self.width - 2), y = self.y, width = 4, height = self.height}
|
||||
@ -126,9 +124,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -200,7 +196,8 @@ function newobject:mousereleased(x, y, button)
|
||||
end
|
||||
end
|
||||
|
||||
if self.parent.resizecolumn and self.parent.resizecolumn == self then
|
||||
local resizecolumn = self.parent.resizecolumn
|
||||
if resizecolumn and resizecolumn == self then
|
||||
self.parent.resizecolumn = nil
|
||||
end
|
||||
|
||||
|
@ -40,23 +40,19 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
if not self.visible then
|
||||
if not self.alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
if parent ~= loveframes.base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
@ -73,9 +69,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -109,17 +103,12 @@ function newobject:mousepressed(x, y, button)
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == "l" then
|
||||
if self.hover and button == "l" then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
local parent1 = self:GetParent()
|
||||
local parent2 = parent1:GetParent()
|
||||
local ctrldown = loveframes.util.IsCtrlDown()
|
||||
parent2:SelectRow(self, ctrldown)
|
||||
self:GetParent():GetParent():SelectRow(self, loveframes.util.IsCtrlDown())
|
||||
end
|
||||
|
||||
end
|
||||
@ -135,17 +124,16 @@ function newobject:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
if self.hover then
|
||||
local parent1 = self:GetParent()
|
||||
local parent2 = parent1:GetParent()
|
||||
local parent = self:GetParent():GetParent()
|
||||
if button == "l" then
|
||||
local onrowclicked = parent2.OnRowClicked
|
||||
local onrowclicked = parent.OnRowClicked
|
||||
if onrowclicked then
|
||||
onrowclicked(parent2, self, self.columndata)
|
||||
onrowclicked(parent, self, self.columndata)
|
||||
end
|
||||
elseif button == "r" then
|
||||
local onrowrightclicked = parent2.OnRowRightClicked
|
||||
local onrowrightclicked = parent.OnRowRightClicked
|
||||
if onrowrightclicked then
|
||||
onrowrightclicked(parent2, self, self.columndata)
|
||||
onrowrightclicked(parent, self, self.columndata)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user