Added Text#text_width method, Text#width now returns value of Text#markup_width

This commit is contained in:
2021-06-03 13:05:11 +00:00
parent a92d1ad746
commit bd54fafc3f
2 changed files with 9 additions and 4 deletions

View File

@@ -61,7 +61,7 @@ module CyberarmEngine
Gosu::Color::WHITE Gosu::Color::WHITE
) )
@title.x = window.width / 2 - @title.width / 2 @title.x = window.width / 2 - @title.text_width / 2
@title.y = (window.height / 2 + (@spacer_height / 2) + @padding) * @animators[1].transition @title.y = (window.height / 2 + (@spacer_height / 2) + @padding) * @animators[1].transition
@title.text = "Powered By" @title.text = "Powered By"
@@ -115,14 +115,14 @@ module CyberarmEngine
height = @title_size + @caption_size + @spacer_height + 2 * @padding + @spacer_height height = @title_size + @caption_size + @spacer_height + 2 * @padding + @spacer_height
Gosu.record(width.ceil, height.ceil) do Gosu.record(width.ceil, height.ceil) do
@title.x = (width - @padding * 2) / 2 - @title.width / 2 @title.x = (width - @padding * 2) / 2 - @title.text_width / 2
@title.y = @padding @title.y = @padding
@title.draw @title.draw
Gosu.draw_rect(0, @padding + @title_size + @padding, @spacer_width, @spacer_height, Gosu::Color::WHITE) Gosu.draw_rect(0, @padding + @title_size + @padding, @spacer_width, @spacer_height, Gosu::Color::WHITE)
Gosu.draw_rect(1, @padding + @title_size + @padding + 1, @spacer_width - 2, @spacer_height - 2, color_hint) Gosu.draw_rect(1, @padding + @title_size + @padding + 1, @spacer_width - 2, @spacer_height - 2, color_hint)
@caption.x = (width - @padding * 2) / 2 - @caption.width / 2 @caption.x = (width - @padding * 2) / 2 - @caption.text_width / 2
@caption.y = @padding + @title_size + @padding + @spacer_height + @padding @caption.y = @padding + @title_size + @padding + @spacer_height + @padding
@caption.draw @caption.draw
end end

View File

@@ -128,6 +128,10 @@ module CyberarmEngine
end end
def width(text = @text) def width(text = @text)
markup_width(text)
end
def text_width(text = @text)
textobject.text_width(text) + @border_size + @shadow_size textobject.text_width(text) + @border_size + @shadow_size
end end
@@ -152,8 +156,9 @@ module CyberarmEngine
_x = @border_size _x = @border_size
_y = @border_size _y = @border_size
_width = method == :draw_markup ? text_width : markup_width
@rendered_border ||= Gosu.render((width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do @rendered_border ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
@textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode) @textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
@textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode) @textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)