1use std::path::PathBuf;
2
3use ambassador::Delegate;
4use serde::{Deserialize, Serialize};
5
6use crate::NodeId;
7use crate::{color::Color, PixelCoordinate, PixelDimension};
8
9use super::ambassador_impl_GenericNodeInfo;
10use super::{GenericNode, GenericNodeInfo};
11
12#[derive(Debug, Delegate, Serialize, Deserialize)]
13#[delegate(GenericNodeInfo, target = "generic")]
14pub struct GroupNode {
15 #[serde(flatten)]
16 generic: GenericNode,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 label: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 #[serde(flatten)]
21 background: Option<Background>,
22}
23
24impl GroupNode {
25 #[allow(clippy::too_many_arguments)]
26 pub fn new(
27 id: NodeId,
28 x: PixelCoordinate,
29 y: PixelCoordinate,
30 width: PixelDimension,
31 height: PixelDimension,
32 color: Option<Color>,
33 label: Option<String>,
34 background: Option<Background>,
35 ) -> Self {
36 Self {
37 generic: GenericNode::new(id, x, y, width, height, color),
38 label,
39 background,
40 }
41 }
42
43 pub fn label(&self) -> Option<&String> {
44 self.label.as_ref()
45 }
46
47 pub fn background(&self) -> Option<&Background> {
48 self.background.as_ref()
49 }
50}
51
52#[derive(Debug, Serialize, Deserialize)]
53#[serde(rename_all = "camelCase")]
54pub struct Background {
55 image: PathBuf,
56 #[serde(skip_serializing_if = "Option::is_none")]
57 background_style: Option<BackgroundStyle>,
58}
59
60impl Background {
61 pub fn new(image: PathBuf, background_style: Option<BackgroundStyle>) -> Background {
62 Background {
63 image,
64 background_style,
65 }
66 }
67}
68
69#[derive(Debug, Serialize, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub enum BackgroundStyle {
72 Cover,
73 Ratio,
74 Repeat,
75}