diff --git a/sys/autorun/clipboard.lua b/sys/autorun/clipboard.lua index 992af47..2a0774c 100644 --- a/sys/autorun/clipboard.lua +++ b/sys/autorun/clipboard.lua @@ -9,7 +9,7 @@ kernel.hook('clipboard_copy', function(_, args) keyboard.clipboard = args[1] end) -keyboard.addHotkey('shift-paste', function() +local function queuePaste() local data = keyboard.clipboard if type(data) == 'table' then @@ -20,4 +20,7 @@ keyboard.addHotkey('shift-paste', function() if data then os.queueEvent('paste', data) end -end) +end + +kernel.hook('clipboard_paste', queuePaste) +keyboard.addHotkey('shift-paste', queuePaste) diff --git a/sys/modules/opus/ui.lua b/sys/modules/opus/ui.lua index a2851aa..7b004f1 100644 --- a/sys/modules/opus/ui.lua +++ b/sys/modules/opus/ui.lua @@ -73,16 +73,14 @@ function Manager:init() monitor_resize = resize, mouse_scroll = function(_, direction, x, y) + local ie = Input:translate('mouse_scroll', direction, x, y) + local currentPage = self:getActivePage() if currentPage then local event = currentPage:pointToChild(x, y) - local directions = { - [ -1 ] = 'up', - [ 1 ] = 'down' - } - -- 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] }) + event.type = ie.code + event.ie = { code = ie.code, x = event.x, y = event.y } + event.element:emit(event) currentPage:sync() end end, @@ -251,10 +249,21 @@ function Manager:click(target, ie) local clickEvent 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 = { element = self.lastClicked, - x = ie.x, - y = ie.y, -- this is not correct (should be relative to element) + x = x, + y = y, dx = ie.dx, dy = ie.dy, } @@ -560,6 +569,7 @@ end function UI.Window:setParent() self.oh, self.ow = self.height, self.width self.ox, self.oy = self.x, self.y + self.oex, self.oey = self.ex, self.ey self:layout() self:initChildren() @@ -568,6 +578,7 @@ end function UI.Window:resize() self.height, self.width = self.oh, self.ow self.x, self.y = self.ox, self.oy + self.ex, self.ey = self.oex, self.oey self:layout() @@ -864,7 +875,6 @@ function UI.Window:release(child) end 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 y = y + self.offy - self.y + 1 if self.children then diff --git a/sys/modules/opus/ui/components/Button.lua b/sys/modules/opus/ui/components/Button.lua index b07dda9..f928707 100644 --- a/sys/modules/opus/ui/components/Button.lua +++ b/sys/modules/opus/ui/components/Button.lua @@ -18,14 +18,14 @@ UI.Button.defaults = { focusIndicator = ' ', event = 'button_press', accelerators = { - space = 'button_activate', + [ ' ' ] = 'button_activate', enter = 'button_activate', mouse_click = 'button_activate', } } function UI.Button:setParent() 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 UI.Window.setParent(self) end @@ -41,7 +41,7 @@ function UI.Button:draw() elseif self.inactive then fg = self:getProperty('textInactiveColor') end - local text = ind .. self.text .. ' ' + local text = self.noPadding and self.text or ind .. self.text .. ' ' if self.centered then self:clear(bg) self:centeredWrite(1 + math.floor(self.height / 2), text, bg, fg) @@ -59,7 +59,7 @@ end function UI.Button:eventHandler(event) if event.type == 'button_activate' then - self:emit({ type = self.event, button = self }) + self:emit({ type = self.event, button = self, element = self }) return true end return false diff --git a/sys/modules/opus/ui/components/DropMenu.lua b/sys/modules/opus/ui/components/DropMenu.lua index e2a75cc..2b61dff 100644 --- a/sys/modules/opus/ui/components/DropMenu.lua +++ b/sys/modules/opus/ui/components/DropMenu.lua @@ -40,9 +40,10 @@ function UI.DropMenu:layout() end function UI.DropMenu:enable() + local menuBar = self.parent:find(self.menuUid) for _,c in pairs(self.children) do - if not c.spacer then - c.inactive = not self:getActive(c) + if not c.spacer and menuBar then + c.inactive = not menuBar:getActive(c) end end diff --git a/sys/modules/opus/ui/components/MenuBar.lua b/sys/modules/opus/ui/components/MenuBar.lua index d7e793f..8f7ef44 100644 --- a/sys/modules/opus/ui/components/MenuBar.lua +++ b/sys/modules/opus/ui/components/MenuBar.lua @@ -81,6 +81,7 @@ function UI.MenuBar:eventHandler(event) x = x, y = y + 1, lastFocus = event.button.uid, + menuUid = self.uid, } self.parent:add({ dropmenu = menu }) diff --git a/sys/modules/opus/ui/components/Page.lua b/sys/modules/opus/ui/components/Page.lua index 0e20f5e..6b25618 100644 --- a/sys/modules/opus/ui/components/Page.lua +++ b/sys/modules/opus/ui/components/Page.lua @@ -9,10 +9,12 @@ UI.Page.defaults = { UIElement = 'Page', accelerators = { down = 'focus_next', + scroll_down = 'focus_next', enter = 'focus_next', tab = 'focus_next', ['shift-tab' ] = 'focus_prev', up = 'focus_prev', + scroll_up = 'focus_prev', }, backgroundColor = UI.colors.primary, textColor = colors.white, diff --git a/sys/modules/opus/ui/components/StatusBar.lua b/sys/modules/opus/ui/components/StatusBar.lua index 6f9b80a..39c72a0 100644 --- a/sys/modules/opus/ui/components/StatusBar.lua +++ b/sys/modules/opus/ui/components/StatusBar.lua @@ -89,11 +89,13 @@ function UI.StatusBar:draw() elseif type(self.values) == 'string' then self:write(1, 1, Util.widthify(' ' .. self.values, self.width)) else - local s = '' + local x = 2 + self:clear() 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 - self:write(1, 1, Util.widthify(s, self.width)) end end diff --git a/sys/modules/opus/ui/components/TextEntry.lua b/sys/modules/opus/ui/components/TextEntry.lua index 06fa712..7470ea2 100644 --- a/sys/modules/opus/ui/components/TextEntry.lua +++ b/sys/modules/opus/ui/components/TextEntry.lua @@ -23,6 +23,7 @@ UI.TextEntry.defaults = { focused = false, textColor = colors.white, shadowTextColor = colors.gray, + markBackgroundColor = colors.gray, backgroundColor = colors.black, -- colors.lightGray, backgroundFocusColor = colors.black, --lightGray, height = 1, @@ -84,7 +85,7 @@ function UI.TextEntry:draw() end 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 if self.focused then @@ -105,6 +106,10 @@ function UI.TextEntry:updateCursor() self:setCursorPos(self.entry.pos - self.entry.scroll + 2, 1) end +function UI.TextEntry:markAll() + self.entry:markAll() +end + function UI.TextEntry:focus() self:draw() if self.focused then diff --git a/sys/modules/opus/ui/transition.lua b/sys/modules/opus/ui/transition.lua index 20189ee..2f8e0d6 100644 --- a/sys/modules/opus/ui/transition.lua +++ b/sys/modules/opus/ui/transition.lua @@ -20,7 +20,7 @@ end function Transition.slideRight(args) 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 tween = Tween.new(ticks, pos, { x = 1 }, easing)