flipperzero-firmware icon indicating copy to clipboard operation
flipperzero-firmware copied to clipboard

Permit replacement of a view's input callback

Open instantiator opened this issue 1 year ago • 0 comments

What's new

  • The assertion that prevents a change to a view's input callback (if one is present) is removed.
  • Removing it permits a developer to replace the input callback of a view.

Verification

  • It's already "safe" to change the input handler in release builds, because assertions are not enforced.
  • dev builds will fail the assertion if application code attempts to change a view's input callback
  • This can be tested using the resistance calculator app (src, fap distribution) which runs fine on release firmware but crashes on dev firmware

Justification

I appreciate this could be a Chesterton's fence - and so if that assertion is protecting something important, then perhaps we can figure out a better way.

I've been tracking this issue against my own app: flipper-zero-experimental-apps/issues/4, which does override the input callback for a widget. It works on release firmware, but it'd be great if it also worked on dev.

  • In this case, the widget should update on up/down/left/right input.
  • Widgets provide their own input handler, gui_widget_view_input_callback, which calls the input handler for each element in the widget.
  • With that assertion in place in the view, it's not possible to replace a widget's input handler.
  • The only element that can support an input handler right now is the button element, and that element creates GUI I don't need. (This also feels like a workaround.)

Alternatives

  • It is not possible to create a new type of widget element that can handle inputs as:
    • all other types of widget element (everything other than button) do not support input callbacks at all
    • the various structs required to create a new widget element are internal
    • widget_add_element is static

Checklist (For Reviewer)

  • [ ] PR has description of feature/bug or link to Confluence/Jira task
  • [ ] Description contains actions to verify feature/bugfix
  • [ ] I've built this code, uploaded it to the device and verified feature/bugfix

instantiator avatar Apr 28 '23 11:04 instantiator