🏡 index : ~doyle/shalom.git

author Jordan Doyle <jordan@doyle.la> 2023-11-03 20:15:06.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-11-03 20:15:06.0 +00:00:00
commit
554be8ff4cc5aa76770c94716ff1e654fd7d4444 [patch]
tree
a6e9b8365f6ca8e34e35f76781976d60f8330e41
parent
2f16b810cb886af026d879381a144e6bd29d2ebf
download
554be8ff4cc5aa76770c94716ff1e654fd7d4444.tar.gz

Show current light colour



Diff

 shalom/src/oracle.rs              |  9 +++++----
 shalom/src/pages/room.rs          |  9 ++++++++-
 shalom/src/widgets/toggle_card.rs | 23 +++++++++++++++--------
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/shalom/src/oracle.rs b/shalom/src/oracle.rs
index 3e0eda7..f0fbf99 100644
--- a/shalom/src/oracle.rs
+++ b/shalom/src/oracle.rs
@@ -16,11 +16,12 @@ use url::Url;
use crate::{
    hass_client::{
        responses::{
            Area, AreaRegistryList, ColorMode, DeviceRegistryList, Entity,
            EntityRegistryList, StateAttributes, StateLightAttributes, StateMediaPlayerAttributes,
            Area, AreaRegistryList, ColorMode, DeviceRegistryList, Entity, EntityRegistryList,
            StateAttributes, StateLightAttributes, StateMediaPlayerAttributes,
            StateWeatherAttributes, StatesList, WeatherCondition,
        }, CallServiceRequestData, CallServiceRequestLight,
        CallServiceRequestLightTurnOn, Event, HassRequestKind,
        },
        CallServiceRequestData, CallServiceRequestLight, CallServiceRequestLightTurnOn, Event,
        HassRequestKind,
    },
    widgets::colour_picker::clamp_to_u8,
};
diff --git a/shalom/src/pages/room.rs b/shalom/src/pages/room.rs
index 1715e53..98bbee4 100644
--- a/shalom/src/pages/room.rs
+++ b/shalom/src/pages/room.rs
@@ -16,6 +16,7 @@ use crate::{
    subscriptions::download_image,
    theme::Icon,
    widgets,
    widgets::colour_picker::colour_from_hsb,
};

#[derive(Debug)]
@@ -108,7 +109,13 @@ impl Room {
                light.on.unwrap_or_default(),
                light.on.is_none(),
            )
            .icon(Icon::Bulb);
            .icon(Icon::Bulb)
            .active_icon_colour(
                light
                    .hs_color
                    .zip(light.brightness)
                    .map(|((h, s), b)| colour_from_hsb(h, s, b / 255.)),
            );

            if let Some(state) = light.on {
                toggle_card = toggle_card
diff --git a/shalom/src/widgets/toggle_card.rs b/shalom/src/widgets/toggle_card.rs
index 60241db..a303e3f 100644
--- a/shalom/src/widgets/toggle_card.rs
+++ b/shalom/src/widgets/toggle_card.rs
@@ -36,6 +36,7 @@ pub struct ToggleCard<M> {
    width: Length,
    active: bool,
    disabled: bool,
    active_icon_colour: Option<Color>,
    on_press: Option<M>,
    on_long_press: Option<M>,
}
@@ -49,6 +50,7 @@ impl<M> Default for ToggleCard<M> {
            width: Length::Fill,
            active: false,
            disabled: false,
            active_icon_colour: None,
            on_press: None,
            on_long_press: None,
        }
@@ -56,6 +58,11 @@ impl<M> Default for ToggleCard<M> {
}

impl<M> ToggleCard<M> {
    pub fn active_icon_colour(mut self, color: Option<Color>) -> Self {
        self.active_icon_colour = color;
        self
    }

    pub fn on_press(mut self, msg: M) -> Self {
        self.on_press = Some(msg);
        self
@@ -116,8 +123,8 @@ impl<M: Clone> iced::widget::Component<M, Renderer> for ToggleCard<M> {
    fn view(&self, state: &Self::State) -> Element<'_, Self::Event, Renderer> {
        let style = match (self.disabled, self.active, state.mouse_down_start) {
            (true, _, _) => Style::Disabled,
            (_, true, None) => Style::Active,
            (_, true, Some(_)) => Style::ActiveHover,
            (_, true, None) => Style::Active(self.active_icon_colour),
            (_, true, Some(_)) => Style::ActiveHover(self.active_icon_colour),
            (_, false, None) => Style::Inactive,
            (_, false, Some(_)) => Style::InactiveHover,
        };
@@ -185,8 +192,8 @@ pub enum ToggleCardEvent {

#[derive(Copy, Clone)]
pub enum Style {
    Active,
    ActiveHover,
    Active(Option<Color>),
    ActiveHover(Option<Color>),
    Inactive,
    InactiveHover,
    Disabled,
@@ -218,14 +225,14 @@ impl container::StyleSheet for Style {
                border_width: 0.0,
                border_color: Color::default(),
            },
            Style::Active => container::Appearance {
            Style::Active(_) => container::Appearance {
                text_color: Some(Color::WHITE),
                background: Some(Background::Color(SKY_400)),
                border_radius: 5.0.into(),
                border_width: 0.0,
                border_color: Color::default(),
            },
            Style::ActiveHover => container::Appearance {
            Style::ActiveHover(_) => container::Appearance {
                text_color: Some(Color::WHITE),
                background: Some(Background::Color(SKY_500)),
                border_radius: 5.0.into(),
@@ -241,8 +248,8 @@ impl svg::StyleSheet for Style {

    fn appearance(&self, _style: &Self::Style) -> svg::Appearance {
        match self {
            Style::Active | Style::ActiveHover => svg::Appearance {
                color: Some(AMBER_200),
            Style::Active(c) | Style::ActiveHover(c) => svg::Appearance {
                color: Some(c.unwrap_or(AMBER_200)),
            },
            Style::Inactive | Style::InactiveHover | Style::Disabled => svg::Appearance {
                color: Some(Color::BLACK),