livesplit_core/layout/layout_state.rs
1use super::{ComponentState, LayoutDirection};
2use crate::{
3 platform::prelude::*,
4 settings::{Color, Font, Gradient},
5};
6use serde::{Deserialize, Serialize};
7
8/// The state object describes the information to visualize for the layout.
9#[derive(Default, Serialize, Deserialize)]
10pub struct LayoutState {
11 /// The state objects for all of the components in the layout.
12 pub components: Vec<ComponentState>,
13 /// The direction which the components are laid out in.
14 pub direction: LayoutDirection,
15 /// The font to use for the timer text. `None` means a default font should
16 /// be used.
17 pub timer_font: Option<Font>,
18 /// The font to use for the times and other values. `None` means a default
19 /// font should be used.
20 pub times_font: Option<Font>,
21 /// The font to use for regular text. `None` means a default font should be
22 /// used.
23 pub text_font: Option<Font>,
24 /// The background to show behind the layout.
25 pub background: Gradient,
26 /// The color of thin separators.
27 pub thin_separators_color: Color,
28 /// The color of normal separators.
29 pub separators_color: Color,
30 /// The text color to use for text that doesn't specify its own color.
31 pub text_color: Color,
32}
33
34#[cfg(feature = "std")]
35impl LayoutState {
36 /// Encodes the state object's information as JSON.
37 pub fn write_json<W>(&self, writer: W) -> serde_json::Result<()>
38 where
39 W: std::io::Write,
40 {
41 serde_json::to_writer(writer, self)
42 }
43}