From 5282dab918ba954fb65dc294519750f1240e461b Mon Sep 17 00:00:00 2001 From: unspeaker Date: Thu, 10 Oct 2024 08:55:39 +0300 Subject: [PATCH] remove old focus implementations --- crates/tek_core/src/focus.rs | 126 ----------------------------------- 1 file changed, 126 deletions(-) diff --git a/crates/tek_core/src/focus.rs b/crates/tek_core/src/focus.rs index f5581aaa..2d4664af 100644 --- a/crates/tek_core/src/focus.rs +++ b/crates/tek_core/src/focus.rs @@ -74,129 +74,3 @@ pub trait FocusGrid { self.update_focus(); } } - -//pub struct FocusFrame<'a, E: Engine>(usize, Vec>); - -//pub struct FocusCell<'a, E: Engine> { - //item: &'a dyn Handle, - //next: Option<&'a FocusCell<'a, E>>, - //prev: Option<&'a FocusCell<'a, E>>, - //up: Option<&'a FocusCell<'a, E>>, - //down: Option<&'a FocusCell<'a, E>>, - //left: Option<&'a FocusCell<'a, E>>, - //right: Option<&'a FocusCell<'a, E>>, -//} - -pub trait FocusContainer { - fn focused (&mut self) -> &mut dyn Handle; - fn handle_focus (&mut self, _: &E::Input) -> Perhaps { - Ok(None) - } -} - -/// A component that may contain [Focusable] components. -pub trait Focus : Widget + Handle { - fn focus (&self) -> usize; - fn focus_mut (&mut self) -> &mut usize; - fn focusable (&self) -> [&dyn Focusable;N]; - fn focusable_mut (&mut self) -> [&mut dyn Focusable;N]; - - fn focused (&self) -> &dyn Focusable { - let focus = self.focus(); - self.focusable()[focus] - } - fn focused_mut (&mut self) -> &mut dyn Focusable { - let focus = self.focus(); - self.focusable_mut()[focus] - } - fn focus_prev (&mut self) { - let focus = self.focus(); - self.focus_set(if focus > 0 { focus - 1 } else { N - 1 }); - } - fn focus_next (&mut self) { - let focus = self.focus(); - self.focus_set(if focus < N - 1 { focus + 1 } else { 0 }); - } - fn focus_set (&mut self, focus: usize) { - *self.focus_mut() = focus; - let focusable = self.focusable_mut(); - for index in 0..N { - focusable[index].set_focused(index == focus); - } - } -} - -/// A component that may be focused. -pub trait Focusable: Widget + Handle { - fn is_focused (&self) -> bool; - fn set_focused (&mut self, focused: bool); -} - -impl, E: Engine> Focusable for Option - where Option: Widget -{ - fn is_focused (&self) -> bool { - match self { - Some(focusable) => focusable.is_focused(), - None => false - } - } - fn set_focused (&mut self, focused: bool) { - if let Some(focusable) = self { - focusable.set_focused(focused) - } - } -} - -impl, E: Engine> Focusable for Arc> { - fn is_focused (&self) -> bool { - self.read().unwrap().is_focused() - } - fn set_focused (&mut self, focused: bool) { - self.write().unwrap().set_focused(focused) - } -} - -/// Implement the [Focus] trait for a component. -#[macro_export] macro_rules! focus { - ($struct:ident ($focus:ident) : $count:expr => [ - $($focusable:ident),* - ]) => { - impl Focus<$count, E> for $struct { - fn focus (&self) -> usize { - self.$focus - } - fn focus_mut (&mut self) -> &mut usize { - &mut self.$focus - } - fn focusable (&self) -> [&dyn Focusable;$count] { - [$(&self.$focusable as &dyn Focusable,)*] - } - fn focusable_mut (&mut self) -> [&mut dyn Focusable;$count] { - [$(&mut self.$focusable as &mut dyn Focusable,)*] - } - } - } -} - -/// Implement the [Focusable] trait for a component. -#[macro_export] macro_rules! focusable { - ($struct:ident) => { - focusable!($struct (focused)); - }; - ($struct:ident ($focused:ident)) => { - impl Focusable for $struct { - fn is_focused (&self) -> bool { self.$focused } - fn set_focused (&mut self, f: bool) { self.$focused = f } - } - } -} - -#[macro_export] macro_rules! focusables { - ($($item:expr),* $(,)?) => { [$(&$item as &dyn Focusable<_>),+] } -} - -#[macro_export] macro_rules! focusables_mut { - ($($item:expr),* $(,)?) => { [$(&mut $item as &mut dyn Focusable<_>),+] } -} -