mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-10 08:18:22 +00:00
width/height shadow properties
This commit is contained in:
@@ -46,7 +46,7 @@ local mainForm = { title = "Test window", id = 'mainWindow', type = 'panel',
|
|||||||
icon = 'icon/32px/Harddrive.png' },
|
icon = 'icon/32px/Harddrive.png' },
|
||||||
},
|
},
|
||||||
{ flow = 'x',
|
{ flow = 'x',
|
||||||
{ id = 'leftSideBox', width = 200,
|
{ id = 'leftSideBox', width = 200, minwidth = 64,
|
||||||
{ text = 'Hi, I\'m centered middle. ', style = 'listThing',
|
{ text = 'Hi, I\'m centered middle. ', style = 'listThing',
|
||||||
align = 'middle center' },
|
align = 'middle center' },
|
||||||
{ text = 'Hi, I\'m centered bottom. ', style = 'listThing',
|
{ 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, },
|
{ type = 'sash', width = 4, },
|
||||||
{ id = 'mainCanvas' },
|
{ id = 'mainCanvas' },
|
||||||
{ type = 'sash', width = 4, },
|
{ 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 = 'panel', text = 'A slider', align = 'bottom', height = 24, padding = 4 },
|
||||||
{ type = 'slider', height = 32, margin = 4, id = 'slidey', value = 0 },
|
{ type = 'slider', height = 32, margin = 4, id = 'slidey', value = 0 },
|
||||||
{ type = 'panel', text = 'A stepper', align = 'bottom', height = 24, padding = 4 },
|
{ type = 'panel', text = 'A stepper', align = 'bottom', height = 24, padding = 4 },
|
||||||
@@ -113,6 +113,7 @@ end)
|
|||||||
|
|
||||||
layout.aButton:onPress(function (event)
|
layout.aButton:onPress(function (event)
|
||||||
layout.aButton.font = nil
|
layout.aButton.font = nil
|
||||||
|
layout.aButton.width = layout.aButton.width + 10
|
||||||
end)
|
end)
|
||||||
|
|
||||||
layout.mainCanvas.font = 'font/liberation/LiberationMono-Regular.ttf'
|
layout.mainCanvas.font = 'font/liberation/LiberationMono-Regular.ttf'
|
||||||
|
|||||||
@@ -154,7 +154,6 @@ function Input:handleReshape (width, height)
|
|||||||
|
|
||||||
root.width = width
|
root.width = width
|
||||||
root.height = height
|
root.height = height
|
||||||
root:reshape()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Input
|
return Input
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ return function (config)
|
|||||||
align = 'center middle',
|
align = 'center middle',
|
||||||
padding = 6,
|
padding = 6,
|
||||||
slices = RESOURCE .. 'button.png',
|
slices = RESOURCE .. 'button.png',
|
||||||
minimumWidth = 24,
|
minwidth = 24,
|
||||||
minimumHeight = 24,
|
minheight = 24,
|
||||||
canFocus = true
|
canFocus = true
|
||||||
},
|
},
|
||||||
button_hovered = {
|
button_hovered = {
|
||||||
@@ -34,8 +34,8 @@ return function (config)
|
|||||||
slider = {
|
slider = {
|
||||||
slices = RESOURCE .. 'button_pressed.png',
|
slices = RESOURCE .. 'button_pressed.png',
|
||||||
padding = 0,
|
padding = 0,
|
||||||
minimumWidth = 24,
|
minwidth = 24,
|
||||||
minimumHeight = 24
|
minheight = 24
|
||||||
},
|
},
|
||||||
panel = {
|
panel = {
|
||||||
background = backColor,
|
background = backColor,
|
||||||
@@ -43,13 +43,13 @@ return function (config)
|
|||||||
progress = {
|
progress = {
|
||||||
slices = RESOURCE .. 'button_pressed.png',
|
slices = RESOURCE .. 'button_pressed.png',
|
||||||
padding = 0,
|
padding = 0,
|
||||||
minimumWidth = 24,
|
minwidth = 24,
|
||||||
minimumHeight = 24
|
minheight = 24
|
||||||
},
|
},
|
||||||
progressInner = {
|
progressInner = {
|
||||||
slices = RESOURCE .. 'progress.png',
|
slices = RESOURCE .. 'progress.png',
|
||||||
padding = 0,
|
padding = 0,
|
||||||
minimumWidth = 12,
|
minwidth = 12,
|
||||||
},
|
},
|
||||||
slider_hovered = {
|
slider_hovered = {
|
||||||
},
|
},
|
||||||
@@ -59,8 +59,8 @@ return function (config)
|
|||||||
align = 'left middle',
|
align = 'left middle',
|
||||||
slices = RESOURCE .. 'text.png',
|
slices = RESOURCE .. 'text.png',
|
||||||
padding = 6,
|
padding = 6,
|
||||||
minimumWidth = 24,
|
minwidth = 24,
|
||||||
minimumHeight = 24,
|
minheight = 24,
|
||||||
canFocus = true,
|
canFocus = true,
|
||||||
cursor = 'ibeam',
|
cursor = 'ibeam',
|
||||||
highlight = highlight,
|
highlight = highlight,
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ local function new (Widget, layout, self)
|
|||||||
self.dimensions = { width = nil, height = nil }
|
self.dimensions = { width = nil, height = nil }
|
||||||
self.shadowProperties = {}
|
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.shadowProperties[property] = self[property]
|
||||||
self[property] = nil
|
self[property] = nil
|
||||||
end
|
end
|
||||||
@@ -54,11 +55,17 @@ local function new (Widget, layout, self)
|
|||||||
if property == 'font'
|
if property == 'font'
|
||||||
or property == 'fontSize'
|
or property == 'fontSize'
|
||||||
or property == 'textColor' then
|
or property == 'textColor' then
|
||||||
rawset(self.shadowProperties, property, value)
|
self.shadowProperties[property] = value
|
||||||
self.fontData = Font(self.font, self.fontSize, self.textColor)
|
self.fontData = Font(self.font, self.fontSize, self.textColor)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if property == 'width' or property == 'height' then
|
||||||
|
self.shadowProperties[property] = value
|
||||||
|
;(self.parent or self):reshape()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
rawset(self, property, value)
|
rawset(self, property, value)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@@ -138,8 +145,8 @@ function Widget:calculateDimension (name)
|
|||||||
return self.dimensions[name]
|
return self.dimensions[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
local min = (name == 'width') and (self.minimumWidth or 0)
|
local min = (name == 'width') and (self.minwidth or 0)
|
||||||
or (self.minimumHeight or 0)
|
or (self.minheight or 0)
|
||||||
|
|
||||||
local max = name == 'width' and love.graphics.getWidth()
|
local max = name == 'width' and love.graphics.getWidth()
|
||||||
or love.graphics.getHeight()
|
or love.graphics.getHeight()
|
||||||
@@ -232,6 +239,10 @@ function Widget:getHeight ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Widget:setDimension (name, size)
|
function Widget:setDimension (name, size)
|
||||||
|
if not self.parent then
|
||||||
|
self[name] = size
|
||||||
|
return
|
||||||
|
end
|
||||||
local parentDimension = self.parent:calculateDimension(name)
|
local parentDimension = self.parent:calculateDimension(name)
|
||||||
local claimed = 0
|
local claimed = 0
|
||||||
for i, widget in ipairs(self.parent.children) do
|
for i, widget in ipairs(self.parent.children) do
|
||||||
@@ -242,7 +253,11 @@ function Widget:setDimension (name, size)
|
|||||||
if claimed + size > parentDimension then
|
if claimed + size > parentDimension then
|
||||||
size = parentDimension - claimed
|
size = parentDimension - claimed
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function Widget:setWidth (size)
|
function Widget:setWidth (size)
|
||||||
@@ -297,6 +312,8 @@ end
|
|||||||
|
|
||||||
-- reshape the widget. Call this after changing position/dimensions.
|
-- reshape the widget. Call this after changing position/dimensions.
|
||||||
function Widget:reshape ()
|
function Widget:reshape ()
|
||||||
|
if self.isReshaping then return end
|
||||||
|
self.isReshaping = true
|
||||||
self.position = {}
|
self.position = {}
|
||||||
self.dimensions = {}
|
self.dimensions = {}
|
||||||
Event.Reshape:emit(self, {
|
Event.Reshape:emit(self, {
|
||||||
@@ -305,6 +322,7 @@ function Widget:reshape ()
|
|||||||
for i, widget in ipairs(self.children) do
|
for i, widget in ipairs(self.children) do
|
||||||
widget:reshape()
|
widget:reshape()
|
||||||
end
|
end
|
||||||
|
self.isReshaping = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(Widget, { __call = new })
|
return setmetatable(Widget, { __call = new })
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ return function (self)
|
|||||||
|
|
||||||
self:onReshape(function ()
|
self:onReshape(function ()
|
||||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||||
local min = bar.minimumWidth
|
local min = bar.minwidth
|
||||||
x1 = x1 + min
|
x1 = x1 + min
|
||||||
bar.width = self.value * (x2 - x1) + min
|
bar.width = self.value * (x2 - x1) + min
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ return function (self)
|
|||||||
local nextSibling = self:getNext()
|
local nextSibling = self:getNext()
|
||||||
local prevSize = prevSibling and prevSibling[dimension]
|
local prevSize = prevSibling and prevSibling[dimension]
|
||||||
local nextSize = nextSibling and nextSibling[dimension]
|
local nextSize = nextSibling and nextSibling[dimension]
|
||||||
|
|
||||||
if prevSize then
|
if prevSize then
|
||||||
prevSibling:setDimension(dimension,
|
prevSibling:setDimension(dimension,
|
||||||
event[axis] - prevSibling:calculatePosition(axis))
|
event[axis] - prevSibling:calculatePosition(axis))
|
||||||
@@ -28,12 +29,9 @@ return function (self)
|
|||||||
if nextSize then
|
if nextSize then
|
||||||
nextSibling:setDimension(dimension,
|
nextSibling:setDimension(dimension,
|
||||||
nextSibling:calculatePosition(axis) +
|
nextSibling:calculatePosition(axis) +
|
||||||
nextSibling[dimension] - event[axis])
|
nextSibling:calculateDimension(dimension) - event[axis])
|
||||||
end
|
end
|
||||||
|
|
||||||
prevSibling:reshape()
|
|
||||||
nextSibling:reshape()
|
|
||||||
self:reshape()
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user