Skip to content

Commit 9a0f341

Browse files
authored
Merge pull request #311 from rigo128/fix_get_screen_aspect_koef
Fix helper.get_screen_aspect_koef() for gui layouts.
2 parents 8ddb6e4 + ce49c3b commit 9a0f341

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

druid/helper.lua

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,23 @@ end
141141
---@return number stretch_x
142142
---@return number stretch_y
143143
function M.get_screen_aspect_koef()
144-
local window_x, window_y = window.get_size()
144+
local gui_width = gui.get_width()
145+
local gui_height = gui.get_height()
146+
local gui_r = gui_width / gui_height
147+
148+
local window_width, window_height = window.get_size()
149+
local window_r = window_width / window_height
145150

146-
local stretch_x = window_x / gui.get_width()
147-
local stretch_y = window_y / gui.get_height()
148-
local stretch_koef = math.min(stretch_x, stretch_y)
151+
local w_s = 1
152+
local h_s = 1
149153

150-
local koef_x = window_x / (stretch_koef * sys.get_config_int("display.width"))
151-
local koef_y = window_y / (stretch_koef * sys.get_config_int("display.height"))
154+
if gui_r < window_r then
155+
w_s = window_r / gui_r
156+
else
157+
h_s = gui_r / window_r
158+
end
152159

153-
return koef_x, koef_y
160+
return w_s, h_s
154161
end
155162

156163

0 commit comments

Comments
 (0)