mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-26 00:45:20 +00:00
60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using Microsoft.Xna.Framework;
|
|
|
|
namespace MonoGame.Extended.Gui.Controls
|
|
{
|
|
public class ListBox : SelectorControl
|
|
{
|
|
public ListBox()
|
|
{
|
|
}
|
|
|
|
public override Size2 GetContentSize(IGuiContext context)
|
|
{
|
|
var width = 0f;
|
|
var height = 0f;
|
|
|
|
foreach (var item in Items)
|
|
{
|
|
var itemSize = GetItemSize(context, item);
|
|
|
|
if (itemSize.Width > width)
|
|
width = itemSize.Width;
|
|
|
|
height += itemSize.Height;
|
|
}
|
|
|
|
return new Size2(width + ClipPadding.Size.Width, height + ClipPadding.Size.Height);
|
|
}
|
|
|
|
protected override Size2 CalculateDesiredSize(IGuiContext context, Size2 availableSize)
|
|
{
|
|
var width = 0f;
|
|
var height = 0f;
|
|
|
|
foreach (var item in Items)
|
|
{
|
|
var itemSize = GetItemSize(context, item);
|
|
|
|
if (itemSize.Width > width)
|
|
width = itemSize.Width;
|
|
|
|
height += itemSize.Height;
|
|
}
|
|
|
|
return new Size2(width + ClipPadding.Size.Width, height + ClipPadding.Size.Height);
|
|
}
|
|
|
|
public override void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
|
|
{
|
|
base.Draw(context, renderer, deltaSeconds);
|
|
|
|
ScrollIntoView(context);
|
|
DrawItemList(context, renderer);
|
|
}
|
|
|
|
protected override Rectangle GetContentRectangle(IGuiContext context)
|
|
{
|
|
return ClippingRectangle;
|
|
}
|
|
}
|
|
} |