#[allow(unused)] use crate::clerk::AsyncClerk;
use kas::TextOrSource;
use kas::prelude::*;
use kas_widgets::{CheckBox, Text};
use std::default::Default;
#[autoimpl(for<T: trait + ?Sized> &mut T, Box<T>)]
pub trait Driver<Key, Item> {
const TAB_NAVIGABLE: bool;
type Widget: kas::Widget<Data = Item>;
fn make(&mut self, key: &Key) -> Self::Widget;
fn set_key(&mut self, widget: &mut Self::Widget, key: &Key) {
*widget = self.make(key);
}
fn navigable(widget: &Self::Widget) -> bool;
fn label(widget: &Self::Widget) -> Option<TextOrSource<'_>> {
let _ = widget;
None
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct View;
macro_rules! impl_via_to_string {
($t:ty) => {
impl<Key> Driver<Key, $t> for View {
const TAB_NAVIGABLE: bool = false;
type Widget = Text<$t>;
fn make(&mut self, _: &Key) -> Self::Widget {
Text::new_gen(|_, data: &$t| data.to_string())
}
fn set_key(&mut self, _: &mut Self::Widget, _: &Key) {
}
fn navigable(_: &Self::Widget) -> bool {
true
}
fn label(widget: &Self::Widget) -> Option<TextOrSource<'_>> {
Some(widget.id().into())
}
}
};
($t:ty, $($tt:ty),+) => {
impl_via_to_string!($t);
impl_via_to_string!($($tt),+);
};
}
impl_via_to_string!(String, &'static str);
impl_via_to_string!(i8, i16, i32, i64, i128, isize);
impl_via_to_string!(u8, u16, u32, u64, u128, usize);
impl_via_to_string!(f32, f64);
impl<Key> Driver<Key, bool> for View {
const TAB_NAVIGABLE: bool = false;
type Widget = CheckBox<bool>;
fn make(&mut self, _: &Key) -> Self::Widget {
CheckBox::new(|_, data: &bool| *data).with_editable(false)
}
fn set_key(&mut self, _: &mut Self::Widget, _: &Key) {
}
fn navigable(_: &Self::Widget) -> bool {
false
}
}