TheEmeraldBee / widgetui

A bevy systems like widget system for ratatui and crossterm
MIT License
38 stars 5 forks source link

Reusable widgets? #7

Open emilyyyylime opened 5 months ago

emilyyyylime commented 5 months ago

Is it possible to write a stateful widget that can have multiple instates in the same app? Like e.g. an input box?

As I understand State must be unique by type so I would have to create a new type for each input box in my app. Is that right?

TheEmeraldBee commented 5 months ago

Not currently, but if you have ideas on how to make one while maintaining a high speed I would be totally up for the ideas!

TheEmeraldBee commented 2 months ago

Closing this in favor of creating a struct that would contain all required inputs in itself

emilyyyylime commented 2 months ago

Closing this in favor of creating a struct that would contain all required inputs in itself

I'm not sure I understand what's your proposed solution. I want for example to have multiple Menu widgets that each keeps track of the selected entry, is this possible?

TheEmeraldBee commented 2 months ago

I'm not sure I'm following what you would like then. The solution here would be to create a single menu that is represented by an enum, or if you wanted something like multiple of a single widget, like a ton of menus, you would you a vector in a single state. The states are treated like bevy's resources in code, so having multiple of a single widget wouldn't work.

If you could give me more of a code example, this would be very helpful, and I might be able to help.

emilyyyylime commented 2 months ago

A vector could work, but it only really makes sense if the menus are somehow related to each other, if I want to create something very reusable like a radio button, it would be really nice if I could associate each instance with an id of some kind and be able to compose my radio buttons into different places in my application without having to worry about manually maintaining a vector and ensuring to initialise it with the right length and that every index into it is unique, etc.

TheEmeraldBee commented 2 months ago

Ah, I understand what you're saying now. With the implementation of the crate, I don't think this would be possible currently. This would be better suited for a fully fledged ECS, but this doesn't have that. I'm looking to go for a total rewrite of the crate to improve usability, so I'll add this to my list of changes.