History

console.lua: refine the hovered item calculation

Calculate the hovered item from the bottom of the screen where the console is anchored. This is simpler and accurate because it accounts for the fact that the empty line between the log and the input line isn't as tall as a full line, for the exact height of an always visible OSC bottombar, and for the empty top pixels present because the height isn't an integer multiple of the font size.

Guido Cella committed 2 years ago

Commit 00e223c1 parent e1680161 file · +12 −17Browse files

Showing the changes to player/lua/console.lua (1 of 1 file). Show all

Unified · Split

player/lua/console.lua+12−17
@@ -822,29 +822,24 @@ end · 821 unmodified lines
822local function determine_hovered_item()822local function determine_hovered_item()
823 local height = select(2, get_scaled_osd_dimensions())823 local height = select(2, get_scaled_osd_dimensions())
824 local y = mp.get_property_native('mouse-pos').y / scale_factor()824 local y = mp.get_property_native('mouse-pos').y / scale_factor()
825 - global_margins.t * height825 local log_bottom_pos = height * (1 - global_margins.b)
826 -- Calculate how many lines could be printed without decreasing them for826 - bottom_left_margin - 1.5 * opts.font_size
827 -- the input line and OSC.
828 local max_lines = height / opts.font_size
829 local clicked_line = math.ceil(y / height * max_lines)
830 827
831 local offset = first_match_to_print - 1828 if y > log_bottom_pos then
832 local min_line = 1829 return
833 max_lines = calculate_max_log_lines()830 end
834 831
832 local max_lines = calculate_max_log_lines()
835 -- Subtract 1 line for the position counter.833 -- Subtract 1 line for the position counter.
836 if first_match_to_print > 1 or offset + max_lines < #matches then834 if #matches > max_lines then
837 min_line = 2835 max_lines = max_lines - 1
838 offset = offset - 1
839 end836 end
837 local last = math.min(first_match_to_print - 1 + max_lines, #matches)
840 838
841 if #matches < max_lines then839 local hovered_item = last - math.floor((log_bottom_pos - y) / opts.font_size)
842 clicked_line = clicked_line - (max_lines - #matches)
843 max_lines = #matches
844 end
845 840
846 if clicked_line >= min_line and clicked_line <= max_lines then841 if hovered_item >= first_match_to_print then
847 return offset + clicked_line842 return hovered_item
848 end843 end
849end844end
850 845

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t