From 98215252bde5cb7e0c6bca8f5d9ada9f57e20198 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 15 Oct 2024 22:05:16 +0200 Subject: [PATCH 1/3] add tooltip text alignment editor options --- Source/Editor/Options/InterfaceOptions.cs | 9 +++++++++ Source/Engine/UI/GUI/Tooltip.cs | 23 ++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index d8493a70a..ea3d613a0 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -217,6 +217,15 @@ namespace FlaxEditor.Options [EditorDisplay("Interface"), EditorOrder(320), Tooltip("Toggles tree line visibility in places like the Scene or Content Panel.")] public bool ShowTreeLines { get; set; } = true; + /// + /// Gets or sets tooltip text alignment. + /// + [DefaultValue(TextAlignment.Center)] + [EditorDisplay("Interface"), EditorOrder(321)] + public TextAlignment TooltipTextAlignment { get; set; } = TextAlignment.Center; + + + /// /// Gets or sets the timestamps prefix mode for output log messages. /// diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index a7f80e152..61bacb934 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -1,5 +1,7 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +using FlaxEditor; +using FlaxEditor.Options; using System; namespace FlaxEngine.GUI @@ -236,7 +238,22 @@ namespace FlaxEngine.GUI // Padding for text var textRect = GetClientArea(); - textRect.X += 5; + + float textX = 0; + switch (Editor.Instance.Options.Options.Interface.TooltipTextAlignment) + { + case TextAlignment.Near: + textX = 15; + break; + case TextAlignment.Center: + textX = 5; + break; + case TextAlignment.Far: + textX = -5; + break; + } + + textRect.X += textX; textRect.Width -= 10; // Tooltip text @@ -245,7 +262,7 @@ namespace FlaxEngine.GUI _currentText, textRect, style.Foreground, - TextAlignment.Center, + Editor.Instance.Options.Options.Interface.TooltipTextAlignment, TextAlignment.Center, TextWrapping.WrapWords ); @@ -265,7 +282,7 @@ namespace FlaxEngine.GUI { var layout = TextLayoutOptions.Default; layout.Bounds = new Rectangle(0, 0, MaxWidth, 10000000); - layout.HorizontalAlignment = TextAlignment.Center; + layout.HorizontalAlignment = TextAlignment.Near; layout.VerticalAlignment = TextAlignment.Center; layout.TextWrapping = TextWrapping.WrapWords; var items = style.FontMedium.ProcessText(_currentText, ref layout); From 7558cce6094f3a3b35df3aa5ae482e1f290d1ddb Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 15 Oct 2024 22:07:09 +0200 Subject: [PATCH 2/3] change back accidentally committed line --- Source/Engine/UI/GUI/Tooltip.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index 61bacb934..bac74b5ab 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -282,7 +282,7 @@ namespace FlaxEngine.GUI { var layout = TextLayoutOptions.Default; layout.Bounds = new Rectangle(0, 0, MaxWidth, 10000000); - layout.HorizontalAlignment = TextAlignment.Near; + layout.HorizontalAlignment = TextAlignment.Center; layout.VerticalAlignment = TextAlignment.Center; layout.TextWrapping = TextWrapping.WrapWords; var items = style.FontMedium.ProcessText(_currentText, ref layout); From b27ccc5f3be689e29e100fbbb35daea340a7be25 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Thu, 17 Oct 2024 18:42:39 +0200 Subject: [PATCH 3/3] condense switch statement --- Source/Engine/UI/GUI/Tooltip.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index bac74b5ab..dbd91ffef 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -239,19 +239,12 @@ namespace FlaxEngine.GUI // Padding for text var textRect = GetClientArea(); - float textX = 0; - switch (Editor.Instance.Options.Options.Interface.TooltipTextAlignment) + float textX = Editor.Instance.Options.Options.Interface.TooltipTextAlignment switch { - case TextAlignment.Near: - textX = 15; - break; - case TextAlignment.Center: - textX = 5; - break; - case TextAlignment.Far: - textX = -5; - break; - } + TextAlignment.Near => 15, + TextAlignment.Center => 5, + TextAlignment.Far => -5, + }; textRect.X += textX; textRect.Width -= 10;