mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 10:08:11 +08:00
Convert u64 IDs to newtypes (#1532)
This commit is contained in:
@@ -7,7 +7,17 @@ use serde::{Deserialize, Serialize};
|
||||
#[impl_message(Message, Layout)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum LayoutMessage {
|
||||
ResendActiveWidget { layout_target: LayoutTarget, dirty_id: u64 },
|
||||
SendLayout { layout: Layout, layout_target: LayoutTarget },
|
||||
UpdateLayout { layout_target: LayoutTarget, widget_id: u64, value: serde_json::Value },
|
||||
ResendActiveWidget {
|
||||
layout_target: LayoutTarget,
|
||||
dirty_id: WidgetId,
|
||||
},
|
||||
SendLayout {
|
||||
layout: Layout,
|
||||
layout_target: LayoutTarget,
|
||||
},
|
||||
UpdateLayout {
|
||||
layout_target: LayoutTarget,
|
||||
widget_id: WidgetId,
|
||||
value: serde_json::Value,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct LayoutMessageHandler {
|
||||
|
||||
impl LayoutMessageHandler {
|
||||
/// Get the widget path for the widget with the specified id
|
||||
fn get_widget_path(widget_layout: &WidgetLayout, id: u64) -> Option<(&WidgetHolder, Vec<usize>)> {
|
||||
fn get_widget_path(widget_layout: &WidgetLayout, id: WidgetId) -> Option<(&WidgetHolder, Vec<usize>)> {
|
||||
let mut stack = widget_layout.layout.iter().enumerate().map(|(index, val)| (vec![index], val)).collect::<Vec<_>>();
|
||||
while let Some((mut widget_path, group)) = stack.pop() {
|
||||
match group {
|
||||
|
||||
@@ -10,6 +10,16 @@ use crate::messages::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub struct WidgetId(pub u64);
|
||||
|
||||
impl core::fmt::Display for WidgetId {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[remain::sorted]
|
||||
#[derive(PartialEq, Clone, Debug, Hash, Eq, Copy, Serialize, Deserialize, specta::Type)]
|
||||
#[repr(u8)]
|
||||
@@ -419,14 +429,17 @@ impl LayoutGroup {
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, specta::Type)]
|
||||
pub struct WidgetHolder {
|
||||
#[serde(rename = "widgetId")]
|
||||
pub widget_id: u64,
|
||||
pub widget_id: WidgetId,
|
||||
pub widget: Widget,
|
||||
}
|
||||
|
||||
impl WidgetHolder {
|
||||
#[deprecated(since = "0.0.0", note = "Please use the builder pattern, e.g. TextLabel::new(\"hello\").widget_holder()")]
|
||||
pub fn new(widget: Widget) -> Self {
|
||||
Self { widget_id: generate_uuid(), widget }
|
||||
Self {
|
||||
widget_id: WidgetId(generate_uuid()),
|
||||
widget,
|
||||
}
|
||||
}
|
||||
|
||||
/// Diffing updates self (where self is old) based on new, updating the list of modifications as it does so.
|
||||
|
||||
Reference in New Issue
Block a user