wip: generic render

This commit is contained in:
🪞👃🪞 2024-09-03 00:57:32 +03:00
parent 7bd2a70e85
commit fcd2d16de9
12 changed files with 314 additions and 351 deletions

View file

@ -1,17 +1,17 @@
use crate::*;
/// A component that may contain [Focusable] components.
pub trait Focus <const N: usize>: Render + Handle {
pub trait Focus <const N: usize, T, U>: Render<T, U> + 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 focusable (&self) -> [&dyn Focusable<T, U>;N];
fn focusable_mut (&mut self) -> [&mut dyn Focusable<T, U>;N];
fn focused (&self) -> &dyn Focusable {
fn focused (&self) -> &dyn Focusable<T, U> {
let focus = self.focus();
self.focusable()[focus]
}
fn focused_mut (&mut self) -> &mut dyn Focusable {
fn focused_mut (&mut self) -> &mut dyn Focusable<T, U> {
let focus = self.focus();
self.focusable_mut()[focus]
}
@ -33,12 +33,14 @@ pub trait Focus <const N: usize>: Render + Handle {
}
/// A component that may be focused.
pub trait Focusable: Render + Handle {
pub trait Focusable<T, U>: Render<T, U> + Handle {
fn is_focused (&self) -> bool;
fn set_focused (&mut self, focused: bool);
}
impl<T: Focusable> Focusable for Option<T> {
impl<F: Focusable<T, U>, T, U> Focusable<T, U> for Option<F>
where Option<F>: Render<T, U>
{
fn is_focused (&self) -> bool {
match self {
Some(focusable) => focusable.is_focused(),