mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Replace gui.get_text_metrics with resource.get_text_metrics
This commit is contained in:
parent
09ecc45921
commit
9d75af2eb9
@ -47,6 +47,7 @@
|
|||||||
|
|
||||||
local Event = require("druid.event")
|
local Event = require("druid.event")
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
|
local helper = require("druid.helper")
|
||||||
local utf8 = require("druid.system.utf8")
|
local utf8 = require("druid.system.utf8")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
@ -77,7 +78,7 @@ local function update_text_area_size(self)
|
|||||||
local max_width = self.text_area.x
|
local max_width = self.text_area.x
|
||||||
local max_height = self.text_area.y
|
local max_height = self.text_area.y
|
||||||
|
|
||||||
local metrics = gui.get_text_metrics_from_node(self.node)
|
local metrics = helper.get_text_metrics_from_node(self.node)
|
||||||
|
|
||||||
local scale_modifier = max_width / metrics.width
|
local scale_modifier = max_width / metrics.width
|
||||||
scale_modifier = math.min(scale_modifier, self.start_scale.x)
|
scale_modifier = math.min(scale_modifier, self.start_scale.x)
|
||||||
@ -133,8 +134,8 @@ end
|
|||||||
-- calculate space width with font
|
-- calculate space width with font
|
||||||
local function get_space_width(self, font)
|
local function get_space_width(self, font)
|
||||||
if not self._space_width[font] then
|
if not self._space_width[font] then
|
||||||
local no_space = gui.get_text_metrics(font, "1", 0, false, 0, 0).width
|
local no_space = resource.get_text_metrics(font, "1").width
|
||||||
local with_space = gui.get_text_metrics(font, " 1", 0, false, 0, 0).width
|
local with_space = resource.get_text_metrics(font, " 1").width
|
||||||
self._space_width[font] = with_space - no_space
|
self._space_width[font] = with_space - no_space
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ local M = {}
|
|||||||
--- Text node or icon node can be nil
|
--- Text node or icon node can be nil
|
||||||
local function get_text_width(text_node)
|
local function get_text_width(text_node)
|
||||||
if text_node then
|
if text_node then
|
||||||
local text_metrics = gui.get_text_metrics_from_node(text_node)
|
local text_metrics = M.get_text_metrics_from_node(text_node)
|
||||||
local text_scale = gui.get_scale(text_node).x
|
local text_scale = gui.get_scale(text_node).x
|
||||||
return text_metrics.width * text_scale
|
return text_metrics.width * text_scale
|
||||||
end
|
end
|
||||||
@ -166,6 +166,22 @@ function M.contains(t, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- 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_name = gui.get_font(text_node)
|
||||||
|
local font = gui.get_font_resource(font_name)
|
||||||
|
return resource.get_text_metrics(font, gui.get_text(text_node), {
|
||||||
|
width = gui.get_size(text_node).x,
|
||||||
|
leading = gui.get_leading(text_node),
|
||||||
|
tracking = gui.get_tracking(text_node),
|
||||||
|
line_break = gui.get_line_break(text_node),
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Check if node is enabled in gui hierarchy.
|
--- Check if node is enabled in gui hierarchy.
|
||||||
-- Return false, if node or any his parent is disabled
|
-- Return false, if node or any his parent is disabled
|
||||||
-- @function helper.is_enabled
|
-- @function helper.is_enabled
|
||||||
|
Loading…
x
Reference in New Issue
Block a user