add icons

This commit is contained in:
LordMZTE 2021-10-25 00:26:46 +02:00
parent ec1e1e979f
commit 616ba9f881
8 changed files with 113 additions and 2 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "resources/hass-hue-icons"]
path = resources/hass-hue-icons
url = https://github.com/arallsopp/hass-hue-icons

View file

@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
angular-units = "0.2.4"
dirs = "4.0.0"
gio = "0.14.8"
gtk = "0.14.3"
log = "0.4.14"
miette = { version = "3.2.0", features = ["fancy"] }
@ -22,4 +23,6 @@ simplelog = "0.10.2"
tokio = { version = "1.12.0", features = ["rt-multi-thread", "macros", "net", "sync", "fs"] }
url = { version = "2.2.2", features = ["serde"] }
[features]
[build-dependencies]
gio = "0.14.8"

7
build.rs Normal file
View file

@ -0,0 +1,7 @@
fn main() {
gio::compile_resources(
"resources",
"resources/resources.gresource.xml",
"compiled.gresource",
);
}

@ -0,0 +1 @@
Subproject commit 80ded5c407137f5f8c4128b959e1384d19cefbff

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/de/mzte/gue">
<file>hass-hue-icons/docs/custom_svgs/centris.svg</file>
<file>hass-hue-icons/docs/custom_svgs/lightstrip-tv.svg</file>
<file>hass-hue-icons/docs/svgs/bloom.svg</file>
<file>hass-hue-icons/docs/svgs/bollard.svg</file>
<file>hass-hue-icons/docs/svgs/bulb-candle.svg</file>
<file>hass-hue-icons/docs/svgs/bulb-classic.svg</file>
<file>hass-hue-icons/docs/svgs/bulb-filament.svg</file>
<file>hass-hue-icons/docs/svgs/bulb-flood.svg</file>
<file>hass-hue-icons/docs/svgs/bulb-spot.svg</file>
<file>hass-hue-icons/docs/svgs/bulb-sultan.svg</file>
<file>hass-hue-icons/docs/svgs/ceiling-round.svg</file>
<file>hass-hue-icons/docs/svgs/ceiling-square.svg</file>
<file>hass-hue-icons/docs/svgs/desk-lamp.svg</file>
<file>hass-hue-icons/docs/svgs/double-spot.svg</file>
<file>hass-hue-icons/docs/svgs/floor-lantern.svg</file>
<file>hass-hue-icons/docs/svgs/floor-shade.svg</file>
<file>hass-hue-icons/docs/svgs/floor-spot.svg</file>
<file>hass-hue-icons/docs/svgs/go.svg</file>
<file>hass-hue-icons/docs/svgs/iris.svg</file>
<file>hass-hue-icons/docs/svgs/lightstrip.svg</file>
<file>hass-hue-icons/docs/svgs/pendant-long.svg</file>
<file>hass-hue-icons/docs/svgs/pendant-round.svg</file>
<file>hass-hue-icons/docs/svgs/play-bar.svg</file>
<file>hass-hue-icons/docs/svgs/recessed-ceiling.svg</file>
<file>hass-hue-icons/docs/svgs/recessed-floor.svg</file>
<file>hass-hue-icons/docs/svgs/single-spot.svg</file>
<file>hass-hue-icons/docs/svgs/table-shade.svg</file>
<file>hass-hue-icons/docs/svgs/table-wash.svg</file>
<file>hass-hue-icons/docs/svgs/wall-lantern.svg</file>
<file>hass-hue-icons/docs/svgs/wall-shade.svg</file>
<file>hass-hue-icons/docs/svgs/wall-spot.svg</file>
</gresource>
</gresources>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 98 KiB

View file

@ -4,7 +4,10 @@ use log::debug;
use prisma::{Hsv, Rgb};
use relm::Widget;
use relm_derive::{widget, Msg};
use rhue::{api::Light, bridge::StateUpdate};
use rhue::{
api::{Light, LightArchetype},
bridge::StateUpdate,
};
use std::{cell::Cell, rc::Rc};
use tokio::sync::mpsc::UnboundedSender;
@ -17,6 +20,7 @@ pub struct LightEntryModel {
on: bool,
brightness: f64,
color: Rc<Cell<Rgb<f64>>>,
icon: String,
}
#[derive(Clone, Msg)]
@ -48,6 +52,7 @@ impl Widget for LightEntry {
)
.into(),
)),
icon: resource_of_archetype(params.1.config.archetype),
}
}
@ -134,6 +139,10 @@ impl Widget for LightEntry {
gtk::Box {
orientation: Orientation::Horizontal,
gtk::Image {
from_resource: Some(&self.model.icon),
},
#[name = "color_indicator"]
gtk::DrawingArea {
width_request: 25,
@ -170,3 +179,51 @@ impl Widget for LightEntry {
}
}
}
fn resource_of_archetype(atype: LightArchetype) -> String {
type At = LightArchetype;
// types of directories used in the gresource paths
let s = "svgs";
let cs = "custom_svgs";
let (dir, file) = match atype {
At::Bollard => (s, "bollard"),
At::Candlebulb => (s, "bulb-candle"),
At::Ceilinground => (s, "ceiling-round"),
At::Ceilingsquare => (s, "ceiling-square"),
// wtf?
At::Christmastree => (s, "bulb-classic"),
At::Classicbulb => (s, "bulb-classic"),
At::Doublespot => (s, "double-spot"),
At::Flexiblelamp => (s, "desk-lamp"),
At::Floodbulb => (s, "bulb-flood"),
At::Floorlantern => (s, "floor-lantern"),
At::Floorshade => (s, "floor-shade"),
At::Groundspot => (s, "floor-spot"),
At::Huebloom => (s, "bloom"),
At::Huecentris => (cs, "centris"),
At::Huego => (s, "go"),
At::Hueiris => (s, "iris"),
At::Huelightstrip => (s, "lightstrip"),
At::Huelightstriptv => (cs, "lightstrip-tv"),
At::Hueplay => (s, "play-bar"),
At::Pendantlong => (s, "pendant-long"),
At::Pendantround => (s, "pendant-round"),
At::Recessedceiling => (s, "recessed-ceiling"),
At::Recessedfloor => (s, "recessed-floor"),
At::Singlespot => (s, "single-spot"),
At::Spotbulb => (s, "bulb-spot"),
At::Sultanbulb => (s, "bulb-sultan"),
At::Tableshade => (s, "table-shade"),
At::Tablewash => (s, "table-wash"),
At::Vintagebulb => (s, "bulb-filament"),
At::Walllantern => (s, "wall-lantern"),
At::Wallshade => (s, "wall-shade"),
At::Wallspot => (s, "wall-spot"),
// default to classic bulb
At::Other => (s, "bulb-classic"),
};
format!("/de/mzte/gue/hass-hue-icons/docs/{}/{}.svg", dir, file)
}

View file

@ -27,6 +27,10 @@ async fn main() -> miette::Result<()> {
.into_diagnostic()
.wrap_err("Failed to init logger")?;
gio::resources_register_include!("compiled.gresource")
.into_diagnostic()
.wrap_err("Failed to register gresource")?;
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
let runtime = Runtime::init(rx).await.wrap_err("Failed to init runtime")?;