accelerators for any event + more inspect examples
This commit is contained in:
@@ -61,3 +61,9 @@ function UI.Checkbox:eventHandler(event)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Checkbox.example()
|
||||
return UI.Checkbox {
|
||||
x = 2, y = 2,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ function UI.Chooser:eventHandler(event)
|
||||
if event.key == 'right' or event.key == 'space' then
|
||||
local _,k = Util.find(self.choices, 'value', self.value)
|
||||
local choice
|
||||
if not k then k = 1 end
|
||||
if not k then k = 0 end
|
||||
if k and k < #self.choices then
|
||||
choice = self.choices[k+1]
|
||||
else
|
||||
@@ -86,3 +86,25 @@ function UI.Chooser:eventHandler(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Chooser.example()
|
||||
return UI.Window {
|
||||
a = UI.Chooser {
|
||||
x = 2, y = 2,
|
||||
choices = {
|
||||
{ name = 'choice1', value = 'value1' },
|
||||
{ name = 'choice2', value = 'value2' },
|
||||
{ name = 'choice3', value = 'value3' },
|
||||
},
|
||||
value = 'value2',
|
||||
},
|
||||
b = UI.Chooser {
|
||||
x = 2, y = 4,
|
||||
choices = {
|
||||
{ name = 'choice1', value = 'value1' },
|
||||
{ name = 'choice2', value = 'value2' },
|
||||
{ name = 'choice3', value = 'value3' },
|
||||
},
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@@ -73,3 +73,16 @@ function UI.DropMenu:eventHandler(event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function UI.DropMenu.example()
|
||||
return UI.MenuBar {
|
||||
buttons = {
|
||||
{ text = 'File', dropdown = {
|
||||
{ text = 'Run', event = 'run' },
|
||||
{ text = 'Shell s', event = 'shell' },
|
||||
{ spacer = true },
|
||||
{ text = 'Quit ^q', event = 'quit' },
|
||||
} },
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@@ -134,3 +134,23 @@ function UI.Form:eventHandler(event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function UI.Form.example()
|
||||
return UI.Form {
|
||||
x = 2, ex = -2, y = 2,
|
||||
ptype = UI.Chooser {
|
||||
formLabel = 'Type', formKey = 'type',
|
||||
width = 10,
|
||||
choices = {
|
||||
{ name = 'Modem', value = 'wireless_modem' },
|
||||
{ name = 'Drive', value = 'disk_drive' },
|
||||
},
|
||||
},
|
||||
drive_id = UI.TextEntry {
|
||||
formLabel = 'Drive', formKey = 'drive_id',
|
||||
required = true,
|
||||
width = 5,
|
||||
transform = 'number',
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
@@ -512,6 +512,9 @@ function UI.Grid.example()
|
||||
{ heading = 'key', key = 'key' },
|
||||
{ heading = 'value', key = 'value' },
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'custom_select',
|
||||
}
|
||||
},
|
||||
noheader = UI.Grid {
|
||||
ex = '48%', y = 6, ey = -2,
|
||||
|
||||
@@ -88,3 +88,12 @@ function UI.MenuBar:eventHandler(event)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function UI.MenuBar.example()
|
||||
return UI.MenuBar {
|
||||
buttons = {
|
||||
{ text = 'Choice1', event = 'event1' },
|
||||
{ text = 'Choice2', event = 'event2' },
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@@ -90,3 +90,28 @@ function UI.Notification:eventHandler(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Notification.example()
|
||||
return UI.Window {
|
||||
notify = UI.Notification {
|
||||
anchor = 'top',
|
||||
},
|
||||
button1 = UI.Button {
|
||||
x = 2, y = 3,
|
||||
text = 'success',
|
||||
event = 'test_success',
|
||||
},
|
||||
button2 = UI.Button {
|
||||
x = 2, y = 5,
|
||||
text = 'error',
|
||||
event = 'test_error',
|
||||
},
|
||||
eventHandler = function (self, event)
|
||||
if event.type == 'test_success' then
|
||||
self.notify:success('Example text')
|
||||
elseif event.type == 'test_error' then
|
||||
self.notify:error('Example text')
|
||||
end
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -75,3 +75,11 @@ function UI.Slider:eventHandler(event)
|
||||
self:draw()
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Slider.example()
|
||||
return UI.Slider {
|
||||
y = 2, x = 2, ex = -2,
|
||||
min = 0, max = 1,
|
||||
help = 'Volume setting',
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user