Skip to content

Commit

Permalink
Added custom dropdown support for MenuItems
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Jan 24, 2025
1 parent b5a2ff4 commit 385f6ac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
13 changes: 12 additions & 1 deletion MonoGameGum/Forms/Controls/MenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ internal MenuItem ParentMenuItem
get;set;
}

public VisualTemplate? ScrollViewerVisualTemplate { get; set; } = null;

#endregion

#region Events
Expand Down Expand Up @@ -243,8 +245,17 @@ internal void TryShowPopup()
if (this.Items?.Count > 0 && itemsPopup == null)
{
timeOpened = MainCursor.LastPrimaryPushTime;
itemsPopup = new ScrollViewer();

var visualTemplateVisual = ScrollViewerVisualTemplate?.CreateContent(null) as InteractiveGue;

if(visualTemplateVisual == null)
{
itemsPopup = new ScrollViewer();
}
else
{
itemsPopup = new ScrollViewer(visualTemplateVisual);
}
//itemsPopup.InnerPanel.Height = 0;
//itemsPopup.InnerPanel.HeightUnits = Gum.DataTypes.DimensionUnitType.RelativeToChildren;
//itemsPopup.InnerPanel.ChildrenLayout = Gum.Managers.ChildrenLayout.TopToBottomStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void Initialize()
var gumProject = GumService.Default.Initialize(_graphics.GraphicsDevice, "FormsGumProject/GumProject.gumx");
FormsUtilities.Cursor.TransformMatrix = Matrix.CreateScale(1/scale);

const int screenNumber = 0;
const int screenNumber = 1;

switch (screenNumber)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Gum.Wireframe;
using Microsoft.Xna.Framework;
using MonoGameGum.Forms;
using MonoGameGum.Forms.Controls;
using MonoGameGum.Forms.DefaultVisuals;
using MonoGameGum.GueDeriving;
Expand Down Expand Up @@ -30,11 +31,11 @@ public void Initialize(List<GraphicalUiElement> roots)

CreateMenu(root);

//CreateColumn1Ui(root);
CreateColumn1Ui(root);

//CreateColumn2Ui(root);
CreateColumn2Ui(root);

//CreateLayeredUi(roots);
CreateLayeredUi(roots);

}

Expand Down Expand Up @@ -74,6 +75,33 @@ private void CreateMenu(GraphicalUiElement root)
editItem.Items.Add($"Edit Item {i}");
}
menu.Items.Add(editItem);



var customMenuItem = new MenuItem();


customMenuItem.Header = "Custom Dropdown";
var customScrollViewerVisualTemplate = new VisualTemplate(() =>
{
var toReturn = new DefaultScrollViewerRuntime();
var background = toReturn.GetGraphicalUiElementByName("Background")
as ColoredRectangleRuntime;

background.Color = Color.Orange;

return toReturn;
});
customMenuItem.ScrollViewerVisualTemplate = customScrollViewerVisualTemplate;


for (int i = 0; i < 10; i++)
{
customMenuItem.Items.Add($"Custom dropdown item {i}");
}
menu.Items.Add(customMenuItem);


menu.Items.Add("Help");

root.Children.Add(menu.Visual);
Expand Down Expand Up @@ -159,6 +187,7 @@ private void CreateColumn1Ui(GraphicalUiElement root)
listBox.Y = currentY;
listBox.Width = 200;
listBox.Height = 200;

for (int i = 0; i < 20; i++)
{
listBox.Items.Add($"Item {i}");
Expand Down

0 comments on commit 385f6ac

Please sign in to comment.