adapt library code to newly correct mouse events

develop
myk002 2022-11-21 17:36:46 -08:00
parent e2218d0429
commit 24dc879888
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
4 changed files with 11 additions and 11 deletions

@ -334,7 +334,7 @@ function EditField:onInput(keys)
elseif keys._MOUSE_L then
local mouse_x, mouse_y = self:getMousePos()
if mouse_x then
self:setCursor(self.start_pos + mouse_x)
self:setCursor(self.start_pos + mouse_x - self.text_offset)
return true
end
elseif keys._STRING then
@ -496,7 +496,7 @@ function Scrollbar:onRenderBody(dc)
if self.is_dragging then
scrollbar_do_drag(self)
end
if df.global.enabler.mouse_lbut_down == 0 then
if df.global.enabler.mouse_lbut == 0 then
self.last_scroll_ms = 0
self.is_dragging = false
self.scroll_spec = nil
@ -928,7 +928,7 @@ end
function HotkeyLabel:onInput(keys)
if HotkeyLabel.super.onInput(self, keys) then
return true
elseif keys._MOUSE_L and self:getMousePos() then
elseif keys._MOUSE_L_DOWN and self:getMousePos() then
self.on_activate()
return true
end
@ -1009,7 +1009,7 @@ end
function CycleHotkeyLabel:onInput(keys)
if CycleHotkeyLabel.super.onInput(self, keys) then
return true
elseif keys._MOUSE_L and self:getMousePos() then
elseif keys._MOUSE_L_DOWN and self:getMousePos() then
self:cycle()
return true
end
@ -1274,7 +1274,7 @@ function List:onInput(keys)
elseif self.on_submit2 and keys.SEC_SELECT then
self:submit2()
return true
elseif keys._MOUSE_L then
elseif keys._MOUSE_L_DOWN then
local idx = self:getIdxUnderMouse()
if idx then
self:setSelected(idx)

@ -207,7 +207,7 @@ function MenuScreen:onInput(keys)
elseif keys.STANDARDSCROLL_RIGHT then
self:onSubmit2(self.subviews.list:getSelected())
return true
elseif keys._MOUSE_L then
elseif keys._MOUSE_L_DOWN then
local list = self.subviews.list
local x = list:getMousePos()
if x == 0 then -- clicked on icon

@ -40,17 +40,17 @@ function test.editfield_click()
expect.eq(5, e.cursor)
mock.patch(e, 'getMousePos', mock.func(0), function()
e:onInput{_MOUSE_L=true}
e:onInput{_MOUSE_L_DOWN=true}
expect.eq(1, e.cursor)
end)
mock.patch(e, 'getMousePos', mock.func(20), function()
e:onInput{_MOUSE_L=true}
e:onInput{_MOUSE_L_DOWN=true}
expect.eq(5, e.cursor, 'should only seek to end of text')
end)
mock.patch(e, 'getMousePos', mock.func(2), function()
e:onInput{_MOUSE_L=true}
e:onInput{_MOUSE_L_DOWN=true}
expect.eq(3, e.cursor)
end)
end

@ -5,7 +5,7 @@ function test.hotkeylabel_click()
local l = widgets.HotkeyLabel{key='SELECT', on_activate=func}
mock.patch(l, 'getMousePos', mock.func(0), function()
l:onInput{_MOUSE_L=true}
l:onInput{_MOUSE_L_DOWN=true}
expect.eq(1, func.call_count)
end)
end
@ -31,7 +31,7 @@ function test.togglehotkeylabel_click()
local l = widgets.ToggleHotkeyLabel{}
expect.true_(l:getOptionValue())
mock.patch(l, 'getMousePos', mock.func(0), function()
l:onInput{_MOUSE_L=true}
l:onInput{_MOUSE_L_DOWN=true}
expect.false_(l:getOptionValue())
end)
end