History

console.lua: default to a proportional font for select

In the select menu there are no completions to align in a grid, so the better looking proportional font of --osd-font can be used by default. It is also easier to read for the visually impaired. The text width calculation is no longer performed if the console is only opened through select, it is only performed the first time something is completed. This avoids having to pass an argument to get_font() to make it use the monospace font regardless of selectable_items. Fixes #15176.

Guido Cella committed 2 years ago

Commit aa66f0d1 parent cb8e3ba2 files · +57 −37Browse files

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

Unified · Split

player/lua/console.lua+49−32
@@ -15,17 +15,6 @@ · 14 unmodified lines
1515 local utils = require 'mp.utils'
1616 local assdraw = require 'mp.assdraw'
1717
18−-- Default options
19−local opts = {
20− font = "",
21− font_size = 24,
22− border_size = 1.5,
23− scale_with_window = "auto",
24− case_sensitive = true,
25− history_dedup = true,
26− font_hw_ratio = 'auto',
27−}
28−
2918 local function detect_platform()
3019 local platform = mp.get_property_native('platform')
3120 if platform == 'darwin' or platform == 'windows' then
@@ -36,16 +25,18 @@ local function detect_platform() · 4 unmodified lines
3625 return 'x11'
3726 end
3827
39−-- Pick a better default font for Windows and macOS
4028 local platform = detect_platform()
41−if platform == 'windows' then
42− opts.font = 'Consolas'
43− opts.case_sensitive = false
44−elseif platform == 'darwin' then
45− opts.font = 'Menlo'
46−else
47− opts.font = 'monospace'
48−end
29+
30+-- Default options
31+local opts = {
32+ font = "",
33+ font_size = 16,
34+ border_size = 1,
35+ scale_with_window = "auto",
36+ case_sensitive = platform ~= 'windows' and true or false,
37+ history_dedup = true,
38+ font_hw_ratio = 'auto',
39+}
4940
5041 -- Apply user-set options
5142 require 'mp.options'.read_options(opts)
@@ -117,6 +108,28 @@ local default_item · 65 unmodified lines
117108 local set_active
118109
119110
111+local function get_font()
112+ if opts.font ~= '' then
113+ return opts.font
114+ end
115+
116+ if selectable_items and not searching_history then
117+ return
118+ end
119+
120+ -- Pick a better default font for Windows and macOS
121+ if platform == 'windows' then
122+ return 'Consolas'
123+ end
124+
125+ if platform == 'darwin' then
126+ return 'Menlo'
127+ end
128+
129+ return 'monospace'
130+end
131+
132+
120133 -- Naive helper function to find the next UTF-8 character in 'str' after 'pos'
121134 -- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.
122135 local function next_utf8(str, pos)
@@ -184,7 +197,7 @@ local function normalized_text_width(text, size, horizontal) · 61 unmodified lines
184197 for i = 1, repetitions_left do
185198 size = size * 0.8
186199 local ass = assdraw.ass_new()
187− ass.text = template:format(align, size, opts.font, rotation, text)
200+ ass.text = template:format(align, size, get_font(), rotation, text)
188201 local _, _, x1, y1 = measure_bounds(ass.text)
189202 -- Check if nothing got clipped
190203 if x1 and x1 < osd_width and y1 < osd_height then
@@ -507,10 +520,12 @@ local function update() · 316 unmodified lines
507520 screenx .. ',' .. screeny
508521 local ass = assdraw.ass_new()
509522 local has_shadow = mp.get_property('osd-border-style'):find('box$') == nil
523+ local font = get_font()
510524 local style = '{\\r' ..
511525 '\\1a&H00&\\3a&H00&\\1c&Heeeeee&\\3c&H111111&' ..
512526 (has_shadow and '\\4a&H99&\\4c&H000000&' or '') ..
513− '\\fn' .. opts.font .. '\\fs' .. opts.font_size ..
527+ (font and '\\fn' .. font or '') ..
528+ '\\fs' .. opts.font_size ..
514529 '\\bord' .. opts.border_size .. '\\xshad0\\yshad1\\fsp0' ..
515530 (selectable_items and '\\q2' or '\\q1') ..
516531 '\\clip(' .. clipping_coordinates .. ')}'
@@ -534,20 +549,24 @@ local function update() · 17 unmodified lines
534549 -- This will render at most screeny / font_size - 1 messages.
535550
536551 local lines_max = calculate_max_log_lines()
537− -- Estimate how many characters fit in one line
538− local width_max = math.floor((screenx - bottom_left_margin -
539− mp.get_property_native('osd-margin-x') * 2 * screeny / 720) /
540− opts.font_size * get_font_hw_ratio())
552+ local suggestion_ass = ''
553+ if next(suggestion_buffer) then
554+ -- Estimate how many characters fit in one line
555+ local width_max = math.floor((screenx - bottom_left_margin -
556+ mp.get_property_native('osd-margin-x') * 2 * screeny / 720)
557+ / opts.font_size * get_font_hw_ratio())
541558
542− local suggestions, rows = format_table(suggestion_buffer, width_max, lines_max)
543− local suggestion_ass = style .. styles.suggestion .. suggestions
559+ local suggestions, rows = format_table(suggestion_buffer, width_max, lines_max)
560+ lines_max = lines_max - rows
561+ suggestion_ass = style .. styles.suggestion .. suggestions .. '\\N'
562+ end
544563
545564 populate_log_with_matches()
546565
547566 local log_ass = ''
548567 local log_buffer = log_buffers[id]
549568 local log_messages = #log_buffer
550− local log_max_lines = math.max(0, lines_max - rows)
569+ local log_max_lines = math.max(0, lines_max)
551570 if log_max_lines < log_messages then
552571 log_messages = log_max_lines
553572 end
@@ -560,9 +579,7 @@ local function update() · 6 unmodified lines
560579 ass:an(1)
561580 ass:pos(bottom_left_margin, screeny - bottom_left_margin - global_margins.b * screeny)
562581 ass:append(log_ass .. '\\N')
563− if #suggestions > 0 then
564− ass:append(suggestion_ass .. '\\N')
565− end
582+ ass:append(suggestion_ass)
566583 ass:append(style .. ass_escape(prompt) .. ' ' .. before_cur)
567584 ass:append(cglyph)
568585 ass:append(style .. after_cur)

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