UI improvement: more stable scrollbar movement
scenario: just tap somewhere on a scrollbar. There should be no scrolling. But before this commit there would be. This made the scrollbars feel unstable. I finally figured this out while noodling over a follow-up question to the previous commit: Why was dragging the scrollbar down ever leaving a trail of more than just the top line's `starty`? In other words, why was my example: line 1: 30 line 2: 60 line 3: 90 line 4: 30 line 5: 30 line 6: 30 ... ..and not: line 1: 30 line 2: 30 line 3: 30 line 4: 30 line 5: 30 line 6: 30 ... ?? The answer: when I grab a scrollbar it always used to jump down! Usability issues can either exacerbate bugs or make them harder to diagnose. If I'd implemented scrollbars like this from the start, we'd either never have noticed the problem of the previous commit or fixed it much more quickly.
This commit is contained in:
parent
793f0daf44
commit
10efcfef8a
|
@ -23,6 +23,8 @@ on.mouse_press = function(x,y, mouse_button)
|
|||
if Show_code then
|
||||
if on_editor_scrollbar(Current_pane.editor_state, x,y) then
|
||||
Current_pane.editor_state.scrollbar_drag = true
|
||||
local sbtop = compute_scrollbar(Current_pane.editor_state)
|
||||
Current_pane.editor_state.scrollbar_offset = y - sbtop
|
||||
elseif on_editor_scrollbar_area(Current_pane.editor_state, x,y) then
|
||||
-- nothing
|
||||
elseif x < Current_pane.editor_state.right + 15 - 5 and y < Current_pane.editor_state.bottom + 5 + 10 - 5 then
|
||||
|
@ -30,6 +32,8 @@ on.mouse_press = function(x,y, mouse_button)
|
|||
edit.mouse_press(Current_pane.editor_state, x,y, mouse_button)
|
||||
elseif on_editor_scrollbar(Current_pane.output_editor_state, x,y) then
|
||||
Current_pane.output_editor_state.scrollbar_drag = true
|
||||
local sbtop = compute_scrollbar(Current_pane.output_editor_state)
|
||||
Current_pane.output_editor_state.scrollbar_offset = y - sbtop
|
||||
elseif on_editor_scrollbar_area(Current_pane.output_editor_state, x,y) then
|
||||
-- nothing
|
||||
end
|
||||
|
@ -38,4 +42,4 @@ on.mouse_press = function(x,y, mouse_button)
|
|||
if car.mouse_press then car.mouse_press(x,y, mouse_button) end
|
||||
if car.mousepressed then car.mousepressed(x,y, mouse_button) end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,6 +14,7 @@ on.mouse_release = function(x,y, mouse_button)
|
|||
if Current_pane.editor_state.scrollbar_drag then
|
||||
adjust_scrollbar(Current_pane.editor_state, y)
|
||||
Current_pane.editor_state.scrollbar_drag = nil
|
||||
Current_pane.editor_state.scrollbar_offset = nil
|
||||
elseif on_editor_scrollbar_area(Current_pane.editor_state, x,y) then
|
||||
adjust_scrollbar(Current_pane.editor_state, y)
|
||||
elseif x < Current_pane.editor_state.right + 15 - 5 and y < Current_pane.editor_state.bottom + 5 + 10 - 5 then
|
||||
|
@ -21,6 +22,7 @@ on.mouse_release = function(x,y, mouse_button)
|
|||
elseif Current_pane.output_editor_state.scrollbar_drag then
|
||||
adjust_scrollbar(Current_pane.output_editor_state, y)
|
||||
Current_pane.output_editor_state.scrollbar_drag = nil
|
||||
Current_pane.output_editor_state.scrollbar_offset = nil
|
||||
elseif on_editor_scrollbar_area(Current_pane.output_editor_state, x,y) then
|
||||
adjust_scrollbar(Current_pane.output_editor_state, y)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
adjust_scrollbar = function(state, y)
|
||||
local s = (y-state.top) / (state.bottom-state.top)
|
||||
local s = (y-state.scrollbar_offset-state.top) / (state.bottom-state.top)
|
||||
local screen_line = s*state.screen_line_count
|
||||
local line = 1
|
||||
for i=1,#state.lines do
|
||||
|
|
Loading…
Reference in New Issue