about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-03-23 21:00:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-03-23 21:00:09 -0700
commit99faf61abbd90f3d5da40788adc43c2883beb470 (patch)
treec305911012de36605bbf62ccf0d2b5022c314922
parent609f0b2fc850e9e6da8eb92b9d855c4e6ccf863b (diff)
downloadtext.love-99faf61abbd90f3d5da40788adc43c2883beb470.tar.gz
mouse wheel support
-rw-r--r--edit.lua14
-rw-r--r--log_browser.lua44
-rw-r--r--main.lua10
-rw-r--r--run.lua5
-rw-r--r--source.lua9
-rw-r--r--source_edit.lua14
6 files changed, 84 insertions, 12 deletions
diff --git a/edit.lua b/edit.lua
index 60561bf..3f87551 100644
--- a/edit.lua
+++ b/edit.lua
@@ -304,6 +304,20 @@ function edit.mouse_release(State, x,y, mouse_button)
   end
 end
 
+function edit.mouse_wheel_move(State, dx,dy)
+  if dy > 0 then
+    State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}
+    for i=1,math.floor(dy) do
+      Text.up(State)
+    end
+  else
+    State.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos}
+    for i=1,math.floor(-dy) do
+      Text.down(State)
+    end
+  end
+end
+
 function edit.text_input(State, t)
   if State.search_term then
     State.search_term = State.search_term..t
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
diff --git a/main.lua b/main.lua
index 31b7f5b..13f2d6a 100644
--- a/main.lua
+++ b/main.lua
@@ -250,6 +250,16 @@ function App.mousereleased(x,y, mouse_button)
   end
 end
 
+function App.wheelmoved(dx,dy)
+  if Current_app == 'run' then
+    if run.mouse_wheel_move then run.mouse_wheel_move(dx,dy) end
+  elseif Current_app == 'source' then
+    if source.mouse_wheel_move then source.mouse_wheel_move(dx,dy) end
+  else
+    assert(false, 'unknown app "'..Current_app..'"')
+  end
+end
+
 function love.quit()
   if Current_app == 'run' then
     local source_settings = Settings.source
diff --git a/run.lua b/run.lua
index 28516f6..ae78d9b 100644
--- a/run.lua
+++ b/run.lua
@@ -163,6 +163,11 @@ function run.mouse_release(x,y, mouse_button)
   return edit.mouse_release(Editor_state, x,y, mouse_button)
 end
 
+function run.mouse_wheel_move(x,y)
+  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
+  return edit.mouse_wheel_move(Editor_state, x,y)
+end
+
 function run.text_input(t)
   Cursor_time = 0  -- ensure cursor is visible immediately after it moves
   return edit.text_input(Editor_state, t)
diff --git a/source.lua b/source.lua
index f4f6600..462985c 100644
--- a/source.lua
+++ b/source.lua
@@ -323,6 +323,15 @@ function source.mouse_release(x,y, mouse_button)
   end
 end
 
+function source.mouse_wheel_move(dx,dy)
+  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
+  if Focus == 'edit' then
+    return edit.mouse_wheel_move(Editor_state, dx,dy)
+  else
+    return log_browser.mouse_wheel_move(Log_browser_state, dx,dy)
+  end
+end
+
 function source.text_input(t)
   Cursor_time = 0  -- ensure cursor is visible immediately after it moves
   if Show_file_navigator then
diff --git a/source_edit.lua b/source_edit.lua
index 964f6ff..60ed027 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -305,6 +305,20 @@ function edit.mouse_release(State, x,y, mouse_button)
   end
 end
 
+function edit.mouse_wheel_move(State, dx,dy)
+  if dy > 0 then
+    State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}
+    for i=1,math.floor(dy) do
+      Text.up(State)
+    end
+  else
+    State.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos}
+    for i=1,math.floor(-dy) do
+      Text.down(State)
+    end
+  end
+end
+
 function edit.text_input(State, t)
   if State.search_term then
     State.search_term = State.search_term..t