width/height shadow properties

This commit is contained in:
airstruck
2015-11-03 01:08:23 -05:00
parent 997f9c8d12
commit ad9c954e7b
6 changed files with 38 additions and 22 deletions

View File

@@ -46,7 +46,7 @@ local mainForm = { title = "Test window", id = 'mainWindow', type = 'panel',
icon = 'icon/32px/Harddrive.png' },
},
{ flow = 'x',
{ id = 'leftSideBox', width = 200,
{ id = 'leftSideBox', width = 200, minwidth = 64,
{ text = 'Hi, I\'m centered middle. ', style = 'listThing',
align = 'middle center' },
{ text = 'Hi, I\'m centered bottom. ', style = 'listThing',
@@ -58,7 +58,7 @@ local mainForm = { title = "Test window", id = 'mainWindow', type = 'panel',
{ type = 'sash', width = 4, },
{ id = 'mainCanvas' },
{ type = 'sash', width = 4, },
{ type = 'panel', id = 'rightSideBox', width = 200,
{ type = 'panel', id = 'rightSideBox', width = 200, minwidth = 64,
{ type = 'panel', text = 'A slider', align = 'bottom', height = 24, padding = 4 },
{ type = 'slider', height = 32, margin = 4, id = 'slidey', value = 0 },
{ type = 'panel', text = 'A stepper', align = 'bottom', height = 24, padding = 4 },
@@ -113,6 +113,7 @@ end)
layout.aButton:onPress(function (event)
layout.aButton.font = nil
layout.aButton.width = layout.aButton.width + 10
end)
layout.mainCanvas.font = 'font/liberation/LiberationMono-Regular.ttf'

View File

@@ -154,7 +154,6 @@ function Input:handleReshape (width, height)
root.width = width
root.height = height
root:reshape()
end
return Input

View File

@@ -12,8 +12,8 @@ return function (config)
align = 'center middle',
padding = 6,
slices = RESOURCE .. 'button.png',
minimumWidth = 24,
minimumHeight = 24,
minwidth = 24,
minheight = 24,
canFocus = true
},
button_hovered = {
@@ -34,8 +34,8 @@ return function (config)
slider = {
slices = RESOURCE .. 'button_pressed.png',
padding = 0,
minimumWidth = 24,
minimumHeight = 24
minwidth = 24,
minheight = 24
},
panel = {
background = backColor,
@@ -43,13 +43,13 @@ return function (config)
progress = {
slices = RESOURCE .. 'button_pressed.png',
padding = 0,
minimumWidth = 24,
minimumHeight = 24
minwidth = 24,
minheight = 24
},
progressInner = {
slices = RESOURCE .. 'progress.png',
padding = 0,
minimumWidth = 12,
minwidth = 12,
},
slider_hovered = {
},
@@ -59,8 +59,8 @@ return function (config)
align = 'left middle',
slices = RESOURCE .. 'text.png',
padding = 6,
minimumWidth = 24,
minimumHeight = 24,
minwidth = 24,
minheight = 24,
canFocus = true,
cursor = 'ibeam',
highlight = highlight,

View File

@@ -30,7 +30,8 @@ local function new (Widget, layout, self)
self.dimensions = { width = nil, height = nil }
self.shadowProperties = {}
for _, property in ipairs { 'font', 'fontSize', 'textColor' } do
for _, property
in ipairs { 'font', 'fontSize', 'textColor', 'width', 'height' } do
self.shadowProperties[property] = self[property]
self[property] = nil
end
@@ -54,11 +55,17 @@ local function new (Widget, layout, self)
if property == 'font'
or property == 'fontSize'
or property == 'textColor' then
rawset(self.shadowProperties, property, value)
self.shadowProperties[property] = value
self.fontData = Font(self.font, self.fontSize, self.textColor)
return
end
if property == 'width' or property == 'height' then
self.shadowProperties[property] = value
;(self.parent or self):reshape()
return
end
rawset(self, property, value)
end
})
@@ -138,8 +145,8 @@ function Widget:calculateDimension (name)
return self.dimensions[name]
end
local min = (name == 'width') and (self.minimumWidth or 0)
or (self.minimumHeight or 0)
local min = (name == 'width') and (self.minwidth or 0)
or (self.minheight or 0)
local max = name == 'width' and love.graphics.getWidth()
or love.graphics.getHeight()
@@ -232,6 +239,10 @@ function Widget:getHeight ()
end
function Widget:setDimension (name, size)
if not self.parent then
self[name] = size
return
end
local parentDimension = self.parent:calculateDimension(name)
local claimed = 0
for i, widget in ipairs(self.parent.children) do
@@ -242,7 +253,11 @@ function Widget:setDimension (name, size)
if claimed + size > parentDimension then
size = parentDimension - claimed
end
self[name] = size
local min = (name == 'width') and (self.minwidth or 0)
or (self.minheight or 0)
self[name] = math.max(size, min)
end
function Widget:setWidth (size)
@@ -297,6 +312,8 @@ end
-- reshape the widget. Call this after changing position/dimensions.
function Widget:reshape ()
if self.isReshaping then return end
self.isReshaping = true
self.position = {}
self.dimensions = {}
Event.Reshape:emit(self, {
@@ -305,6 +322,7 @@ function Widget:reshape ()
for i, widget in ipairs(self.children) do
widget:reshape()
end
self.isReshaping = nil
end
return setmetatable(Widget, { __call = new })

View File

@@ -13,7 +13,7 @@ return function (self)
self:onReshape(function ()
local x1, y1, x2, y2 = self:getRectangle(true, true)
local min = bar.minimumWidth
local min = bar.minwidth
x1 = x1 + min
bar.width = self.value * (x2 - x1) + min
end)

View File

@@ -21,6 +21,7 @@ return function (self)
local nextSibling = self:getNext()
local prevSize = prevSibling and prevSibling[dimension]
local nextSize = nextSibling and nextSibling[dimension]
if prevSize then
prevSibling:setDimension(dimension,
event[axis] - prevSibling:calculatePosition(axis))
@@ -28,12 +29,9 @@ return function (self)
if nextSize then
nextSibling:setDimension(dimension,
nextSibling:calculatePosition(axis) +
nextSibling[dimension] - event[axis])
nextSibling:calculateDimension(dimension) - event[axis])
end
prevSibling:reshape()
nextSibling:reshape()
self:reshape()
end)
end