opus/sys/modules/opus/ui/components/SlideOut.lua

76 lines
1.3 KiB
Lua
Raw Normal View History

local class = require('opus.class')
local UI = require('opus.ui')
2019-02-06 04:03:57 +00:00
UI.SlideOut = class(UI.Window)
UI.SlideOut.defaults = {
UIElement = 'SlideOut',
2020-03-31 15:57:23 +00:00
transitionHint = 'expandUp',
modal = true,
2019-02-06 04:03:57 +00:00
}
function UI.SlideOut:enable()
end
function UI.SlideOut:toggle()
if self.enabled then
self:hide()
else
self:show()
end
end
2019-02-06 04:03:57 +00:00
function UI.SlideOut:show(...)
UI.Window.enable(self, ...)
self:draw()
self:focusFirst()
end
function UI.SlideOut:hide()
self:disable()
2020-03-31 15:57:23 +00:00
end
function UI.SlideOut:draw()
if not self.noFill then
2020-04-22 04:32:12 +00:00
self:fillArea(1, 1, self.width, self.height, string.rep('\127', self.width), 'black', 'gray')
2020-03-31 15:57:23 +00:00
end
self:drawChildren()
2019-02-06 04:03:57 +00:00
end
function UI.SlideOut:eventHandler(event)
if event.type == 'slide_show' then
self:show()
return true
elseif event.type == 'slide_hide' then
self:hide()
return true
end
end
2019-11-14 22:43:20 +00:00
function UI.SlideOut.example()
2020-03-31 15:57:23 +00:00
return UI.Window {
y = 3,
backgroundColor = 2048,
2019-11-14 22:43:20 +00:00
button = UI.Button {
2019-11-17 05:12:02 +00:00
x = 2, y = 5,
2019-11-14 22:43:20 +00:00
text = 'show',
},
slideOut = UI.SlideOut {
2020-03-31 15:57:23 +00:00
backgroundColor = 16,
y = -7, height = 4, x = 3, ex = -3,
titleBar = UI.TitleBar {
title = 'test',
},
2019-11-14 22:43:20 +00:00
button = UI.Button {
x = 2, y = 2,
text = 'hide',
2020-03-31 15:57:23 +00:00
--visualize = true,
2019-11-14 22:43:20 +00:00
},
},
eventHandler = function (self, event)
if event.type == 'button_press' then
self.slideOut:toggle()
2019-11-14 22:43:20 +00:00
end
end,
}
end