Progress #210 Add set_max_gui_upscale for layout component

This commit is contained in:
Insality
2022-12-03 16:15:48 +02:00
parent dad54d8de3
commit 4f7dbf49d3
2 changed files with 64 additions and 12 deletions

View File

@@ -107,6 +107,13 @@ function M.get_screen_aspect_koef()
end
function M.get_gui_scale()
local window_x, window_y = window.get_size()
return math.min(window_x / gui.get_width(),
window_y / gui.get_height())
end
function M.step(current, target, step)
if current < target then
return math.min(current + step, target)
@@ -183,6 +190,23 @@ function M.is_enabled(node)
end
--- Return current node scene scale
-- @function helper.is_enabled
-- @tparam node node Gui node
-- @tparam bool include_passed_node_scale True if add current node scale to result
-- @treturn vector3 The scene node scale
function M.get_scene_scale(node, include_passed_node_scale)
local scale = include_passed_node_scale and gui.get_scale(node) or vmath.vector3(1)
local parent = gui.get_parent(node)
while parent do
scale = vmath.mul_per_elem(scale, gui.get_scale(parent))
parent = gui.get_parent(parent)
end
return scale
end
--- Return closest non inverted clipping parent node for node
-- @function helper.get_closest_stencil_node
-- @tparam node node Gui node
@@ -280,20 +304,23 @@ function M.get_border(node, offset)
end
function M.get_text_metrics_from_node(node)
local font_resource = gui.get_font_resource(gui.get_font(node))
--- Get text metric from gui node. Replacement of previous gui.get_text_metrics_from_node function
-- @tparam Node text_node
-- @treturn table {width, height, max_ascent, max_descent}
function M.get_text_metrics_from_node(text_node)
local font_resource = gui.get_font_resource(gui.get_font(text_node))
local options = {
tracking = gui.get_tracking(node),
line_break = gui.get_line_break(node),
tracking = gui.get_tracking(text_node),
line_break = gui.get_line_break(text_node),
}
-- Gather other options only if it used in node
if options.line_break then
options.width = gui.get_size(node).x
options.leading = gui.get_leading(node)
options.width = gui.get_size(text_node).x
options.leading = gui.get_leading(text_node)
end
return resource.get_text_metrics(font_resource, gui.get_text(node), options)
return resource.get_text_metrics(font_resource, gui.get_text(text_node), options)
end