Add utility Copy option for various labels in assets editors
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user