diff --git a/Source/Editor/CustomEditors/Elements/LabelElement.cs b/Source/Editor/CustomEditors/Elements/LabelElement.cs index 3c1ee8ff7..061b1adff 100644 --- a/Source/Editor/CustomEditors/Elements/LabelElement.cs +++ b/Source/Editor/CustomEditors/Elements/LabelElement.cs @@ -1,5 +1,8 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. +using System; +using FlaxEditor.GUI; +using FlaxEditor.GUI.ContextMenu; using FlaxEngine; using FlaxEngine.GUI; @@ -11,23 +14,48 @@ namespace FlaxEditor.CustomEditors.Elements /// public class LabelElement : LayoutElement { + private Action _customContextualOptions; + /// /// The label. /// - public readonly Label Label; + public readonly ClickableLabel Label; /// /// Initializes a new instance of the class. /// public LabelElement() { - Label = new Label(0, 0, 100, 18) + Label = new ClickableLabel { - HorizontalAlignment = TextAlignment.Near + Size = new Vector2(100, 18), + HorizontalAlignment = TextAlignment.Near, }; // TODO: auto height for label } + /// + /// Adds a simple context menu with utility to copy label text. Can be extended with more options. + /// + public LabelElement AddCopyContextMenu(Action customOptions = null) + { + Label.RightClick += OnRightClick; + return this; + } + + private void OnRightClick() + { + var menu = new ContextMenu(); + menu.AddButton("Copy text").Clicked += OnCopyText; + _customContextualOptions?.Invoke(menu); + menu.Show(Label, Label.PointFromScreen(Input.MouseScreenPosition)); + } + + private void OnCopyText() + { + Clipboard.Text = Label.Text; + } + /// public override Control Control => Label; } diff --git a/Source/Editor/Windows/Assets/CubeTextureWindow.cs b/Source/Editor/Windows/Assets/CubeTextureWindow.cs index 278dd6f3a..845b40ee1 100644 --- a/Source/Editor/Windows/Assets/CubeTextureWindow.cs +++ b/Source/Editor/Windows/Assets/CubeTextureWindow.cs @@ -46,7 +46,7 @@ namespace FlaxEditor.Windows.Assets var group = layout.Group("General"); group.Label("Format: " + texture.Format); - group.Label(string.Format("Size: {0}x{1}", texture.Width, texture.Height)); + group.Label(string.Format("Size: {0}x{1}", texture.Width, texture.Height)).AddCopyContextMenu(); group.Label("Mip levels: " + texture.MipLevels); group.Label("Memory usage: " + Utilities.Utils.FormatBytesCount(texture.TotalMemoryUsage)); } diff --git a/Source/Editor/Windows/Assets/ModelWindow.cs b/Source/Editor/Windows/Assets/ModelWindow.cs index 28fbe9e98..f47901038 100644 --- a/Source/Editor/Windows/Assets/ModelWindow.cs +++ b/Source/Editor/Windows/Assets/ModelWindow.cs @@ -191,9 +191,9 @@ namespace FlaxEditor.Windows.Assets minScreenSize.FloatValue.MinValue = 0.0f; minScreenSize.FloatValue.MaxValue = 1.0f; minScreenSize.FloatValue.Value = proxy.Asset.MinScreenSize; - minScreenSize.FloatValue.ValueChanged += () => + minScreenSize.FloatValue.BoxValueChanged += b => { - proxy.Asset.MinScreenSize = minScreenSize.FloatValue.Value; + proxy.Asset.MinScreenSize = b.Value; proxy.Window.MarkAsEdited(); }; } @@ -218,15 +218,15 @@ namespace FlaxEditor.Windows.Assets vertexCount += mesh.VertexCount; } - group.Label(string.Format("Triangles: {0:N0} Vertices: {1:N0}", triangleCount, vertexCount)); - group.Label("Size: " + lod.Box.Size); + group.Label(string.Format("Triangles: {0:N0} Vertices: {1:N0}", triangleCount, vertexCount)).AddCopyContextMenu(); + group.Label("Size: " + lod.Box.Size).AddCopyContextMenu(); var screenSize = group.FloatValue("Screen Size", "The screen size to switch LODs. Bottom limit of the model screen size to render this LOD."); screenSize.FloatValue.MinValue = 0.0f; screenSize.FloatValue.MaxValue = 10.0f; screenSize.FloatValue.Value = lod.ScreenSize; - screenSize.FloatValue.ValueChanged += () => + screenSize.FloatValue.BoxValueChanged += b => { - lod.ScreenSize = screenSize.FloatValue.Value; + lod.ScreenSize = b.Value; proxy.Window.MarkAsEdited(); }; @@ -234,7 +234,7 @@ namespace FlaxEditor.Windows.Assets for (int meshIndex = 0; meshIndex < meshes.Length; meshIndex++) { var mesh = meshes[meshIndex]; - group.Label($"Mesh {meshIndex} (tris: {mesh.TriangleCount:N0}, verts: {mesh.VertexCount:N0})"); + group.Label($"Mesh {meshIndex} (tris: {mesh.TriangleCount:N0}, verts: {mesh.VertexCount:N0})").AddCopyContextMenu(); // Material Slot var materialSlot = group.ComboBox("Material Slot", "Material slot used by this mesh during rendering"); diff --git a/Source/Editor/Windows/Assets/SkinnedModelWindow.cs b/Source/Editor/Windows/Assets/SkinnedModelWindow.cs index 4927de680..069e6aece 100644 --- a/Source/Editor/Windows/Assets/SkinnedModelWindow.cs +++ b/Source/Editor/Windows/Assets/SkinnedModelWindow.cs @@ -219,7 +219,7 @@ namespace FlaxEditor.Windows.Assets vertexCount += mesh.VertexCount; } - group.Label(string.Format("Triangles: {0:N0} Vertices: {1:N0}", triangleCount, vertexCount)); + group.Label(string.Format("Triangles: {0:N0} Vertices: {1:N0}", triangleCount, vertexCount)).AddCopyContextMenu(); group.Label("Size: " + lod.Box.Size); var screenSize = group.FloatValue("Screen Size", "The screen size to switch LODs. Bottom limit of the model screen size to render this LOD."); screenSize.FloatValue.MinValue = 0.0f; @@ -235,7 +235,7 @@ namespace FlaxEditor.Windows.Assets for (int meshIndex = 0; meshIndex < meshes.Length; meshIndex++) { var mesh = meshes[meshIndex]; - group.Label($"Mesh {meshIndex} (tris: {mesh.TriangleCount:N0}, verts: {mesh.VertexCount:N0})"); + group.Label($"Mesh {meshIndex} (tris: {mesh.TriangleCount:N0}, verts: {mesh.VertexCount:N0})").AddCopyContextMenu(); // Material Slot var materialSlot = group.ComboBox("Material Slot", "Material slot used by this mesh during rendering"); diff --git a/Source/Editor/Windows/Assets/TextureWindow.cs b/Source/Editor/Windows/Assets/TextureWindow.cs index 5918de2a9..84c734365 100644 --- a/Source/Editor/Windows/Assets/TextureWindow.cs +++ b/Source/Editor/Windows/Assets/TextureWindow.cs @@ -36,9 +36,9 @@ namespace FlaxEditor.Windows.Assets // Texture info var general = layout.Group("General"); general.Label("Format: " + texture.Format); - general.Label(string.Format("Size: {0}x{1}", texture.Width, texture.Height)); + general.Label(string.Format("Size: {0}x{1}", texture.Width, texture.Height)).AddCopyContextMenu(); general.Label("Mip levels: " + texture.MipLevels); - general.Label("Memory usage: " + Utilities.Utils.FormatBytesCount(texture.TotalMemoryUsage)); + general.Label("Memory usage: " + Utilities.Utils.FormatBytesCount(texture.TotalMemoryUsage)).AddCopyContextMenu(); // Texture properties var properties = layout.Group("Properties");