Add utility Copy option for various labels in assets editors

This commit is contained in:
Wojciech Figat
2022-03-22 17:16:15 +01:00
parent 885d2f0771
commit 832a4bf86a
5 changed files with 43 additions and 15 deletions

View File

@@ -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
/// <seealso cref="FlaxEditor.CustomEditors.LayoutElement" />
public class LabelElement : LayoutElement
{
private Action<ContextMenu> _customContextualOptions;
/// <summary>
/// The label.
/// </summary>
public readonly Label Label;
public readonly ClickableLabel Label;
/// <summary>
/// Initializes a new instance of the <see cref="CheckBoxElement"/> class.
/// </summary>
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
}
/// <summary>
/// Adds a simple context menu with utility to copy label text. Can be extended with more options.
/// </summary>
public LabelElement AddCopyContextMenu(Action<ContextMenu> 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;
}
/// <inheritdoc />
public override Control Control => Label;
}

View File

@@ -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));
}

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");