mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36: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);
|
base.Draw(g);
|
||||||
|
|
||||||
|
if (mMenuItem.mWidget != null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (mMenuItem.mLabel == null)
|
if (mMenuItem.mLabel == null)
|
||||||
g.DrawButton(DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.MenuSepHorz), GS!(28), 0, mWidth - GS!(32));
|
g.DrawButton(DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.MenuSepHorz), GS!(28), 0, mWidth - GS!(32));
|
||||||
else
|
else
|
||||||
|
@ -107,6 +110,16 @@ namespace Beefy.theme.dark
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
base.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 (mMenuItem.mItems.Count > 0)
|
||||||
{
|
{
|
||||||
if (mIndex == mMenuWidget.mSelectIdx)
|
if (mIndex == mMenuWidget.mSelectIdx)
|
||||||
|
@ -319,6 +332,10 @@ namespace Beefy.theme.dark
|
||||||
/*using (g.PushColor(0xFFFF0000))
|
/*using (g.PushColor(0xFFFF0000))
|
||||||
g.FillRect(0, 0, mWidth, mHeight);*/
|
g.FillRect(0, 0, mWidth, mHeight);*/
|
||||||
|
|
||||||
|
for (var item in mItemWidgets)
|
||||||
|
if (item.mMenuItem.mWidget != null)
|
||||||
|
return;
|
||||||
|
|
||||||
float mDrawHeight = mHeight;
|
float mDrawHeight = mHeight;
|
||||||
g.DrawButtonVert(DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.MenuSepVert), GS!(18), GS!(2), mDrawHeight - GS!(4));
|
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);
|
float curY = GS!(2);
|
||||||
for (MenuItemWidget item in mItemWidgets)
|
for (MenuItemWidget item in mItemWidgets)
|
||||||
{
|
{
|
||||||
if (item.mMenuItem.mLabel != null)
|
if (item.mMenuItem.mWidget != null)
|
||||||
maxWidth = Math.Max(maxWidth, mFont.GetWidth(item.mMenuItem.mLabel));
|
{
|
||||||
|
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.Resize(0, curY, mWidth - GS!(8), mItemSpacing);
|
||||||
item.mMouseInsets = new Insets(0, GS!(6), 0, 0);
|
item.mMouseInsets = new Insets(0, GS!(6), 0, 0);
|
||||||
curY += mItemSpacing;
|
curY += mItemSpacing;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +398,13 @@ namespace Beefy.theme.dark
|
||||||
float maxWidth = 0;
|
float maxWidth = 0;
|
||||||
for (MenuItemWidget item in mItemWidgets)
|
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)
|
if (item.mMenuItem.mLabel != null)
|
||||||
maxWidth = Math.Max(maxWidth, mFont.GetWidth(item.mMenuItem.mLabel));
|
maxWidth = Math.Max(maxWidth, mFont.GetWidth(item.mMenuItem.mLabel));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,22 @@ namespace Beefy.widgets
|
||||||
public this(Menu menuItem)
|
public this(Menu menuItem)
|
||||||
{
|
{
|
||||||
mMenuItem = 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()
|
public override void MouseEnter()
|
||||||
{
|
{
|
||||||
base.MouseEnter();
|
base.MouseEnter();
|
||||||
|
@ -570,11 +584,13 @@ namespace Beefy.widgets
|
||||||
public Event<delegate void(Menu menu)> mOnMenuItemSelected ~ _.Dispose();
|
public Event<delegate void(Menu menu)> mOnMenuItemSelected ~ _.Dispose();
|
||||||
public Event<delegate void(Menu menu)> mOnMenuItemUpdate ~ _.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, Menu itemSelected)> mOnMenuClosed ~ _.Dispose();
|
||||||
|
public Event<delegate void(Menu menu)> mOnChildOpen ~ _.Dispose();
|
||||||
public Object mThemeData;
|
public Object mThemeData;
|
||||||
public bool mDisabled;
|
public bool mDisabled;
|
||||||
public bool mBold;
|
public bool mBold;
|
||||||
public IDrawable mIconImage;
|
public IDrawable mIconImage;
|
||||||
public bool mForceParent;
|
public bool mForceParent;
|
||||||
|
public Widget mWidget ~ delete _;
|
||||||
|
|
||||||
public ~this()
|
public ~this()
|
||||||
{
|
{
|
||||||
|
@ -613,6 +629,15 @@ namespace Beefy.widgets
|
||||||
return item;
|
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)
|
public void SetDisabled(bool disabled)
|
||||||
{
|
{
|
||||||
mDisabled = disabled;
|
mDisabled = disabled;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue