- Description panel now updates when navigating items with keyboard

- First test of drawing images in description panel (showing class type)
- Layout and style changes to work with images and make evertything a bit tighter
This commit is contained in:
Nils Hausfeld
2024-06-10 18:45:03 +02:00
parent da6883489e
commit 1da00264a0
4 changed files with 86 additions and 26 deletions

View File

@@ -197,6 +197,7 @@ namespace FlaxEditor.Surface
{ {
Groups = StateMachineGroupArchetypes, Groups = StateMachineGroupArchetypes,
CanSpawnNode = (_, _) => true, CanSpawnNode = (_, _) => true,
Style = Style,
}); });
_cmStateMachineMenu.ShowExpanded = true; _cmStateMachineMenu.ShowExpanded = true;
} }
@@ -214,6 +215,7 @@ namespace FlaxEditor.Surface
CanSpawnNode = CanUseNodeType, CanSpawnNode = CanUseNodeType,
ParametersGetter = null, ParametersGetter = null,
CustomNodesGroup = GetCustomNodes(), CustomNodesGroup = GetCustomNodes(),
Style = Style,
}); });
_cmStateMachineTransitionMenu.AddGroup(StateMachineTransitionGroupArchetype, false); _cmStateMachineTransitionMenu.AddGroup(StateMachineTransitionGroupArchetype, false);
} }

View File

@@ -51,15 +51,29 @@ namespace FlaxEditor.Surface.ContextMenu
private Elements.Box _selectedBox; private Elements.Box _selectedBox;
private NodeArchetype _parameterGetNodeArchetype; private NodeArchetype _parameterGetNodeArchetype;
private NodeArchetype _parameterSetNodeArchetype; private NodeArchetype _parameterSetNodeArchetype;
private bool _useDescriptionPanel;
private Panel _descriptionPanel; // Description panel elements
private Label _descriptionSignatureLabel; private readonly bool _useDescriptionPanel;
private Label _descriptionLabel; private readonly Panel _descriptionPanel;
private readonly Image _descriptionClassImage;
private readonly Label _descriptionSignatureLabel;
private readonly Label _descriptionLabel;
private VisjectCMItem _selectedItem;
/// <summary> /// <summary>
/// The selected item /// The selected item
/// </summary> /// </summary>
public VisjectCMItem SelectedItem; public VisjectCMItem SelectedItem
{
get => _selectedItem;
set
{
_selectedItem = value;
_selectedItem?.OnSelect();
}
}
/// <summary> /// <summary>
/// Event fired when any item in this popup menu gets clicked. /// Event fired when any item in this popup menu gets clicked.
@@ -120,6 +134,11 @@ namespace FlaxEditor.Surface.ContextMenu
/// The parameter setter node archetype to spawn when adding the parameter getter. Can be null. /// The parameter setter node archetype to spawn when adding the parameter getter. Can be null.
/// </summary> /// </summary>
public NodeArchetype ParameterSetNodeArchetype; public NodeArchetype ParameterSetNodeArchetype;
/// <summary>
/// The surface style to use to draw images in the description panel
/// </summary>
public SurfaceStyle Style;
} }
/// <summary> /// <summary>
@@ -151,7 +170,7 @@ namespace FlaxEditor.Surface.ContextMenu
}; };
// Title bar // Title bar
var titleFontReference = new FontReference(Style.Current.FontMedium.Asset, 11); var titleFontReference = new FontReference(Style.Current.FontLarge.Asset, 10);
var titleLabel = new Label var titleLabel = new Label
{ {
Width = Width * 0.5f - 8f, Width = Width * 0.5f - 8f,
@@ -200,7 +219,6 @@ namespace FlaxEditor.Surface.ContextMenu
Bounds = new Rectangle(0, _searchBox.Bottom + 1, Width, Height - _searchBox.Bottom - 2), Bounds = new Rectangle(0, _searchBox.Bottom + 1, Width, Height - _searchBox.Bottom - 2),
Parent = this Parent = this
}; };
_panel1 = panel1; _panel1 = panel1;
// Create second panel (for groups arrangement) // Create second panel (for groups arrangement)
@@ -215,16 +233,25 @@ namespace FlaxEditor.Surface.ContextMenu
// Create description panel if enabled // Create description panel if enabled
if (_useDescriptionPanel) if (_useDescriptionPanel)
{ {
var descriptionPanel = new Panel(ScrollBars.None) _descriptionPanel = new Panel(ScrollBars.None)
{ {
Parent = this, Parent = this,
Bounds = new Rectangle(0, Height, Width, 0), Bounds = new Rectangle(0, Height, Width, 0),
BackgroundColor = Style.Current.BackgroundNormal, BackgroundColor = Style.Current.BackgroundNormal,
}; };
_descriptionPanel = descriptionPanel;
var signatureFontReference = new FontReference(Style.Current.FontMedium.Asset, 10); var spriteHandle = info.Style.Icons.BoxClose;
var signatureLabel = new Label(8, 12, Width - 16, 0) _descriptionClassImage = new Image(8, 12, 20, 20)
{
Parent = _descriptionPanel,
Brush = new SpriteBrush(spriteHandle),
Color = Color.Aqua,
MouseOverColor = Color.Aqua,
AutoFocus = false,
};
var signatureFontReference = new FontReference(Style.Current.FontMedium.Asset, 9f);
_descriptionSignatureLabel = new Label(32, 8, Width - 40, 0)
{ {
Parent = _descriptionPanel, Parent = _descriptionPanel,
HorizontalAlignment = TextAlignment.Near, HorizontalAlignment = TextAlignment.Near,
@@ -232,22 +259,20 @@ namespace FlaxEditor.Surface.ContextMenu
Wrapping = TextWrapping.WrapWords, Wrapping = TextWrapping.WrapWords,
Font = signatureFontReference, Font = signatureFontReference,
Bold = true, Bold = true,
Italic = true,
AutoHeight = true, AutoHeight = true,
}; };
signatureLabel.SetAnchorPreset(AnchorPresets.TopLeft, true); _descriptionSignatureLabel.SetAnchorPreset(AnchorPresets.TopLeft, true);
_descriptionSignatureLabel = signatureLabel;
_descriptionLabel = new Label(32, 0, Width - 40, 0)
var descriptionLabel = new Label(8, 0, Width - 16, 0)
{ {
Parent = _descriptionPanel, Parent = _descriptionPanel,
HorizontalAlignment = TextAlignment.Near, HorizontalAlignment = TextAlignment.Near,
VerticalAlignment = TextAlignment.Near, VerticalAlignment = TextAlignment.Near,
Wrapping = TextWrapping.WrapWords, Wrapping = TextWrapping.WrapWords,
Font = signatureFontReference,
AutoHeight = true, AutoHeight = true,
}; };
descriptionLabel.SetAnchorPreset(AnchorPresets.TopLeft, true); _descriptionLabel.SetAnchorPreset(AnchorPresets.TopLeft, true);
_descriptionLabel = descriptionLabel;
} }
// Init groups // Init groups
@@ -597,20 +622,44 @@ namespace FlaxEditor.Surface.ContextMenu
_groups[i].Open(animate); _groups[i].Open(animate);
} }
public void SetDescriptionText(string header, string text) /// <summary>
/// Updates the description panel and shows information about the set archetype
/// </summary>
/// <param name="archetype">The node archetype</param>
public void SetDescriptionPanelArchetype(NodeArchetype archetype)
{ {
if(!_useDescriptionPanel) if(!_useDescriptionPanel)
return; return;
if (archetype == null)
{
HideDescriptionPanel();
return;
}
_descriptionSignatureLabel.Text = header; Profiler.BeginEvent("VisjectCM.SetDescriptionPanelArchetype");
var panelHeight = _descriptionSignatureLabel.Height;
_descriptionSignatureLabel.Text = archetype.Signature;
float panelHeight = _descriptionSignatureLabel.Height;
_descriptionLabel.Y = _descriptionSignatureLabel.Bounds.Bottom + 8f; _descriptionLabel.Y = _descriptionSignatureLabel.Bounds.Bottom + 6f;
_descriptionLabel.Text = text; _descriptionLabel.Text = archetype.Description;
panelHeight += _descriptionLabel.Height + 8f + 24f; panelHeight += _descriptionLabel.Height + 6f + 18f;
_descriptionPanel.Height = panelHeight; _descriptionPanel.Height = panelHeight;
Size = new Float2(300, 400 + _descriptionPanel.Height); Height = 400 + Mathf.RoundToInt(_descriptionPanel.Height);
UpdateWindowSize();
Profiler.EndEvent();
}
/// <summary>
/// Hides the description panel and resets the context menu to its original size
/// </summary>
public void HideDescriptionPanel()
{
Height = 400;
UpdateWindowSize(); UpdateWindowSize();
} }

View File

@@ -315,6 +315,14 @@ namespace FlaxEditor.Surface.ContextMenu
} }
} }
/// <summary>
/// Callback when selected by the visject CM
/// </summary>
public void OnSelect()
{
Group.ContextMenu.SetDescriptionPanelArchetype(_archetype);
}
/// <inheritdoc /> /// <inheritdoc />
public override bool OnMouseDown(Float2 location, MouseButton button) public override bool OnMouseDown(Float2 location, MouseButton button)
{ {
@@ -342,7 +350,7 @@ namespace FlaxEditor.Surface.ContextMenu
public override void OnMouseEnter(Float2 location) public override void OnMouseEnter(Float2 location)
{ {
base.OnMouseEnter(location); base.OnMouseEnter(location);
Group.ContextMenu.SetDescriptionText(_archetype.Signature, _archetype.Description); Group.ContextMenu.SetDescriptionPanelArchetype(_archetype);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -243,6 +243,7 @@ namespace FlaxEditor.Surface
ParametersGetter = () => Parameters, ParametersGetter = () => Parameters,
CustomNodesGroup = GetCustomNodes(), CustomNodesGroup = GetCustomNodes(),
ParameterGetNodeArchetype = GetParameterGetterNodeArchetype(out _), ParameterGetNodeArchetype = GetParameterGetterNodeArchetype(out _),
Style = Style,
}); });
} }