Added a AlwaysFocused component #26
This commit is contained in:
@@ -23,6 +23,7 @@ pub fn app(screen: Arc<Screen>) -> Rsx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
|
@AlwaysFocused;
|
||||||
Paginator {
|
Paginator {
|
||||||
FlexRow {
|
FlexRow {
|
||||||
Heading, smooth: false, { "OSUI" }
|
Heading, smooth: false, { "OSUI" }
|
||||||
|
|||||||
+22
-10
@@ -1,8 +1,19 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use crate::component;
|
||||||
|
|
||||||
use super::Extension;
|
use super::Extension;
|
||||||
|
|
||||||
use crossterm::event::{Event as CrosstermEvent, KeyCode};
|
use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyModifiers};
|
||||||
|
|
||||||
|
component!(AlwaysFocused);
|
||||||
|
|
||||||
|
enum Direction {
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RelativeFocusExtension {
|
pub struct RelativeFocusExtension {
|
||||||
cursor: usize,
|
cursor: usize,
|
||||||
@@ -13,7 +24,9 @@ impl Extension for RelativeFocusExtension {
|
|||||||
fn event(&mut self, ctx: &super::Context, event: &dyn super::Event) {
|
fn event(&mut self, ctx: &super::Context, event: &dyn super::Event) {
|
||||||
if let Some(e) = event.get::<CrosstermEvent>() {
|
if let Some(e) = event.get::<CrosstermEvent>() {
|
||||||
match e {
|
match e {
|
||||||
CrosstermEvent::Key(k) => match k.code {
|
CrosstermEvent::Key(k) => {
|
||||||
|
if k.modifiers.contains(KeyModifiers::SHIFT) {
|
||||||
|
match k.code {
|
||||||
KeyCode::Right => {
|
KeyCode::Right => {
|
||||||
let rendered = self.rendered.lock().unwrap();
|
let rendered = self.rendered.lock().unwrap();
|
||||||
let (_, current_x, current_y) = rendered
|
let (_, current_x, current_y) = rendered
|
||||||
@@ -94,13 +107,19 @@ impl Extension for RelativeFocusExtension {
|
|||||||
self.cursor = index;
|
self.cursor = index;
|
||||||
|
|
||||||
for (i, w) in ctx.get_widgets().iter().enumerate() {
|
for (i, w) in ctx.get_widgets().iter().enumerate() {
|
||||||
|
if let Some(AlwaysFocused) = w.get() {
|
||||||
|
w.set_focused(true);
|
||||||
|
} else {
|
||||||
w.set_focused(i == self.cursor);
|
w.set_focused(i == self.cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,13 +162,6 @@ impl RelativeFocusExtension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Direction {
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_closest_in_direction(
|
fn find_closest_in_direction(
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
current_x: u16,
|
current_x: u16,
|
||||||
|
|||||||
Reference in New Issue
Block a user