pub trait Focusable: Component {
// Required methods
fn is_focused(state: &Self::State) -> bool;
fn set_focused(state: &mut Self::State, focused: bool);
// Provided methods
fn focus(state: &mut Self::State) { ... }
fn blur(state: &mut Self::State) { ... }
}Expand description
A component that can receive keyboard focus.
Focus is used to determine which component receives keyboard input when multiple components are on screen. Only one component should typically be focused at a time.
§Visual Feedback
Components should provide visual feedback when focused, such as:
- Highlighted borders
- Changed colors
- Cursor visibility
§Example
use envision::component::{Component, Focusable};
use ratatui::prelude::*;
struct TextInput;
#[derive(Clone, Default)]
struct TextInputState {
value: String,
focused: bool,
}
impl Focusable for TextInput {
fn is_focused(state: &Self::State) -> bool {
state.focused
}
fn set_focused(state: &mut Self::State, focused: bool) {
state.focused = focused;
}
}Required Methods§
Sourcefn is_focused(state: &Self::State) -> bool
fn is_focused(state: &Self::State) -> bool
Returns true if this component is currently focused.
Sourcefn set_focused(state: &mut Self::State, focused: bool)
fn set_focused(state: &mut Self::State, focused: bool)
Sets the focus state of this component.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.