gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.26k stars 243 forks source link

[FEATURE] `CheckBox` as multichoice with similarity to `RadioGroup` #763

Open michalfita opened 12 months ago

michalfita commented 12 months ago

Is your feature request related to a problem? Please describe. Looks like the CheckBox is not a popular widget. I found it bizarre that contrary to radio box it's not linked with it's label (I have to make LinearLayout with TextView on the right, but then highlighting for selection work only over check boxes, not the whole line.

On top of that would be nice to have some kind of MultichoiceGroup control, returning HashSet<T> or HashSet<Rc<T>> with selections.

Describe the solution you'd like

Describe alternatives you've considered I brutally encoded bunch of CheckBoxes with TextViews linked by horizontal LinearLayout, but it's not visually appealing on focus. Then I'd have to handle evens individually to maintain a state of possible selections.

Additional context image

I'm willing to provide PR if API of CheckBox::new() can be aligned with RadioBox::new(), or a new builder ::labelled() can be introduced and we let both widgets be created w/o attached label, so RadioBox::new() looses the argument and label member becomes Optional<StyledString>.

gyscos commented 8 months ago

Hi, and thanks for the report!

Indeed, it would be nice to unify the radio and check boxes. I'm not against adding a label to the Checkbox to match what Radiobox has, but I'm wondering if we could be more general, and make it easier to attach an arbitrary TextView (or anything else really) and have a nice highlighting over both. This way, we wouldn't have to support left vs right, various padding, ...

michalfita commented 7 months ago

I don't mind. This, however, would breaking change.

The advantage of current one is much simpler creation. I did my PR trying to not break things, and this is working for me. At the moment I don't have capacity to do anything above that.