diff --git a/src/Common/FilteredList.cs b/src/Common/FilteredList.cs index 9bbdace..a45f0f4 100644 --- a/src/Common/FilteredList.cs +++ b/src/Common/FilteredList.cs @@ -15,12 +15,16 @@ namespace Cthangover.Tools.Common /// public partial class FilteredList : VBoxContainer { + // Scroll bar, item padding and a little text room on the right. + private const int IconBoxMargin = 40; + private readonly LineEdit _search; private readonly ItemList _list; private readonly List<(string Id, string Text, Texture2D Icon)> _items = new(); private readonly List _visibleIds = new(); private string _selectedId; private bool _silent; + private int _fitSide; /// Raised when the user selects a row (click or keyboard). public event Action Chosen; @@ -65,6 +69,19 @@ namespace Cthangover.Tools.Common _list.FixedColumnWidth = iconSize + 24; } + /// + /// Scales row icons to fit a box at most px high and never wider than the + /// list (minus room for the scroll bar): pictures of any size — a 1024×1920 portrait as well as a + /// 32 px icon — keep their aspect and the row stays inside the panel. The box follows the list + /// width, so narrowing the panel shrinks the pictures further. + /// + public void FitIcons(int maxSide) + { + _fitSide = maxSide; + _list.Resized += UpdateIconBox; + UpdateIconBox(); + } + /// Replaces all items; keeps the current selection when its id is still present. public void SetItems(IEnumerable<(string Id, string Text, Texture2D Icon)> items) { @@ -131,6 +148,12 @@ namespace Cthangover.Tools.Common Chosen?.Invoke(_selectedId); } + private void UpdateIconBox() + { + var width = (int)_list.Size.X - IconBoxMargin; + _list.FixedIconSize = new Vector2I(Math.Clamp(width, 16, _fitSide), _fitSide); + } + private string IdAt(int index) => index >= 0 && index < _visibleIds.Count ? _visibleIds[index] : null; } } diff --git a/src/EntityEditor/EntityEditorWindow.cs b/src/EntityEditor/EntityEditorWindow.cs index 25ba5fd..7afa71c 100644 --- a/src/EntityEditor/EntityEditorWindow.cs +++ b/src/EntityEditor/EntityEditorWindow.cs @@ -110,6 +110,7 @@ namespace Cthangover.Tools.EntityEditor listColumn.AddChild(ToolUi.Section("tools/entity_editor/section_list")); list = new FilteredList(320f, "tools/entity_editor/search"); list.SizeFlagsVertical = Control.SizeFlags.ExpandFill; + list.FitIcons(64); list.Chosen += OnChosen; listColumn.AddChild(list); var listPanel = CreateSidebar(listColumn, 320);