Skip to content

Commit

Permalink
Added table function for generic table view creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-Cosner committed Jan 4, 2025
1 parent dd9d1c0 commit 2401c2a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/table-view/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use chrono::Datelike;
use cosmic::app::{Core, Settings, Task};
use cosmic::iced_core::Size;
use cosmic::widget::nav_bar;
use cosmic::widget::table;
use cosmic::widget::{self, nav_bar};
use cosmic::{executor, iced, Element};

#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -194,12 +194,12 @@ impl cosmic::Application for App {
fn view(&self) -> Element<Self::Message> {
cosmic::widget::responsive(|size| {
if size.width < 600.0 {
table::SingleSelectTableView::new(&self.table_model)
widget::table(&self.table_model)
.on_item_select(Message::ItemSelect)
.on_category_select(Message::CategorySelect)
.element_compact()
} else {
table::SingleSelectTableView::new(&self.table_model)
widget::table(&self.table_model)
.on_item_select(Message::ItemSelect)
.on_category_select(Message::CategorySelect)
.element_standard()
Expand Down
1 change: 1 addition & 0 deletions src/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ pub use spin_button::{spin_button, vertical as vertical_spin_button, SpinButton}
pub mod tab_bar;

pub mod table;
pub use table::table;

pub mod text;
#[doc(inline)]
Expand Down
13 changes: 13 additions & 0 deletions src/widget/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ pub type SingleSelectModel<Item, Category> = Model<SingleSelect, Item, Category>
pub type MultiSelectTableView<'a, Item, Category, Message> =
TableView<'a, MultiSelect, Item, Category, Message>;
pub type MultiSelectModel<Item, Category> = Model<MultiSelect, Item, Category>;

pub fn table<'a, SelectionMode, Item, Category, Message>(
model: &'a Model<SelectionMode, Item, Category>,
) -> TableView<'a, SelectionMode, Item, Category, Message>
where
Message: Clone,
SelectionMode: Default,
Category: ItemCategory,
Item: ItemInterface<Category>,
Model<SelectionMode, Item, Category>: model::selection::Selectable,
{
TableView::new(model)
}

0 comments on commit 2401c2a

Please sign in to comment.