LoveFrames/loveframes/objects/internal/columnlist/columnlistheader.lua

204 lines
5.0 KiB
Lua
Raw Permalink Normal View History

2012-05-06 00:24:42 +00:00
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
2014-01-14 11:29:11 +00:00
-- Copyright (c) 2012-2014 Kenny Shields --
2012-05-06 00:24:42 +00:00
--]]------------------------------------------------
2019-03-06 23:19:58 +00:00
return function(loveframes)
---------- module start ----------
-- columnlistheader class
local newobject = loveframes.NewObject("columnlistheader", "loveframes_object_columnlistheader", true)
2012-05-06 00:24:42 +00:00
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function newobject:initialize(name, parent)
2012-05-06 00:24:42 +00:00
self.type = "columnlistheader"
self.parent = parent
self.name = name
self.state = parent.state
self.width = parent.defaultcolumnwidth
2014-08-23 08:36:47 +00:00
self.height = parent.columnheight
self.columnid = 0
self.hover = false
self.down = false
self.clickable = true
self.enabled = true
2012-05-06 00:24:42 +00:00
self.descending = true
self.resizebox = nil
self.internal = true
2012-05-06 00:24:42 +00:00
table.insert(parent.children, self)
local key = 0
for k, v in ipairs(parent.children) do
2012-05-06 00:24:42 +00:00
if v == self then
key = k
end
end
self.OnClick = function(object)
local descending = object.descending
local parent = object.parent
local pinternals = parent.internals
local list = pinternals[1]
if descending then
object.descending = false
2012-05-06 00:24:42 +00:00
else
object.descending = true
2012-05-06 00:24:42 +00:00
end
list:Sort(key, object.descending)
2012-05-06 00:24:42 +00:00
end
-- apply template properties to the object
2019-03-06 23:19:58 +00:00
loveframes.ApplyTemplatesToObject(self)
self:SetDrawFunc()
2012-05-06 00:24:42 +00:00
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function newobject:update(dt)
2012-05-06 00:24:42 +00:00
2014-08-23 08:36:47 +00:00
if not self.visible then
if not self.alwaysupdate then
2012-05-06 00:24:42 +00:00
return
end
end
local update = self.Update
2014-08-23 08:36:47 +00:00
local parent = self.parent
local list = parent.internals[1]
local vbody = list:GetVerticalScrollBody()
local width = list.width
if vbody then
width = width - vbody.width
end
self.clickbounds = {x = list.x, y = list.y, width = width, height = list.height}
2012-05-06 00:24:42 +00:00
self:CheckHover()
if not self.hover then
self.down = false
else
if loveframes.downobject == self then
self.down = true
end
end
2012-05-06 00:24:42 +00:00
-- move to parent if there is a parent
2014-08-23 08:36:47 +00:00
if parent ~= loveframes.base then
self.x = (parent.x + self.staticx) - parent.internals[1].offsetx
self.y = parent.y + self.staticy
2012-05-06 00:24:42 +00:00
end
2014-08-23 08:36:47 +00:00
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
2014-08-23 08:36:47 +00:00
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}
if update then
update(self, dt)
2012-05-06 00:24:42 +00:00
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function newobject:mousepressed(x, y, button)
if not self.parent.resizecolumn and self.parent.canresizecolumns then
local box = self.resizebox
2019-03-06 23:19:58 +00:00
local col = loveframes.BoundingBox(x, box.x, y, box.y, 1, box.width, 1, box.height)
if col then
self.resizing = true
self.parent.resizecolumn = self
end
end
2015-10-31 13:40:19 +00:00
if self.hover and button == 1 then
2012-05-06 00:24:42 +00:00
local baseparent = self:GetBaseParent()
2015-10-31 13:40:19 +00:00
if baseparent and baseparent.type == "frame" and button == 1 then
2012-05-06 00:24:42 +00:00
baseparent:MakeTop()
end
self.down = true
loveframes.downobject = self
2012-05-06 00:24:42 +00:00
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function newobject:mousereleased(x, y, button)
2012-05-06 00:24:42 +00:00
if not self.visible then
2012-05-06 00:24:42 +00:00
return
end
local hover = self.hover
local down = self.down
2012-05-06 00:24:42 +00:00
local clickable = self.clickable
local enabled = self.enabled
local onclick = self.OnClick
2012-05-06 00:24:42 +00:00
2015-10-31 13:40:19 +00:00
if hover and down and clickable and button == 1 then
if enabled then
onclick(self, x, y)
2012-05-06 00:24:42 +00:00
end
end
2014-08-23 08:36:47 +00:00
local resizecolumn = self.parent.resizecolumn
if resizecolumn and resizecolumn == self then
self.parent.resizecolumn = nil
end
2012-05-06 00:24:42 +00:00
self.down = false
end
2014-08-23 19:06:35 +00:00
--[[---------------------------------------------------------
- func: SetName(name)
- desc: sets the object's name
--]]---------------------------------------------------------
function newobject:SetName(name)
self.name = name
return self
end
--[[---------------------------------------------------------
- func: GetName()
- desc: gets the object's name
--]]---------------------------------------------------------
function newobject:GetName()
return self.name
end
2019-03-06 23:19:58 +00:00
---------- module end ----------
end