Ellpeck / MLEM

Libraries for MonoGame and FNA that provide abstractions, quality of life improvements and additional features like a ui system and easy input handling.
https://mlem.ellpeck.de/
MIT License
84 stars 6 forks source link

Allow dropdowns to have scrollable panels #8

Closed Monniasza closed 1 year ago

Monniasza commented 1 year ago

Hi. I'm using MLEM in my upcoming remake of MultiMachineBuilder. I'll want to make an inventory list, but there are no list controls. Please add a scrollable list with customizable rendering and model types

Ellpeck commented 1 year ago

Hi, what you're looking for is a Panel. You can optionally allow it to scroll and add elements to it as you wish.

For more info on basic components, I recommend checking out the UI demo's code!

Monniasza commented 1 year ago

Maybe dropdowns are better for this?

Ellpeck commented 1 year ago

What do you mean?

MLEM.Ui also has the Dropdown component which displays a Panel when opened as well. There's currently no built-in way to make that panel able to scroll (other than adding a second panel with a null Texture into it), but if you want that feature added, I can definitely do so!

Monniasza commented 1 year ago

I'd like to have scrollable dropdowns. They can be then turned into scrollable lists

Monniasza commented 1 year ago

I've got this in the dropdown. The names of the blocks are single column image

Ellpeck commented 1 year ago

You likely didn't set their width high enough. If you set their width to 1, they'll automatically have the same size as the panel's content. I recommend checking out the demo project linked above, as well as the introductory documentation on sizing.

Monniasza commented 1 year ago

I've fixed then and they look great image

Monniasza commented 1 year ago

And now the list panel works correctly image

Monniasza commented 1 year ago

I'll trash the old, broken scrollable list

Monniasza commented 1 year ago

How can I implement a list with selectable items?

Ellpeck commented 1 year ago

Hi, what do you mean by a list?

As I said at the top, a Panel supports the ability to have a scroll bar in it. Any element type can be made selectable by setting its CanBeSelected to true, and if you want an element to react to clicks and gamepad/touch interactions, you can subscribe to its OnPressed or OnSecondaryPressed events.

If you want to use the new feature that allows dropdowns to contain scrollabel content, you can install the latest development version of MLEM.Ui from https://nuget.ellpeck.de/ and update your Dropdown's constructor accordingly.

Have you checked out the UI demo yet? It contains a lot of examples of simple & complex UI setups, including dropdowns, scrollable lists, and even nested scrollable lists.

Monniasza commented 1 year ago

How do I select elements?

Ellpeck commented 1 year ago

If an element has CanBeSelected set to true, gamepad navigation and keyboard navigation (controls for both of which can be found and changed in UiControls) allow for the element to be selected.

When using mouse or touch controls, the most recently clicked element also counts as selected, but a selection indicator is not displayed there by default. You can change that behavior by subscribing to (or overwriting) the UiSystem.OnSelectedElementDrawn event.

If you want to set an element to be selected programmatically, you can do so using your ui system's UiControls' SelectElement method, or the element's Root's SelectElement method.

Monniasza commented 1 year ago

I've implemented lists for my game, and the work well, but no mutiple selection is supported. Could I submit code for them so they gen integrated into MLEM?

Ellpeck commented 1 year ago

As I said numerous times, various types of lists are already supported by MLEM. There are currently no plans to add further default elements, as the existing elements cover a broad range of use cases.

Please explain what you mean by "lists".

Monniasza commented 1 year ago

My implementation is a list which generates and manages elements as needed using a listenable list

Ellpeck commented 1 year ago

Ah! I don't think an implementation like that is currently required as part of the MLEM.Ui package, since it is rather easy to implement and often depends on the way the developer intends for the list to work. Thanks though!