ofxDropdown icon indicating copy to clipboard operation
ofxDropdown copied to clipboard

[feature request] option to prevent "no selection" (aka radio button set)

Open artificiel opened this issue 10 months ago • 1 comments

it would be great to be able to enforce at least one selection: in conjunction with disableMultipleSelection(), it would behave like a radio button, where one of the options is always required. perhaps some call like disallowEmptySelectedValue().

thought it would be a simple implementation but (as far as I understand) the ofxDropdownOption process their own mouse clicks and toggle themselves, without being aware if a rule would prevent themselves to toggle off?

would the design be to propagate a new _bDisallowSelfTurningOff bool into the Options? there seems to be the idea around _bSelectOnMouseRelease but it's not clear what happens if the flag is set before children are populated?

artificiel avatar Feb 24 '25 02:02 artificiel

Hi @artificiel ! Thanks for the feedback. It actually makes a lot of sense. I am not sure about the implementation as I have not checked the code of this addon for quite a long time. I will check and let you know. But if you have something working please make a PR.

On the other hand, in the cases where I want it to always be just a single selection, where it is always just one selected, I prefer using enums and an int parameter. This will always be just one of the options and at the same time is allows for cleaner code; it becomes something like a state machine, where you only need to check for a particular state rather than keeping track of multiple booleans and their possible combinations.

roymacdonald avatar Feb 24 '25 11:02 roymacdonald