Changed insert method and removed default requirement for Item

This commit is contained in:
Adam Cosner 2025-01-18 22:57:04 -08:00
parent 1ef9e1330a
commit d4f3004338
3 changed files with 6 additions and 6 deletions

View file

@ -143,7 +143,7 @@ impl cosmic::Application for App {
let mut table_model = let mut table_model =
table::Model::new(vec![Category::Name, Category::Date, Category::Size]); table::Model::new(vec![Category::Name, Category::Date, Category::Size]);
table_model.insert().item(Item { let _ = table_model.insert(Item {
name: "Foo".into(), name: "Foo".into(),
date: chrono::DateTime::default() date: chrono::DateTime::default()
.with_day(1) .with_day(1)
@ -154,7 +154,7 @@ impl cosmic::Application for App {
.unwrap(), .unwrap(),
size: 2, size: 2,
}); });
table_model.insert().item(Item { let _ = table_model.insert(Item {
name: "Bar".into(), name: "Bar".into(),
date: chrono::DateTime::default() date: chrono::DateTime::default()
.with_day(2) .with_day(2)
@ -165,7 +165,7 @@ impl cosmic::Application for App {
.unwrap(), .unwrap(),
size: 4, size: 4,
}); });
table_model.insert().item(Item { let _ = table_model.insert(Item {
name: "Baz".into(), name: "Baz".into(),
date: chrono::DateTime::default() date: chrono::DateTime::default()
.with_day(3) .with_day(3)

View file

@ -11,7 +11,7 @@ pub trait ItemCategory:
fn width(&self) -> iced::Length; fn width(&self) -> iced::Length;
} }
pub trait ItemInterface<Category: ItemCategory>: Default { pub trait ItemInterface<Category: ItemCategory> {
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) -> Cow<'static, str>;

View file

@ -221,8 +221,8 @@ where
/// let id = model.insert().text("Item A").icon("custom-icon").id(); /// let id = model.insert().text("Item A").icon("custom-icon").id();
/// ``` /// ```
#[must_use] #[must_use]
pub fn insert(&mut self) -> EntityMut<SelectionMode, Item, Category> { pub fn insert(&mut self, item: Item) -> EntityMut<SelectionMode, Item, Category> {
let id = self.items.insert(Item::default()); let id = self.items.insert(item);
self.order.push_back(id); self.order.push_back(id);
EntityMut { model: self, id } EntityMut { model: self, id }
} }