Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commented out problematic line, Vic needs to change some more stuff #503

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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