mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
stuff
This commit is contained in:
@@ -43,24 +43,6 @@ type initializer function will run once when the widget is constructed.
|
|||||||
--]]--
|
--]]--
|
||||||
Attribute.type = {}
|
Attribute.type = {}
|
||||||
|
|
||||||
--[[
|
|
||||||
function Attribute.type.set (widget, value)
|
|
||||||
local oldType = widget.attributes.type
|
|
||||||
|
|
||||||
widget.attributes.type = value
|
|
||||||
|
|
||||||
if value and not widget.hasType then
|
|
||||||
widget.hasType = true
|
|
||||||
local Widget = require(ROOT .. 'widget')
|
|
||||||
local decorate = Widget.typeDecorators[value]
|
|
||||||
|
|
||||||
if decorate then
|
|
||||||
decorate(widget)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--]]
|
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Widget identifier.
|
Widget identifier.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
local RESOURCE = (...):gsub('%.', '/') .. '/'
|
|
||||||
|
|
||||||
return function (config)
|
return function (config)
|
||||||
config = config or {}
|
config = config or {}
|
||||||
local resources = assert(config.resources, 'missing config.resources')
|
local resources = assert(config.resources, 'missing config.resources')
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ Widget.textData = nil
|
|||||||
@section end
|
@section end
|
||||||
--]]--
|
--]]--
|
||||||
|
|
||||||
|
|
||||||
Widget.typeDecorators = {
|
Widget.typeDecorators = {
|
||||||
button = require(ROOT .. 'widget.button'),
|
button = require(ROOT .. 'widget.button'),
|
||||||
check = require(ROOT .. 'widget.check'),
|
check = require(ROOT .. 'widget.check'),
|
||||||
@@ -167,7 +168,7 @@ end
|
|||||||
|
|
||||||
-- setting attributes triggers special behavior
|
-- setting attributes triggers special behavior
|
||||||
local function metaNewIndex (self, property, value)
|
local function metaNewIndex (self, property, value)
|
||||||
local A = self.attributeDescriptors[property] or Attribute[property]
|
local A = self.attributeDescriptors[property]
|
||||||
if A then
|
if A then
|
||||||
if A.set then
|
if A.set then
|
||||||
A.set(self, value, property)
|
A.set(self, value, property)
|
||||||
@@ -186,9 +187,9 @@ end
|
|||||||
local attributeNames = {}
|
local attributeNames = {}
|
||||||
|
|
||||||
for name in pairs(Attribute) do
|
for name in pairs(Attribute) do
|
||||||
if name ~= 'type' then -- type must be handled last
|
--if name ~= 'type' then -- type must be handled last
|
||||||
attributeNames[#attributeNames + 1] = name
|
attributeNames[#attributeNames + 1] = name
|
||||||
end
|
--end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- attributeNames[#attributeNames + 1] = 'type'
|
-- attributeNames[#attributeNames + 1] = 'type'
|
||||||
@@ -241,7 +242,12 @@ end
|
|||||||
|
|
||||||
function Widget:init ()
|
function Widget:init ()
|
||||||
self.initted = true
|
self.initted = true
|
||||||
-- [[
|
for _, name in pairs(attributeNames) do
|
||||||
|
if not self.attributeDescriptors[name] then
|
||||||
|
self:defineAttribute(name, Attribute[name])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--[[
|
||||||
for _, property in ipairs(attributeNames) do
|
for _, property in ipairs(attributeNames) do
|
||||||
if not self.attributeDescriptors[key] then
|
if not self.attributeDescriptors[key] then
|
||||||
local value = rawget(self, property)
|
local value = rawget(self, property)
|
||||||
@@ -282,14 +288,12 @@ A table, optionally containing `get` and `set` functions (see `Attribute`).
|
|||||||
Return this widget for chaining.
|
Return this widget for chaining.
|
||||||
--]]--
|
--]]--
|
||||||
function Widget:defineAttribute (name, descriptor)
|
function Widget:defineAttribute (name, descriptor)
|
||||||
|
local descriptors = self.attributeDescriptors
|
||||||
|
assert(not descriptors[name], 'attribute already defined')
|
||||||
local value = rawget(self, name)
|
local value = rawget(self, name)
|
||||||
if value == nil then value = self.attributes[name] end
|
|
||||||
self.attributeDescriptors[name] = descriptor or {}
|
|
||||||
--[[
|
|
||||||
rawset(self, name, nil)
|
rawset(self, name, nil)
|
||||||
self.attributes[name] = nil
|
descriptors[name] = descriptor
|
||||||
self[name] = value
|
self[name] = value
|
||||||
--]]
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -449,8 +453,9 @@ end
|
|||||||
|
|
||||||
function Widget:calculateDimension (name)
|
function Widget:calculateDimension (name)
|
||||||
-- If dimensions are already calculated, return them.
|
-- If dimensions are already calculated, return them.
|
||||||
if self.dimensions[name] then
|
local dim = self.dimensions
|
||||||
return self.dimensions[name]
|
if dim[name] then
|
||||||
|
return dim[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get minimum width/height from attributes.
|
-- Get minimum width/height from attributes.
|
||||||
@@ -461,13 +466,13 @@ function Widget:calculateDimension (name)
|
|||||||
if self[name] then
|
if self[name] then
|
||||||
-- and if width/height is "auto" then shrink to fit content
|
-- and if width/height is "auto" then shrink to fit content
|
||||||
if self[name] == 'auto' then
|
if self[name] == 'auto' then
|
||||||
self.dimensions[name] = self:calculateDimensionMinimum(name)
|
dim[name] = self:calculateDimensionMinimum(name)
|
||||||
return self.dimensions[name]
|
return dim[name]
|
||||||
end
|
end
|
||||||
-- else width/height should be a number; use that value,
|
-- else width/height should be a number; use that value,
|
||||||
-- clamped to minimum.
|
-- clamped to minimum.
|
||||||
self.dimensions[name] = math.max(self[name], min)
|
dim[name] = math.max(self[name], min)
|
||||||
return self.dimensions[name]
|
return dim[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If the widget is a layout root (and has no width/height),
|
-- If the widget is a layout root (and has no width/height),
|
||||||
@@ -476,8 +481,8 @@ function Widget:calculateDimension (name)
|
|||||||
if not parent then
|
if not parent then
|
||||||
local windowWidth, windowHeight = Backend.getWindowSize()
|
local windowWidth, windowHeight = Backend.getWindowSize()
|
||||||
local size = name == 'width' and windowWidth or windowHeight
|
local size = name == 'width' and windowWidth or windowHeight
|
||||||
self.dimensions[name] = size
|
dim[name] = size
|
||||||
return self.dimensions[name]
|
return dim[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Widgets expand to fit their parents when no width/height is specified.
|
-- Widgets expand to fit their parents when no width/height is specified.
|
||||||
@@ -491,8 +496,8 @@ function Widget:calculateDimension (name)
|
|||||||
local parentFlow = parent.flow or 'y'
|
local parentFlow = parent.flow or 'y'
|
||||||
if (parentFlow ~= 'x' and name == 'width')
|
if (parentFlow ~= 'x' and name == 'width')
|
||||||
or (parentFlow == 'x' and name == 'height') then
|
or (parentFlow == 'x' and name == 'height') then
|
||||||
self.dimensions[name] = math.max(parentDimension, min)
|
dim[name] = math.max(parentDimension, min)
|
||||||
return self.dimensions[name]
|
return dim[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If the dimension is in the same direction as the parent flow
|
-- If the dimension is in the same direction as the parent flow
|
||||||
@@ -520,7 +525,7 @@ function Widget:calculateDimension (name)
|
|||||||
local size = (parentDimension - claimed) / unsized
|
local size = (parentDimension - claimed) / unsized
|
||||||
|
|
||||||
size = math.max(size, min)
|
size = math.max(size, min)
|
||||||
self.dimensions[name] = size
|
dim[name] = size
|
||||||
return size
|
return size
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -826,7 +831,8 @@ function Widget:scrollBy (amount)
|
|||||||
local scrollX = self.scrollX - amount * 10
|
local scrollX = self.scrollX - amount * 10
|
||||||
local inner = math.max(self:getContentWidth(), self.innerWidth or 0)
|
local inner = math.max(self:getContentWidth(), self.innerWidth or 0)
|
||||||
local maxX = inner - self:getWidth()
|
local maxX = inner - self:getWidth()
|
||||||
+ (self.padding or 0) * 2 + (self.margin or 0) * 2
|
+ (self.padding or 0) * 2
|
||||||
|
+ (self.margin or 0) * 2
|
||||||
scrollX = math.max(math.min(scrollX, maxX), 0)
|
scrollX = math.max(math.min(scrollX, maxX), 0)
|
||||||
if scrollX ~= self.scrollX then
|
if scrollX ~= self.scrollX then
|
||||||
self.scrollX = scrollX
|
self.scrollX = scrollX
|
||||||
@@ -838,7 +844,8 @@ function Widget:scrollBy (amount)
|
|||||||
local scrollY = self.scrollY - amount * 10
|
local scrollY = self.scrollY - amount * 10
|
||||||
local inner = math.max(self:getContentHeight(), self.innerHeight or 0)
|
local inner = math.max(self:getContentHeight(), self.innerHeight or 0)
|
||||||
local maxY = inner - self:getHeight()
|
local maxY = inner - self:getHeight()
|
||||||
+ (self.padding or 0) * 2 + (self.margin or 0) * 2
|
+ (self.padding or 0) * 2
|
||||||
|
+ (self.margin or 0) * 2
|
||||||
scrollY = math.max(math.min(scrollY, maxY), 0)
|
scrollY = math.max(math.min(scrollY, maxY), 0)
|
||||||
if scrollY ~= self.scrollY then
|
if scrollY ~= self.scrollY then
|
||||||
self.scrollY = scrollY
|
self.scrollY = scrollY
|
||||||
|
|||||||
Reference in New Issue
Block a user