Crate rat_focus

source ·
Expand description

§Focus handling

This crate works by adding a FocusFlag to each widgets state.

Focus is list of references to all relevant focus-flags. It has methods next() and prev() that can change the focus. This way each widget has its focused-state nearby and the list of focusable widget can be constructed flexibly.

The trait HasFocusFlag mediates between the two sides.

§Macros

There are the macros on_lost, on_gained and match_focus that ease the use of the focus-flags, providing a match like syntax.

§Composition

There is support for composite widgets too. You can use Focus::new_accu() to create the focus cycle. There you can give one extra FocusFlag that will contain a summary of the focus-state for all contained widgets.

If any of the contained widgets is focused, the summary will have the focus flag too. Lost and Gained work that if any contained widget gained the focus and no other contained widget lost it, only then will the composite widget have a gained flag set. Lost works vice versa.

There is the method Focus::append, which can append another focus cycle. This can stack to arbitrary depth.

There is a nice demo to illustrate this with focus_recursive2.

Modules§

  • Rexported eventhandling traits.

Macros§

  • Does a match on the state struct of a widget. If widget_state.is_focused() is true the block is executed. There is a _ branch too, that is evaluated if none of the given widget-states has the focus.
  • Does a match on the state struct of a widget. If widget_state.gained_focus() is true the block is executed. This requires that widget_state implements HasFocusFlag, but that’s the basic requirement for this whole crate.
  • Does a match on the state struct of a widget. If widget_state.lost_focus() is true the block is executed. This requires that widget_state implements HasFocusFlag, but that’s the basic requirement for this whole crate.

Structs§

  • Keeps track of the focus.
  • Contains flags for the focus. This struct is embedded in the widget state.

Traits§