Add safe check for LinkedLabel to prevent errors

This commit is contained in:
Wojtek Figat
2024-03-29 17:27:00 +01:00
parent 1017472957
commit 08e88587e6
6 changed files with 67 additions and 46 deletions

View File

@@ -111,6 +111,8 @@ namespace FlaxEditor.CustomEditors.Editors
SetLinkStyle();
var textSize = FlaxEngine.GUI.Style.Current.FontMedium.MeasureText(LinkedLabel.Text.Value);
_linkButton.LocalX += textSize.X + 10;
if (LinkedLabel != null)
{
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
@@ -119,6 +121,7 @@ namespace FlaxEditor.CustomEditors.Editors
else
menu.AddButton("Link", ToggleLink).LinkTooltip("Links scale components for uniform scaling");
};
}
// Override colors
var back = FlaxEngine.GUI.Style.Current.TextBoxBackground;

View File

@@ -34,6 +34,8 @@ namespace FlaxEditor.CustomEditors.Editors
if (valueCategory != Utils.ValueCategory.None)
{
doubleValue.SetCategory(valueCategory);
if (LinkedLabel != null)
{
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
@@ -44,6 +46,7 @@ namespace FlaxEditor.CustomEditors.Editors
}
}
}
}
private void OnValueChanged()
{

View File

@@ -53,6 +53,8 @@ namespace FlaxEditor.CustomEditors.Editors
if (valueCategory != Utils.ValueCategory.None)
{
floatValue.SetCategory(valueCategory);
if (LinkedLabel != null)
{
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
@@ -63,6 +65,7 @@ namespace FlaxEditor.CustomEditors.Editors
}
}
}
}
private void OnValueChanged()
{

View File

@@ -22,6 +22,7 @@ namespace FlaxEditor.CustomEditors.Editors
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
if (LinkedLabel != null)
LinkedLabel.SetupContextMenu += OnSetupContextMenu;
var comboBoxElement = layout.ComboBox();
_comboBox = comboBoxElement.ComboBox;

View File

@@ -59,6 +59,8 @@ namespace FlaxEditor.CustomEditors.Editors
ZElement.ValueBox.ValueChanged += OnValueChanged;
ZElement.ValueBox.SlidingEnd += ClearToken;
if (LinkedLabel != null)
{
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
@@ -66,6 +68,7 @@ namespace FlaxEditor.CustomEditors.Editors
menu.AddButton("Copy Euler", () => { Clipboard.Text = JsonSerializer.Serialize(value); }).TooltipText = "Copy the Euler Angles in Degrees";
};
}
}
private void OnValueChanged()
{

View File

@@ -96,6 +96,9 @@ namespace FlaxEditor.CustomEditors.Editors
ZElement.SetCategory(category);
ZElement.ValueBox.ValueChanged += OnZValueChanged;
ZElement.ValueBox.SlidingEnd += ClearToken;
if (LinkedLabel != null)
{
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
@@ -109,6 +112,7 @@ namespace FlaxEditor.CustomEditors.Editors
mb.Checked = XElement.ValueBox.Category != Utils.ValueCategory.None;
};
}
}
private void OnXValueChanged()
{
@@ -294,6 +298,9 @@ namespace FlaxEditor.CustomEditors.Editors
ZElement.SetCategory(category);
ZElement.ValueBox.ValueChanged += OnValueChanged;
ZElement.ValueBox.SlidingEnd += ClearToken;
if (LinkedLabel != null)
{
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
@@ -307,6 +314,7 @@ namespace FlaxEditor.CustomEditors.Editors
mb.Checked = XElement.ValueBox.Category != Utils.ValueCategory.None;
};
}
}
private void OnValueChanged()
{