Added ghost elements to avoid focusing on them

This commit is contained in:
2025-08-09 02:27:16 +02:00
parent c8ebe36d78
commit 3520369e35
7 changed files with 75 additions and 11 deletions
+10 -1
View File
@@ -7,6 +7,7 @@ use super::Extension;
use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyModifiers};
component!(AlwaysFocused);
component!(Focused);
enum Direction {
Left,
@@ -21,6 +22,14 @@ pub struct RelativeFocusExtension {
}
impl Extension for RelativeFocusExtension {
fn init(&mut self, _ctx: &super::Context) {
for widget in _ctx.get_widgets().iter() {
if let Some(Focused) = widget.get() {
widget.set_focused(true);
}
}
}
fn event(&mut self, ctx: &super::Context, event: &dyn super::Event) {
if let Some(e) = event.get::<CrosstermEvent>() {
match e {
@@ -145,7 +154,7 @@ impl Extension for RelativeFocusExtension {
if let Some(p) = ctx
.get_widgets()
.iter()
.position(|w| Arc::ptr_eq(w, &widget))
.position(|w| Arc::ptr_eq(w, &widget) && !w.is_ghost())
{
rendered.lock().unwrap().push((p, t.x, t.y));
}