Merge pull request #18 from rozenmad/master

Added grid span feature, and other fixes
This commit is contained in:
Caldas Lopes 2021-10-20 19:07:16 +01:00 committed by GitHub
commit 773321041c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 497 additions and 311 deletions

View File

@ -3,37 +3,56 @@ example.title = "Grid"
example.category = "Object Demonstrations" example.category = "Object Demonstrations"
function example.func(loveframes, centerarea) function example.func(loveframes, centerarea)
local frame = loveframes.Create("frame") local frame = loveframes.Create("frame")
frame:SetName("Grid") frame:SetName("Grid")
frame:CenterWithinArea(unpack(centerarea)) frame:CenterWithinArea(unpack(centerarea))
local grid = loveframes.Create("grid", frame) local grid = loveframes.Create("grid", frame)
grid:SetPos(5, 30) grid:SetPos(5, 30)
grid:SetRows(5) grid:SetRows(5)
grid:SetColumns(5) grid:SetColumns(5)
grid:SetCellWidth(25) grid:SetCellWidth(45)
grid:SetCellHeight(25) grid:SetCellHeight(45)
grid:SetCellPadding(5) grid:SetCellPadding(2)
grid:SetItemAutoSize(true) grid:SetItemAutoSize(true)
local id = 1 grid:SetItemAutoSize(true)
for i=1, 5 do grid:ColSpanAt(1, 1, 5)
for n=1, 5 do grid:RowSpanAt(1, 1, 3)
local button = loveframes.Create("button")
button:SetSize(15, 15) grid:RowSpanAt(4, 1, 2)
button:SetText(id) grid:ColSpanAt(4, 1, 2)
grid:AddItem(button, i, n)
id = id + 1 grid:ColSpanAt(5, 3, 2)
end
local list = loveframes.Create('list')
grid:AddItem(list, 1, 1)
for i = 1, 10 do
local button = loveframes.Create("button")
button:SetText(tostring(i))
list:AddItem(button)
end end
local button = loveframes.Create("button")
button:SetText('4, 1')
grid:AddItem(button, 4, 1, 'center')
local button = loveframes.Create("button")
button:SetText('5, 5')
grid:AddItem(button, 5, 5, 'left')
local button = loveframes.Create("button")
button:SetText(('5, 3'))
grid:AddItem(button, 5, 3, 'right')
grid.OnSizeChanged = function(object) grid.OnSizeChanged = function(object)
frame:SetSize(object:GetWidth() + 10, object:GetHeight() + 35) frame:SetSize(object:GetWidth() + 10, object:GetHeight() + 35)
frame:CenterWithinArea(unpack(centerarea)) frame:CenterWithinArea(unpack(centerarea))
end end
end end
return example return example

View File

@ -244,11 +244,8 @@ function loveframes.mousereleased(x, y, button)
base:mousereleased(x, y, button) base:mousereleased(x, y, button)
-- reset the hover object -- reset the hover object
if button == 1 then loveframes.downobject = false
loveframes.downobject = false loveframes.selectedobject = false
loveframes.selectedobject = false
end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------

View File

@ -251,9 +251,9 @@ end
function loveframes.Round(num, idp) function loveframes.Round(num, idp)
local mult = 10^(idp or 0) local mult = 10^(idp or 0)
if num >= 0 then if num >= 0 then
return math.floor(num * mult + 0.5) / mult return math.floor(num * mult + 0.5) / mult
else else
return math.ceil(num * mult - 0.5) / mult return math.ceil(num * mult - 0.5) / mult
end end
end end

View File

@ -797,7 +797,7 @@ function newobject:CheckHover()
local visible = self.visible local visible = self.visible
local type = self.type local type = self.type
local hoverobject = loveframes.hoverobject local hoverobject = loveframes.hoverobject
-- check if the mouse is colliding with the object -- check if the mouse is colliding with the object
if state == curstate and visible then if state == curstate and visible then
local collide = self.collide local collide = self.collide
@ -820,7 +820,7 @@ function newobject:CheckHover()
end end
-- check if the object is being hovered -- check if the object is being hovered
if hoverobject == self and type ~= "base" then if selfcol and hoverobject == self and type ~= "base" then
self.hover = true self.hover = true
else else
self.hover = false self.hover = false
@ -1066,13 +1066,29 @@ end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: SetAlwaysUpdate(bool) - func: SetAlwaysUpdate(bool)
- desc: sets the object's skin - desc: sets the object will always update
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:SetAlwaysUpdate(bool) function newobject:SetAlwaysUpdate(bool)
local children = self.children
local internals = self.internals
self.alwaysupdate = bool self.alwaysupdate = bool
return self
if children then
for k, v in ipairs(children) do
v:SetAlwaysUpdate(bool)
end
end
if internals then
for k, v in ipairs(internals) do
v:SetAlwaysUpdate(bool)
end
end
return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------

View File

@ -57,7 +57,6 @@ function newobject:update(dt)
self:CheckHover() self:CheckHover()
local hover = self.hover local hover = self.hover
local down = self.down
local downobject = loveframes.downobject local downobject = loveframes.downobject
local parent = self.parent local parent = self.parent
local base = loveframes.base local base = loveframes.base
@ -76,8 +75,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if update then if update then
@ -107,7 +106,7 @@ function newobject:mousepressed(x, y, button)
local hover = self.hover local hover = self.hover
if hover and button == 1 then if hover then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then if baseparent and baseparent.type == "frame" then
baseparent:MakeTop() baseparent:MakeTop()
@ -116,6 +115,7 @@ function newobject:mousepressed(x, y, button)
loveframes.downobject = self loveframes.downobject = self
end end
self.pressed_button = button
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -143,7 +143,7 @@ function newobject:mousereleased(x, y, button)
local enabled = self.enabled local enabled = self.enabled
local onclick = self.OnClick local onclick = self.OnClick
if hover and down and clickable and button == 1 then if hover and down and clickable and self.pressed_button == button then
if enabled then if enabled then
if self.groupIndex ~= 0 then if self.groupIndex ~= 0 then
local baseparent = self.parent local baseparent = self.parent
@ -159,7 +159,7 @@ function newobject:mousereleased(x, y, button)
self.checked = true self.checked = true
end end
if onclick then if onclick then
onclick(self, x, y) onclick(self, x, y, self.pressed_button)
end end
if self.toggleable then if self.toggleable then
local ontoggle = self.OnToggle local ontoggle = self.OnToggle
@ -170,7 +170,7 @@ function newobject:mousereleased(x, y, button)
end end
end end
end end
self.down = false self.down = false
end end

View File

@ -15,8 +15,8 @@ local newobject = loveframes.NewObject("checkbox", "loveframes_object_checkbox",
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:initialize() function newobject:initialize()
self.type = "checkbox" self.type = "checkbox"
self.width = 0 self.width = 16
self.height = 0 self.height = 16
self.boxwidth = 16 self.boxwidth = 16
self.boxheight = 16 self.boxheight = 16
self.font = loveframes.basicfont self.font = loveframes.basicfont

View File

@ -62,9 +62,9 @@ function newobject:update(dt)
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base and parent.type ~= "list" then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if open and curobject then if open and curobject then

View File

@ -14,7 +14,7 @@ local newobject = loveframes.NewObject("columnlist", "loveframes_object_columnli
- desc: intializes the element - desc: intializes the element
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:initialize() function newobject:initialize()
self.type = "columnlist" self.type = "columnlist"
self.width = 300 self.width = 300
self.height = 100 self.height = 100
@ -39,7 +39,7 @@ function newobject:initialize()
local list = loveframes.objects["columnlistarea"]:new(self) local list = loveframes.objects["columnlistarea"]:new(self)
table.insert(self.internals, list) table.insert(self.internals, list)
self:SetDrawFunc() self:SetDrawFunc()
end end
@ -48,48 +48,48 @@ end
- desc: updates the object - desc: updates the object
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:update(dt) function newobject:update(dt)
local state = loveframes.state local state = loveframes.state
local selfstate = self.state local selfstate = self.state
if state ~= selfstate then if state ~= selfstate then
return return
end end
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if not visible then if not visible then
if not alwaysupdate then if not alwaysupdate then
return return
end end
end end
local parent = self.parent local parent = self.parent
local base = loveframes.base local base = loveframes.base
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
local update = self.Update local update = self.Update
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
for k, v in ipairs(internals) do for k, v in ipairs(internals) do
v:update(dt) v:update(dt)
end end
for k, v in ipairs(children) do for k, v in ipairs(children) do
v.columnid = k v.columnid = k
v:update(dt) v:update(dt)
end end
self.startadjustment = false self.startadjustment = false
if update then if update then
update(self, dt) update(self, dt)
end end
@ -108,49 +108,49 @@ function newobject:draw()
if not self.visible then if not self.visible then
return return
end end
local vbody = self.internals[1]:GetVerticalScrollBody() local vbody = self.internals[1]:GetVerticalScrollBody()
local hbody = self.internals[1]:GetHorizontalScrollBody() local hbody = self.internals[1]:GetHorizontalScrollBody()
local width = self.width local width = self.width
local height = self.height local height = self.height
if vbody then if vbody then
width = width - vbody.width width = width - vbody.width
end end
if hbody then if hbody then
height = height - hbody.height height = height - hbody.height
end end
local stencilfunc = function() local stencilfunc = function()
love.graphics.rectangle("fill", self.x, self.y, width, height) love.graphics.rectangle("fill", self.x, self.y, width, height)
end end
-- set the object's draw order -- set the object's draw order
self:SetDrawOrder() self:SetDrawOrder()
local drawfunc = self.Draw or self.drawfunc local drawfunc = self.Draw or self.drawfunc
if drawfunc then if drawfunc then
drawfunc(self) drawfunc(self)
end end
local internals = self.internals local internals = self.internals
if internals then if internals then
for k, v in ipairs(internals) do for k, v in ipairs(internals) do
v:draw() v:draw()
end end
end end
love.graphics.stencil(stencilfunc) love.graphics.stencil(stencilfunc)
love.graphics.setStencilTest("greater", 0) love.graphics.setStencilTest("greater", 0)
local children = self.children local children = self.children
if children then if children then
for k, v in ipairs(children) do for k, v in ipairs(children) do
v:draw() v:draw()
end end
end end
local drawfunc = self.DrawOver or self.drawoverfunc local drawfunc = self.DrawOver or self.drawoverfunc
if drawfunc then if drawfunc then
drawfunc(self) drawfunc(self)
@ -167,36 +167,36 @@ function newobject:mousepressed(x, y, button)
local state = loveframes.state local state = loveframes.state
local selfstate = self.state local selfstate = self.state
if state ~= selfstate then if state ~= selfstate then
return return
end end
local visible = self.visible local visible = self.visible
if not visible then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
if hover and button == 1 then if hover and button == 1 then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then if baseparent and baseparent.type == "frame" then
baseparent:MakeTop() baseparent:MakeTop()
end end
end end
for k, v in ipairs(internals) do for k, v in ipairs(internals) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
for k, v in ipairs(children) do for k, v in ipairs(children) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -207,28 +207,28 @@ function newobject:mousereleased(x, y, button)
local state = loveframes.state local state = loveframes.state
local selfstate = self.state local selfstate = self.state
if state ~= selfstate then if state ~= selfstate then
return return
end end
local visible = self.visible local visible = self.visible
if not visible then if not visible then
return return
end end
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
for k, v in ipairs(internals) do for k, v in ipairs(internals) do
v:mousereleased(x, y, button) v:mousereleased(x, y, button)
end end
for k, v in ipairs(children) do for k, v in ipairs(children) do
v:mousereleased(x, y, button) v:mousereleased(x, y, button)
end end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -236,16 +236,16 @@ end
- desc: positions the object's columns - desc: positions the object's columns
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:PositionColumns() function newobject:PositionColumns()
local x = 0 local x = 0
for k, v in ipairs(self.children) do for k, v in ipairs(self.children) do
v:SetPos(x, 0) v:SetPos(x, 0)
x = x + v.width x = x + v.width
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -259,15 +259,15 @@ function newobject:AddColumn(name)
local list = internals[1] local list = internals[1]
local width = self.width local width = self.width
local height = self.height local height = self.height
loveframes.objects["columnlistheader"]:new(name, self) loveframes.objects["columnlistheader"]:new(name, self)
self:PositionColumns() self:PositionColumns()
list:SetSize(width, height) list:SetSize(width, height)
list:SetPos(0, 0) list:SetPos(0, 0)
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -279,10 +279,10 @@ function newobject:AddRow(...)
local arg = {...} local arg = {...}
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
list:AddRow(arg) list:AddRow(arg)
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -293,7 +293,7 @@ function newobject:GetColumnSize()
local children = self.children local children = self.children
local numchildren = #self.children local numchildren = #self.children
if numchildren > 0 then if numchildren > 0 then
local column = self.children[1] local column = self.children[1]
local colwidth = column.width local colwidth = column.width
@ -302,7 +302,7 @@ function newobject:GetColumnSize()
else else
return 0, 0 return 0, 0
end end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -310,31 +310,31 @@ end
- desc: sets the object's size - desc: sets the object's size
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:SetSize(width, height, r1, r2) function newobject:SetSize(width, height, r1, r2)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
if r1 then if r1 then
self.width = self.parent.width * width self.width = self.parent.width * width
else else
self.width = width self.width = width
end end
if r2 then if r2 then
self.height = self.parent.height * height self.height = self.parent.height * height
else else
self.height = height self.height = height
end end
self:PositionColumns() self:PositionColumns()
list:SetSize(width, height) list:SetSize(width, height)
list:SetPos(0, 0) list:SetPos(0, 0)
list:CalculateSize() list:CalculateSize()
list:RedoLayout() list:RedoLayout()
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -342,25 +342,25 @@ end
- desc: sets the object's width - desc: sets the object's width
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:SetWidth(width, relative) function newobject:SetWidth(width, relative)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
if relative then if relative then
self.width = self.parent.width * width self.width = self.parent.width * width
else else
self.width = width self.width = width
end end
self:PositionColumns() self:PositionColumns()
list:SetSize(width) list:SetSize(width)
list:SetPos(0, 0) list:SetPos(0, 0)
list:CalculateSize() list:CalculateSize()
list:RedoLayout() list:RedoLayout()
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -368,25 +368,25 @@ end
- desc: sets the object's height - desc: sets the object's height
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:SetHeight(height, relative) function newobject:SetHeight(height, relative)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
if relative then if relative then
self.height = self.parent.height * height self.height = self.parent.height * height
else else
self.height = height self.height = height
end end
self:PositionColumns() self:PositionColumns()
list:SetSize(height) list:SetSize(height)
list:SetPos(0, 0) list:SetPos(0, 0)
list:CalculateSize() list:CalculateSize()
list:RedoLayout() list:RedoLayout()
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -398,10 +398,10 @@ function newobject:SetMaxColorIndex(num)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
list.colorindexmax = num list.colorindexmax = num
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -412,10 +412,10 @@ function newobject:Clear()
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
list:Clear() list:Clear()
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -429,17 +429,17 @@ function newobject:SetAutoScroll(bool)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
local scrollbar = list:GetScrollBar() local scrollbar = list:GetScrollBar()
self.autoscroll = bool self.autoscroll = bool
if list then if list then
if scrollbar then if scrollbar then
scrollbar.autoscroll = bool scrollbar.autoscroll = bool
end end
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -452,7 +452,7 @@ function newobject:SetButtonScrollAmount(amount)
self.buttonscrollamount = amount self.buttonscrollamount = amount
self.internals[1].buttonscrollamount = amount self.internals[1].buttonscrollamount = amount
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -463,7 +463,7 @@ end
function newobject:GetButtonScrollAmount() function newobject:GetButtonScrollAmount()
return self.buttonscrollamount return self.buttonscrollamount
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -475,17 +475,17 @@ function newobject:SetMouseWheelScrollAmount(amount)
self.mousewheelscrollamount = amount self.mousewheelscrollamount = amount
self.internals[1].mousewheelscrollamount = amount self.internals[1].mousewheelscrollamount = amount
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: GetMouseWheelScrollAmount() - func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel - desc: gets the scroll amount of the mouse wheel
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:GetButtonScrollAmount() function newobject:GetMouseWheelScrollAmount()
return self.mousewheelscrollamount return self.mousewheelscrollamount
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -497,17 +497,17 @@ function newobject:SetColumnHeight(height)
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
self.columnheight = height self.columnheight = height
for k, v in ipairs(children) do for k, v in ipairs(children) do
v:SetHeight(height) v:SetHeight(height)
end end
list:CalculateSize() list:CalculateSize()
list:RedoLayout() list:RedoLayout()
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -520,7 +520,7 @@ function newobject:SetDTScrolling(bool)
self.dtscrolling = bool self.dtscrolling = bool
self.internals[1].dtscrolling = bool self.internals[1].dtscrolling = bool
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -531,7 +531,7 @@ end
function newobject:GetDTScrolling() function newobject:GetDTScrolling()
return self.dtscrolling return self.dtscrolling
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -542,16 +542,16 @@ end
function newobject:SelectRow(row, ctrl) function newobject:SelectRow(row, ctrl)
local selectionenabled = self.selectionenabled local selectionenabled = self.selectionenabled
if not selectionenabled then if not selectionenabled then
return return
end end
local list = self.internals[1] local list = self.internals[1]
local children = list.children local children = list.children
local multiselect = self.multiselect local multiselect = self.multiselect
local onrowselected = self.OnRowSelected local onrowselected = self.OnRowSelected
for k, v in ipairs(children) do for k, v in ipairs(children) do
if v == row then if v == row then
if v.selected and ctrl then if v.selected and ctrl then
@ -568,9 +568,9 @@ function newobject:SelectRow(row, ctrl)
end end
end end
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -582,7 +582,7 @@ function newobject:DeselectRow(row)
row.selected = false row.selected = false
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -590,19 +590,19 @@ end
- desc: gets the object's selected rows - desc: gets the object's selected rows
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:GetSelectedRows() function newobject:GetSelectedRows()
local rows = {} local rows = {}
local list = self.internals[1] local list = self.internals[1]
local children = list.children local children = list.children
for k, v in ipairs(children) do for k, v in ipairs(children) do
if v.selected then if v.selected then
table.insert(rows, v) table.insert(rows, v)
end end
end end
return rows return rows
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -614,7 +614,7 @@ function newobject:SetSelectionEnabled(bool)
self.selectionenabled = bool self.selectionenabled = bool
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -625,7 +625,7 @@ end
function newobject:GetSelectionEnabled() function newobject:GetSelectionEnabled()
return self.selectionenabled return self.selectionenabled
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -637,7 +637,7 @@ function newobject:SetMultiselectEnabled(bool)
self.multiselect = bool self.multiselect = bool
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -648,7 +648,7 @@ end
function newobject:GetMultiselectEnabled() function newobject:GetMultiselectEnabled()
return self.multiselect return self.multiselect
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -658,15 +658,15 @@ end
function newobject:RemoveColumn(id) function newobject:RemoveColumn(id)
local children = self.children local children = self.children
for k, v in ipairs(children) do for k, v in ipairs(children) do
if k == id then if k == id then
v:Remove() v:Remove()
end end
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -676,15 +676,15 @@ end
function newobject:SetColumnName(id, name) function newobject:SetColumnName(id, name)
local children = self.children local children = self.children
for k, v in ipairs(children) do for k, v in ipairs(children) do
if k == id then if k == id then
v.name = name v.name = name
end end
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -694,15 +694,15 @@ end
function newobject:GetColumnName(id) function newobject:GetColumnName(id)
local children = self.children local children = self.children
for k, v in ipairs(children) do for k, v in ipairs(children) do
if k == id then if k == id then
return v.name return v.name
end end
end end
return false return false
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -714,7 +714,7 @@ end
modifications. modifications.
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:SizeToChildren(max) function newobject:SizeToChildren(max)
local oldheight = self.height local oldheight = self.height
local list = self.internals[1] local list = self.internals[1]
local listchildren = list.children local listchildren = list.children
@ -724,15 +724,15 @@ function newobject:SizeToChildren(max)
local h = listchildren[1].height local h = listchildren[1].height
local c = #listchildren local c = #listchildren
local height = buf + h*c local height = buf + h*c
if max then if max then
height = math.min(max, oldheight) height = math.min(max, oldheight)
end end
self:SetSize(width, height) self:SetSize(width, height)
self:PositionColumns() self:PositionColumns()
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -744,11 +744,11 @@ function newobject:RemoveRow(id)
local list = self.internals[1] local list = self.internals[1]
local listchildren = list.children local listchildren = list.children
local row = listchildren[id] local row = listchildren[id]
if row then if row then
row:Remove() row:Remove()
end end
list:CalculateSize() list:CalculateSize()
list:RedoLayout() list:RedoLayout()
return self return self
@ -760,17 +760,17 @@ end
- desc: sets a cell's text - desc: sets a cell's text
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:SetCellText(text, rowid, columnid) function newobject:SetCellText(text, rowid, columnid)
local list = self.internals[1] local list = self.internals[1]
local listchildren = list.children local listchildren = list.children
local row = listchildren[rowid] local row = listchildren[rowid]
if row and row.columndata[columnid]then if row and row.columndata[columnid]then
row.columndata[columnid] = text row.columndata[columnid] = text
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -778,15 +778,15 @@ end
- desc: gets a cell's text - desc: gets a cell's text
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:GetCellText(rowid, columnid) function newobject:GetCellText(rowid, columnid)
local row = self.internals[1].children[rowid] local row = self.internals[1].children[rowid]
if row and row.columndata[columnid] then if row and row.columndata[columnid] then
return row.columndata[columnid] return row.columndata[columnid]
else else
return false return false
end end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -798,15 +798,15 @@ function newobject:SetRowColumnData(rowid, columndata)
local list = self.internals[1] local list = self.internals[1]
local listchildren = list.children local listchildren = list.children
local row = listchildren[rowid] local row = listchildren[rowid]
if row then if row then
for k, v in ipairs(columndata) do for k, v in ipairs(columndata) do
row.columndata[k] = tostring(v) row.columndata[k] = tostring(v)
end end
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -816,13 +816,13 @@ end
function newobject:GetTotalColumnWidth() function newobject:GetTotalColumnWidth()
local width = 0 local width = 0
for k, v in ipairs(self.children) do for k, v in ipairs(self.children) do
width = width + v.width width = width + v.width
end end
return width return width
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -842,9 +842,9 @@ function newobject:SetColumnWidth(id, width)
self.internals[1]:CalculateSize() self.internals[1]:CalculateSize()
self.internals[1]:RedoLayout() self.internals[1]:RedoLayout()
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -857,9 +857,9 @@ function newobject:GetColumnWidth(id)
if column then if column then
return column.width return column.width
end end
return false return false
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -872,22 +872,22 @@ function newobject:ResizeColumns()
local children = self.children local children = self.children
local width = 0 local width = 0
local vbody = self.internals[1]:GetVerticalScrollBody() local vbody = self.internals[1]:GetVerticalScrollBody()
if vbody then if vbody then
width = (self:GetWidth() - vbody:GetWidth())/#children width = (self:GetWidth() - vbody:GetWidth())/#children
else else
width = self:GetWidth()/#children width = self:GetWidth()/#children
end end
for k, v in ipairs(children) do for k, v in ipairs(children) do
v:SetWidth(width) v:SetWidth(width)
self:PositionColumns() self:PositionColumns()
self.internals[1]:CalculateSize() self.internals[1]:CalculateSize()
self.internals[1]:RedoLayout() self.internals[1]:RedoLayout()
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -898,7 +898,7 @@ function newobject:SetDefaultColumnWidth(width)
self.defaultcolumnwidth = width self.defaultcolumnwidth = width
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -908,7 +908,7 @@ end
function newobject:GetDefaultColumnWidth() function newobject:GetDefaultColumnWidth()
return self.defaultcolumnwidth return self.defaultcolumnwidth
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -920,7 +920,7 @@ function newobject:SetColumnResizeEnabled(bool)
self.canresizecolumns = bool self.canresizecolumns = bool
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -931,7 +931,7 @@ end
function newobject:GetColumnResizeEnabled() function newobject:GetColumnResizeEnabled()
return self.canresizecolumns return self.canresizecolumns
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -944,21 +944,21 @@ function newobject:SizeColumnToData(columnid)
local column = self.children[columnid] local column = self.children[columnid]
local list = self.internals[1] local list = self.internals[1]
local largest = 0 local largest = 0
for k, v in ipairs(list.children) do for k, v in ipairs(list.children) do
local width = v:GetFont():getWidth(self:GetCellText(k, columnid)) local width = v:GetFont():getWidth(self:GetCellText(k, columnid))
if width > largest then if width > largest then
largest = width + v.textx largest = width + v.textx
end end
end end
if largest <= 0 then if largest <= 0 then
largest = 10 largest = 10
end end
self:SetColumnWidth(columnid, largest) self:SetColumnWidth(columnid, largest)
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -969,15 +969,15 @@ function newobject:SetColumnOrder(curid, newid)
local column = self.children[curid] local column = self.children[curid]
local totalcolumns = #self.children local totalcolumns = #self.children
if column and totalcolumns > 1 and newid <= totalcolumns and newid >= 1 then if column and totalcolumns > 1 and newid <= totalcolumns and newid >= 1 then
column:Remove() column:Remove()
table.insert(self.children, newid, column) table.insert(self.children, newid, column)
self:PositionColumns() self:PositionColumns()
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------

View File

@ -14,7 +14,6 @@ local newobject = loveframes.NewObject("grid", "loveframes_object_grid", true)
- desc: initializes the object - desc: initializes the object
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:initialize() function newobject:initialize()
self.type = "grid" self.type = "grid"
self.width = 100 self.width = 100
self.height = 100 self.height = 100
@ -28,7 +27,9 @@ function newobject:initialize()
self.itemautosize = false self.itemautosize = false
self.children = {} self.children = {}
self.OnSizeChanged = nil self.OnSizeChanged = nil
self.rowspans = {}
self.colspans = {}
self:SetDrawFunc() self:SetDrawFunc()
end end
@ -62,12 +63,10 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
local cw = self.cellwidth + (self.cellpadding * 2)
local ch = self.cellheight + (self.cellpadding * 2)
local prevwidth = self.prevwidth local prevwidth = self.prevwidth
local prevheight = self.prevheight local prevheight = self.prevheight
@ -78,24 +77,49 @@ function newobject:update(dt)
local onsizechanged = self.OnSizeChanged local onsizechanged = self.OnSizeChanged
self.prevwidth = self.width self.prevwidth = self.width
self.prevheight = self.height self.prevheight = self.height
self:_update_children_position()
if onsizechanged then if onsizechanged then
onsizechanged(self) onsizechanged(self)
end end
end end
for k, v in ipairs(children) do for k, v in ipairs(children) do
local x = 0 + ((cw * v.gridcolumn) - cw ) + (cw/2 - v.width/2)
local y = 0 + ((ch * v.gridrow) - ch) + (ch/2 - v.height/2)
v.staticx = x
v.staticy = y
v:update(dt) v:update(dt)
end end
local update = self.Update local update = self.Update
if update then update(self, dt) end if update then update(self, dt) end
end end
function newobject:_update_children_position()
for k, v in ipairs(self.children) do
local rs, cs = self:GetCellSpanSize(v.gridrow, v.gridcolumn)
local csw = cs * self.cellwidth + (cs * self.cellpadding * 2)
local csh = rs * self.cellheight + (rs * self.cellpadding * 2)
local cw = self.cellwidth + (self.cellpadding * 2)
local ch = self.cellheight + (self.cellpadding * 2)
local x
local y = ((ch * v.gridrow) - ch) + (csh/2 - v.height/2)
if
v.align == 'center' then
x = (cw * (v.gridcolumn - 1)) + (csw/2 - v.width/2)
elseif
v.align == 'right' then
x = (cw * (v.gridcolumn - 1)) + (csw - v.width) - self.cellpadding
elseif
v.align == 'left' then
x = self.cellpadding + (cw * (v.gridcolumn - 1))
end
v.staticx = x
v.staticy = y
end
end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: mousepressed(x, y, button) - func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button - desc: called when the player presses a mouse button
@ -157,31 +181,105 @@ function newobject:mousereleased(x, y, button)
end end
--[[---------------------------------------------------------
- func: RowSpanAt(row, col, size)
- desc: expands the size of the row at position
--]]---------------------------------------------------------
function newobject:RowSpanAt(row, col, size)
self.colspans[col] = self.colspans[col] or {}
local colsize = self.colspans[col][row]
local s = colsize or 1
for i = col, col + s - 1 do
for j = row, row + size - 1 do
self.rowspans[i] = self.rowspans[i] or {}
self.colspans[i] = self.colspans[i] or {}
self.rowspans[i][j] = -1
self.colspans[i][j] = -1
end
end
self.rowspans[col][row] = size
self.colspans[col][row] = colsize
return self
end
--[[---------------------------------------------------------
- func: ColSpanAt(row, col, size)
- desc: expands the size of the column at position
--]]---------------------------------------------------------
function newobject:ColSpanAt(row, col, size)
self.rowspans[col] = self.rowspans[col] or {}
local rowsize = self.rowspans[col][row]
local s = rowsize or 1
for i = col, col + size - 1 do
for j = row, row + s - 1 do
self.rowspans[i] = self.rowspans[i] or {}
self.colspans[i] = self.colspans[i] or {}
self.rowspans[i][j] = -1
self.colspans[i][j] = -1
end
end
self.rowspans[col][row] = rowsize
self.colspans[col][row] = size
return self
end
--[[---------------------------------------------------------
- func: GetCellSpanSize(row, col, size)
- desc: get span size of cell
--]]---------------------------------------------------------
function newobject:GetCellSpanSize(row, col)
self.rowspans[col] = self.rowspans[col] or {}
local rs = self.rowspans[col][row] or 1
self.colspans[col] = self.colspans[col] or {}
local cs = self.colspans[col][row] or 1
return rs, cs
end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: AddItem(object, row, column) - func: AddItem(object, row, column)
- desc: adds and item to the object - desc: adds and item to the object
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:AddItem(object, row, column) function newobject:AddItem(object, row, col, align)
local itemautosize = self.itemautosize local itemautosize = self.itemautosize
local children = self.children local children = self.children
object:Remove() object:Remove()
table.insert(children, object) table.insert(children, object)
object.parent = self object.parent = self
object.gridrow = row object.gridrow = row
object.gridcolumn = column object.gridcolumn = col
object.align = align or 'center'
if itemautosize then if itemautosize then
local cw = self.cellwidth + (self.cellpadding * 2) if object.type == 'text' or object.type == 'checkbox' then
local ch = self.cellheight + (self.cellpadding * 2) return self
end
local rs, cs = self:GetCellSpanSize(row, col)
local cw = cs * self.cellwidth + (self.cellpadding * 2)
local ch = rs * self.cellheight + (self.cellpadding * 2)
object.width = cw - (self.cellpadding * 2) object.width = cw - (self.cellpadding * 2)
object.height = ch - (self.cellpadding * 2) object.height = ch - (self.cellpadding * 2)
if object.CalculateSize then object:CalculateSize() end
if object.RedoLayout then object:RedoLayout() end
end end
return self return self
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------

View File

@ -62,8 +62,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if update then if update then

View File

@ -77,8 +77,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if update then if update then

View File

@ -55,8 +55,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if parentinternals[1] ~= self then if parentinternals[1] ~= self then

View File

@ -53,9 +53,10 @@ function newobject:update(dt)
end end
end end
self:CheckHover()
local hover = self.hover local hover = self.hover
self:CheckHover()
local parent = self.parent local parent = self.parent
local option_type = self.option_type local option_type = self.option_type
local activated = self.activated local activated = self.activated
@ -96,8 +97,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if update then if update then
@ -111,7 +112,7 @@ end
- desc: called when the player presses a mouse button - desc: called when the player presses a mouse button
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:mousepressed(x, y, button) function newobject:mousepressed(x, y, button)
local state = loveframes.state local state = loveframes.state
local selfstate = self.state local selfstate = self.state
@ -125,6 +126,7 @@ function newobject:mousepressed(x, y, button)
return return
end end
self.down = true
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -148,7 +150,7 @@ function newobject:mousereleased(x, y, button)
local hover = self.hover local hover = self.hover
local option_type = self.option_type local option_type = self.option_type
if hover and option_type ~= "divider" and button == 1 then if hover and option_type ~= "divider" and button == 1 and self.down then
local func = self.func local func = self.func
if func then if func then
local text = self.text local text = self.text
@ -156,8 +158,9 @@ function newobject:mousereleased(x, y, button)
end end
local basemenu = self.parent:GetBaseMenu() local basemenu = self.parent:GetBaseMenu()
basemenu:SetVisible(false) basemenu:SetVisible(false)
self.hover = false
end end
self.down = false
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------

View File

@ -125,8 +125,9 @@ function newobject:initialize(parent, bartype)
-- apply template properties to the object -- apply template properties to the object
loveframes.ApplyTemplatesToObject(self) loveframes.ApplyTemplatesToObject(self)
self:SetDrawFunc() self:SetDrawFunc()
end
self:SetAlwaysUpdate(true)
end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: update(deltatime) - func: update(deltatime)
- desc: updates the object - desc: updates the object

View File

@ -145,10 +145,12 @@ function newobject:mousepressed(x, y, button)
if self.hover and button == 1 then if self.hover and button == 1 then
local time = os.time() local time = os.time()
if self.lastclick + 0.40 > time then if self.lastclick + 0.30 > time then
self.open = not self.open self.open = not self.open
self.lastclick = 0
else
self.lastclick = time
end end
self.lastclick = time
local onselectnode = self.tree.OnSelectNode local onselectnode = self.tree.OnSelectNode
self.tree.selectednode = self self.tree.selectednode = self
if onselectnode then if onselectnode then
@ -181,6 +183,16 @@ function newobject:mousereleased(x, y, button)
v:mousereleased(x, y, button) v:mousereleased(x, y, button)
end end
if self.hover then
if button == 2 then
local onselectnoderightclick = self.tree.OnSelectNodeRightClick
self.tree.selectednode = self
if onselectnoderightclick then
onselectnoderightclick(self.parent, self)
end
end
end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -271,6 +283,13 @@ function newobject:RemoveNode(id)
end end
function newobject:SetSelected()
self.tree.selectednode = self
return self
end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: SetOpen(bool) - func: SetOpen(bool)
- desc: sets whether or not the object is open - desc: sets whether or not the object is open

View File

@ -53,8 +53,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if update then if update then
@ -98,8 +98,8 @@ function newobject:mousepressed(x, y, button)
end end
end end
self.parent:SetOpen(bool) self.parent:SetOpen(bool)
print("!") --print("!")
print(self.parent.level) --print(self.parent.level)
end end
end end

View File

@ -38,7 +38,10 @@ function newobject:initialize()
self.internals = {} self.internals = {}
self.children = {} self.children = {}
self.OnScroll = nil self.OnScroll = nil
self.scrollx = loveframes.objects["scrollbody"]:new(self, "horizontal")
self.scrolly = loveframes.objects["scrollbody"]:new(self, "vertical")
self:SetDrawFunc() self:SetDrawFunc()
end end
@ -56,7 +59,7 @@ function newobject:update(dt)
end end
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if not visible then if not visible then
if not alwaysupdate then if not alwaysupdate then
@ -76,34 +79,35 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
for k, v in ipairs(internals) do for k, v in ipairs(internals) do
v:update(dt) v:update(dt)
for _, p in pairs(self:GetParents()) do --[[for _, p in pairs(self:GetParents()) do
v.x = v.x - (p.offsetx or 0) v.x = v.x - (p.offsetx or 0)
v.y = v.y - (p.offsety or 0) v.y = v.y - (p.offsety or 0)
end end]]
end end
local x = self.x local x = self.x
local y = self.y local y = self.y
local width = self.width
local height = self.height
local offsetx = self.offsetx local offsetx = self.offsetx
local offsety = self.offsety local offsety = self.offsety
local width = self.width
local height = self.height
for k, v in ipairs(children) do for k, v in ipairs(children) do
v:update(dt) v:update(dt)
v:SetClickBounds(x, y, width, height) v:SetClickBounds(x, y, width, height)
v.x = (v.parent.x + v.staticx) - offsetx --v.x = (v.parent.x + v.staticx) - offsetx
v.y = (v.parent.y + v.staticy) - offsety --v.y = (v.parent.y + v.staticy) - offsety
for _, p in pairs(self:GetParents()) do
--[[for _, p in pairs(self:GetParents()) do
v.x = v.x - (p.offsetx or 0) v.x = v.x - (p.offsetx or 0)
v.y = v.y - (p.offsety or 0) v.y = v.y - (p.offsety or 0)
end end]]
if display == "vertical" then if display == "vertical" then
if v.lastheight ~= v.height then if v.lastheight ~= v.height then
self:CalculateSize() self:CalculateSize()
@ -135,9 +139,6 @@ function newobject:draw()
local y = self.y local y = self.y
local width = self.width local width = self.width
local height = self.height local height = self.height
local stencilfunc = function()
love.graphics.rectangle("fill", x, y, width, height)
end
self:SetDrawOrder() self:SetDrawOrder()
@ -145,10 +146,10 @@ function newobject:draw()
if drawfunc then if drawfunc then
drawfunc(self) drawfunc(self)
end end
local scx, scy, scw, sch = love.graphics.getScissor()
love.graphics.stencil(stencilfunc)
love.graphics.setStencilTest("greater", 0) love.graphics.intersectScissor(x, y, width, height)
local children = self.children local children = self.children
if children then if children then
for k, v in ipairs(children) do for k, v in ipairs(children) do
@ -158,8 +159,8 @@ function newobject:draw()
end end
end end
end end
love.graphics.setStencilTest() love.graphics.setScissor(scx, scy, scw, sch)
local drawfunc = self.DrawOver or self.drawoverfunc local drawfunc = self.DrawOver or self.drawoverfunc
if drawfunc then if drawfunc then
@ -348,15 +349,16 @@ function newobject:CalculateSize()
if itemheight > height then if itemheight > height then
self.extraheight = itemheight - height self.extraheight = itemheight - height
if not vbar then if not vbar then
local scrollbar = loveframes.objects["scrollbody"]:new(self, display) table.insert(internals, self.scrolly)
table.insert(internals, scrollbar)
self.vbar = true self.vbar = true
self:GetScrollBar().autoscroll = self.autoscroll local bar = self:GetScrollBar()
bar.autoscroll = self.autoscroll
bar:ScrollTo(0)
self.scrolly:update(0)
end end
else else
if vbar then if vbar then
local bar = internals[1] self.scrolly:Remove()
bar:Remove()
self.vbar = false self.vbar = false
self.offsety = 0 self.offsety = 0
end end
@ -416,13 +418,13 @@ function newobject:RedoLayout()
end end
if #children > 0 then if #children > 0 then
local scrollbar = self:GetScrollBar()
if display == "vertical" then if display == "vertical" then
if horizontalstacking then if horizontalstacking then
local curwidth = padding local curwidth = padding
local curheight = padding local curheight = padding
local maxwidth = self.width - padding * 2 local maxwidth = self.width - padding * 2
local prevheight = 0 local prevheight = 0
local scrollbar = self:GetScrollBar()
if scrollbar then if scrollbar then
maxwidth = maxwidth - scrollbar.width maxwidth = maxwidth - scrollbar.width
end end
@ -451,7 +453,7 @@ function newobject:RedoLayout()
v.staticx = padding v.staticx = padding
v.staticy = starty v.staticy = starty
v.lastheight = itemheight v.lastheight = itemheight
if vbar then if vbar and scrollbar.visible then
if itemwidth + padding > (width - scrollbodywidth) then if itemwidth + padding > (width - scrollbodywidth) then
v:SetWidth((width - scrollbodywidth) - (padding * 2)) v:SetWidth((width - scrollbodywidth) - (padding * 2))
end end
@ -476,7 +478,7 @@ function newobject:RedoLayout()
local retainsize = v.retainsize local retainsize = v.retainsize
v.staticx = startx v.staticx = startx
v.staticy = padding v.staticy = padding
if hbar then if hbar and scrollbar.visible then
if itemheight + padding > (height - scrollbodyheight) then if itemheight + padding > (height - scrollbodyheight) then
v:SetHeight((height - scrollbodyheight) - (padding * 2)) v:SetHeight((height - scrollbodyheight) - (padding * 2))
end end
@ -743,7 +745,7 @@ end
- func: GetMouseWheelScrollAmount() - func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel - desc: gets the scroll amount of the mouse wheel
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:GetButtonScrollAmount() function newobject:GetMouseWheelScrollAmount()
return self.mousewheelscrollamount return self.mousewheelscrollamount

View File

@ -60,8 +60,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(self.internals) do
@ -120,7 +120,6 @@ end
- desc: called when the player presses a mouse button - desc: called when the player presses a mouse button
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:mousepressed(x, y, button) function newobject:mousepressed(x, y, button)
local state = loveframes.state local state = loveframes.state
local selfstate = self.state local selfstate = self.state
@ -133,7 +132,11 @@ function newobject:mousepressed(x, y, button)
if not visible then if not visible then
return return
end end
local internals = self.internals
for k, v in ipairs(internals) do
v:mousepressed(x, y, button)
end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------

View File

@ -65,8 +65,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if update then if update then
@ -251,6 +251,21 @@ function newobject:GetChoice()
end end
--[[---------------------------------------------------------
- func: GetChoiceIndex()
- desc: gets the current choice index
--]]---------------------------------------------------------
function newobject:GetChoiceIndex()
local choices = self.choices
for i, v in ipairs(choices) do
if self.choice == v then
return i
end
end
end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: SetText(text) - func: SetText(text)
- desc: sets the object's text - desc: sets the object's text
@ -310,7 +325,7 @@ end
- func: GetMouseWheelScrollAmount() - func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel - desc: gets the scroll amount of the mouse wheel
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:GetButtonScrollAmount() function newobject:GetMouseWheelScrollAmount()
return self.mousewheelscrollamount return self.mousewheelscrollamount

View File

@ -109,8 +109,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
-- completion check -- completion check

View File

@ -80,8 +80,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
self:CheckHover() self:CheckHover()
@ -642,7 +642,7 @@ end
- func: GetMouseWheelScrollAmount() - func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel - desc: gets the scroll amount of the mouse wheel
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:GetButtonScrollAmount() function newobject:GetMouseWheelScrollAmount()
return self.mousewheelscrollamount return self.mousewheelscrollamount

View File

@ -122,13 +122,13 @@ function newobject:update(dt)
end end
self.linkcol = linkcol self.linkcol = linkcol
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
if update then if update then
update(self, dt) update(self, dt)
end end

View File

@ -567,7 +567,6 @@ function newobject:RunKey(key, istext)
local numlines = #lines local numlines = #lines
local curline = lines[line] local curline = lines[line]
local text = curline local text = curline
local ckey = ""
local font = self.font local font = self.font
local swidth = self.width local swidth = self.width
local textoffsetx = self.textoffsetx local textoffsetx = self.textoffsetx
@ -663,14 +662,14 @@ function newobject:RunKey(key, istext)
-- key input checking system -- key input checking system
if key == "backspace" then if key == "backspace" then
ckey = key
if alltextselected then if alltextselected then
self:Clear() self:Clear()
self.alltextselected = false self.alltextselected = false
indicatornum = self.indicatornum indicatornum = self.indicatornum
else else
local removed_text = ''
if text ~= "" and indicatornum ~= 0 then if text ~= "" and indicatornum ~= 0 then
text = self:RemoveFromText(indicatornum) text, removed_text = self:RemoveFromText(indicatornum)
self:MoveIndicator(-1) self:MoveIndicator(-1)
lines[line] = text lines[line] = text
end end
@ -693,9 +692,9 @@ function newobject:RunKey(key, istext)
local cwidth = 0 local cwidth = 0
if masked then if masked then
local maskchar = self.maskchar local maskchar = self.maskchar
cwidth = font:getWidth(loveframes.utf8.gsub(text, ".", maskchar)) cwidth = font:getWidth(loveframes.utf8.gsub(removed_text, ".", maskchar))
else else
cwidth = font:getWidth(text) cwidth = font:getWidth(removed_text)
end end
if self.offsetx > 0 then if self.offsetx > 0 then
self.offsetx = self.offsetx - cwidth self.offsetx = self.offsetx - cwidth
@ -707,7 +706,6 @@ function newobject:RunKey(key, istext)
if not editable then if not editable then
return return
end end
ckey = key
if alltextselected then if alltextselected then
self:Clear() self:Clear()
self.alltextselected = false self.alltextselected = false
@ -727,7 +725,6 @@ function newobject:RunKey(key, istext)
end end
end end
elseif key == "return" or key == "kpenter" then elseif key == "return" or key == "kpenter" then
ckey = key
-- call onenter if it exists -- call onenter if it exists
if onenter then if onenter then
onenter(self, text) onenter(self, text)
@ -765,7 +762,6 @@ function newobject:RunKey(key, istext)
if alltextselected then if alltextselected then
return return
end end
ckey = key
self.lines[self.line] = self:AddIntoText(self.tabreplacement, self.indicatornum) self.lines[self.line] = self:AddIntoText(self.tabreplacement, self.indicatornum)
self:MoveIndicator(loveframes.utf8.len(self.tabreplacement)) self:MoveIndicator(loveframes.utf8.len(self.tabreplacement))
end end
@ -1031,9 +1027,10 @@ function newobject:RemoveFromText(p)
local curline = lines[line] local curline = lines[line]
local text = curline local text = curline
local part1 = loveframes.utf8.sub(text, 1, p - 1) local part1 = loveframes.utf8.sub(text, 1, p - 1)
local removed_part = loveframes.utf8.sub(text, p, p + 1)
local part2 = loveframes.utf8.sub(text, p + 1) local part2 = loveframes.utf8.sub(text, p + 1)
local new = part1 .. part2 local new = part1 .. part2
return new return new, removed_part
end end

View File

@ -66,8 +66,8 @@ function newobject:update(dt)
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy - (parent.offsety or 0)
end end
self.itemwidth = 0 self.itemwidth = 0
@ -174,6 +174,8 @@ function newobject:draw()
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height - 16) end stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height - 16) end
elseif self.vbar and self.hbar then elseif self.vbar and self.hbar then
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width - 16, self.height - 16) end stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width - 16, self.height - 16) end
else
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
end end
self:SetDrawOrder() self:SetDrawOrder()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 212 B

After

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 223 B

After

Width:  |  Height:  |  Size: 176 B

View File

@ -853,7 +853,7 @@ function skin.multichoice(object)
skin.PrintText(choice, x + 5, y + height/2 - theight/2) skin.PrintText(choice, x + 5, y + height/2 - theight/2)
end end
love.graphics.draw(image, x + width - 20, y + 5) love.graphics.draw(image, x + width - 20, y + (height - 16) / 2)
love.graphics.setColor(border) love.graphics.setColor(border)
skin.OutlinedRectangle(x, y, width, height) skin.OutlinedRectangle(x, y, width, height)
@ -1540,8 +1540,6 @@ function skin.grid(object)
local skin = object:GetSkin() local skin = object:GetSkin()
local x = object:GetX() local x = object:GetX()
local y = object:GetY() local y = object:GetY()
local width = object:GetWidth()
local height = object:GetHeight()
--love.graphics.setColor(colors.hl4) --love.graphics.setColor(colors.hl4)
--love.graphics.rectangle("fill", x-1, y-1, width+2, height+2) --love.graphics.rectangle("fill", x-1, y-1, width+2, height+2)
@ -1551,24 +1549,37 @@ function skin.grid(object)
local cw = object.cellwidth + (object.cellpadding * 2) local cw = object.cellwidth + (object.cellpadding * 2)
local ch = object.cellheight + (object.cellpadding * 2) local ch = object.cellheight + (object.cellpadding * 2)
for i=1, object.rows do local row = 1
for n=1, object.columns do while row <= object.rows do
local ovt = false local col = 1
local ovl = false while col <= object.columns do
if i > 1 then local cs = (object.colspans[col] or {})[row] or 1
ovt = true local rs = (object.rowspans[col] or {})[row] or 1
if rs ~= -1 and cs ~= -1 then
local ovt = false
local ovl = false
if row > 1 then
ovt = true
end
if col > 1 then
ovl = true
end
local x = cx + (col - 1) * cw
local y = cy + (row - 1) * ch
local w = cw * cs
local h = ch * rs
love.graphics.setColor(skin.controls.color_back1)
love.graphics.rectangle("fill", x, y, w, h)
love.graphics.setColor(skin.controls.color_back3)
skin.OutlinedRectangle(x, y, w, h, ovt, false, ovl, false)
end end
if n > 1 then col = col + 1
ovl = true
end
love.graphics.setColor(skin.controls.color_back1)
love.graphics.rectangle("fill", cx, cy, cw, ch)
love.graphics.setColor(skin.controls.color_back3)
skin.OutlinedRectangle(cx, cy, cw, ch, ovt, false, ovl, false)
cx = cx + cw
end end
cx = x row = row + 1
cy = cy + ch
end end
end end
@ -1723,15 +1734,18 @@ function skin.treenodebutton(object)
local leftpadding = 15 * object.parent.level local leftpadding = 15 * object.parent.level
local image local image
local fore = skin.controls.color_fore0
if object.parent.tree.selectednode == object.parent then
fore = {1, 1, 1, 1}
end
if object.parent.open then if object.parent.open then
image = skin.images["tree-node-button-close.png"] image = skin.images["tree-node-button-close.png"]
else else
image = skin.images["tree-node-button-open.png"] image = skin.images["tree-node-button-open.png"]
end end
--image:setFilter("nearest", "nearest") --image:setFilter("nearest", "nearest")
love.graphics.setColor(fore)
love.graphics.setColor(skin.controls.color_image) --love.graphics.setColor(skin.controls.color_image)
love.graphics.draw(image, object.x, object.y) love.graphics.draw(image, object.x, object.y)
object:SetPos(2 + leftpadding, 3) object:SetPos(2 + leftpadding, 3)