diff --git a/objects/columnlist.lua b/objects/columnlist.lua index ee4e4fb..273942b 100644 --- a/objects/columnlist.lua +++ b/objects/columnlist.lua @@ -23,8 +23,10 @@ function newobject:initialize() self.internal = false self.selectionenabled = true self.multiselect = false + self.startadjustment = false self.children = {} self.internals = {} + self.resizecolumn = nil self.OnRowClicked = nil self.OnRowRightClicked = nil self.OnRowSelected = nil @@ -76,9 +78,12 @@ function newobject:update(dt) end for k, v in ipairs(children) do + v.columnid = k v:update(dt) end + self.startadjustment = false + if update then update(self, dt) end @@ -104,6 +109,21 @@ function newobject:draw() return end + local stencilfunc + local vbar = self.internals[1]:GetVerticalScrollBar() + local hbar = self.internals[1]:GetHorizontalScrollBar() + local width = self.width + local height = self.height + + if vbar then + width = width - vbar.width + end + + if hbar then + height = height - hbar.height + end + + local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, width, height) end local children = self.children local internals = self.internals local skins = loveframes.skins.available @@ -128,9 +148,13 @@ function newobject:draw() v:draw() end + love.graphics.setStencil(stencilfunc) + for k, v in ipairs(children) do v:draw() end + + love.graphics.setStencil() end @@ -213,9 +237,9 @@ end function newobject:AdjustColumns() local width = self.width - local bar = self.internals[1].bar + local vbar = self.internals[1]:GetVerticalScrollBar() - if bar then + if vbar then width = width - self.internals[1].internals[1].width end @@ -797,4 +821,27 @@ function newobject:SetRowColumnData(rowid, columndata) return self +end + +function newobject:GetTotalColumnWidth() + + local width = 0 + + for k, v in ipairs(self.children) do + width = width + v.width + end + + return width + +end + +function newobject:GetColumnWidth(id) + + local column = self.children[id] + if column then + return column.width + end + + return false + end \ No newline at end of file diff --git a/objects/internal/columnlist/columnlistarea.lua b/objects/internal/columnlist/columnlistarea.lua index 520071c..6695c51 100644 --- a/objects/internal/columnlist/columnlistarea.lua +++ b/objects/internal/columnlist/columnlistarea.lua @@ -27,7 +27,8 @@ function newobject:initialize(parent) self.rowcolorindexmax = 2 self.buttonscrollamount = parent.buttonscrollamount self.mousewheelscrollamount = parent.mousewheelscrollamount - self.bar = false + self.vbar = false + self.hbar = false self.dtscrolling = parent.dtscrolling self.internal = true self.internals = {} @@ -68,10 +69,6 @@ function newobject:update(dt) self.y = parent.y + self.staticy end - for k, v in ipairs(internals) do - v:update(dt) - end - for k, v in ipairs(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 @@ -82,6 +79,10 @@ function newobject:update(dt) v.x = (v.parent.x + v.staticx) - self.offsetx end + for k, v in ipairs(self.internals) do + v:update(dt) + end + if update then update(self, dt) end @@ -104,7 +105,6 @@ function newobject:draw() local y = self.y local width = self.width local height = self.height - local stencilfunc = function() love.graphics.rectangle("fill", x, y, width, height) end local skins = loveframes.skins.available local skinindex = loveframes.config["ACTIVESKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"] @@ -117,6 +117,19 @@ function newobject:draw() local internals = self.internals local children = self.children + local swidth = width + local sheight = height + + if self.vbar then + swidth = swidth - self:GetVerticalScrollBar():GetWidth() + end + + if self.hbar then + sheight = sheight - self:GetHorizontalScrollBar():GetHeight() + end + + local stencilfunc = function() love.graphics.rectangle("fill", x, y, swidth, sheight) end + -- set the object's draw order self:SetDrawOrder() @@ -129,7 +142,7 @@ function newobject:draw() love.graphics.setStencil(stencilfunc) for k, v in ipairs(children) do - local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height) + local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, width, v.width, height, v.height) if col then v:draw() end @@ -231,24 +244,58 @@ function newobject:CalculateSize() for k, v in ipairs(children) do itemheight = itemheight + v.height end - + self.itemheight = itemheight - - if self.itemheight > height then + self.itemwidth = self.parent:GetTotalColumnWidth() + + local hbarheight = 0 + local hbar = self:GetHorizontalScrollBar() + if hbar then + hbarheight = hbar.height + end + + if self.itemheight > (height - hbarheight) then + if hbar then + self.itemheight = self.itemheight + hbarheight + end self.extraheight = self.itemheight - height - if not bar then + if not self.vbar then table.insert(self.internals, loveframes.objects["scrollbody"]:new(self, "vertical")) - self.bar = true - self:GetScrollBar().autoscroll = self.parent.autoscroll + self.vbar = true + self:GetVerticalScrollBar().autoscroll = self.parent.autoscroll end else - if bar then - self.internals[1]:Remove() - self.bar = false + if self.vbar then + self:GetVerticalScrollBar():Remove() + self.vbar = false self.offsety = 0 end end + local vbarwidth = 0 + local vbar = self:GetVerticalScrollBar() + if vbar then + vbarwidth = vbar.width + end + + if self.itemwidth > (self.width - vbarwidth) then + if vbar then + self.itemwidth = self.itemwidth + vbarwidth + end + self.extrawidth = self.itemwidth - self.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 + end + else + if self.hbar then + self:GetHorizontalScrollBar():Remove() + self.hbar = false + self.offsetx = 0 + end + end + end --[[--------------------------------------------------------- @@ -266,15 +313,32 @@ function newobject:RedoLayout() 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 bar then - v:SetWidth(self.width - self.internals[1].width) - self.internals[1].staticx = self.width - self.internals[1].width - self.internals[1].height = self.height + 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) + --v:SetWidth(self.width) + end + 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 + else + --self:SetHeight(self.parent.height) end starty = starty + v.height v.lastheight = v.height @@ -377,4 +441,28 @@ function newobject:Clear() self.parent:AdjustColumns() self.rowcolorindex = 1 +end + +function newobject:GetVerticalScrollBar() + + for k, v in ipairs(self.internals) do + if v.bartype == "vertical" then + return v + end + end + + return false + +end + +function newobject:GetHorizontalScrollBar() + + for k, v in ipairs(self.internals) do + if v.bartype == "horizontal" then + return v + end + end + + return false + end \ No newline at end of file diff --git a/objects/internal/columnlist/columnlistheader.lua b/objects/internal/columnlist/columnlistheader.lua index e960152..8b36387 100644 --- a/objects/internal/columnlist/columnlistheader.lua +++ b/objects/internal/columnlist/columnlistheader.lua @@ -18,11 +18,13 @@ function newobject:initialize(name, parent) self.state = parent.state self.width = 80 self.height = self.parent.columnheight + self.columnid = 0 self.hover = false self.down = false self.clickable = true self.enabled = true self.descending = true + self.resizebox = nil self.internal = true table.insert(parent.children, self) @@ -72,6 +74,14 @@ function newobject:update(dt) local base = loveframes.base local update = self.Update + local list = self.parent.internals[1] + local vbar = list:GetVerticalScrollBar() + local width = list.width + if vbar then + width = width - vbar.width + end + + self.clickbounds = {x = list.x, y = list.y, width = width, height = list.height} self:CheckHover() if not self.hover then @@ -84,10 +94,26 @@ function newobject:update(dt) -- move to parent if there is a parent if parent ~= base then - self.x = parent.x + self.staticx + self.x = (parent.x + self.staticx) - self.parent.internals[1].offsetx self.y = parent.y + self.staticy end + if self.parent.resizecolumn and self.parent.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 + end + + self.resizebox = {x = self.x + (self.width - 2), y = self.y, width = 4, height = self.height} + if update then update(self, dt) end @@ -131,7 +157,16 @@ end - desc: called when the player presses a mouse button --]]--------------------------------------------------------- function newobject:mousepressed(x, y, button) - + + if not self.parent.resizecolumn then + local box = self.resizebox + local col = loveframes.util.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 + if self.hover and button == "l" then local baseparent = self:GetBaseParent() if baseparent and baseparent.type == "frame" and button == "l" then @@ -165,6 +200,10 @@ function newobject:mousereleased(x, y, button) end end + if self.parent.resizecolumn and self.parent.resizecolumn == self then + self.parent.resizecolumn = nil + end + self.down = false end diff --git a/skins/Blue/skin.lua b/skins/Blue/skin.lua index c3e749c..9d835b2 100644 --- a/skins/Blue/skin.lua +++ b/skins/Blue/skin.lua @@ -155,6 +155,46 @@ skin.controls.menuoption_body_hover_color = {51, 204, 255, 255} skin.controls.menuoption_text_hover_color = {255, 255, 255, 255} skin.controls.menuoption_text_color = {180, 180, 180, 255} +local function ParseHeaderText(str, hx, hwidth, tx) + + local font = love.graphics.getFont() + local twidth = love.graphics.getFont():getWidth(str) + + if (tx + twidth) - hwidth/2 > hx + hwidth then + if #str > 1 then + return ParseHeaderText(str:sub(1, #str - 1), hx, hwidth, tx, twidth) + else + return str + end + else + return str + end + +end + +local function ParseRowText(str, rx, rwidth, tx1, tx2) + + local twidth = love.graphics.getFont():getWidth(str) + + if (tx1 + tx2) + twidth > rx + rwidth then + if #str > 1 then + return ParseRowText(str:sub(1, #str - 1), rx, rwidth, tx1, tx2) + else + return str + end + else + return str + end + +end + +--[[ +local function DrawColumnHeaderText(text, hx, hwidth, tx, twidth) + + local new = "" + if tx + width > hx + hwidth then +--]] + --[[--------------------------------------------------------- - func: OutlinedRectangle(x, y, width, height, ovt, ovb, ovl, ovr) - desc: creates and outlined rectangle @@ -1483,10 +1523,8 @@ function skin.DrawColumnListHeader(object) local width = object:GetWidth() local height = object:GetHeight() local hover = object:GetHover() - local name = object:GetName() local down = object.down local font = skin.controls.columnlistheader_text_font - local twidth = font:getWidth(object.name) local theight = font:getHeight(object.name) local bodydowncolor = skin.controls.columnlistheader_body_down_color local textdowncolor = skin.controls.columnlistheader_text_down_color @@ -1495,6 +1533,9 @@ function skin.DrawColumnListHeader(object) local nohovercolor = skin.controls.columnlistheader_body_nohover_color local textnohovercolor = skin.controls.columnlistheader_text_nohover_color + local name = ParseHeaderText(object:GetName(), x, width, x + width/2, twidth) + local twidth = font:getWidth(name) + if down then local image = skin.images["button-down.png"] local imageheight = image:getHeight() @@ -1508,7 +1549,7 @@ function skin.DrawColumnListHeader(object) love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) -- header border love.graphics.setColor(bordercolor) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + skin.OutlinedRectangle(x, y, width, height) elseif hover then local image = skin.images["button-hover.png"] local imageheight = image:getHeight() @@ -1522,7 +1563,7 @@ function skin.DrawColumnListHeader(object) love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) -- header border love.graphics.setColor(bordercolor) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + skin.OutlinedRectangle(x, y, width, height) else local image = skin.images["button-nohover.png"] local imageheight = image:getHeight() @@ -1536,7 +1577,7 @@ function skin.DrawColumnListHeader(object) love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) -- header border love.graphics.setColor(bordercolor) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + skin.OutlinedRectangle(x, y, width, height) end end @@ -1557,6 +1598,22 @@ function skin.DrawColumnListArea(object) love.graphics.setColor(bodycolor) love.graphics.rectangle("fill", x, y, width, height) + local cheight = 0 + local columns = object:GetParent():GetChildren() + if #columns > 0 then + cheight = columns[1]:GetHeight() + end + + local image = skin.images["button-nohover.png"] + local scaley = cheight/image:getHeight() + + -- header body + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y, 0, width, scaley) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, cheight, true, false, true, true) + end --[[--------------------------------------------------------- @@ -1593,7 +1650,6 @@ function skin.DrawColumnListRow(object) local textx = object:GetTextX() local texty = object:GetTextY() local parent = object:GetParent() - local cwidth, cheight = parent:GetParent():GetColumnSize() local theight = font:getHeight("a") local hover = object:GetHover() local selected = object:GetSelected() @@ -1623,6 +1679,7 @@ function skin.DrawColumnListRow(object) for k, v in ipairs(columndata) do love.graphics.setFont(font) + local text = ParseRowText(v, x, parent.parent:GetColumnWidth(k), x, textx) if selected then love.graphics.setColor(textselectedcolor) elseif hover then @@ -1630,9 +1687,8 @@ function skin.DrawColumnListRow(object) else love.graphics.setColor(textcolor) end - local text = v love.graphics.print(text, x + textx, y + texty) - x = x + cwidth + x = x + parent.parent.children[k]:GetWidth() end end