Added custom widget version of table
Currently does not have mouse interaction, in the demo the normal one is right and custom is left
This commit is contained in:
parent
9bd8f011b7
commit
6958a4cc36
3 changed files with 25 additions and 12 deletions
|
|
@ -32,11 +32,11 @@ impl std::fmt::Display for Category {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl table::ItemCategory for Category {
|
impl table::ItemCategory for Category {
|
||||||
fn width(&self) -> iced::Length {
|
fn width(&self) -> u16 {
|
||||||
match self {
|
match self {
|
||||||
Self::Name => iced::Length::Fill,
|
Self::Name => 300,
|
||||||
Self::Date => iced::Length::Fixed(200.0),
|
Self::Date => 200,
|
||||||
Self::Size => iced::Length::Fixed(150.0),
|
Self::Size => 150,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -66,11 +66,11 @@ impl table::ItemInterface<Category> for Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_text(&self, category: Category) -> std::borrow::Cow<'static, str> {
|
fn get_text(&self, category: Category) -> Option<String> {
|
||||||
match category {
|
match category {
|
||||||
Category::Name => self.name.clone().into(),
|
Category::Name => Some(self.name.clone()),
|
||||||
Category::Date => self.date.format("%Y/%m/%d").to_string().into(),
|
Category::Date => Some(self.date.format("%Y/%m/%d").to_string()),
|
||||||
Category::Size => format!("{} items", self.size).into(),
|
Category::Size => Some(format!("{} items", self.size)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ pub trait ItemCategory:
|
||||||
Default + std::fmt::Display + Clone + Copy + PartialEq + Eq + std::hash::Hash
|
Default + std::fmt::Display + Clone + Copy + PartialEq + Eq + std::hash::Hash
|
||||||
{
|
{
|
||||||
/// Function that gets the width of the data
|
/// Function that gets the width of the data
|
||||||
fn width(&self) -> iced::Length;
|
fn width(&self) -> u16;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ItemInterface<Category: ItemCategory>: Default {
|
pub trait ItemInterface<Category: ItemCategory>: Default {
|
||||||
fn get_icon(&self, category: Category) -> Option<Icon>;
|
fn get_icon(&self, category: Category) -> Option<Icon>;
|
||||||
fn get_text(&self, category: Category) -> Cow<'static, str>;
|
fn get_text(&self, category: Category) -> Option<String>;
|
||||||
|
|
||||||
fn compare(&self, other: &Self, category: Category) -> std::cmp::Ordering;
|
fn compare(&self, other: &Self, category: Category) -> std::cmp::Ordering;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,21 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use iced::Size;
|
||||||
use slotmap::SecondaryMap;
|
use slotmap::SecondaryMap;
|
||||||
|
|
||||||
use crate::widget::table::Entity;
|
use crate::widget::table::{Entity, ItemCategory};
|
||||||
|
|
||||||
pub struct State {
|
pub struct State<Category>
|
||||||
|
where
|
||||||
|
Category: ItemCategory + 'static,
|
||||||
|
{
|
||||||
pub(super) num_items: usize,
|
pub(super) num_items: usize,
|
||||||
pub(super) selected: SecondaryMap<Entity, bool>,
|
pub(super) selected: SecondaryMap<Entity, bool>,
|
||||||
|
pub(super) paragraphs: SecondaryMap<Entity, HashMap<Category, crate::Plain>>,
|
||||||
|
pub(super) text_hashes: SecondaryMap<Entity, u64>,
|
||||||
|
pub(super) item_layout: Vec<Size>,
|
||||||
|
|
||||||
|
pub(super) sort_hash: HashMap<Category, u64>,
|
||||||
|
pub(super) header_paragraphs: HashMap<Category, crate::Plain>,
|
||||||
|
pub(super) category_layout: Vec<Size>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue