remove dependency on iced_aw (segmented button)
iced_aw is dropping the segmented_button in Beta branch, suggesting to use iced button
This commit is contained in:
parent
61c02ceea6
commit
83ffb682d6
|
@ -10,7 +10,6 @@ tracing = ["dep:lttng-ust"]
|
||||||
#iced = "0.4.2"
|
#iced = "0.4.2"
|
||||||
#iced_native = "0.5.1"
|
#iced_native = "0.5.1"
|
||||||
iced = { path = "../iced", features = ["advanced"] }
|
iced = { path = "../iced", features = ["advanced"] }
|
||||||
iced_aw = { path = "../iced_aw", default-features = false, features = ["segmented_button", "tab_bar", "icons"] }
|
|
||||||
chrono = { version = "0.4", features = ["unstable-locales"] }
|
chrono = { version = "0.4", features = ["unstable-locales"] }
|
||||||
lttng-ust = { version = "0.1.0", optional = true }
|
lttng-ust = { version = "0.1.0", optional = true }
|
||||||
icalendar = "0.15.4"
|
icalendar = "0.15.4"
|
||||||
|
|
|
@ -6,20 +6,7 @@ use chrono::{
|
||||||
NaiveDate,
|
NaiveDate,
|
||||||
Locale,
|
Locale,
|
||||||
};
|
};
|
||||||
use iced::{
|
use iced::{Alignment, Background, Border, Element, Length, Theme, alignment, theme::palette, widget::{Button, Row, Text, button::{Status, Style, secondary}, row, text}};
|
||||||
alignment,
|
|
||||||
Alignment,
|
|
||||||
Element,
|
|
||||||
Length,
|
|
||||||
widget::{
|
|
||||||
button,
|
|
||||||
row,
|
|
||||||
Row,
|
|
||||||
Button,
|
|
||||||
Text, text,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use iced_aw::widgets::segmented_button::SegmentedButton;
|
|
||||||
|
|
||||||
//#[derive(Default)]
|
//#[derive(Default)]
|
||||||
pub struct Controls {
|
pub struct Controls {
|
||||||
|
@ -48,13 +35,13 @@ impl Controls {
|
||||||
.padding(5)
|
.padding(5)
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.push(row![
|
.push(row![
|
||||||
SegmentedButton::new(text("Week"), ViewMode::Week, self.mode, Message::ViewModeSelected),
|
Button::new(text("Week")).on_press(Message::ViewModeSelected(ViewMode::Week)).style(self.get_mode_style(ViewMode::Week)),
|
||||||
SegmentedButton::new(text("Month"), ViewMode::Month, self.mode, Message::ViewModeSelected),
|
Button::new(text("Month")).on_press(Message::ViewModeSelected(ViewMode::Month)).style(self.get_mode_style(ViewMode::Month)),
|
||||||
SegmentedButton::new(text("Year"), ViewMode::Year, self.mode, Message::ViewModeSelected),
|
Button::new(text("Year")).on_press(Message::ViewModeSelected(ViewMode::Year)).style(self.get_mode_style(ViewMode::Year)),
|
||||||
])
|
])
|
||||||
.push(row![
|
.push(row![
|
||||||
Button::new(Text::new("<")).on_press(self.get_msg_prev()).style(button::secondary),
|
Button::new(Text::new("<")).on_press(self.get_msg_prev()).style(secondary),
|
||||||
Button::new(Text::new(">")).on_press(self.get_msg_next()).style(button::secondary),
|
Button::new(Text::new(">")).on_press(self.get_msg_next()).style(secondary),
|
||||||
].spacing(0).padding(0)
|
].spacing(0).padding(0)
|
||||||
)
|
)
|
||||||
.push(
|
.push(
|
||||||
|
@ -89,4 +76,67 @@ impl Controls {
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_mode_style(&self, view_mode: ViewMode) -> impl Fn(&Theme, Status) -> Style {
|
||||||
|
if let Some(current_view_mode) = self.mode {
|
||||||
|
if current_view_mode == view_mode {
|
||||||
|
mode_selected
|
||||||
|
} else {
|
||||||
|
mode_not_selected
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: copied from iced button
|
||||||
|
fn styled(pair: palette::Pair) -> Style {
|
||||||
|
Style {
|
||||||
|
background: Some(Background::Color(pair.color)),
|
||||||
|
text_color: pair.text,
|
||||||
|
border: Border::rounded(2),
|
||||||
|
..Style::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn disabled(style: Style) -> Style {
|
||||||
|
Style {
|
||||||
|
background: style
|
||||||
|
.background
|
||||||
|
.map(|background| background.scale_alpha(0.5)),
|
||||||
|
text_color: style.text_color.scale_alpha(0.5),
|
||||||
|
..style
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mode_not_selected(theme: &Theme, status: Status) -> Style {
|
||||||
|
let palette = theme.extended_palette();
|
||||||
|
let base = styled(palette.secondary.base);
|
||||||
|
|
||||||
|
match status {
|
||||||
|
Status::Active | Status::Pressed => base,
|
||||||
|
Status::Hovered => Style {
|
||||||
|
background: Some(Background::Color(palette.secondary.strong.color)),
|
||||||
|
..base
|
||||||
|
},
|
||||||
|
Status::Disabled => disabled(base),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mode_selected(theme: &Theme, status: Status) -> Style {
|
||||||
|
let palette = theme.extended_palette();
|
||||||
|
let base = styled(palette.secondary.base);
|
||||||
|
|
||||||
|
match status {
|
||||||
|
Status::Active | Status::Pressed => Style {
|
||||||
|
background: Some(Background::Color(palette.secondary.strong.color)),
|
||||||
|
..base
|
||||||
|
},
|
||||||
|
Status::Hovered => Style {
|
||||||
|
background: Some(Background::Color(palette.secondary.strong.color)),
|
||||||
|
..base
|
||||||
|
},
|
||||||
|
Status::Disabled => disabled(base),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue