mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 15:26:00 +02:00
Support for custom menu widget
This commit is contained in:
parent
20b1827632
commit
b18ec8ccd3
2 changed files with 63 additions and 6 deletions
|
@ -22,6 +22,9 @@ namespace Beefy.theme.dark
|
|||
{
|
||||
base.Draw(g);
|
||||
|
||||
if (mMenuItem.mWidget != null)
|
||||
return;
|
||||
|
||||
if (mMenuItem.mLabel == null)
|
||||
g.DrawButton(DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.MenuSepHorz), GS!(28), 0, mWidth - GS!(32));
|
||||
else
|
||||
|
@ -107,6 +110,16 @@ namespace Beefy.theme.dark
|
|||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
for (var item in mMenuItem.mItems)
|
||||
{
|
||||
if (item.mWidget != null)
|
||||
{
|
||||
if (item.mWidget.mMouseOver)
|
||||
mDeselectedTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (mMenuItem.mItems.Count > 0)
|
||||
{
|
||||
if (mIndex == mMenuWidget.mSelectIdx)
|
||||
|
@ -319,6 +332,10 @@ namespace Beefy.theme.dark
|
|||
/*using (g.PushColor(0xFFFF0000))
|
||||
g.FillRect(0, 0, mWidth, mHeight);*/
|
||||
|
||||
for (var item in mItemWidgets)
|
||||
if (item.mMenuItem.mWidget != null)
|
||||
return;
|
||||
|
||||
float mDrawHeight = mHeight;
|
||||
g.DrawButtonVert(DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.MenuSepVert), GS!(18), GS!(2), mDrawHeight - GS!(4));
|
||||
|
||||
|
@ -359,12 +376,20 @@ namespace Beefy.theme.dark
|
|||
float curY = GS!(2);
|
||||
for (MenuItemWidget item in mItemWidgets)
|
||||
{
|
||||
if (item.mMenuItem.mLabel != null)
|
||||
maxWidth = Math.Max(maxWidth, mFont.GetWidth(item.mMenuItem.mLabel));
|
||||
if (item.mMenuItem.mWidget != null)
|
||||
{
|
||||
item.mMenuItem.mWidget.mX = GS!(4);
|
||||
item.mMenuItem.mWidget.mY = curY;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.mMenuItem.mLabel != null)
|
||||
maxWidth = Math.Max(maxWidth, mFont.GetWidth(item.mMenuItem.mLabel));
|
||||
|
||||
item.Resize(0, curY, mWidth - GS!(8), mItemSpacing);
|
||||
item.mMouseInsets = new Insets(0, GS!(6), 0, 0);
|
||||
curY += mItemSpacing;
|
||||
item.Resize(0, curY, mWidth - GS!(8), mItemSpacing);
|
||||
item.mMouseInsets = new Insets(0, GS!(6), 0, 0);
|
||||
curY += mItemSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,6 +398,13 @@ namespace Beefy.theme.dark
|
|||
float maxWidth = 0;
|
||||
for (MenuItemWidget item in mItemWidgets)
|
||||
{
|
||||
if (item.mMenuItem.mWidget != null)
|
||||
{
|
||||
mWidth = item.mMenuItem.mWidget.mWidth + GS!(6);
|
||||
mHeight = item.mMenuItem.mWidget.mHeight + GS!(4);
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.mMenuItem.mLabel != null)
|
||||
maxWidth = Math.Max(maxWidth, mFont.GetWidth(item.mMenuItem.mLabel));
|
||||
}
|
||||
|
|
|
@ -21,8 +21,22 @@ namespace Beefy.widgets
|
|||
public this(Menu menuItem)
|
||||
{
|
||||
mMenuItem = menuItem;
|
||||
if (mMenuItem.mWidget != null)
|
||||
AddWidget(mMenuItem.mWidget);
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void RemovedFromWindow()
|
||||
{
|
||||
base.RemovedFromWindow();
|
||||
if (mMenuItem.mWidget != null)
|
||||
RemoveWidget(mMenuItem.mWidget);
|
||||
}
|
||||
|
||||
public override void MouseEnter()
|
||||
{
|
||||
base.MouseEnter();
|
||||
|
@ -570,11 +584,13 @@ namespace Beefy.widgets
|
|||
public Event<delegate void(Menu menu)> mOnMenuItemSelected ~ _.Dispose();
|
||||
public Event<delegate void(Menu menu)> mOnMenuItemUpdate ~ _.Dispose();
|
||||
public Event<delegate void(Menu menu, Menu itemSelected)> mOnMenuClosed ~ _.Dispose();
|
||||
public Event<delegate void(Menu menu)> mOnChildOpen ~ _.Dispose();
|
||||
public Object mThemeData;
|
||||
public bool mDisabled;
|
||||
public bool mBold;
|
||||
public IDrawable mIconImage;
|
||||
public bool mForceParent;
|
||||
public Widget mWidget ~ delete _;
|
||||
|
||||
public ~this()
|
||||
{
|
||||
|
@ -613,6 +629,15 @@ namespace Beefy.widgets
|
|||
return item;
|
||||
}
|
||||
|
||||
public virtual Menu AddWidgetItem(Widget widget)
|
||||
{
|
||||
Menu item = new Menu();
|
||||
item.mParent = this;
|
||||
item.mWidget = widget;
|
||||
mItems.Add(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
public void SetDisabled(bool disabled)
|
||||
{
|
||||
mDisabled = disabled;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue