Add alternate bulb list view
This commit is contained in:
@ -2,7 +2,7 @@ use crate::components::color_picker::{ColorPicker, ColorPickerMsg};
|
|||||||
use crate::css::C;
|
use crate::css::C;
|
||||||
use common::{BulbGroup, BulbGroupShape, BulbMap, BulbPrefs, ClientMessage, Param, ServerMessage};
|
use common::{BulbGroup, BulbGroupShape, BulbMap, BulbPrefs, ClientMessage, Param, ServerMessage};
|
||||||
use lighter_lib::{BulbId, BulbMode};
|
use lighter_lib::{BulbId, BulbMode};
|
||||||
use seed::{attrs, button, div, empty, h2, input, table, td, tr, C};
|
use seed::{attrs, button, div, empty, h1, h2, input, label, span, table, td, tr, C};
|
||||||
use seed::{prelude::*, IF};
|
use seed::{prelude::*, IF};
|
||||||
use seed_router::Page;
|
use seed_router::Page;
|
||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::{BTreeMap, HashSet};
|
||||||
@ -14,11 +14,16 @@ use std::iter::repeat;
|
|||||||
pub struct Model {
|
pub struct Model {
|
||||||
bulb_states: BTreeMap<BulbId, BulbState>,
|
bulb_states: BTreeMap<BulbId, BulbState>,
|
||||||
|
|
||||||
|
select_mode: SelectMode,
|
||||||
|
|
||||||
bulb_map: BulbMap,
|
bulb_map: BulbMap,
|
||||||
|
|
||||||
/// the currently selected bulb map groups
|
/// the currently selected bulbs on the map
|
||||||
selected_groups: HashSet<usize>,
|
selected_groups: HashSet<usize>,
|
||||||
|
|
||||||
|
/// the currently selected bulbs on the list
|
||||||
|
selected_bulbs: HashSet<BulbId>,
|
||||||
|
|
||||||
/// whether the currently selected map groups have been interacted with
|
/// whether the currently selected map groups have been interacted with
|
||||||
groups_interacted: bool,
|
groups_interacted: bool,
|
||||||
|
|
||||||
@ -37,6 +42,9 @@ pub enum Msg {
|
|||||||
|
|
||||||
SelectGroup(usize),
|
SelectGroup(usize),
|
||||||
DeselectGroups,
|
DeselectGroups,
|
||||||
|
|
||||||
|
SelectBulb(BulbId),
|
||||||
|
|
||||||
ColorPicker(ColorPickerMsg),
|
ColorPicker(ColorPickerMsg),
|
||||||
SetBulbPower(bool),
|
SetBulbPower(bool),
|
||||||
|
|
||||||
@ -46,6 +54,15 @@ pub enum Msg {
|
|||||||
name: String,
|
name: String,
|
||||||
value: Param,
|
value: Param,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
SetSelectMode(SelectMode),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||||
|
pub enum SelectMode {
|
||||||
|
#[default]
|
||||||
|
Map,
|
||||||
|
List,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Page for Model {
|
impl Page for Model {
|
||||||
@ -70,8 +87,6 @@ impl Page for Model {
|
|||||||
mode: new_mode,
|
mode: new_mode,
|
||||||
prefs,
|
prefs,
|
||||||
};
|
};
|
||||||
|
|
||||||
//color_picker.set_color(mode.color);
|
|
||||||
}
|
}
|
||||||
ServerMessage::BulbMap(bulb_map) => {
|
ServerMessage::BulbMap(bulb_map) => {
|
||||||
self.bulb_map = bulb_map;
|
self.bulb_map = bulb_map;
|
||||||
@ -106,6 +121,11 @@ impl Page for Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Msg::SelectBulb(bulb) => {
|
||||||
|
if !self.selected_bulbs.remove(&bulb) {
|
||||||
|
self.selected_bulbs.insert(bulb);
|
||||||
|
}
|
||||||
|
}
|
||||||
Msg::ColorPicker(ColorPickerMsg::SetColor(color)) => {
|
Msg::ColorPicker(ColorPickerMsg::SetColor(color)) => {
|
||||||
self.groups_interacted = true;
|
self.groups_interacted = true;
|
||||||
self.for_selected_bulbs(|id, _| {
|
self.for_selected_bulbs(|id, _| {
|
||||||
@ -150,36 +170,13 @@ impl Page for Model {
|
|||||||
orders.notify(message);
|
orders.notify(message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Msg::SetSelectMode(mode) => {
|
||||||
|
self.select_mode = mode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Node<Self::Msg> {
|
fn view(&self) -> Node<Self::Msg> {
|
||||||
//let view_bulb = |(id, (mode, color_picker)): (&BulbId, &(BulbMode, ColorPicker))| {
|
|
||||||
// div![
|
|
||||||
// C![C.bulb_box],
|
|
||||||
// h1![id],
|
|
||||||
// div![
|
|
||||||
// C![C.bulb_controls],
|
|
||||||
// {
|
|
||||||
// let id = id.clone();
|
|
||||||
// color_picker.view().map_msg(|msg| Msg::ColorPicker(id, msg))
|
|
||||||
// },
|
|
||||||
// button![
|
|
||||||
// if mode.power {
|
|
||||||
// C![C.bulb_power_button, C.bulb_power_button_on]
|
|
||||||
// } else {
|
|
||||||
// C![C.bulb_power_button]
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// let id = id.clone();
|
|
||||||
// let power = !mode.power;
|
|
||||||
// ev(Ev::Click, move |_| Msg::SetBulbPower(id, power))
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// ],
|
|
||||||
// ]
|
|
||||||
//};
|
|
||||||
|
|
||||||
let bulb_map_width = self
|
let bulb_map_width = self
|
||||||
.bulb_map
|
.bulb_map
|
||||||
.groups
|
.groups
|
||||||
@ -196,7 +193,7 @@ impl Page for Model {
|
|||||||
.max()
|
.max()
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
let view_bulb_group = |(i, group): (usize, &BulbGroup)| {
|
let bulb_group_map = |(i, group): (usize, &BulbGroup)| {
|
||||||
let (w, h) = (group.shape.width(), group.shape.height());
|
let (w, h) = (group.shape.width(), group.shape.height());
|
||||||
let mut style = String::new();
|
let mut style = String::new();
|
||||||
write!(
|
write!(
|
||||||
@ -227,13 +224,51 @@ impl Page for Model {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
let selected_bulb = self
|
let bulb_group_list = |(_i, group): (usize, &BulbGroup)| {
|
||||||
.selected_groups
|
div![
|
||||||
|
C![C.bulb_list_group],
|
||||||
|
h1![&group.name],
|
||||||
|
group.bulbs.iter().map(|bulb| {
|
||||||
|
let select_ev = || {
|
||||||
|
let bulb = bulb.clone();
|
||||||
|
ev(Ev::Click, |_| Msg::SelectBulb(bulb))
|
||||||
|
};
|
||||||
|
|
||||||
|
button![
|
||||||
|
C![C.bulb_list_bulb],
|
||||||
|
select_ev(),
|
||||||
|
div![
|
||||||
|
C![C.bulb_list_checkbox],
|
||||||
|
label![
|
||||||
|
C![C.container],
|
||||||
|
input![
|
||||||
|
attrs! { At::Type => "checkbox" },
|
||||||
|
IF!(self.selected_bulbs.contains(bulb) => attrs! { At::Checked => true }),
|
||||||
|
select_ev(),
|
||||||
|
],
|
||||||
|
div![C![C.checkmark]],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
span![bulb],
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
// pick one (arbitrary) selected bulb to pull values for the controls from
|
||||||
|
let selected_bulb = if let SelectMode::Map = self.select_mode {
|
||||||
|
self.selected_groups
|
||||||
.iter()
|
.iter()
|
||||||
.next()
|
.next()
|
||||||
.and_then(|&index| self.bulb_map.groups.get(index))
|
.and_then(|&index| self.bulb_map.groups.get(index))
|
||||||
.and_then(|group| group.bulbs.first())
|
.and_then(|group| group.bulbs.first())
|
||||||
.and_then(|id| self.bulb_states.get(id));
|
.and_then(|id| self.bulb_states.get(id))
|
||||||
|
} else {
|
||||||
|
self.selected_bulbs
|
||||||
|
.iter()
|
||||||
|
.next()
|
||||||
|
.and_then(|id| self.bulb_states.get(id))
|
||||||
|
};
|
||||||
|
|
||||||
let script_param = |script: &str, name: &str, value: &Param| {
|
let script_param = |script: &str, name: &str, value: &Param| {
|
||||||
let name = name.to_string();
|
let name = name.to_string();
|
||||||
@ -278,13 +313,35 @@ impl Page for Model {
|
|||||||
div![
|
div![
|
||||||
C![C.bulb_box],
|
C![C.bulb_box],
|
||||||
div![
|
div![
|
||||||
|
C![C.selector_selector],
|
||||||
|
button![
|
||||||
|
"Map",
|
||||||
|
ev(Ev::Click, move |_| Msg::SetSelectMode(SelectMode::Map))
|
||||||
|
],
|
||||||
|
div![
|
||||||
|
C![C.selector_selector_arrow],
|
||||||
|
IF!(self.select_mode == SelectMode::Map =>
|
||||||
|
attrs! { At::Style => "transform: rotateY(180deg);"}),
|
||||||
|
],
|
||||||
|
button![
|
||||||
|
"List",
|
||||||
|
ev(Ev::Click, move |_| Msg::SetSelectMode(SelectMode::List))
|
||||||
|
],
|
||||||
|
],
|
||||||
|
match self.select_mode {
|
||||||
|
SelectMode::Map => div![
|
||||||
C![C.bulb_map],
|
C![C.bulb_map],
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Style => format!("min-width: {}rem; height: {}rem;", bulb_map_width, bulb_map_height),
|
At::Style => format!("min-width: {}rem; height: {}rem;", bulb_map_width, bulb_map_height),
|
||||||
},
|
},
|
||||||
ev(Ev::Click, |_| Msg::DeselectGroups),
|
ev(Ev::Click, |_| Msg::DeselectGroups),
|
||||||
self.bulb_map.groups.iter().enumerate().map(view_bulb_group),
|
self.bulb_map.groups.iter().enumerate().map(bulb_group_map),
|
||||||
],
|
],
|
||||||
|
SelectMode::List => div![
|
||||||
|
C![C.bulb_list],
|
||||||
|
self.bulb_map.groups.iter().enumerate().map(bulb_group_list),
|
||||||
|
],
|
||||||
|
},
|
||||||
div![
|
div![
|
||||||
C![C.bulb_controls],
|
C![C.bulb_controls],
|
||||||
IF!(selected_bulb.is_none() => C![C.cross_out]),
|
IF!(selected_bulb.is_none() => C![C.cross_out]),
|
||||||
@ -326,6 +383,7 @@ impl Page for Model {
|
|||||||
|
|
||||||
impl Model {
|
impl Model {
|
||||||
fn for_selected_bulbs(&mut self, mut f: impl FnMut(&BulbId, &mut BulbState)) {
|
fn for_selected_bulbs(&mut self, mut f: impl FnMut(&BulbId, &mut BulbState)) {
|
||||||
|
if let SelectMode::Map = self.select_mode {
|
||||||
for &index in &self.selected_groups {
|
for &index in &self.selected_groups {
|
||||||
let Some(group) = self.bulb_map.groups.get(index) else {
|
let Some(group) = self.bulb_map.groups.get(index) else {
|
||||||
continue;
|
continue;
|
||||||
@ -337,5 +395,12 @@ impl Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for id in &self.selected_bulbs {
|
||||||
|
if let Some(bulb) = self.bulb_states.get_mut(id) {
|
||||||
|
f(id, bulb);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
frontend/static/images/circle-arrow.svg
Normal file
5
frontend/static/images/circle-arrow.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg" xmlns:bx="https://boxy-svg.com">
|
||||||
|
<ellipse style="vector-effect: non-scaling-stroke; stroke-width: 0px; stroke: rgb(245, 222, 179); fill: rgb(245, 222, 179);" cx="250" cy="250" rx="250" ry="250"/>
|
||||||
|
<path d="M 59.4 209.201 H 308.253 L 274.16 131.459 L 447.051 254.953 L 274.16 378.446 L 308.253 300.704 H 59.4 V 209.201 Z" style="transform-origin: 447.051px 254.952px; stroke-width: 16px; stroke: rgb(193, 168, 123);" bx:shape="arrow 59.4 131.459 387.651 246.987 91.503 172.891 34.093 1@d4e47a6f"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 607 B |
@ -102,6 +102,42 @@ body {
|
|||||||
margin-bottom: 1.5rem;
|
margin-bottom: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* lol i'm so funny */
|
||||||
|
.selector_selector {
|
||||||
|
margin-bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
//background: #534f44;
|
||||||
|
}
|
||||||
|
.selector_selector > button {
|
||||||
|
width: 10rem;
|
||||||
|
border: solid 0.1rem wheat;
|
||||||
|
background-color: #3a3743;
|
||||||
|
color: white;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
border-left: solid white 0.1rem;
|
||||||
|
border-right: solid white 0.1rem;
|
||||||
|
}
|
||||||
|
.selector_selector > button:hover {
|
||||||
|
background-color: #4c4858;
|
||||||
|
}
|
||||||
|
.selector_selector > button:active {
|
||||||
|
background-color: #312e38;
|
||||||
|
}
|
||||||
|
.selector_selector > button:first-child {
|
||||||
|
border-top-left-radius: 0.5rem;
|
||||||
|
}
|
||||||
|
.selector_selector > button:last-child {
|
||||||
|
border-top-right-radius: 0.5rem;
|
||||||
|
}
|
||||||
|
.selector_selector_arrow {
|
||||||
|
position: absolute;
|
||||||
|
width: 2.15rem;
|
||||||
|
height: 2.15rem;
|
||||||
|
background: url("/images/circle-arrow.svg");
|
||||||
|
transition: transform 0.5s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
.bulb_controls {
|
.bulb_controls {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@ -150,6 +186,47 @@ body {
|
|||||||
}
|
}
|
||||||
@keyframes to_width_90 { to { width: 90%; } }
|
@keyframes to_width_90 { to { width: 90%; } }
|
||||||
|
|
||||||
|
.bulb_list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bulb_list_group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bulb_list_group > h1 {
|
||||||
|
margin-top: 0.6em;
|
||||||
|
margin-bottom: 0;
|
||||||
|
font-size: 1.3em;
|
||||||
|
border-bottom: solid 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bulb_list_bulb {
|
||||||
|
font-family: Ubuntu Mono;
|
||||||
|
display: flex;
|
||||||
|
font-size: 0.8em;
|
||||||
|
padding-top: 0.5em;
|
||||||
|
padding-bottom: 0.5em;
|
||||||
|
margin-top: 0.3em;
|
||||||
|
background-color: #3a3743;
|
||||||
|
border: solid 0.2em #45374f;
|
||||||
|
border-radius: 0.5em;
|
||||||
|
color: wheat;
|
||||||
|
}
|
||||||
|
.bulb_list_bulb:hover {
|
||||||
|
background-color: #4c4858;
|
||||||
|
}
|
||||||
|
.bulb_list_bulb:active {
|
||||||
|
background-color: #312e38;
|
||||||
|
}
|
||||||
|
.bulb_list_bulb > span {
|
||||||
|
margin: auto;
|
||||||
|
flex-grow: 1;
|
||||||
|
padding-right: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
.bulb_map {
|
.bulb_map {
|
||||||
background: url(images/blueprint_bg.png);
|
background: url(images/blueprint_bg.png);
|
||||||
background-size: auto;
|
background-size: auto;
|
||||||
@ -371,3 +448,65 @@ body {
|
|||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bulb_list_checkbox {}
|
||||||
|
.bulb_list_checkbox input[type="checkbox"] {
|
||||||
|
visibility: hidden;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bulb_list_checkbox *,
|
||||||
|
.bulb_list_checkbox ::after,
|
||||||
|
.bulb_list_checkbox ::before {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bulb_list_checkbox .container {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 25px;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create a custom checkbox */
|
||||||
|
.bulb_list_checkbox .checkmark {
|
||||||
|
position: relative;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 1.3em;
|
||||||
|
width: 1.3em;
|
||||||
|
background: black;
|
||||||
|
border-radius: 50px;
|
||||||
|
transition: all 0.7s;
|
||||||
|
--spread: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* When the checkbox is checked, add a blue background */
|
||||||
|
.bulb_list_checkbox .container input:checked ~ .checkmark {
|
||||||
|
background: black;
|
||||||
|
/* spawn a bunch of colored balls and blur them together */
|
||||||
|
box-shadow: -5px -5px var(--spread) 0px #5B51D8, 0 -5px var(--spread) 0px #833AB4, 5px -5px var(--spread) 0px #E1306C, 5px 0 var(--spread) 0px #FD1D1D, 5px 5px var(--spread) 0px #F77737, 0 5px var(--spread) 0px #FCAF45, -5px 5px var(--spread) 0px #FFDC80;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create the checkmark/indicator (hidden when not checked) */
|
||||||
|
.bulb_list_checkbox .checkmark::after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Show the checkmark when checked */
|
||||||
|
.bulb_list_checkbox .container input:checked ~ .checkmark::after {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Style the checkmark/indicator */
|
||||||
|
.bulb_list_checkbox .container .checkmark::after {
|
||||||
|
left: 0.5em;
|
||||||
|
top: 0.34em;
|
||||||
|
width: 0.25em;
|
||||||
|
height: 0.5em;
|
||||||
|
border: solid wheat;
|
||||||
|
border-width: 0 0.15em 0.15em 0;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user