From baa4c2c6806c555e48ab75b3e4520cb5c0c7ed10 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 22 Oct 2024 21:27:16 -0500 Subject: [PATCH] Fix tooltip having editor references. --- Source/Editor/Options/InterfaceOptions.cs | 11 +++++++++-- Source/Editor/Options/OptionsModule.cs | 2 ++ Source/Engine/UI/GUI/Tooltip.cs | 11 +++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index ea3d613a0..ca053dcab 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using FlaxEditor.GUI.Docking; using FlaxEditor.Utilities; using FlaxEngine; +using FlaxEngine.GUI; namespace FlaxEditor.Options { @@ -222,9 +223,15 @@ namespace FlaxEditor.Options /// [DefaultValue(TextAlignment.Center)] [EditorDisplay("Interface"), EditorOrder(321)] - public TextAlignment TooltipTextAlignment { get; set; } = TextAlignment.Center; - + public TextAlignment TooltipTextAlignment { get => _tooltipTextAlignment; + set + { + _tooltipTextAlignment = value; + Style.Current.SharedTooltip.HorizontalTextAlignment = value; + } + } + private TextAlignment _tooltipTextAlignment = TextAlignment.Center; /// /// Gets or sets the timestamps prefix mode for output log messages. diff --git a/Source/Editor/Options/OptionsModule.cs b/Source/Editor/Options/OptionsModule.cs index d43af963e..24dea810e 100644 --- a/Source/Editor/Options/OptionsModule.cs +++ b/Source/Editor/Options/OptionsModule.cs @@ -331,6 +331,7 @@ namespace FlaxEditor.Options SharedTooltip = new Tooltip(), }; + style.SharedTooltip.HorizontalTextAlignment = Editor.Instance.Options.Options.Interface.TooltipTextAlignment; style.DragWindow = style.BackgroundSelected * 0.7f; return style; } @@ -386,6 +387,7 @@ namespace FlaxEditor.Options SharedTooltip = new Tooltip(), }; + style.SharedTooltip.HorizontalTextAlignment = Editor.Instance.Options.Options.Interface.TooltipTextAlignment; return style; } diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index 16b9abe8e..40aae0067 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -1,7 +1,5 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. -using FlaxEditor; -using FlaxEditor.Options; using System; namespace FlaxEngine.GUI @@ -19,6 +17,11 @@ namespace FlaxEngine.GUI private string _currentText; private Window _window; + /// + /// The horizontal alignment of the text. + /// + public TextAlignment HorizontalTextAlignment = TextAlignment.Center; + /// /// Gets or sets the time in seconds that mouse have to be over the target to show the tooltip. /// @@ -238,7 +241,7 @@ namespace FlaxEngine.GUI // Padding for text var textRect = GetClientArea(); - float textX = Editor.Instance.Options.Options.Interface.TooltipTextAlignment switch + float textX = HorizontalTextAlignment switch { TextAlignment.Near => 15, TextAlignment.Center => 5, @@ -254,7 +257,7 @@ namespace FlaxEngine.GUI _currentText, textRect, style.Foreground, - Editor.Instance.Options.Options.Interface.TooltipTextAlignment, + HorizontalTextAlignment, TextAlignment.Center, TextWrapping.WrapWords );