Skip to content

Commit

Permalink
rework of table to include new iced_aw style widget
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Apr 10, 2024
1 parent 8fb807a commit 5b39461
Show file tree
Hide file tree
Showing 2 changed files with 257 additions and 0 deletions.
42 changes: 42 additions & 0 deletions crates/core/src/theme/table_header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use iced::{Background, Color};
use iced_aw::style::table_header::Appearance;
use iced_aw::table;

use super::Theme;

#[derive(Debug, Clone, Copy, Default)]
pub enum TableHeaderStyle {
#[default]
Default,
}

impl table::TableHeaderStyleSheet for Theme {
type Style = TableHeaderStyle;

fn appearance(&self, style: &Self::Style) -> Appearance {
let palette = self.palette;

match style {
TableHeaderStyle::Default => Appearance {
//text_color: Some(self.palette.bright.surface),
text_color: palette.base.foreground,
background: Some(Background::Color(palette.base.background)),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_right: 0.0,
offset_left: 0.0,
},
}
}

fn hovered(&self, style: &Self::Style) -> Appearance {
let palette = self.palette;
match style {
TableHeaderStyle::Default => Appearance {
background: None,
..Appearance::default()
},
}
}
}
215 changes: 215 additions & 0 deletions crates/core/src/theme/table_row.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
use iced::{Background, Color};
use iced_aw::style::table_row::{Appearance, RowOrCellAppearance};
use iced_aw::table;

use super::Theme;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TableRowStyle {
#[default]
Default,
TableRowAlternate,
TableRowHighlight,
TableRowLowlight,
TableRowSelected,
}

impl table::TableRowStyleSheet for Theme {
type Style = TableRowStyle;
fn appearance(&self, style: &Self::Style, row_id: u16) -> Appearance {
let palette = self.palette;

match style {
TableRowStyle::Default => Appearance {
row: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(palette.base.foreground)),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_left: 0.0,
offset_right: 0.0,
},
cell: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(palette.base.foreground)),
border_radius: 0.0.into(),
border_width: 1.0,
border_color: Color::BLACK,
offset_left: 0.0,
offset_right: 0.0,
},
},
TableRowStyle::TableRowAlternate => Appearance {
row: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(Color {
a: 0.50,
..palette.base.foreground
})),
..RowOrCellAppearance::default()
},
cell: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(Color {
a: 0.50,
..palette.normal.primary
})),
..RowOrCellAppearance::default()
},
},
TableRowStyle::TableRowHighlight => Appearance {
row: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(Color {
a: 0.30,
..palette.base.foreground
})),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_left: 0.0,
offset_right: 0.0,
},
cell: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(Color {
a: 0.30,
..palette.base.foreground
})),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_left: 0.0,
offset_right: 0.0,
},
},
TableRowStyle::TableRowLowlight => Appearance {
row: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(Color::TRANSPARENT)),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_left: 0.0,
offset_right: 0.0,
},
cell: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(Color::TRANSPARENT)),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_left: 0.0,
offset_right: 0.0,
},
},
TableRowStyle::TableRowSelected => Appearance {
row: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(palette.normal.primary)),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_left: 0.0,
offset_right: 0.0,
},
cell: RowOrCellAppearance {
text_color: palette.normal.primary,
background: Some(Background::Color(palette.normal.primary)),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_left: 0.0,
offset_right: 0.0,
},
},
}
}

fn hovered(&self, style: &Self::Style, row_id: u16) -> Appearance {
let palette = self.palette;
match style {
TableRowStyle::Default => Appearance {
row: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.60,
..palette.normal.primary
})),
..self.appearance(style, row_id).row
},
cell: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.60,
..palette.normal.primary
})),
..self.appearance(style, row_id).cell
},
},
TableRowStyle::TableRowAlternate => Appearance {
row: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.25,
..palette.normal.primary
})),
..self.appearance(style, row_id).row
},
cell: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.25,
..palette.normal.primary
})),
..self.appearance(style, row_id).cell
},
},
TableRowStyle::TableRowHighlight => Appearance {
row: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.60,
..palette.normal.primary
})),
..self.appearance(style, row_id).row
},
cell: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.60,
..palette.normal.primary
})),
..self.appearance(style, row_id).cell
},
},
TableRowStyle::TableRowLowlight => Appearance {
row: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.60,
..palette.normal.primary
})),
..self.appearance(style, row_id).row
},
cell: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.60,
..palette.normal.primary
})),
..self.appearance(style, row_id).cell
},
},
TableRowStyle::TableRowSelected => Appearance {
row: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.60,
..palette.normal.primary
})),
..self.appearance(style, row_id).row
},
cell: RowOrCellAppearance {
background: Some(Background::Color(Color {
a: 0.60,
..palette.normal.primary
})),
..self.appearance(style, row_id).cell
},
},
}
}
}

0 comments on commit 5b39461

Please sign in to comment.