mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Solve #217 Fix error font argument, remove deprecated gui.get_text_metrics
This commit is contained in:
parent
5d3625e2a8
commit
7f5be3ffb0
@ -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
|
||||||
@ -280,6 +280,23 @@ function M.get_border(node, offset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.get_text_metrics_from_node(node)
|
||||||
|
local font_resource = gui.get_font_resource(gui.get_font(node))
|
||||||
|
local options = {
|
||||||
|
tracking = gui.get_tracking(node),
|
||||||
|
line_break = gui.get_line_break(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)
|
||||||
|
end
|
||||||
|
|
||||||
|
return resource.get_text_metrics(font_resource, gui.get_text(node), options)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Show deprecated message. Once time per message
|
--- Show deprecated message. Once time per message
|
||||||
-- @function helper.deprecated
|
-- @function helper.deprecated
|
||||||
-- @tparam string message The deprecated message
|
-- @tparam string message The deprecated message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user