Replace clickable images with actual buttons

With the new icons the clickable images for adding functions for the Visject surface got too small and unreadable. Instead using more visible buttons should counteract this.
This commit is contained in:
W2Wizard
2021-06-13 14:49:10 +02:00
parent 63ef1e544a
commit eb6e3a7e8e
2 changed files with 38 additions and 47 deletions

View File

@@ -167,6 +167,8 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc />
public override DisplayStyle Style => DisplayStyle.InlineIntoParent;
private Control _overrideButton;
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
@@ -178,6 +180,21 @@ namespace FlaxEditor.Windows.Assets
var group = layout.Group("Functions");
var nodes = window.VisjectSurface.Nodes;
var grid = group.CustomContainer<UniformGridPanel>();
var gridControl = grid.CustomControl;
gridControl.ClipChildren = false;
gridControl.Height = Button.DefaultHeight;
gridControl.SlotsHorizontally = 2;
gridControl.SlotsVertically = 1;
var addOverride = grid.Button("Add Override");
addOverride.Button.Clicked += OnOverrideMethodClicked;
// TODO: Add sender arg to button clicked action?
_overrideButton = addOverride.Control;
var addFuncction = grid.Button("Add Function");
addFuncction.Button.Clicked += OnAddNewFunctionClicked;
// List of functions in the graph
for (int i = 0; i < nodes.Count; i++)
{
@@ -192,60 +209,20 @@ namespace FlaxEditor.Windows.Assets
}
else if (node is Surface.Archetypes.Function.MethodOverrideNode overrideNode)
{
var label = group.ClickableLabel(overrideNode.Title + " (override)").CustomControl;
var label = group.ClickableLabel($"{overrideNode.Title} (override)").CustomControl;
label.TextColorHighlighted = Color.FromBgra(0xFFA0A0A0);
label.TooltipText = overrideNode.TooltipText;
label.DoubleClick += () => ((VisualScriptWindow)Values[0]).Surface.FocusNode(overrideNode);
label.RightClick += () => ShowContextMenu(overrideNode, label);
}
}
// New function button
const float groupPanelButtonSize = 14;
var addNewFunction = new Image
{
TooltipText = "Add new function",
AutoFocus = true,
AnchorPreset = AnchorPresets.TopRight,
Parent = group.Panel,
Bounds = new Rectangle(group.Panel.Width - groupPanelButtonSize, 0, groupPanelButtonSize, groupPanelButtonSize),
IsScrollable = false,
Color = FlaxEngine.GUI.Style.Current.ForegroundGrey,
Margin = new Margin(1),
Brush = new SpriteBrush(Editor.Instance.Icons.Add64),
};
addNewFunction.Clicked += OnAddNewFunctionClicked;
// Override method button
var overrideMethod = new Image
{
TooltipText = "Override method",
AutoFocus = true,
AnchorPreset = AnchorPresets.TopRight,
Parent = group.Panel,
Bounds = new Rectangle(group.Panel.Width - groupPanelButtonSize * 2, 0, groupPanelButtonSize, groupPanelButtonSize),
IsScrollable = false,
Color = FlaxEngine.GUI.Style.Current.ForegroundGrey,
Margin = new Margin(1),
Brush = new SpriteBrush(Editor.Instance.Icons.Import64),
};
overrideMethod.Clicked += OnOverrideMethodClicked;
}
private void OnAddNewFunctionClicked(Image image, MouseButton button)
{
if (button != MouseButton.Left)
return;
var surface = ((VisualScriptWindow)Values[0]).Surface;
var surfaceBounds = surface.AllNodesBounds;
surface.ShowArea(new Rectangle(surfaceBounds.BottomLeft, new Vector2(200, 150)).MakeExpanded(400.0f));
var node = surface.Context.SpawnNode(16, 6, surfaceBounds.BottomLeft + new Vector2(0, 50));
surface.Select(node);
}
private void ShowContextMenu(SurfaceNode node, ClickableLabel label)
{
// TODO: Execute only on "Edit Signature...", this makes the "Show" button useless
((VisualScriptWindow)Values[0]).Surface.FocusNode(node);
var cm = new ContextMenu();
cm.AddButton("Show", () => ((VisualScriptWindow)Values[0]).Surface.FocusNode(node)).Icon = Editor.Instance.Icons.Search12;
cm.AddButton("Delete", () => ((VisualScriptWindow)Values[0]).Surface.Delete(node)).Icon = Editor.Instance.Icons.Cross12;
@@ -253,11 +230,17 @@ namespace FlaxEditor.Windows.Assets
cm.Show(label, new Vector2(0, label.Height));
}
private void OnOverrideMethodClicked(Image image, MouseButton button)
private void OnAddNewFunctionClicked()
{
if (button != MouseButton.Left)
return;
var surface = ((VisualScriptWindow)Values[0]).Surface;
var surfaceBounds = surface.AllNodesBounds;
surface.ShowArea(new Rectangle(surfaceBounds.BottomLeft, new Vector2(200, 150)).MakeExpanded(400.0f));
var node = surface.Context.SpawnNode(16, 6, surfaceBounds.BottomLeft + new Vector2(0, 50));
surface.Select(node);
}
private void OnOverrideMethodClicked()
{
var cm = new ContextMenu();
var window = (VisualScriptWindow)Values[0];
var scriptMeta = window.Asset.Meta;
@@ -310,7 +293,7 @@ namespace FlaxEditor.Windows.Assets
{
cm.AddButton("Nothing to override");
}
cm.Show(image, new Vector2(0, image.Height));
cm.Show(_overrideButton, new Vector2(0, _overrideButton.Height));
}
}