Refactor ContextMenuChildMenu to inherit from ContextMenuButton
This commit is contained in:
@@ -108,7 +108,6 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
/// <inheritdoc />
|
||||
public override void Draw()
|
||||
{
|
||||
// Cache data
|
||||
var style = Style.Current;
|
||||
var backgroundRect = new Rectangle(-X + 3, 0, Parent.Width - 6, Height);
|
||||
var textRect = new Rectangle(0, 0, Width - 8, Height);
|
||||
@@ -228,15 +227,11 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
{
|
||||
var style = Style.Current;
|
||||
float width = 20;
|
||||
|
||||
if (style.FontMedium)
|
||||
{
|
||||
width += style.FontMedium.MeasureText(Text).X;
|
||||
|
||||
if (ShortKeys.Length > 0)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ShortKeys))
|
||||
width += 40 + style.FontMedium.MeasureText(ShortKeys).X;
|
||||
}
|
||||
}
|
||||
|
||||
return Mathf.Max(width, base.MinimumWidth);
|
||||
|
||||
@@ -10,13 +10,8 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
/// </summary>
|
||||
/// <seealso cref="ContextMenuItem" />
|
||||
[HideInEditor]
|
||||
public class ContextMenuChildMenu : ContextMenuItem
|
||||
public class ContextMenuChildMenu : ContextMenuButton
|
||||
{
|
||||
/// <summary>
|
||||
/// The item text.
|
||||
/// </summary>
|
||||
public string Text;
|
||||
|
||||
/// <summary>
|
||||
/// The child context menu.
|
||||
/// </summary>
|
||||
@@ -28,7 +23,7 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
/// <param name="parent">The parent context menu.</param>
|
||||
/// <param name="text">The text.</param>
|
||||
public ContextMenuChildMenu(ContextMenu parent, string text)
|
||||
: base(parent, 8, 22)
|
||||
: base(parent, text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
@@ -36,21 +31,16 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
/// <inheritdoc />
|
||||
public override void Draw()
|
||||
{
|
||||
// Cache data
|
||||
var style = Style.Current;
|
||||
var backgroundRect = new Rectangle(-X + 3, 0, Parent.Width - 6, Height);
|
||||
var clientRect = new Rectangle(Vector2.Zero, Size);
|
||||
bool isCMopened = ContextMenu.IsOpened;
|
||||
|
||||
// Draw background
|
||||
if (isCMopened || (IsMouseOver && Enabled))
|
||||
if (isCMopened)
|
||||
Render2D.FillRectangle(backgroundRect, style.LightBackground);
|
||||
|
||||
base.Draw();
|
||||
|
||||
// Draw text
|
||||
Render2D.DrawText(style.FontMedium, Text, clientRect, Enabled ? style.Foreground : style.ForegroundDisabled, TextAlignment.Near, TextAlignment.Center);
|
||||
|
||||
// Draw arrow
|
||||
if (ContextMenu.HasChildren)
|
||||
Render2D.DrawSprite(style.ArrowRight, new Rectangle(Width - 15, (Height - 12) / 2, 12, 12), Enabled ? isCMopened ? style.BackgroundSelected : style.Foreground : style.ForegroundDisabled);
|
||||
@@ -73,22 +63,5 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
// Hide parent CM popups and set itself as child
|
||||
parentContextMenu.ShowChild(ContextMenu, PointToParent(ParentContextMenu, new Vector2(Width, 0)));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float MinimumWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
var style = Style.Current;
|
||||
float width = 16;
|
||||
|
||||
if (style.FontMedium)
|
||||
{
|
||||
width += style.FontMedium.MeasureText(Text).X;
|
||||
}
|
||||
|
||||
return Mathf.Max(width, base.MinimumWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user