Skip to content

Commit a032521

Browse files
Make checkboxes not use interior mutability
1 parent 34a8b9b commit a032521

2 files changed

Lines changed: 4 additions & 33 deletions

File tree

editor/src/messages/layout/utility_types/widgets/input_widgets.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use graphene_std::Color;
55
use graphene_std::raster::curve::Curve;
66
use graphene_std::transform::ReferencePoint;
77
use graphite_proc_macros::WidgetBuilder;
8-
use once_cell::sync::OnceCell;
9-
use std::sync::Arc;
108

119
#[derive(Clone, Derivative, serde::Serialize, serde::Deserialize, WidgetBuilder, specta::Type)]
1210
#[derivative(Debug, PartialEq)]
@@ -20,7 +18,6 @@ pub struct CheckboxInput {
2018

2119
pub tooltip: String,
2220

23-
#[serde(rename = "forLabel", skip_serializing_if = "checkbox_id_is_empty")]
2421
pub for_label: CheckboxId,
2522

2623
#[serde(skip)]
@@ -51,12 +48,12 @@ impl Default for CheckboxInput {
5148
}
5249
}
5350

54-
#[derive(Clone, Default, Debug, Eq, PartialEq)]
55-
pub struct CheckboxId(Arc<OnceCell<u64>>);
51+
#[derive(Clone, Default, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
52+
pub struct CheckboxId(u64);
5653

5754
impl CheckboxId {
58-
pub fn fill(&mut self) {
59-
let _ = self.0.set(graphene_std::uuid::generate_uuid());
55+
pub fn new(&mut self) -> Self {
56+
Self(graphene_std::uuid::generate_uuid())
6057
}
6158
}
6259
impl specta::Type for CheckboxId {
@@ -65,31 +62,6 @@ impl specta::Type for CheckboxId {
6562
specta::datatype::DataType::Primitive(specta::datatype::PrimitiveType::u64)
6663
}
6764
}
68-
impl serde::Serialize for CheckboxId {
69-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
70-
where
71-
S: serde::Serializer,
72-
{
73-
self.0.get().copied().serialize(serializer)
74-
}
75-
}
76-
impl<'a> serde::Deserialize<'a> for CheckboxId {
77-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
78-
where
79-
D: serde::Deserializer<'a>,
80-
{
81-
let optional_id: Option<u64> = Option::deserialize(deserializer)?;
82-
// TODO: This is potentially weird because after deserialization the two labels will be decoupled if the value not existent
83-
let id = optional_id.unwrap_or(0);
84-
let checkbox_id = CheckboxId(OnceCell::new().into());
85-
checkbox_id.0.set(id).map_err(serde::de::Error::custom)?;
86-
Ok(checkbox_id)
87-
}
88-
}
89-
90-
fn checkbox_id_is_empty(id: &CheckboxId) -> bool {
91-
id.0.get().is_none()
92-
}
9365

9466
#[derive(Clone, serde::Serialize, serde::Deserialize, Derivative, WidgetBuilder, specta::Type)]
9567
#[derivative(Debug, PartialEq, Default)]

editor/src/messages/layout/utility_types/widgets/label_widgets.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub struct TextLabel {
6868

6969
impl TextLabel {
7070
pub fn for_checkbox(mut self, id: &mut CheckboxId) -> Self {
71-
id.fill();
7271
self.checkbox_id = id.clone();
7372
self
7473
}

0 commit comments

Comments
 (0)