// Copyright (c) Wojciech Figat. All rights reserved.
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.Surface.Elements
{
///
/// Text box input element.
///
///
///
[HideInEditor]
public sealed class TextBoxView : TextBox, ISurfaceNodeElement
{
///
public SurfaceNode ParentNode { get; }
///
public NodeElementArchetype Archetype { get; }
///
/// Gets the surface.
///
public VisjectSurface Surface => ParentNode.Surface;
///
public TextBoxView(SurfaceNode parentNode, NodeElementArchetype archetype)
: base(archetype.BoxID == 1, archetype.Position.X, archetype.Position.Y, archetype.Size.X)
{
ParentNode = parentNode;
Archetype = archetype;
Size = archetype.Size;
if (archetype.ValueIndex >= 0)
{
OnNodeValuesChanged();
EditEnd += () => ParentNode.SetValue(Archetype.ValueIndex, Text);
ParentNode.ValuesChanged += OnNodeValuesChanged;
}
}
private void OnNodeValuesChanged()
{
Text = (string)ParentNode.Values[Archetype.ValueIndex];
}
///
public override void Draw()
{
base.Draw();
// Draw border
if (!IsFocused)
Render2D.DrawRectangle(new Rectangle(Float2.Zero, Size), Style.Current.BorderNormal);
}
}
}