Fixed GUI having a total recalculation whenever a style changed, made tooltip not be centered on mouse, removed duplicate loc from Text

This commit is contained in:
2021-05-28 00:43:40 +00:00
parent 0b63986b64
commit 850bb610bb
3 changed files with 11 additions and 3 deletions

View File

@@ -23,7 +23,6 @@ module CyberarmEngine
@shadow = true if options[:shadow].nil?
@shadow_size = options[:shadow_size] || 1
@shadow_alpha = options[:shadow_alpha] || 30
@shadow_alpha = options[:shadow_alpha] || 30
@shadow_color = options[:shadow_color]
@textobject = check_cache(@size, @font)

View File

@@ -118,6 +118,9 @@ module CyberarmEngine
end
def update_styles(event = :default)
old_width = width
old_height = height
_style = @style.send(event)
@style_event = event
@@ -126,7 +129,13 @@ module CyberarmEngine
@text.swap_font(_style&.dig(:text_size) || @style.default[:text_size], _style&.dig(:font) || @style.default[:font])
end
return if self.is_a?(ToolTip)
if old_width != width || old_height != height
(root&.gui_state || @gui_state).request_recalculate
else
stylize
end
end
def default_events

View File

@@ -103,7 +103,7 @@ module CyberarmEngine
if Vector.new(window.mouse_x, window.mouse_y) == @last_mouse_pos
if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
@tip.value = @mouse_over.tip if @mouse_over
@tip.x = window.mouse_x - @tip.width / 2
@tip.x = window.mouse_x
@tip.x = 0 if @tip.x < 0
@tip.x = window.width - @tip.width if @tip.x + @tip.width > window.width
@tip.y = window.mouse_y - (@tip.height + 5)