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
15local utils = require 'mp.utils'15local utils = require 'mp.utils'
16local assdraw = require 'mp.assdraw'16local assdraw = require 'mp.assdraw'
17 17
18-- Default options
19local 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
29local function detect_platform()18local function detect_platform()
30 local platform = mp.get_property_native('platform')19 local platform = mp.get_property_native('platform')
31 if platform == 'darwin' or platform == 'windows' then20 if platform == 'darwin' or platform == 'windows' then
@@ -36,16 +25,18 @@ local function detect_platform() · 4 unmodified lines
36 return 'x11'25 return 'x11'
37end26end
38 27
39-- Pick a better default font for Windows and macOS
40local platform = detect_platform()28local platform = detect_platform()
41if platform == 'windows' then29
42 opts.font = 'Consolas'30-- Default options
43 opts.case_sensitive = false31local opts = {
44elseif platform == 'darwin' then32 font = "",
45 opts.font = 'Menlo'33 font_size = 16,
46else34 border_size = 1,
47 opts.font = 'monospace'35 scale_with_window = "auto",
48end36 case_sensitive = platform ~= 'windows' and true or false,
37 history_dedup = true,
38 font_hw_ratio = 'auto',
39}
49 40
50-- Apply user-set options41-- Apply user-set options
51require 'mp.options'.read_options(opts)42require 'mp.options'.read_options(opts)
@@ -117,6 +108,28 @@ local default_item · 65 unmodified lines
117local set_active108local set_active
118 109
119 110
111local 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'
130end
131
132
120-- Naive helper function to find the next UTF-8 character in 'str' after 'pos'133-- Naive helper function to find the next UTF-8 character in 'str' after 'pos'
121-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.134-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.
122local function next_utf8(str, pos)135local function next_utf8(str, pos)
@@ -184,7 +197,7 @@ local function normalized_text_width(text, size, horizontal) · 61 unmodified lines
184 for i = 1, repetitions_left do197 for i = 1, repetitions_left do
185 size = size * 0.8198 size = size * 0.8
186 local ass = assdraw.ass_new()199 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)
188 local _, _, x1, y1 = measure_bounds(ass.text)201 local _, _, x1, y1 = measure_bounds(ass.text)
189 -- Check if nothing got clipped202 -- Check if nothing got clipped
190 if x1 and x1 < osd_width and y1 < osd_height then203 if x1 and x1 < osd_width and y1 < osd_height then
@@ -507,10 +520,12 @@ local function update() · 316 unmodified lines
507 screenx .. ',' .. screeny520 screenx .. ',' .. screeny
508 local ass = assdraw.ass_new()521 local ass = assdraw.ass_new()
509 local has_shadow = mp.get_property('osd-border-style'):find('box$') == nil522 local has_shadow = mp.get_property('osd-border-style'):find('box$') == nil
523 local font = get_font()
510 local style = '{\\r' ..524 local style = '{\\r' ..
511 '\\1a&H00&\\3a&H00&\\1c&Heeeeee&\\3c&H111111&' ..525 '\\1a&H00&\\3a&H00&\\1c&Heeeeee&\\3c&H111111&' ..
512 (has_shadow and '\\4a&H99&\\4c&H000000&' or '') ..526 (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 ..
514 '\\bord' .. opts.border_size .. '\\xshad0\\yshad1\\fsp0' ..529 '\\bord' .. opts.border_size .. '\\xshad0\\yshad1\\fsp0' ..
515 (selectable_items and '\\q2' or '\\q1') ..530 (selectable_items and '\\q2' or '\\q1') ..
516 '\\clip(' .. clipping_coordinates .. ')}'531 '\\clip(' .. clipping_coordinates .. ')}'
@@ -534,20 +549,24 @@ local function update() · 17 unmodified lines
534 -- This will render at most screeny / font_size - 1 messages.549 -- This will render at most screeny / font_size - 1 messages.
535 550
536 local lines_max = calculate_max_log_lines()551 local lines_max = calculate_max_log_lines()
537 -- Estimate how many characters fit in one line552 local suggestion_ass = ''
538 local width_max = math.floor((screenx - bottom_left_margin -553 if next(suggestion_buffer) then
539 mp.get_property_native('osd-margin-x') * 2 * screeny / 720) /554 -- Estimate how many characters fit in one line
540 opts.font_size * get_font_hw_ratio())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())
541 558
542 local suggestions, rows = format_table(suggestion_buffer, width_max, lines_max)559 local suggestions, rows = format_table(suggestion_buffer, width_max, lines_max)
543 local suggestion_ass = style .. styles.suggestion .. suggestions560 lines_max = lines_max - rows
561 suggestion_ass = style .. styles.suggestion .. suggestions .. '\\N'
562 end
544 563
545 populate_log_with_matches()564 populate_log_with_matches()
546 565
547 local log_ass = ''566 local log_ass = ''
548 local log_buffer = log_buffers[id]567 local log_buffer = log_buffers[id]
549 local log_messages = #log_buffer568 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)
551 if log_max_lines < log_messages then570 if log_max_lines < log_messages then
552 log_messages = log_max_lines571 log_messages = log_max_lines
553 end572 end
@@ -560,9 +579,7 @@ local function update() · 6 unmodified lines
560 ass:an(1)579 ass:an(1)
561 ass:pos(bottom_left_margin, screeny - bottom_left_margin - global_margins.b * screeny)580 ass:pos(bottom_left_margin, screeny - bottom_left_margin - global_margins.b * screeny)
562 ass:append(log_ass .. '\\N')581 ass:append(log_ass .. '\\N')
563 if #suggestions > 0 then582 ass:append(suggestion_ass)
564 ass:append(suggestion_ass .. '\\N')
565 end
566 ass:append(style .. ass_escape(prompt) .. ' ' .. before_cur)583 ass:append(style .. ass_escape(prompt) .. ' ' .. before_cur)
567 ass:append(cglyph)584 ass:append(cglyph)
568 ass:append(style .. after_cur)585 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