Skip to content

Commit

Permalink
Merge pull request #503 from vchelaru/dropdown-layer-fix
Browse files Browse the repository at this point in the history
commented out problematic line, Vic needs to change some more stuff
  • Loading branch information
vchelaru authored Jan 25, 2025
2 parents 987cb30 + 529c0d8 commit 1a662a5
Showing 1 changed file with 37 additions and 44 deletions.
81 changes: 37 additions & 44 deletions MonoGameGum/Forms/Controls/ListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ public override void UpdateState()
base.UpdateVerticalScrollBarValues();
}

/// <summary>
/// Shows the argument popup using the argument listBoxParent to determine its destination layer.
/// </summary>
/// <param name="popup">The popup to show, for example a dropdown from a ComboBox or MenuItem</param>
/// <param name="listBoxParent">The parent visual, which would be something like the ComboBox.Visual</param>
public static void ShowPopupListBox(ScrollViewer popup, GraphicalUiElement listBoxParent)
{
popup.IsVisible = true;
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1a662a5

Please sign in to comment.