add status widget and attribute

This commit is contained in:
airstruck
2015-12-05 15:43:40 -05:00
parent 3daff0bcad
commit c21611748c
7 changed files with 62 additions and 55 deletions

View File

@@ -1,8 +1,10 @@
return { id = 'mainWindow', type = 'panel', return { id = 'mainWindow', type = 'panel',
{ type = 'menu', id = 'menubar', flow = 'x', { type = 'menu', id = 'menubar', flow = 'x',
{ text = 'File', { text = 'File',
{ text = 'Save', id = 'menuSave', key = 'ctrl-s' }, { text = 'Save', id = 'menuSave', key = 'ctrl-s',
{ text = 'Quit', id = 'menuQuit', key = 'escape' }, status = 'Save to disk' },
{ text = 'Quit', id = 'menuQuit', key = 'escape',
status = 'Quit the demo' },
}, },
{ text = 'Edit', { text = 'Edit',
{ text = 'Cut', key = 'ctrl-c' }, { text = 'Cut', key = 'ctrl-c' },
@@ -27,11 +29,14 @@ return { id = 'mainWindow', type = 'panel',
}, },
{ type = 'panel', id = 'toolbar', style = 'toolbar', flow = 'x', { type = 'panel', id = 'toolbar', style = 'toolbar', flow = 'x',
{ type = 'button', id = 'newButton', style = 'toolButton', key = 'z', { type = 'button', id = 'newButton', style = 'toolButton', key = 'z',
icon = 'icon/32px/Blueprint.png' }, icon = 'icon/32px/Blueprint.png',
status = 'Create a new thing' },
{ type = 'button', id = 'loadButton', style = 'toolButton', { type = 'button', id = 'loadButton', style = 'toolButton',
icon = 'icon/32px/Calendar.png' }, icon = 'icon/32px/Calendar.png',
status = 'Load a thing' },
{ type = 'button', id = 'saveButton', style = 'toolButton', { type = 'button', id = 'saveButton', style = 'toolButton',
icon = 'icon/32px/Harddrive.png' }, icon = 'icon/32px/Harddrive.png',
status = 'Save a thing' },
}, },
{ flow = 'x', { flow = 'x',
{ id = 'leftSideBox', width = 200, minwidth = 64, scroll = true, type = 'panel', { id = 'leftSideBox', width = 200, minwidth = 64, scroll = true, type = 'panel',
@@ -72,5 +77,5 @@ return { id = 'mainWindow', type = 'panel',
{ type = 'button', key='return', width = 80, id = 'aButton', text = 'Styling!', { type = 'button', key='return', width = 80, id = 'aButton', text = 'Styling!',
font = 'font/DejaVuSansMono.ttf' }, font = 'font/DejaVuSansMono.ttf' },
}, },
{ type = 'panel', id = 'statusbar', height = 24, padding = 4, color = { 255, 0, 0 } }, { type = 'status', id = 'statusbar', height = 24, padding = 4, color = { 255, 0, 0 } },
} }

View File

@@ -5,31 +5,11 @@ local style = require 'style'
local layout = Layout(require 'layout.main') local layout = Layout(require 'layout.main')
layout:setStyle(style) layout:setStyle(style)
-- layout:setTheme(require 'luigi.theme.light')
layout.leftSideBox:addChild {
text = 'Alright man this is a great song\nwith a really long title...',
style = 'listThing',
align = 'middle right'
}
layout.slidey:onChange(function (event) layout.slidey:onChange(function (event)
layout.progressBar.value = event.value layout.progressBar.value = event.value
end) end)
layout:onMove(function (event)
local w = event.target
layout.statusbar.text = (tostring(w.type)) .. ' ' ..
(w.id or '(unnamed)') .. ' ' ..
w:getX() .. ', ' .. w:getY() .. ' | ' ..
w:getWidth() .. 'x' .. w:getHeight()
end)
layout.newButton:onMove(function (event)
layout.statusbar.text = 'Create a new thing'
return false
end)
layout.newButton:onPress(function (event) layout.newButton:onPress(function (event)
print('creating a new thing!') print('creating a new thing!')
end) end)
@@ -60,31 +40,29 @@ layout.mainCanvas.align = 'top'
layout.mainCanvas.wrap = true layout.mainCanvas.wrap = true
-- license dialog -- help dialogs
local aboutDialog = Layout(require 'layout.about')
local licenseDialog = Layout(require 'layout.license') local licenseDialog = Layout(require 'layout.license')
aboutDialog:setStyle(style)
licenseDialog:setStyle(style) licenseDialog:setStyle(style)
aboutDialog.closeButton:onPress(function()
aboutDialog:hide()
end)
licenseDialog.closeButton:onPress(function() licenseDialog.closeButton:onPress(function()
licenseDialog:hide() licenseDialog:hide()
end) end)
layout.license:onPress(function() layout.license:onPress(function()
aboutDialog:hide()
licenseDialog:show() licenseDialog:show()
end) end)
-- about dialog
local aboutDialog = Layout(require 'layout.about')
aboutDialog:setStyle(style)
aboutDialog.closeButton:onPress(function()
aboutDialog:hide()
end)
layout.about:onPress(function() layout.about:onPress(function()
licenseDialog:hide()
aboutDialog:show() aboutDialog:show()
end) end)

View File

@@ -32,7 +32,7 @@ function Attribute.type (widget, value)
end end
--[[-- --[[--
widget identifier. Widget identifier.
Should contain a unique string identifying the widget, if present. Should contain a unique string identifying the widget, if present.
@@ -100,7 +100,7 @@ function Attribute.key (widget, value)
end end
--[[-- --[[--
widget value. Widget value.
Some widget types expect the value to be of a specific type and Some widget types expect the value to be of a specific type and
within a specific range. For example, `slider` and `progress` within a specific range. For example, `slider` and `progress`
@@ -118,7 +118,7 @@ function Attribute.value (widget, value)
end end
--[[-- --[[--
widget style. Widget style.
Should contain a string or array of strings identifying Should contain a string or array of strings identifying
style rules to be applied to the widget. When resolving 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) widget.reshape(widget.parent or widget)
end 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. Scroll ability.

View File

@@ -227,7 +227,8 @@ function Input:handleWheelMove (layout, x, y)
local root = layout.root local root = layout.root
local mx, my = Backend.getMousePosition() local mx, my = Backend.getMousePosition()
local widget = layout:getWidgetAt(mx, my) local widget = layout:getWidgetAt(mx, my)
local hit = true
if not widget then if not widget then
hit = nil hit = nil
widget = layout.root widget = layout.root

View File

@@ -255,19 +255,7 @@ function Layout:getWidgetAt (x, y, root)
if root:isAt(x, y) then return root end if root:isAt(x, y) then return root end
end end
-- Internal, called from Widget:new -- Add handlers for keyboard accelerators, tab focus, and mouse wheel scroll
--[[
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
function Layout:addDefaultHandlers () function Layout:addDefaultHandlers ()
self.accelerators = {} self.accelerators = {}
@@ -331,6 +319,7 @@ function Layout:addDefaultHandlers ()
end) end)
self:onWheelMove(function (event) self:onWheelMove(function (event)
if not event.hit then return end
for widget in event.target:eachAncestor(true) do for widget in event.target:eachAncestor(true) do
if widget.scroll then if widget.scroll then
if not widget.scrollY then if not widget.scrollY then
@@ -354,6 +343,14 @@ function Layout:addDefaultHandlers ()
return false return false
end) -- wheel move 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 end
Event.injectBinders(Layout) Event.injectBinders(Layout)

View File

@@ -26,6 +26,7 @@ Widget.typeDecorators = {
radio = require(ROOT .. 'widget.radio'), radio = require(ROOT .. 'widget.radio'),
sash = require(ROOT .. 'widget.sash'), sash = require(ROOT .. 'widget.sash'),
slider = require(ROOT .. 'widget.slider'), slider = require(ROOT .. 'widget.slider'),
status = require(ROOT .. 'widget.status'),
stepper = require(ROOT .. 'widget.stepper'), stepper = require(ROOT .. 'widget.stepper'),
text = require(ROOT .. 'widget.text'), text = require(ROOT .. 'widget.text'),
} }
@@ -59,7 +60,8 @@ local function metaIndex (self, property)
-- cascading attributes -- cascading attributes
-- TODO: custom accessors in attribute module? -- 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] local value = self.parent and self.parent[property]
if value ~= nil then return maybeCall(value, self) end if value ~= nil then return maybeCall(value, self) end
end end

9
luigi/widget/status.lua Normal file
View File

@@ -0,0 +1,9 @@
--[[--
A status bar.
@widget status
--]]--
return function (self)
self.layout.statusWidget = self
end