From 2916951e98e642aea505662eb33381c603ad0636 Mon Sep 17 00:00:00 2001 From: Justin Johnson Date: Thu, 16 Jan 2025 08:28:57 -0700 Subject: [PATCH 1/2] commented out problematic line, Vic needs to change some more stuff --- MonoGameGum/Forms/Controls/ListBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MonoGameGum/Forms/Controls/ListBox.cs b/MonoGameGum/Forms/Controls/ListBox.cs index 1315fe55..87c8e68a 100644 --- a/MonoGameGum/Forms/Controls/ListBox.cs +++ b/MonoGameGum/Forms/Controls/ListBox.cs @@ -597,7 +597,7 @@ public static void ShowPopupListBox(ScrollViewer popup, GraphicalUiElement listB var mainRoot = listBoxParent.ElementGueContainingThis ?? listBoxParent; - if(mainRoot.Children == null) + //if(mainRoot.Children == null) { // The main root is a screen which would not have layers // therefore we have to get the parent that still has children: From 529c0d80ef1a81481bca47215c13132ff2932b2f Mon Sep 17 00:00:00 2001 From: Victor Chelaru Date: Sat, 25 Jan 2025 08:05:18 -0700 Subject: [PATCH 2/2] Finished fixing issue with listboxes. --- MonoGameGum/Forms/Controls/ListBox.cs | 81 ++++++++++++--------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/MonoGameGum/Forms/Controls/ListBox.cs b/MonoGameGum/Forms/Controls/ListBox.cs index 87c8e68a..579f82d9 100644 --- a/MonoGameGum/Forms/Controls/ListBox.cs +++ b/MonoGameGum/Forms/Controls/ListBox.cs @@ -572,6 +572,11 @@ public override void UpdateState() base.UpdateVerticalScrollBarValues(); } + /// + /// Shows the argument popup using the argument listBoxParent to determine its destination layer. + /// + /// The popup to show, for example a dropdown from a ComboBox or MenuItem + /// The parent visual, which would be something like the ComboBox.Visual public static void ShowPopupListBox(ScrollViewer popup, GraphicalUiElement listBoxParent) { popup.IsVisible = true; @@ -586,53 +591,10 @@ public static void ShowPopupListBox(ScrollViewer popup, GraphicalUiElement listB popup.Visual.WidthUnits = DimensionUnitType.Absolute; popup.Visual.HeightUnits = DimensionUnitType.Absolute; - - // let's just make sure it's removed popup.Visual.RemoveFromManagers(); - var managers = listBoxParent.Managers ?? SystemManagers.Default; - - var layerToAddListBoxTo = managers.Renderer.MainLayer; - - var mainRoot = listBoxParent.ElementGueContainingThis ?? listBoxParent; - - //if(mainRoot.Children == null) - { - // The main root is a screen which would not have layers - // therefore we have to get the parent that still has children: - var parentWithChildren = listBoxParent as IRenderableIpso; - while (parentWithChildren != null) - { - var potentialParent = parentWithChildren.Parent; - if(potentialParent?.Children != null) - { - // continue okay - parentWithChildren = potentialParent.Parent; - } - else - { - break; - } - } - if(parentWithChildren != null) - { - mainRoot = parentWithChildren as InteractiveGue; - } - } - - // do a search in the layers to see where this is held - expensive but we can at least look in non-main layers - foreach (var layer in managers.Renderer.Layers) - { - if (layer != managers.Renderer.MainLayer) - { - if (layer.Renderables.Contains(mainRoot) || layer.Renderables.Contains(mainRoot?.RenderableComponent as IRenderableIpso)) - { - layerToAddListBoxTo = layer; - break; - } - } - } + var layerToAddListBoxTo = GetLayerToAddTo(listBoxParent); #if FRB popup.Visual.AddToManagers(listBoxParent.EffectiveManagers, @@ -675,6 +637,37 @@ public static void ShowPopupListBox(ScrollViewer popup, GraphicalUiElement listB } + private static Layer GetLayerToAddTo(GraphicalUiElement listBoxParent) + { + var managers = listBoxParent.Managers ?? SystemManagers.Default; + + var layerToAddListBoxTo = managers.Renderer.MainLayer; + + var mainRoot = listBoxParent.ElementGueContainingThis ?? listBoxParent; + + // We need to loop up the parents to see if there is a layer that contains this: + var parent = listBoxParent; + while(parent != null) + { + foreach (var layer in managers.Renderer.Layers) + { + if (layer != layerToAddListBoxTo) + { + if (layer.Renderables.Contains(parent) || layer.Renderables.Contains(parent.RenderableComponent as IRenderableIpso)) + { + layerToAddListBoxTo = layer; + break; + } + } + } + + parent = parent.Parent as GraphicalUiElement; + } + + + return layerToAddListBoxTo; + } + #region IInputReceiver Methods public void OnFocusUpdate()