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

View file

@ -11,7 +11,7 @@ pub trait ItemCategory:
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_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();
/// ```
#[must_use]
pub fn insert(&mut self) -> EntityMut<SelectionMode, Item, Category> {
let id = self.items.insert(Item::default());
pub fn insert(&mut self, item: Item) -> EntityMut<SelectionMode, Item, Category> {
let id = self.items.insert(item);
self.order.push_back(id);
EntityMut { model: self, id }
}