mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-10 08:18:22 +00:00
attrib fixup wip
This commit is contained in:
@@ -43,6 +43,7 @@ type initializer function will run once when the widget is constructed.
|
|||||||
--]]--
|
--]]--
|
||||||
Attribute.type = {}
|
Attribute.type = {}
|
||||||
|
|
||||||
|
--[[
|
||||||
function Attribute.type.set (widget, value)
|
function Attribute.type.set (widget, value)
|
||||||
local oldType = widget.attributes.type
|
local oldType = widget.attributes.type
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ function Attribute.type.set (widget, value)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--]]
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Widget identifier.
|
Widget identifier.
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ for name in pairs(Attribute) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attributeNames[#attributeNames + 1] = 'type'
|
-- attributeNames[#attributeNames + 1] = 'type'
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Widget pseudo-constructor.
|
Widget pseudo-constructor.
|
||||||
@@ -221,13 +221,16 @@ local function metaCall (Widget, layout, self)
|
|||||||
self.painter = Painter(self)
|
self.painter = Painter(self)
|
||||||
|
|
||||||
setmetatable(self, { __index = metaIndex, __newindex = metaNewIndex })
|
setmetatable(self, { __index = metaIndex, __newindex = metaNewIndex })
|
||||||
|
|
||||||
|
local decorate = Widget.typeDecorators[self.type]
|
||||||
|
|
||||||
for _, property in ipairs(attributeNames) do
|
if decorate then
|
||||||
local value = rawget(self, property)
|
decorate(self)
|
||||||
rawset(self, property, nil)
|
|
||||||
self[property] = value
|
|
||||||
end
|
end
|
||||||
|
if not self.initted then
|
||||||
|
self:init()
|
||||||
|
end
|
||||||
|
|
||||||
for k, v in ipairs(self) do
|
for k, v in ipairs(self) do
|
||||||
self[k] = v.isWidget and v or metaCall(Widget, self.layout, v)
|
self[k] = v.isWidget and v or metaCall(Widget, self.layout, v)
|
||||||
self[k].parent = self
|
self[k].parent = self
|
||||||
@@ -236,6 +239,28 @@ local function metaCall (Widget, layout, self)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Widget:init ()
|
||||||
|
self.initted = true
|
||||||
|
-- [[
|
||||||
|
for _, property in ipairs(attributeNames) do
|
||||||
|
if not self.attributeDescriptors[key] then
|
||||||
|
local value = rawget(self, property)
|
||||||
|
rawset(self, property, nil)
|
||||||
|
self[property] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for property in pairs(self.attributeDescriptors) do
|
||||||
|
local value = rawget(self, property)
|
||||||
|
rawset(self, property, nil)
|
||||||
|
self[property] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
local value = rawget(self, 'type')
|
||||||
|
rawset(self, 'type', nil)
|
||||||
|
self.type = value
|
||||||
|
--]]
|
||||||
|
end
|
||||||
|
|
||||||
function Widget:getMasterLayout ()
|
function Widget:getMasterLayout ()
|
||||||
return self.layout.master or self.layout
|
return self.layout.master or self.layout
|
||||||
end
|
end
|
||||||
@@ -260,9 +285,11 @@ function Widget:defineAttribute (name, descriptor)
|
|||||||
local value = rawget(self, name)
|
local value = rawget(self, name)
|
||||||
if value == nil then value = self.attributes[name] end
|
if value == nil then value = self.attributes[name] end
|
||||||
self.attributeDescriptors[name] = descriptor or {}
|
self.attributeDescriptors[name] = descriptor or {}
|
||||||
|
--[[
|
||||||
rawset(self, name, nil)
|
rawset(self, name, nil)
|
||||||
self.attributes[name] = nil
|
self.attributes[name] = nil
|
||||||
self[name] = value
|
self[name] = value
|
||||||
|
--]]
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,5 +26,4 @@ layout:show()
|
|||||||
--]]--
|
--]]--
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ local function createLayout (self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
|
self:init()
|
||||||
extractChildren(self)
|
extractChildren(self)
|
||||||
initialize(self)
|
initialize(self)
|
||||||
registerEvents(self)
|
registerEvents(self)
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ between 0 and 1 (inclusive) to change the width of the bar.
|
|||||||
--]]--
|
--]]--
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
self.value = self.value or 0
|
|
||||||
|
|
||||||
local pad = self:addChild {
|
local pad = self:addChild {
|
||||||
width = 0,
|
width = 0,
|
||||||
}
|
}
|
||||||
@@ -24,10 +22,11 @@ return function (self)
|
|||||||
self:onReshape(function ()
|
self:onReshape(function ()
|
||||||
local x1, y1, w, h = self:getRectangle(true, true)
|
local x1, y1, w, h = self:getRectangle(true, true)
|
||||||
local x2, y2 = x1 + w, y1 + h
|
local x2, y2 = x1 + w, y1 + h
|
||||||
|
local value = self.value or 0
|
||||||
if self.flow == 'x' then
|
if self.flow == 'x' then
|
||||||
local min = bar.minwidth or 0
|
local min = bar.minwidth or 0
|
||||||
x1 = x1 + min
|
x1 = x1 + min
|
||||||
bar.width = self.value * (x2 - x1) + min
|
bar.width = value * (x2 - x1) + min
|
||||||
bar.height = false
|
bar.height = false
|
||||||
pad.height = 0
|
pad.height = 0
|
||||||
else
|
else
|
||||||
@@ -35,7 +34,7 @@ return function (self)
|
|||||||
y1 = y1 + min
|
y1 = y1 + min
|
||||||
bar.width = false
|
bar.width = false
|
||||||
bar.height = false
|
bar.height = false
|
||||||
pad.height = math.ceil(h - (self.value * (y2 - y1) + min))
|
pad.height = math.ceil(h - (value * (y2 - y1) + min))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ local function setGroup (self, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Special Attributes
|
Special Attributes
|
||||||
|
|
||||||
@@ -89,6 +88,8 @@ in the same group change to `false`.
|
|||||||
if not self.value then return false end
|
if not self.value then return false end
|
||||||
self.groupWidget.selected = self
|
self.groupWidget.selected = self
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
self:init()
|
||||||
|
|
||||||
self.value = not not self.value
|
self.value = not not self.value
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ number between 0 and 1, inclusive.
|
|||||||
--]]--
|
--]]--
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
|
|
||||||
local function clamp (value)
|
local function clamp (value)
|
||||||
return value < 0 and 0 or value > 1 and 1 or value
|
return value < 0 and 0 or value > 1 and 1 or value
|
||||||
end
|
end
|
||||||
|
|
||||||
self.value = clamp(self.value or 0)
|
|
||||||
self.step = self.step or 0.01
|
self.step = self.step or 0.01
|
||||||
|
|
||||||
local spacer = self:addChild()
|
local spacer = self:addChild()
|
||||||
@@ -73,16 +73,17 @@ return function (self)
|
|||||||
self:onReshape(function (event)
|
self:onReshape(function (event)
|
||||||
local x1, y1, w, h = self:getRectangle(true, true)
|
local x1, y1, w, h = self:getRectangle(true, true)
|
||||||
local x2, y2 = x1 + w, y1 + h
|
local x2, y2 = x1 + w, y1 + h
|
||||||
|
local value = self.value or 0
|
||||||
if self.flow == 'x' then
|
if self.flow == 'x' then
|
||||||
local halfThumb = thumb:getWidth() / 2
|
local halfThumb = thumb:getWidth() / 2
|
||||||
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
||||||
spacer.width = self.value * (x2 - x1)
|
spacer.width = value * (x2 - x1)
|
||||||
spacer.height = false
|
spacer.height = false
|
||||||
else
|
else
|
||||||
local halfThumb = thumb:getHeight() / 2
|
local halfThumb = thumb:getHeight() / 2
|
||||||
y1, y2 = y1 + halfThumb, y2 - halfThumb
|
y1, y2 = y1 + halfThumb, y2 - halfThumb
|
||||||
spacer.width = false
|
spacer.width = false
|
||||||
spacer.height = (1 - self.value) * (y2 - y1)
|
spacer.height = (1 - value) * (y2 - y1)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -346,6 +346,8 @@ local function isKeyTextInput (key)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
|
self:init()
|
||||||
|
|
||||||
self.startIndex, self.endIndex = 0, 0
|
self.startIndex, self.endIndex = 0, 0
|
||||||
self.startX, self.endX = -1, -1
|
self.startX, self.endX = -1, -1
|
||||||
self.scrollX = 0
|
self.scrollX = 0
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ end)
|
|||||||
|
|
||||||
-- show the window
|
-- show the window
|
||||||
window:show()
|
window:show()
|
||||||
|
z
|
||||||
@widget window
|
@widget window
|
||||||
--]]--
|
--]]--
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user