Skip to content

Commit

Permalink
change icon based on container status
Browse files Browse the repository at this point in the history
  • Loading branch information
13hannes11 committed May 30, 2024
1 parent 2015ae6 commit b889e80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ use std::collections::HashSet;
use std::thread::sleep;
use std::time::Duration;

use gtk::prelude::{
ApplicationExt, ApplicationWindowExt, GtkWindowExt, OrientableExt, SettingsExt, WidgetExt,
};
use gtk::{gio, glib};

use crate::config::{APP_ID, PROFILE};
use crate::factories::container_list::Container;
use crate::factories::container_list::ContainerStatus;
use crate::modals::about::AboutDialog;
use crate::modals::unsupported::UnsupportedDialog;
use crate::modals::unsupported::UnsupportedDialogOutput;
use crate::util::toolbox::ToolbxStatus;
use gtk::prelude::{
ApplicationExt, ApplicationWindowExt, GtkWindowExt, OrientableExt, SettingsExt, WidgetExt,
};
use gtk::{gio, glib};

pub(super) struct App {
unsupported_dialog: Controller<UnsupportedDialog>,
Expand Down Expand Up @@ -223,6 +224,10 @@ impl Component for App {
toolbox.id.clone(),
ContainerInit {
name: toolbox.name.clone(),
status: match toolbox.status {
ToolbxStatus::Running => ContainerStatus::Running,
_ => ContainerStatus::NotRunning,
},
},
);
updated_containers.insert(toolbox.id.clone());
Expand Down
17 changes: 15 additions & 2 deletions src/factories/container_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ use relm4::gtk;
use relm4::gtk::prelude::WidgetExt;
use relm4_icons::icon_names;

#[derive(Debug)]
pub enum ContainerStatus {
Running,
NotRunning,
}

#[derive(Debug)]
pub struct Container {
hash: String,
value: String,
status: ContainerStatus,
}

#[derive(Debug)]
Expand All @@ -22,6 +29,7 @@ pub enum ContainerMsg {

pub struct ContainerInit {
pub name: String,
pub status: ContainerStatus,
}

#[relm4::factory(pub)]
Expand All @@ -38,15 +46,19 @@ impl FactoryComponent for Container {
root = adw::ActionRow {
#[watch]
set_title: &self.value,
#[watch]
set_subtitle: &self.hash,

add_prefix = &gtk::Box{
gtk::AspectFrame{
set_ratio: 1.0,
#[name(play_button)]
gtk::Button {
// TODO: make component with state that either is waiting, play or pause
set_icon_name: icon_names::PLAY,
#[watch]
set_icon_name: match &self.status {
ContainerStatus::NotRunning => icon_names::PLAY,
ContainerStatus::Running => icon_names::PAUSE,
},
set_margin_top: 10,
set_margin_bottom: 10,
set_css_classes: &["circular"],
Expand Down Expand Up @@ -76,6 +88,7 @@ impl FactoryComponent for Container {
Self {
hash: index.clone(),
value: value.name.clone(),
status: value.status,
}
}

Expand Down

0 comments on commit b889e80

Please sign in to comment.