feathersui-openfl
feathersui-openfl copied to clipboard
ToggleButton: expose changeState()
When customizing a ListView or similar component, you may want to set a button's state in response to your own input method. The safest and easiest way to do this seems to be changeState(), but that's private.
The one potential issue I see with changeState() is the button will change back automatically based on mouse or keyboard events. Not a problem for my use case (in fact, it's ideal), but it could catch users off-guard and would need to be documented.
(There's also the possibility of using a custom ItemRenderer with a custom PointerToState, but that isn't documented yet and I can't figure out how it's meant to work.)
Yes, a custom item renderer is probably your best bet for customizing the mouse/touch state behavior.
I would strongly prefer not to expose changeState() because I consider it to be an internal implementation detail. Especially considering your point about things that "could catch users off-guard", it doesn't feel safe to expose this publicly and be forced to support it for many years in the future.
Alternatively, you could use @:privateAccess, but of course, there is the risk that changeState() may no longer exist in a future version, and you'd need to find an alternative approach. It's up to you whether that's worth the risk or not.
Yes, a custom item renderer is probably your best bet for customizing the mouse/touch state behavior.
If customItemRendererVariant had a proper explanation, I'd certainly use it. Until then, I'll stick with @:privateAccess.
Don't worry, I'm not using this in any serious projects yet.
The customItemRendererVariant property is used to set the variant property on each of the item renderers. The variant property is used by the theme to determine how to style each component. customItemRendererVariant does not tell the ListView to use a different item renderer class than the default. The itemRendererRecycler property allows you to do that.
There is a simple example of using itemRendererRecycler in the documentation for ListView:
https://feathersui.com/learn/haxe-openfl/list-view/#item-renderers
The cookbook has a few more simple examples:
https://feathersui.com/learn/haxe-openfl/cookbook/#item-renderers