beardgame/ui

Invalid state around CanBeFocused is possible.

Opened this issue ยท 1 comments

๐Ÿ› Bug Report

A Control has a IsFocused and a CanBeFocused property. A control could change it's CanBeFocused property after it receives Focus, allowing the Control to be in an invalid state. Currently the abstract Control class is relying on his subclasses to behave properly and not do this, which breaks proper encapsulation.

Context

The currently latest version (2020-10-23), I do not know what that version is (it sais 1.0.0 in the properties everywhere, but I don't really believe that).

Expected behavior

The CanBeFocused property should not allow setting it to an invalid state. Either refuse to set CanBeFocused to false if it's currently Focused (probably by throwing), or by Unfocusing when CanBeFocused is set to false.

To reproduce

Create a custom control, give it focus, set that it can't be focused and voila, you have a focused unfocusable object.

My preference would be to have the control be unfocused if CanBeFocused is set to false. For example, a hidden controlmay set this property to false, and still having the focus exist would be unexpected.

Focus probably needs another revisit, because it doesn't work entirely intuitive right now, but unfocusing the control when CanBeFocused is set to false sounds like a net positive either way.