扩展 UI 编辑器数据模型

- 为 `Node` 添加 `id` 字段,支持更全面的节点标识。
- 在 `NodeMetadata` 中新增 `status` 和 `source` 字段,增强元数据定义。
- 调整模块定义路径,优化类型序列化支持。
- 更新 Rust 结构体的字段为 `pub`,提升数据访问灵活性。
- 整理导入路径,移除或调整重复声明。
This commit is contained in:
2026-08-13 20:29:56 +08:00
parent 2f58c13b7a
commit 69a2dc79fe
15 changed files with 47 additions and 30 deletions
@@ -3,11 +3,11 @@ use std::{error::Error, fmt};
use crate::ui_editor::component::common::error::ComponentValueError;
use crate::ui_editor::layout::transform::Transform;
use crate::ui_editor::resource::sprite::SpriteAsset;
use crate::ui_editor::utils::SpriteAssetId;
use nalgebra::Vector2;
use serde::{Deserialize, Serialize};
use ts_rs::TS;
use typed_floats::tf32::StrictlyPositiveFinite;
use crate::ui_editor::utils::SpriteAssetId;
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
@@ -1,10 +1,10 @@
use crate::ui_editor::component::common::error::ComponentValueError;
use crate::ui_editor::resource::sprite::{Color, WHITE};
use crate::ui_editor::utils::FontAssetId;
use serde::{Deserialize, Serialize};
use std::num::NonZeroU32;
use ts_rs::TS;
use typed_floats::tf32::StrictlyPositiveFinite;
use crate::ui_editor::utils::FontAssetId;
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
@@ -7,34 +7,33 @@ use ts_rs::TS;
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
pub struct Node {
id: NodeId,
transform: Transform,
metadata: NodeMetadata,
components: Vec<Component>,
children: Vec<Node>,
pub id: NodeId,
pub transform: Transform,
pub metadata: NodeMetadata,
pub components: Vec<Component>,
pub children: Vec<Node>,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
pub enum NodeSource {
Human,
Llm,
Human,
Llm,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
pub enum NodeStatus {
Passed,
NeedReview(String), // reason inside
Blocked,
Passed,
NeedReview(String), // reason inside
Blocked,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
pub struct NodeMetadata {
name: String,
description: String,
status: NodeStatus,
source: NodeSource,
pub name: String,
pub description: String,
pub status: NodeStatus,
pub source: NodeSource,
}
@@ -1,6 +1,6 @@
pub mod commands;
pub mod component;
pub mod layout;
pub mod resource;
pub mod state;
pub mod commands;
mod utils;
@@ -1,6 +1,6 @@
use crate::ui_editor::utils::FontAssetId;
use serde::{Deserialize, Serialize};
use ts_rs::TS;
use crate::ui_editor::utils::FontAssetId;
// TODO
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
@@ -1,9 +1,9 @@
use crate::ui_editor::component::common::error::ComponentValueError;
use crate::ui_editor::utils::SpriteAssetId;
use nalgebra::Vector2;
use serde::{Deserialize, Serialize};
use ts_rs::TS;
use typed_floats::tf32::StrictlyPositiveFinite;
use crate::ui_editor::utils::SpriteAssetId;
pub type Color = [u8; 4];
@@ -1,11 +1,12 @@
use crate::ui_editor::utils::UIDesignImageId;
use nalgebra::Vector2;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter, Write};
use ts_rs::TS;
use typed_floats::tf32::StrictlyPositiveFinite;
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
pub enum UIDesignImageRole {
Page,
@@ -2,23 +2,23 @@ use crate::ui_editor::layout::node::Node;
use crate::ui_editor::resource::font::FontAsset;
use crate::ui_editor::resource::sprite::SpriteAsset;
use crate::ui_editor::resource::ui_design_image::UIDesignImage;
use crate::ui_editor::utils::{FontAssetId, SpriteAssetId, UIDesignImageId};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use ts_rs::TS;
use crate::ui_editor::utils::{FontAssetId, SpriteAssetId, UIDesignImageId};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
pub struct UITree {
src_ui_design: UIDesignImageId,
children: Vec<Node>,
pub src_ui_design: UIDesignImageId,
pub children: Vec<Node>,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
pub struct State {
pub(crate) ui_trees: Vec<UITree>,
pub(crate) ui_design_images: HashMap<UIDesignImageId, UIDesignImage>,
pub(crate) sprite_assets: HashMap<SpriteAssetId, SpriteAsset>,
pub(crate) font_assets: HashMap<FontAssetId, FontAsset>,
pub ui_trees: Vec<UITree>,
pub ui_design_images: HashMap<UIDesignImageId, UIDesignImage>,
pub sprite_assets: HashMap<SpriteAssetId, SpriteAsset>,
pub font_assets: HashMap<FontAssetId, FontAsset>,
}
@@ -12,6 +12,7 @@ macro_rules! define_id {
PartialOrd,
serde::Deserialize,
serde::Serialize,
schemars::JsonSchema,
ts_rs::TS,
)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
@@ -1,6 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Component } from "./Component";
import type { NodeId } from "./NodeId";
import type { NodeMetadata } from "./NodeMetadata";
import type { Transform } from "./Transform";
export type Node = { transform: Transform, metadata: NodeMetadata, components: Array<Component>, children: Array<Node>, };
export type Node = { id: NodeId, transform: Transform, metadata: NodeMetadata, components: Array<Component>, children: Array<Node>, };
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type NodeId = string;
@@ -1,3 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { NodeSource } from "./NodeSource";
import type { NodeStatus } from "./NodeStatus";
export type NodeMetadata = { name: string, description: string, from: string, };
export type NodeMetadata = { name: string, description: string, status: NodeStatus, source: NodeSource, };
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type NodeSource = "Human" | "Llm";
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type NodeStatus = "Passed" | { "NeedReview": string } | "Blocked";
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { UITree } from "./UITree";
export type RecognitionDTO = { ui_trees: Array<UITree>, };