From 0e29b6b2260e6dfb65733a61c15e42e3b71cb777 Mon Sep 17 00:00:00 2001 From: Adam Cosner Date: Thu, 2 Jan 2025 22:29:00 -0800 Subject: [PATCH] Revert "Added custom widget version of table" This reverts commit 825792e36710818a65d57b2633cf374b3f231b6a. --- examples/table-view/src/main.rs | 18 +++++++++--------- src/widget/table/model/category.rs | 4 ++-- src/widget/table/widget/state.rs | 17 ++--------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/examples/table-view/src/main.rs b/examples/table-view/src/main.rs index 64bbbe75..387035d2 100644 --- a/examples/table-view/src/main.rs +++ b/examples/table-view/src/main.rs @@ -13,7 +13,7 @@ use cosmic::widget::table; use cosmic::widget::{self, nav_bar}; use cosmic::{executor, iced}; -#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)] +#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)] pub enum Category { #[default] Name, @@ -32,11 +32,11 @@ impl std::fmt::Display for Category { } impl table::ItemCategory for Category { - fn width(&self) -> u16 { + fn width(&self) -> iced::Length { match self { - Self::Name => 300, - Self::Date => 200, - Self::Size => 150, + Self::Name => iced::Length::Fill, + Self::Date => iced::Length::Fixed(200.0), + Self::Size => iced::Length::Fixed(150.0), } } } @@ -66,11 +66,11 @@ impl table::ItemInterface for Item { } } - fn get_text(&self, category: Category) -> Option { + fn get_text(&self, category: Category) -> std::borrow::Cow<'static, str> { match category { - Category::Name => Some(self.name.clone()), - Category::Date => Some(self.date.format("%Y/%m/%d").to_string()), - Category::Size => Some(format!("{} items", self.size)), + Category::Name => self.name.clone().into(), + Category::Date => self.date.format("%Y/%m/%d").to_string().into(), + Category::Size => format!("{} items", self.size).into(), } } diff --git a/src/widget/table/model/category.rs b/src/widget/table/model/category.rs index cc06c76a..5c79d404 100644 --- a/src/widget/table/model/category.rs +++ b/src/widget/table/model/category.rs @@ -8,12 +8,12 @@ pub trait ItemCategory: Default + std::fmt::Display + Clone + Copy + PartialEq + Eq + std::hash::Hash { /// Function that gets the width of the data - fn width(&self) -> u16; + fn width(&self) -> iced::Length; } pub trait ItemInterface: Default { fn get_icon(&self, category: Category) -> Option; - fn get_text(&self, category: Category) -> Option; + fn get_text(&self, category: Category) -> Cow<'static, str>; fn compare(&self, other: &Self, category: Category) -> std::cmp::Ordering; } diff --git a/src/widget/table/widget/state.rs b/src/widget/table/widget/state.rs index 82fb88db..4d529db4 100644 --- a/src/widget/table/widget/state.rs +++ b/src/widget/table/widget/state.rs @@ -1,21 +1,8 @@ -use std::collections::HashMap; - -use iced::Size; use slotmap::SecondaryMap; -use crate::widget::table::{Entity, ItemCategory}; +use crate::widget::table::Entity; -pub struct State -where - Category: ItemCategory + 'static, -{ +pub struct State { pub(super) num_items: usize, pub(super) selected: SecondaryMap, - pub(super) paragraphs: SecondaryMap>, - pub(super) text_hashes: SecondaryMap, - pub(super) item_layout: Vec, - - pub(super) sort_hash: HashMap, - pub(super) header_paragraphs: HashMap, - pub(super) category_layout: Vec, }