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,14 +111,17 @@ namespace FlaxEditor.CustomEditors.Editors
SetLinkStyle();
var textSize = FlaxEngine.GUI.Style.Current.FontMedium.MeasureText(LinkedLabel.Text.Value);
_linkButton.LocalX += textSize.X + 10;
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
if (LinkedLabel != null)
{
menu.AddSeparator();
if (LinkValues)
menu.AddButton("Unlink", ToggleLink).LinkTooltip("Unlinks scale components from uniform scaling");
else
menu.AddButton("Link", ToggleLink).LinkTooltip("Links scale components for uniform scaling");
};
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
if (LinkValues)
menu.AddButton("Unlink", ToggleLink).LinkTooltip("Unlinks scale components from uniform scaling");
else
menu.AddButton("Link", ToggleLink).LinkTooltip("Links scale components for uniform scaling");
};
}
// Override colors
var back = FlaxEngine.GUI.Style.Current.TextBoxBackground;

View File

@@ -34,13 +34,16 @@ namespace FlaxEditor.CustomEditors.Editors
if (valueCategory != Utils.ValueCategory.None)
{
doubleValue.SetCategory(valueCategory);
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
if (LinkedLabel != null)
{
menu.AddSeparator();
var mb = menu.AddButton("Show formatted", bt => { doubleValue.SetCategory(bt.Checked ? valueCategory : Utils.ValueCategory.None); });
mb.AutoCheck = true;
mb.Checked = doubleValue.ValueBox.Category != Utils.ValueCategory.None;
};
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
var mb = menu.AddButton("Show formatted", bt => { doubleValue.SetCategory(bt.Checked ? valueCategory : Utils.ValueCategory.None); });
mb.AutoCheck = true;
mb.Checked = doubleValue.ValueBox.Category != Utils.ValueCategory.None;
};
}
}
}
}

View File

@@ -40,7 +40,7 @@ namespace FlaxEditor.CustomEditors.Editors
_element = slider;
return;
}
var floatValue = layout.FloatValue();
floatValue.ValueBox.ValueChanged += OnValueChanged;
floatValue.ValueBox.SlidingEnd += ClearToken;
@@ -53,13 +53,16 @@ namespace FlaxEditor.CustomEditors.Editors
if (valueCategory != Utils.ValueCategory.None)
{
floatValue.SetCategory(valueCategory);
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
if (LinkedLabel != null)
{
menu.AddSeparator();
var mb = menu.AddButton("Show formatted", bt => { floatValue.SetCategory(bt.Checked ? valueCategory : Utils.ValueCategory.None); });
mb.AutoCheck = true;
mb.Checked = floatValue.ValueBox.Category != Utils.ValueCategory.None;
};
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
var mb = menu.AddButton("Show formatted", bt => { floatValue.SetCategory(bt.Checked ? valueCategory : Utils.ValueCategory.None); });
mb.AutoCheck = true;
mb.Checked = floatValue.ValueBox.Category != Utils.ValueCategory.None;
};
}
}
}
}

View File

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

View File

@@ -59,12 +59,15 @@ namespace FlaxEditor.CustomEditors.Editors
ZElement.ValueBox.ValueChanged += OnValueChanged;
ZElement.ValueBox.SlidingEnd += ClearToken;
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
if (LinkedLabel != null)
{
menu.AddSeparator();
var value = ((Quaternion)Values[0]).EulerAngles;
menu.AddButton("Copy Euler", () => { Clipboard.Text = JsonSerializer.Serialize(value); }).TooltipText = "Copy the Euler Angles in Degrees";
};
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
var value = ((Quaternion)Values[0]).EulerAngles;
menu.AddButton("Copy Euler", () => { Clipboard.Text = JsonSerializer.Serialize(value); }).TooltipText = "Copy the Euler Angles in Degrees";
};
}
}
private void OnValueChanged()

View File

@@ -96,18 +96,22 @@ namespace FlaxEditor.CustomEditors.Editors
ZElement.SetCategory(category);
ZElement.ValueBox.ValueChanged += OnZValueChanged;
ZElement.ValueBox.SlidingEnd += ClearToken;
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
if (LinkedLabel != null)
{
menu.AddSeparator();
var mb = menu.AddButton("Show formatted", bt =>
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
XElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
YElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
ZElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
});
mb.AutoCheck = true;
mb.Checked = XElement.ValueBox.Category != Utils.ValueCategory.None;
};
menu.AddSeparator();
var mb = menu.AddButton("Show formatted", bt =>
{
XElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
YElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
ZElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
});
mb.AutoCheck = true;
mb.Checked = XElement.ValueBox.Category != Utils.ValueCategory.None;
};
}
}
private void OnXValueChanged()
@@ -294,18 +298,22 @@ namespace FlaxEditor.CustomEditors.Editors
ZElement.SetCategory(category);
ZElement.ValueBox.ValueChanged += OnValueChanged;
ZElement.ValueBox.SlidingEnd += ClearToken;
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
if (LinkedLabel != null)
{
menu.AddSeparator();
var mb = menu.AddButton("Show formatted", bt =>
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
XElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
YElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
ZElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
});
mb.AutoCheck = true;
mb.Checked = XElement.ValueBox.Category != Utils.ValueCategory.None;
};
menu.AddSeparator();
var mb = menu.AddButton("Show formatted", bt =>
{
XElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
YElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
ZElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None);
});
mb.AutoCheck = true;
mb.Checked = XElement.ValueBox.Category != Utils.ValueCategory.None;
};
}
}
private void OnValueChanged()