mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-10 08:18:22 +00:00
add status widget and attribute
This commit is contained in:
@@ -32,7 +32,7 @@ function Attribute.type (widget, value)
|
||||
end
|
||||
|
||||
--[[--
|
||||
widget identifier.
|
||||
Widget identifier.
|
||||
|
||||
Should contain a unique string identifying the widget, if present.
|
||||
|
||||
@@ -100,7 +100,7 @@ function Attribute.key (widget, value)
|
||||
end
|
||||
|
||||
--[[--
|
||||
widget value.
|
||||
Widget value.
|
||||
|
||||
Some widget types expect the value to be of a specific type and
|
||||
within a specific range. For example, `slider` and `progress`
|
||||
@@ -118,7 +118,7 @@ function Attribute.value (widget, value)
|
||||
end
|
||||
|
||||
--[[--
|
||||
widget style.
|
||||
Widget style.
|
||||
|
||||
Should contain a string or array of strings identifying
|
||||
style rules to be applied to the widget. When resolving
|
||||
@@ -140,6 +140,21 @@ function Attribute.style (widget, value)
|
||||
widget.reshape(widget.parent or widget)
|
||||
end
|
||||
|
||||
--[[--
|
||||
Status message.
|
||||
|
||||
Should contain a short, single-line string describing the
|
||||
purpose or state of the widget.
|
||||
|
||||
This string will appear in any `status` type widgets
|
||||
in the same layout, or in the master layout if one exists.
|
||||
|
||||
@attrib status
|
||||
--]]--
|
||||
function Attribute.status (widget, value)
|
||||
widget.attributes.status = value
|
||||
end
|
||||
|
||||
--[[--
|
||||
Scroll ability.
|
||||
|
||||
|
||||
@@ -227,7 +227,8 @@ function Input:handleWheelMove (layout, x, y)
|
||||
local root = layout.root
|
||||
local mx, my = Backend.getMousePosition()
|
||||
local widget = layout:getWidgetAt(mx, my)
|
||||
|
||||
local hit = true
|
||||
|
||||
if not widget then
|
||||
hit = nil
|
||||
widget = layout.root
|
||||
|
||||
@@ -255,19 +255,7 @@ function Layout:getWidgetAt (x, y, root)
|
||||
if root:isAt(x, y) then return root end
|
||||
end
|
||||
|
||||
-- Internal, called from Widget:new
|
||||
--[[
|
||||
function Layout:addWidget (widget)
|
||||
if widget.id then
|
||||
self[widget.id] = widget
|
||||
end
|
||||
if widget.key then
|
||||
self.accelerators[widget.key] = widget
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
||||
-- Add handlers for keyboard accelerators and tab focus
|
||||
-- Add handlers for keyboard accelerators, tab focus, and mouse wheel scroll
|
||||
function Layout:addDefaultHandlers ()
|
||||
self.accelerators = {}
|
||||
|
||||
@@ -331,6 +319,7 @@ function Layout:addDefaultHandlers ()
|
||||
end)
|
||||
|
||||
self:onWheelMove(function (event)
|
||||
if not event.hit then return end
|
||||
for widget in event.target:eachAncestor(true) do
|
||||
if widget.scroll then
|
||||
if not widget.scrollY then
|
||||
@@ -354,6 +343,14 @@ function Layout:addDefaultHandlers ()
|
||||
return false
|
||||
end) -- wheel move
|
||||
|
||||
self:onEnter(function (event)
|
||||
local statusWidget = (self.master or self).statusWidget
|
||||
if not statusWidget then return end
|
||||
|
||||
statusWidget.text = event.target.status
|
||||
return false
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
Event.injectBinders(Layout)
|
||||
|
||||
@@ -26,6 +26,7 @@ Widget.typeDecorators = {
|
||||
radio = require(ROOT .. 'widget.radio'),
|
||||
sash = require(ROOT .. 'widget.sash'),
|
||||
slider = require(ROOT .. 'widget.slider'),
|
||||
status = require(ROOT .. 'widget.status'),
|
||||
stepper = require(ROOT .. 'widget.stepper'),
|
||||
text = require(ROOT .. 'widget.text'),
|
||||
}
|
||||
@@ -59,7 +60,8 @@ local function metaIndex (self, property)
|
||||
|
||||
-- cascading attributes
|
||||
-- TODO: custom accessors in attribute module?
|
||||
if property == 'color' or property == 'font' or property == 'size' then
|
||||
if property == 'color' or property == 'font' or property == 'size'
|
||||
or property == 'status' then
|
||||
local value = self.parent and self.parent[property]
|
||||
if value ~= nil then return maybeCall(value, self) end
|
||||
end
|
||||
|
||||
9
luigi/widget/status.lua
Normal file
9
luigi/widget/status.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
--[[--
|
||||
A status bar.
|
||||
|
||||
@widget status
|
||||
--]]--
|
||||
|
||||
return function (self)
|
||||
self.layout.statusWidget = self
|
||||
end
|
||||
Reference in New Issue
Block a user