mirror of https://github.com/kepler155c/opus
bugfixes + tweaks for editor 2.0
This commit is contained in:
parent
fc1a308193
commit
d88ef00652
|
@ -9,7 +9,7 @@ kernel.hook('clipboard_copy', function(_, args)
|
||||||
keyboard.clipboard = args[1]
|
keyboard.clipboard = args[1]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
keyboard.addHotkey('shift-paste', function()
|
local function queuePaste()
|
||||||
local data = keyboard.clipboard
|
local data = keyboard.clipboard
|
||||||
|
|
||||||
if type(data) == 'table' then
|
if type(data) == 'table' then
|
||||||
|
@ -20,4 +20,7 @@ keyboard.addHotkey('shift-paste', function()
|
||||||
if data then
|
if data then
|
||||||
os.queueEvent('paste', data)
|
os.queueEvent('paste', data)
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
kernel.hook('clipboard_paste', queuePaste)
|
||||||
|
keyboard.addHotkey('shift-paste', queuePaste)
|
||||||
|
|
|
@ -73,16 +73,14 @@ function Manager:init()
|
||||||
monitor_resize = resize,
|
monitor_resize = resize,
|
||||||
|
|
||||||
mouse_scroll = function(_, direction, x, y)
|
mouse_scroll = function(_, direction, x, y)
|
||||||
|
local ie = Input:translate('mouse_scroll', direction, x, y)
|
||||||
|
|
||||||
local currentPage = self:getActivePage()
|
local currentPage = self:getActivePage()
|
||||||
if currentPage then
|
if currentPage then
|
||||||
local event = currentPage:pointToChild(x, y)
|
local event = currentPage:pointToChild(x, y)
|
||||||
local directions = {
|
event.type = ie.code
|
||||||
[ -1 ] = 'up',
|
event.ie = { code = ie.code, x = event.x, y = event.y }
|
||||||
[ 1 ] = 'down'
|
event.element:emit(event)
|
||||||
}
|
|
||||||
-- revisit - should send out scroll_up and scroll_down events
|
|
||||||
-- let the element convert them to up / down
|
|
||||||
event.element:emit({ type = 'key', key = directions[direction] })
|
|
||||||
currentPage:sync()
|
currentPage:sync()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -251,10 +249,21 @@ function Manager:click(target, ie)
|
||||||
local clickEvent
|
local clickEvent
|
||||||
|
|
||||||
if ie.code == 'mouse_drag' then
|
if ie.code == 'mouse_drag' then
|
||||||
|
local function getPosition(element, x, y)
|
||||||
|
repeat
|
||||||
|
x = x - element.x + 1
|
||||||
|
y = y - element.y + 1
|
||||||
|
element = element.parent
|
||||||
|
until not element
|
||||||
|
return x, y
|
||||||
|
end
|
||||||
|
|
||||||
|
local x, y = getPosition(self.lastClicked, ie.x, ie.y)
|
||||||
|
|
||||||
clickEvent = {
|
clickEvent = {
|
||||||
element = self.lastClicked,
|
element = self.lastClicked,
|
||||||
x = ie.x,
|
x = x,
|
||||||
y = ie.y, -- this is not correct (should be relative to element)
|
y = y,
|
||||||
dx = ie.dx,
|
dx = ie.dx,
|
||||||
dy = ie.dy,
|
dy = ie.dy,
|
||||||
}
|
}
|
||||||
|
@ -560,6 +569,7 @@ end
|
||||||
function UI.Window:setParent()
|
function UI.Window:setParent()
|
||||||
self.oh, self.ow = self.height, self.width
|
self.oh, self.ow = self.height, self.width
|
||||||
self.ox, self.oy = self.x, self.y
|
self.ox, self.oy = self.x, self.y
|
||||||
|
self.oex, self.oey = self.ex, self.ey
|
||||||
|
|
||||||
self:layout()
|
self:layout()
|
||||||
self:initChildren()
|
self:initChildren()
|
||||||
|
@ -568,6 +578,7 @@ end
|
||||||
function UI.Window:resize()
|
function UI.Window:resize()
|
||||||
self.height, self.width = self.oh, self.ow
|
self.height, self.width = self.oh, self.ow
|
||||||
self.x, self.y = self.ox, self.oy
|
self.x, self.y = self.ox, self.oy
|
||||||
|
self.ex, self.ey = self.oex, self.oey
|
||||||
|
|
||||||
self:layout()
|
self:layout()
|
||||||
|
|
||||||
|
@ -864,7 +875,6 @@ function UI.Window:release(child)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Window:pointToChild(x, y)
|
function UI.Window:pointToChild(x, y)
|
||||||
-- TODO: get rid of this offx/y mess and scroll canvas instead
|
|
||||||
x = x + self.offx - self.x + 1
|
x = x + self.offx - self.x + 1
|
||||||
y = y + self.offy - self.y + 1
|
y = y + self.offy - self.y + 1
|
||||||
if self.children then
|
if self.children then
|
||||||
|
|
|
@ -18,14 +18,14 @@ UI.Button.defaults = {
|
||||||
focusIndicator = ' ',
|
focusIndicator = ' ',
|
||||||
event = 'button_press',
|
event = 'button_press',
|
||||||
accelerators = {
|
accelerators = {
|
||||||
space = 'button_activate',
|
[ ' ' ] = 'button_activate',
|
||||||
enter = 'button_activate',
|
enter = 'button_activate',
|
||||||
mouse_click = 'button_activate',
|
mouse_click = 'button_activate',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function UI.Button:setParent()
|
function UI.Button:setParent()
|
||||||
if not self.width and not self.ex then
|
if not self.width and not self.ex then
|
||||||
self.width = #self.text + 2
|
self.width = self.noPadding and #self.text or #self.text + 2
|
||||||
end
|
end
|
||||||
UI.Window.setParent(self)
|
UI.Window.setParent(self)
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ function UI.Button:draw()
|
||||||
elseif self.inactive then
|
elseif self.inactive then
|
||||||
fg = self:getProperty('textInactiveColor')
|
fg = self:getProperty('textInactiveColor')
|
||||||
end
|
end
|
||||||
local text = ind .. self.text .. ' '
|
local text = self.noPadding and self.text or ind .. self.text .. ' '
|
||||||
if self.centered then
|
if self.centered then
|
||||||
self:clear(bg)
|
self:clear(bg)
|
||||||
self:centeredWrite(1 + math.floor(self.height / 2), text, bg, fg)
|
self:centeredWrite(1 + math.floor(self.height / 2), text, bg, fg)
|
||||||
|
@ -59,7 +59,7 @@ end
|
||||||
|
|
||||||
function UI.Button:eventHandler(event)
|
function UI.Button:eventHandler(event)
|
||||||
if event.type == 'button_activate' then
|
if event.type == 'button_activate' then
|
||||||
self:emit({ type = self.event, button = self })
|
self:emit({ type = self.event, button = self, element = self })
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -40,9 +40,10 @@ function UI.DropMenu:layout()
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.DropMenu:enable()
|
function UI.DropMenu:enable()
|
||||||
|
local menuBar = self.parent:find(self.menuUid)
|
||||||
for _,c in pairs(self.children) do
|
for _,c in pairs(self.children) do
|
||||||
if not c.spacer then
|
if not c.spacer and menuBar then
|
||||||
c.inactive = not self:getActive(c)
|
c.inactive = not menuBar:getActive(c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ function UI.MenuBar:eventHandler(event)
|
||||||
x = x,
|
x = x,
|
||||||
y = y + 1,
|
y = y + 1,
|
||||||
lastFocus = event.button.uid,
|
lastFocus = event.button.uid,
|
||||||
|
menuUid = self.uid,
|
||||||
}
|
}
|
||||||
self.parent:add({ dropmenu = menu })
|
self.parent:add({ dropmenu = menu })
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,12 @@ UI.Page.defaults = {
|
||||||
UIElement = 'Page',
|
UIElement = 'Page',
|
||||||
accelerators = {
|
accelerators = {
|
||||||
down = 'focus_next',
|
down = 'focus_next',
|
||||||
|
scroll_down = 'focus_next',
|
||||||
enter = 'focus_next',
|
enter = 'focus_next',
|
||||||
tab = 'focus_next',
|
tab = 'focus_next',
|
||||||
['shift-tab' ] = 'focus_prev',
|
['shift-tab' ] = 'focus_prev',
|
||||||
up = 'focus_prev',
|
up = 'focus_prev',
|
||||||
|
scroll_up = 'focus_prev',
|
||||||
},
|
},
|
||||||
backgroundColor = UI.colors.primary,
|
backgroundColor = UI.colors.primary,
|
||||||
textColor = colors.white,
|
textColor = colors.white,
|
||||||
|
|
|
@ -89,11 +89,13 @@ function UI.StatusBar:draw()
|
||||||
elseif type(self.values) == 'string' then
|
elseif type(self.values) == 'string' then
|
||||||
self:write(1, 1, Util.widthify(' ' .. self.values, self.width))
|
self:write(1, 1, Util.widthify(' ' .. self.values, self.width))
|
||||||
else
|
else
|
||||||
local s = ''
|
local x = 2
|
||||||
|
self:clear()
|
||||||
for _,c in ipairs(self.columns) do
|
for _,c in ipairs(self.columns) do
|
||||||
s = s .. ' ' .. Util.widthify(tostring(self.values[c.key] or ''), c.cw)
|
local s = Util.widthify(tostring(self.values[c.key] or ''), c.cw)
|
||||||
|
self:write(x, 1, s, c.bg, c.fg)
|
||||||
|
x = x + c.cw + 1
|
||||||
end
|
end
|
||||||
self:write(1, 1, Util.widthify(s, self.width))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ UI.TextEntry.defaults = {
|
||||||
focused = false,
|
focused = false,
|
||||||
textColor = colors.white,
|
textColor = colors.white,
|
||||||
shadowTextColor = colors.gray,
|
shadowTextColor = colors.gray,
|
||||||
|
markBackgroundColor = colors.gray,
|
||||||
backgroundColor = colors.black, -- colors.lightGray,
|
backgroundColor = colors.black, -- colors.lightGray,
|
||||||
backgroundFocusColor = colors.black, --lightGray,
|
backgroundFocusColor = colors.black, --lightGray,
|
||||||
height = 1,
|
height = 1,
|
||||||
|
@ -84,7 +85,7 @@ function UI.TextEntry:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
if tx ~= tex then
|
if tx ~= tex then
|
||||||
self:write(tx + 2, 1, text:sub(tx + 1, tex), colors.gray, tc)
|
self:write(tx + 2, 1, text:sub(tx + 1, tex), self.markBackgroundColor, tc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if self.focused then
|
if self.focused then
|
||||||
|
@ -105,6 +106,10 @@ function UI.TextEntry:updateCursor()
|
||||||
self:setCursorPos(self.entry.pos - self.entry.scroll + 2, 1)
|
self:setCursorPos(self.entry.pos - self.entry.scroll + 2, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.TextEntry:markAll()
|
||||||
|
self.entry:markAll()
|
||||||
|
end
|
||||||
|
|
||||||
function UI.TextEntry:focus()
|
function UI.TextEntry:focus()
|
||||||
self:draw()
|
self:draw()
|
||||||
if self.focused then
|
if self.focused then
|
||||||
|
|
|
@ -20,7 +20,7 @@ end
|
||||||
|
|
||||||
function Transition.slideRight(args)
|
function Transition.slideRight(args)
|
||||||
local ticks = args.ticks or 10
|
local ticks = args.ticks or 10
|
||||||
local easing = args.easing or'outQuint'
|
local easing = args.easing or 'outQuint'
|
||||||
local pos = { x = -args.canvas.width }
|
local pos = { x = -args.canvas.width }
|
||||||
local tween = Tween.new(ticks, pos, { x = 1 }, easing)
|
local tween = Tween.new(ticks, pos, { x = 1 }, easing)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue