attrib fixup wip

This commit is contained in:
nobody
2016-02-17 18:33:52 -05:00
parent bd9e142456
commit 352027a9bf
9 changed files with 48 additions and 16 deletions

View File

@@ -43,6 +43,7 @@ type initializer function will run once when the widget is constructed.
--]]--
Attribute.type = {}
--[[
function Attribute.type.set (widget, value)
local oldType = widget.attributes.type
@@ -58,6 +59,7 @@ function Attribute.type.set (widget, value)
end
end
end
--]]
--[[--
Widget identifier.

View File

@@ -191,7 +191,7 @@ for name in pairs(Attribute) do
end
end
attributeNames[#attributeNames + 1] = 'type'
-- attributeNames[#attributeNames + 1] = 'type'
--[[--
Widget pseudo-constructor.
@@ -221,13 +221,16 @@ local function metaCall (Widget, layout, self)
self.painter = Painter(self)
setmetatable(self, { __index = metaIndex, __newindex = metaNewIndex })
local decorate = Widget.typeDecorators[self.type]
for _, property in ipairs(attributeNames) do
local value = rawget(self, property)
rawset(self, property, nil)
self[property] = value
if decorate then
decorate(self)
end
if not self.initted then
self:init()
end
for k, v in ipairs(self) do
self[k] = v.isWidget and v or metaCall(Widget, self.layout, v)
self[k].parent = self
@@ -236,6 +239,28 @@ local function metaCall (Widget, layout, self)
return self
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 ()
return self.layout.master or self.layout
end
@@ -260,9 +285,11 @@ function Widget:defineAttribute (name, descriptor)
local value = rawget(self, name)
if value == nil then value = self.attributes[name] end
self.attributeDescriptors[name] = descriptor or {}
--[[
rawset(self, name, nil)
self.attributes[name] = nil
self[name] = value
--]]
return self
end

View File

@@ -26,5 +26,4 @@ layout:show()
--]]--
return function (self)
end

View File

@@ -232,6 +232,7 @@ local function createLayout (self)
end
return function (self)
self:init()
extractChildren(self)
initialize(self)
registerEvents(self)

View File

@@ -8,8 +8,6 @@ between 0 and 1 (inclusive) to change the width of the bar.
--]]--
return function (self)
self.value = self.value or 0
local pad = self:addChild {
width = 0,
}
@@ -24,10 +22,11 @@ return function (self)
self:onReshape(function ()
local x1, y1, w, h = self:getRectangle(true, true)
local x2, y2 = x1 + w, y1 + h
local value = self.value or 0
if self.flow == 'x' then
local min = bar.minwidth or 0
x1 = x1 + min
bar.width = self.value * (x2 - x1) + min
bar.width = value * (x2 - x1) + min
bar.height = false
pad.height = 0
else
@@ -35,7 +34,7 @@ return function (self)
y1 = y1 + min
bar.width = 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

View File

@@ -46,7 +46,6 @@ local function setGroup (self, value)
end
return function (self)
--[[--
Special Attributes
@@ -89,6 +88,8 @@ in the same group change to `false`.
if not self.value then return false end
self.groupWidget.selected = self
end)
self:init()
self.value = not not self.value
end

View File

@@ -8,11 +8,11 @@ number between 0 and 1, inclusive.
--]]--
return function (self)
local function clamp (value)
return value < 0 and 0 or value > 1 and 1 or value
end
self.value = clamp(self.value or 0)
self.step = self.step or 0.01
local spacer = self:addChild()
@@ -73,16 +73,17 @@ return function (self)
self:onReshape(function (event)
local x1, y1, w, h = self:getRectangle(true, true)
local x2, y2 = x1 + w, y1 + h
local value = self.value or 0
if self.flow == 'x' then
local halfThumb = thumb:getWidth() / 2
x1, x2 = x1 + halfThumb, x2 - halfThumb
spacer.width = self.value * (x2 - x1)
spacer.width = value * (x2 - x1)
spacer.height = false
else
local halfThumb = thumb:getHeight() / 2
y1, y2 = y1 + halfThumb, y2 - halfThumb
spacer.width = false
spacer.height = (1 - self.value) * (y2 - y1)
spacer.height = (1 - value) * (y2 - y1)
end
end)
end

View File

@@ -346,6 +346,8 @@ local function isKeyTextInput (key)
end
return function (self)
self:init()
self.startIndex, self.endIndex = 0, 0
self.startX, self.endX = -1, -1
self.scrollX = 0

View File

@@ -26,7 +26,7 @@ end)
-- show the window
window:show()
z
@widget window
--]]--