diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-03-23 21:00:09 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-03-23 21:00:09 -0700 |
commit | 99faf61abbd90f3d5da40788adc43c2883beb470 (patch) | |
tree | c305911012de36605bbf62ccf0d2b5022c314922 /log_browser.lua | |
parent | 609f0b2fc850e9e6da8eb92b9d855c4e6ccf863b (diff) | |
download | text.love-99faf61abbd90f3d5da40788adc43c2883beb470.tar.gz |
mouse wheel support
Diffstat (limited to 'log_browser.lua')
-rw-r--r-- | log_browser.lua | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/log_browser.lua b/log_browser.lua index 5946e3e..cd0d8fc 100644 --- a/log_browser.lua +++ b/log_browser.lua @@ -263,25 +263,27 @@ end function log_browser.mouse_release(State, x,y, mouse_button) end +function log_browser.mouse_wheel_move(State, dx,dy) + if dy > 0 then + for i=1,math.floor(dy) do + log_browser.up(State) + end + else + for i=1,math.floor(-dy) do + log_browser.down(State) + end + end +end + function log_browser.text_input(State, t) end function log_browser.keychord_press(State, chord, key) -- move if chord == 'up' then - while State.screen_top1.line > 1 do - State.screen_top1.line = State.screen_top1.line-1 - if should_show(State.lines[State.screen_top1.line]) then - break - end - end + log_browser.up(State) elseif chord == 'down' then - while State.screen_top1.line < #State.lines do - State.screen_top1.line = State.screen_top1.line+1 - if should_show(State.lines[State.screen_top1.line]) then - break - end - end + log_browser.down(State) elseif chord == 'pageup' then local y = 0 while State.screen_top1.line > 1 and y < App.screen.height - 100 do @@ -301,6 +303,24 @@ function log_browser.keychord_press(State, chord, key) end end +function log_browser.up(State) + while State.screen_top1.line > 1 do + State.screen_top1.line = State.screen_top1.line-1 + if should_show(State.lines[State.screen_top1.line]) then + break + end + end +end + +function log_browser.down(State) + while State.screen_top1.line < #State.lines do + State.screen_top1.line = State.screen_top1.line+1 + if should_show(State.lines[State.screen_top1.line]) then + break + end + end +end + function log_browser.height(State, line_index) local line = State.lines[line_index] if line.data == nil then |