mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-04 02:08:37 +00:00
Rect now uses it's textual representation for (de)serializing.
This commit is contained in:
parent
67266f28f9
commit
dec01d514f
22
profile.json
22
profile.json
@ -4,16 +4,7 @@
|
||||
"panels_shader": { "FadeWhite": { "strength": 10 } },
|
||||
"panels": [
|
||||
{
|
||||
"geometry": {
|
||||
"pos": {
|
||||
"x": 0,
|
||||
"y": 312
|
||||
},
|
||||
"size": {
|
||||
"x": 1360,
|
||||
"y": 768
|
||||
}
|
||||
},
|
||||
"geometry": "1360x768+0+312",
|
||||
"duration": 1800,
|
||||
"fade_point": 1440,
|
||||
"parallax": {
|
||||
@ -22,16 +13,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"geometry": {
|
||||
"pos": {
|
||||
"x": 1360,
|
||||
"y": 0
|
||||
},
|
||||
"size": {
|
||||
"x": 1920,
|
||||
"y": 1080
|
||||
}
|
||||
},
|
||||
"geometry": "1920x1080+1360+0",
|
||||
"duration": 1800,
|
||||
"fade_point": 1440,
|
||||
"parallax": {
|
||||
|
||||
@ -4,12 +4,11 @@
|
||||
use {
|
||||
anyhow::Context,
|
||||
cgmath::{num_traits::Num, Point2, Vector2},
|
||||
std::{error::Error, fmt},
|
||||
std::{borrow::Cow, error::Error, fmt},
|
||||
};
|
||||
|
||||
/// A rectangle
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
#[derive(serde::Serialize, serde::Deserialize)] // TODO: serialize to string
|
||||
pub struct Rect<P, S = P> {
|
||||
/// Position
|
||||
pub pos: Point2<P>,
|
||||
@ -131,3 +130,22 @@ impl fmt::Display for Rect<i32, u32> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> serde::Deserialize<'de> for Rect<i32, u32> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let s = Cow::deserialize(deserializer)?;
|
||||
Self::parse_from_geometry(&s).map_err(serde::de::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for Rect<i32, u32> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user