load real toolbx information on startup

This commit is contained in:
2022-04-21 21:03:49 +02:00
parent fec7f6271f
commit e731426650
5 changed files with 80 additions and 161 deletions

View File

@@ -8,22 +8,21 @@ use relm4::{
gtk, send, view, Sender,
};
use crate::ui::{
app::model::ToolboxStatus,
use crate::{ui::{
ui_strings::{
APP_ICON, APP_TOOLTIP, SETTINGS_ICON, SETTINGS_TOOLTIP, SHUTDOWN_ICON, SHUTDOWN_TOOLTIP,
START_ICON, START_TOOLTIP, TERMINAL_ICON, TERMINAL_TOOLTIP, UPDATE_ICON, UPDATE_TOOLTIP,
},
};
}, toolbx::ToolbxContainer};
use super::{messages::AppMsg, model::ToolboxContainer};
use super::{messages::AppMsg};
#[derive(Debug)]
pub struct FactoryWidgets {
pub action_row: adw::ActionRow,
}
impl FactoryPrototype for ToolboxContainer {
impl FactoryPrototype for ToolbxContainer {
type Factory = FactoryVec<Self>;
type Widgets = FactoryWidgets;
type Root = adw::ActionRow;
@@ -37,79 +36,97 @@ impl FactoryPrototype for ToolboxContainer {
) -> Self::Widgets {
view! {
suffix_box = &gtk::Box{
append = &gtk::Button::from_icon_name(APP_ICON) {
set_margin_start: 10,
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(APP_TOOLTIP),
set_css_classes: &["flat"],
connect_clicked(sender) => move |btn| {
send!(sender, AppMsg::ShowToolboxAppsRequest);
append = &gtk::AspectFrame{
set_ratio: 1.0,
set_child = Some(&gtk::Button::from_icon_name(APP_ICON)) {
set_margin_start: 10,
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(APP_TOOLTIP),
set_css_classes: &["flat"],
connect_clicked(sender) => move |btn| {
send!(sender, AppMsg::ShowToolboxAppsRequest);
},
}
},
append = &gtk::AspectFrame{
set_ratio: 1.0,
set_child = Some(&gtk::Button::from_icon_name(TERMINAL_ICON)) {
set_margin_start: 10,
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(TERMINAL_TOOLTIP),
set_css_classes: &["flat"],
}
},
append = &gtk::AspectFrame{
set_ratio: 1.0,
set_child = Some(&gtk::Button::from_icon_name(SETTINGS_ICON)) {
set_margin_start: 10,set_margin_start: 10,
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(SETTINGS_TOOLTIP),
set_css_classes: &["circular"],
connect_clicked(sender) => move |btn| {
send!(sender, AppMsg::ShowToolboxSettingsRequest);
},
},
},
append = &gtk::Button::from_icon_name(TERMINAL_ICON) {
set_margin_start: 10,
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(TERMINAL_TOOLTIP),
set_css_classes: &["flat"],
},
append = &gtk::Button::from_icon_name(SETTINGS_ICON) {
set_margin_start: 10,set_margin_start: 10,
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(SETTINGS_TOOLTIP),
set_css_classes: &["circular"],
connect_clicked(sender) => move |btn| {
send!(sender, AppMsg::ShowToolboxSettingsRequest);
},
},
}
}
};
/*
if self.update_available {
view! {
update_button = &gtk::Button::from_icon_name(UPDATE_ICON) {
set_margin_top: 10,
set_margin_bottom: 10,
set_margin_end: 10,
set_tooltip_text: Some(UPDATE_TOOLTIP),
set_css_classes: &["suggested-action"],
update_button = &gtk::AspectFrame{
set_ratio: 1.0,
set_child = Some(&gtk::Button::from_icon_name(UPDATE_ICON)) {
set_margin_top: 10,
set_margin_bottom: 10,
set_margin_end: 10,
set_tooltip_text: Some(UPDATE_TOOLTIP),
set_css_classes: &["suggested-action"],
}
}
};
suffix_box.prepend(&update_button);
}
let is_on = true;
*/
let mut status_button_tooltip = START_TOOLTIP;
let mut status_button_icon = START_ICON;
match &self.status {
&ToolboxStatus::Running => {
match self.status.as_str() {
"running" => {
status_button_tooltip = SHUTDOWN_TOOLTIP;
status_button_icon = SHUTDOWN_ICON;
}
&ToolboxStatus::Stopped => {
_ => {
status_button_tooltip = START_TOOLTIP;
status_button_icon = START_ICON;
}
}
let subtitle = format!("created {}\n{}", self.created, self.image);
view! {
action_row = &adw::ActionRow {
set_title: &self.name,
set_subtitle: "additional information",
set_subtitle: subtitle.as_str(),
add_prefix = &gtk::Box {
append = &gtk::Button::from_icon_name(status_button_icon) {
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(status_button_tooltip),
set_css_classes: &["circular"],
append = &gtk::AspectFrame{
set_ratio: 1.0,
set_child = Some(&gtk::Button::from_icon_name(status_button_icon)) {
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(status_button_tooltip),
set_css_classes: &["circular"],
},
},
},
add_suffix: &suffix_box,
}
};
FactoryWidgets { action_row }
}