improve auto dimensions

This commit is contained in:
airstruck
2015-12-09 13:33:45 -05:00
parent 5e6cd8c29e
commit bcfed7b737
5 changed files with 47 additions and 19 deletions

View File

@@ -298,7 +298,14 @@ Minimum width.
Attribute.minwidth = {}
function Attribute.minwidth.set (widget, value)
widget.attributes.minwidth = value
local attributes = widget.attributes
attributes.minwidth = value
if type(value) == 'number' then
local current = attributes.width
if type(current) == 'number' then
attributes.width = math.max(current, value)
end
end
widget.reshape(widget.parent or widget)
end
@@ -310,7 +317,14 @@ Minimum height.
Attribute.minheight = {}
function Attribute.minheight.set (widget, value)
widget.attributes.minheight = value
local attributes = widget.attributes
attributes.minheight = value
if type(value) == 'number' then
local current = attributes.height
if type(current) == 'number' then
attributes.height = math.max(current, value)
end
end
widget.reshape(widget.parent or widget)
end

View File

@@ -98,7 +98,8 @@ return function (config)
type = 'control',
background = backColor,
padding = 4,
align = 'left middle',
align = 'left bottom',
height = 14,
},
menu = {
height = 24,

View File

@@ -347,7 +347,9 @@ function Widget:calculateDimension (name)
end
claimed = claimed + widget.dimensions[name]
elseif value then
claimed = claimed + value
local min = (name == 'width') and (widget.minwidth or 0)
or (widget.minheight or 0)
claimed = claimed + math.max(value, min)
else
unsized = unsized + 1
end
@@ -416,9 +418,15 @@ function Widget:calculatePosition (axis)
end
function Widget:calculateDimensionMinimum (name)
local space = (self.margin or 0) * 2 + (self.padding or 0) * 2
local min = name == 'width' and 'minwidth' or 'minheight'
local value = space
local dim = self[name]
local min = (name == 'width') and (self.minwidth or 0)
or (self.minheight or 0)
if type(dim) == 'number' then
return math.max(dim, min)
end
local value = 0
for _, child in ipairs(self) do
if (name == 'width' and self.flow == 'x')
@@ -428,9 +436,13 @@ function Widget:calculateDimensionMinimum (name)
value = math.max(value, child:calculateDimensionMinimum(name))
end
end
local dim = self[name]
dim = type(dim) == 'number' and dim
return math.max(value, dim or 0, self[min] or 0)
if value > 0 then
local space = (self.margin or 0) * 2 + (self.padding or 0) * 2
value = value + space
end
return math.max(value, min)
end
--[[--