// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; using FlaxEditor.GUI; using FlaxEditor.GUI.ContextMenu; using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.CustomEditors.Elements { /// /// The label element. /// /// public class LabelElement : LayoutElement { private Action _customContextualOptions; /// /// The label. /// public readonly ClickableLabel Label; /// /// Initializes a new instance of the class. /// public LabelElement() { Label = new ClickableLabel { Size = new Float2(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; _customContextualOptions = customOptions; 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; } }