1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-19 01:37:39 +00:00

embedded windows

This commit is contained in:
kepler155c@gmail.com
2018-01-21 22:08:30 -05:00
parent 8451c94abe
commit 1eea0d7cd8
4 changed files with 357 additions and 247 deletions

View File

@@ -3,6 +3,7 @@ local class = require('class')
local Event = require('event')
local Input = require('input')
local Peripheral = require('peripheral')
local Terminal = require('terminal')
local Transition = require('ui.transition')
local Util = require('util')
@@ -13,6 +14,7 @@ local device = _G.device
local fs = _G.fs
local os = _G.os
local term = _G.term
local window = _G.window
--[[
Using the shorthand window definition, elements are created from
@@ -2405,6 +2407,63 @@ function UI.SlideOut:eventHandler(event)
end
end
--[[-- Embedded --]]--
UI.Embedded = class(UI.Window)
UI.Embedded.defaults = {
UIElement = 'Embedded',
backgroundColor = colors.black,
textColor = colors.white,
accelerators = {
up = 'scroll_up',
down = 'scroll_down',
}
}
function UI.Embedded:setParent()
UI.Window.setParent(self)
self.win = window.create(UI.term.device, 1, 1, self.width, self.height, false)
Canvas.convertWindow(self.win, UI.term.device, self.x, self.y)
Terminal.scrollable(self.win, 100)
local canvas = self:getCanvas()
self.win.canvas.parent = canvas
table.insert(canvas.layers, self.win.canvas)
self.canvas = self.win.canvas
self.win.setCursorPos(1, 1)
self.win.setBackgroundColor(self.backgroundColor)
self.win.setTextColor(self.textColor)
self.win.clear()
end
function UI.Embedded:draw()
self.canvas:dirty()
end
function UI.Embedded:enable()
self.canvas:setVisible(true)
UI.Window.enable(self)
end
function UI.Embedded:disable()
self.canvas:setVisible(false)
UI.Window.disable(self)
end
function UI.Embedded:eventHandler(event)
if event.type == 'scroll_up' then
self.win.scrollUp()
return true
elseif event.type == 'scroll_down' then
self.win.scrollDown()
return true
end
end
function UI.Embedded:focus()
-- allow scrolling
end
--[[-- Notification --]]--
UI.Notification = class(UI.Window)
UI.Notification.defaults = {

View File

@@ -129,7 +129,6 @@ end
function Canvas:writeBlit(x, y, text, bg, fg)
if y > 0 and y <= self.height and x <= self.width then
local width = #text
-- fix ffs
@@ -342,6 +341,7 @@ function Canvas.convertWindow(win, parent, wx, wy)
str,
win.getBackgroundColor(),
win.getTextColor())
win.setCursorPos(x + #str, y)
end
function win.blit(text, fg, bg)
@@ -353,8 +353,10 @@ function Canvas.convertWindow(win, parent, wx, wy)
win.canvas:redraw(parent)
end
function win.scroll()
error('scroll: not implemented')
function win.scroll(n)
table.insert(win.canvas.lines, table.remove(win.canvas.lines, 1))
win.canvas.lines[#win.canvas.lines].text = _rep(' ', win.canvas.width)
win.canvas:dirty()
end
function win.reposition(x, y, width, height)

View File

@@ -55,11 +55,11 @@ function Util.tostring(pattern, ...)
end
str = str .. string.format(' %s: %s\n', k, value)
end
if #str < width then
str = str:gsub('\n', '') .. ' }'
else
--if #str < width then
--str = str:gsub('\n', '') .. ' }'
--else
str = str .. '}'
end
--end
return str
end