重构 UI 编辑器数据结构并扩展序列化支持
- 重构导入的 UI 数据结构,移除过时的 `ui_editor/import` 模块 - 引入和扩展 `serde` 序列化支持,为大部分核心组件添加 `Deserialize` 和 `Serialize` - 增加新模块 `state`,设计 UI 状态管理,包括 UI Tree 和素材管理 - 拓展现有类型(如 `SpriteAsset`, `Node`, `ImageComponent` 等),添加更多元数据字段
This commit is contained in:
+3
@@ -2762,6 +2762,7 @@ dependencies = [
|
||||
"num-complex",
|
||||
"num-rational",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"simba",
|
||||
"typenum",
|
||||
]
|
||||
@@ -2910,6 +2911,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5982,6 +5984,7 @@ checksum = "436de2fdc42c0f07890f4b51dcc90a468b0b12280f49caff1cf57ce2e646817c"
|
||||
dependencies = [
|
||||
"const_fn",
|
||||
"rustversion",
|
||||
"serde",
|
||||
"typed_floats_macros",
|
||||
]
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ tauri-build = { version = "2.6.2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
ts-rs = "12.0.1"
|
||||
typed_floats = "1.0.7"
|
||||
nalgebra = "0.35.0"
|
||||
typed_floats = { version = "1.0.7", features = ["serde"] }
|
||||
nalgebra = { version = "0.35.0", features = ["serde-serialize"] }
|
||||
agent-runtime-core = { path = "../../../server-rs/crates/agent-runtime-core" }
|
||||
base64 = "0.22"
|
||||
chromiumoxide = "0.9.1"
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
use std::{fs, io, path::PathBuf};
|
||||
|
||||
use ts_rs::{Config, TS};
|
||||
|
||||
use super::{
|
||||
component::{
|
||||
image::{
|
||||
FillMethod, HorizontalFillOrigin, ImageComponent, ImageType, Radial180Origin,
|
||||
Radial360Origin, Radial90Origin, VerticalFillOrigin,
|
||||
},
|
||||
text::{
|
||||
BestFitFontSize, FontSizing, FontStyle, HorizontalTextOverflow, TextAlignment,
|
||||
TextComponent, VerticalTextOverflow,
|
||||
},
|
||||
Component,
|
||||
},
|
||||
layout::{dimension::UIRect, node::Node, transform::Transform},
|
||||
resource::{
|
||||
asset_id::{FontAssetId, SpriteAssetId},
|
||||
sprite::{SpriteAsset, SpriteBorder},
|
||||
},
|
||||
};
|
||||
|
||||
const GENERATED_HEADER: &str =
|
||||
"// This file was generated by ts-rs. Do not edit this file manually.";
|
||||
|
||||
fn typescript_bindings() -> String {
|
||||
let config = Config::default();
|
||||
let declarations = [
|
||||
FontAssetId::decl(&config),
|
||||
SpriteAssetId::decl(&config),
|
||||
SpriteBorder::decl(&config),
|
||||
SpriteAsset::decl(&config),
|
||||
UIRect::decl(&config),
|
||||
Transform::decl(&config),
|
||||
HorizontalFillOrigin::decl(&config),
|
||||
VerticalFillOrigin::decl(&config),
|
||||
Radial90Origin::decl(&config),
|
||||
Radial180Origin::decl(&config),
|
||||
Radial360Origin::decl(&config),
|
||||
FillMethod::decl(&config),
|
||||
ImageType::decl(&config),
|
||||
ImageComponent::decl(&config),
|
||||
FontStyle::decl(&config),
|
||||
TextAlignment::decl(&config),
|
||||
HorizontalTextOverflow::decl(&config),
|
||||
VerticalTextOverflow::decl(&config),
|
||||
BestFitFontSize::decl(&config),
|
||||
FontSizing::decl(&config),
|
||||
TextComponent::decl(&config),
|
||||
Component::decl(&config),
|
||||
Node::decl(&config),
|
||||
];
|
||||
|
||||
format!(
|
||||
"{GENERATED_HEADER}\n\nexport {}\n",
|
||||
declarations.join("\n\nexport ")
|
||||
)
|
||||
}
|
||||
|
||||
fn bindings_path() -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../src/features/ui-editor/types.ts")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_typescript_bindings() -> io::Result<()> {
|
||||
fs::write(bindings_path(), typescript_bindings())
|
||||
}
|
||||
@@ -4,22 +4,26 @@ use crate::ui_editor::component::common::error::ComponentValueError;
|
||||
use crate::ui_editor::layout::transform::Transform;
|
||||
use crate::ui_editor::resource::sprite::SpriteAsset;
|
||||
use nalgebra::Vector2;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
use typed_floats::tf32::StrictlyPositiveFinite;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum HorizontalFillOrigin {
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum VerticalFillOrigin {
|
||||
Bottom,
|
||||
Top,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum Radial90Origin {
|
||||
BottomLeft,
|
||||
TopLeft,
|
||||
@@ -27,7 +31,8 @@ pub enum Radial90Origin {
|
||||
BottomRight,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum Radial180Origin {
|
||||
Bottom,
|
||||
Left,
|
||||
@@ -35,7 +40,8 @@ pub enum Radial180Origin {
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum Radial360Origin {
|
||||
Bottom,
|
||||
Right,
|
||||
@@ -43,7 +49,8 @@ pub enum Radial360Origin {
|
||||
Left,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum FillMethod {
|
||||
Horizontal(HorizontalFillOrigin),
|
||||
Vertical(VerticalFillOrigin),
|
||||
@@ -71,7 +78,8 @@ fn validate_fill_amount(amount: f32) -> Result<(), ComponentValueError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum ImageType {
|
||||
Simple {
|
||||
preserve_aspect: bool,
|
||||
@@ -173,7 +181,8 @@ impl fmt::Display for SetNativeSizeError {
|
||||
impl Error for SetNativeSizeError {}
|
||||
|
||||
/// Image 渲染组件;布局由同一 Entity 上独立的 `Control` 提供。
|
||||
#[derive(Clone, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct ImageComponent {
|
||||
pub target_graphic: Option<SpriteAsset>,
|
||||
pub image_type: ImageType,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
pub mod common;
|
||||
pub mod image;
|
||||
pub mod text;
|
||||
#[derive(ts_rs::TS)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, ts_rs::TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum Component {
|
||||
Image(image::ImageComponent),
|
||||
Text(text::TextComponent),
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use crate::ui_editor::component::common::error::ComponentValueError;
|
||||
use crate::ui_editor::resource::asset_id::FontAssetId;
|
||||
use crate::ui_editor::resource::sprite::{Color, WHITE};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::num::NonZeroU32;
|
||||
use ts_rs::TS;
|
||||
use typed_floats::tf32::StrictlyPositiveFinite;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum FontStyle {
|
||||
Normal,
|
||||
Bold,
|
||||
@@ -13,7 +15,8 @@ pub enum FontStyle {
|
||||
BoldItalic,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum TextAlignment {
|
||||
UpperLeft,
|
||||
UpperCenter,
|
||||
@@ -26,19 +29,22 @@ pub enum TextAlignment {
|
||||
LowerRight,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum HorizontalTextOverflow {
|
||||
Wrap,
|
||||
Overflow,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum VerticalTextOverflow {
|
||||
Truncate,
|
||||
Overflow,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct BestFitFontSize {
|
||||
min: NonZeroU32,
|
||||
max: NonZeroU32,
|
||||
@@ -61,7 +67,8 @@ impl BestFitFontSize {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum FontSizing {
|
||||
Fixed(NonZeroU32),
|
||||
BestFit(BestFitFontSize),
|
||||
@@ -74,7 +81,8 @@ impl Default for FontSizing {
|
||||
}
|
||||
|
||||
/// Text / Label 渲染组件;布局由同一 Entity 上独立的 `Control` 提供。
|
||||
#[derive(Clone, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct TextComponent {
|
||||
pub content: String,
|
||||
pub font: Option<FontAssetId>,
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
pub mod ui_design_image;
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
pub enum UIDesignImageRole{
|
||||
Page,
|
||||
Section,
|
||||
Modal,
|
||||
Drawer,
|
||||
Popover,
|
||||
State,
|
||||
Scrolled,
|
||||
Detail,
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
use nalgebra::{Point2, Vector2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
|
||||
/// UI 布局在父级坐标系中的轴对齐矩形。
|
||||
///
|
||||
/// `min` 是矩形的最小角,`size` 是沿两个坐标轴的尺寸。这里不规定 Y 轴方向,
|
||||
/// 因而既能用于 Y 轴向上的游戏坐标,也能用于 Y 轴向下的画布坐标。
|
||||
#[derive(Clone, Copy, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct UIRect {
|
||||
#[ts(as = "[f32; 2]")]
|
||||
pub min: Point2<f32>,
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
use crate::ui_editor::component::Component;
|
||||
use crate::ui_editor::layout::transform::Transform;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
|
||||
#[derive(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 {
|
||||
transform: Transform,
|
||||
metadata: NodeMetadata,
|
||||
components: Vec<Component>,
|
||||
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 NodeMetadata {
|
||||
name: String,
|
||||
description: String,
|
||||
// TODO
|
||||
from: String,
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use crate::ui_editor::layout::dimension::UIRect;
|
||||
use nalgebra::Vector2;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct Transform {
|
||||
#[ts(as = "[f32; 2]")]
|
||||
pub anchor_min: Vector2<f32>,
|
||||
|
||||
@@ -2,6 +2,5 @@ pub mod component;
|
||||
pub mod layout;
|
||||
pub mod resource;
|
||||
|
||||
#[cfg(test)]
|
||||
mod bindings;
|
||||
pub mod import;
|
||||
pub mod agent;
|
||||
pub mod state;
|
||||
|
||||
@@ -2,7 +2,19 @@ use crate::ui_editor::component::common::error::ComponentValueError;
|
||||
|
||||
macro_rules! define_asset_id {
|
||||
($name:ident) => {
|
||||
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, ts_rs::TS)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Eq,
|
||||
Hash,
|
||||
Ord,
|
||||
PartialEq,
|
||||
PartialOrd,
|
||||
serde::Deserialize,
|
||||
serde::Serialize,
|
||||
ts_rs::TS,
|
||||
)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct $name(String);
|
||||
|
||||
impl $name {
|
||||
@@ -29,3 +41,4 @@ macro_rules! define_asset_id {
|
||||
|
||||
define_asset_id!(FontAssetId);
|
||||
define_asset_id!(SpriteAssetId);
|
||||
define_asset_id!(UIDesignImageId);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
use crate::ui_editor::resource::asset_id::FontAssetId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
|
||||
// TODO
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct FontAsset {
|
||||
asset_id: FontAssetId,
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
pub mod asset_id;
|
||||
pub mod font;
|
||||
pub mod sprite;
|
||||
pub mod ui_design_image;
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
use crate::ui_editor::component::common::error::ComponentValueError;
|
||||
use crate::ui_editor::resource::asset_id::SpriteAssetId;
|
||||
use image::Rgba;
|
||||
use nalgebra::Vector2;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
use typed_floats::tf32::StrictlyPositiveFinite;
|
||||
|
||||
pub type Color = Rgba<u8>;
|
||||
pub type Color = [u8; 4];
|
||||
|
||||
pub(in crate::ui_editor) const WHITE: Color = Rgba([255, 255, 255, 255]);
|
||||
pub(in crate::ui_editor) const WHITE: Color = [255, 255, 255, 255];
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct SpriteBorder {
|
||||
left: f32,
|
||||
right: f32,
|
||||
@@ -68,10 +69,20 @@ impl Default for SpriteBorder {
|
||||
}
|
||||
}
|
||||
|
||||
/// UI Sprite 引用以及 `Set Native Size` / 9-slice 所需的导入元数据。
|
||||
#[derive(Clone, Debug, PartialEq, TS)]
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct SpriteAssetMetadata {
|
||||
name: String,
|
||||
// TODO
|
||||
asset_type: String,
|
||||
}
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct SpriteAsset {
|
||||
asset_id: SpriteAssetId,
|
||||
metadata: SpriteAssetMetadata,
|
||||
// TODO
|
||||
path: String,
|
||||
#[ts(as = "[f32; 2]")]
|
||||
pixel_size: Vector2<f32>,
|
||||
#[ts(as = "f32")]
|
||||
@@ -97,6 +108,11 @@ impl SpriteAsset {
|
||||
}
|
||||
Ok(Self {
|
||||
asset_id,
|
||||
metadata: SpriteAssetMetadata {
|
||||
name: String::new(),
|
||||
asset_type: String::new(),
|
||||
},
|
||||
path: String::new(),
|
||||
pixel_size,
|
||||
pixels_per_unit,
|
||||
border,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
use nalgebra::Vector2;
|
||||
use crate::ui_editor::resource::asset_id::UIDesignImageId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
use typed_floats::tf32::StrictlyPositiveFinite;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub enum UIDesignImageRole {
|
||||
Page,
|
||||
Section,
|
||||
Modal,
|
||||
Drawer,
|
||||
Popover,
|
||||
State,
|
||||
Scrolled,
|
||||
Detail,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct UIDesignImage {
|
||||
path: String,
|
||||
#[ts(as = "[f32; 2]")]
|
||||
pixel_size: Vector2<f32>,
|
||||
#[ts(as = "f32")]
|
||||
pixels_per_unit: StrictlyPositiveFinite,
|
||||
}
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
pub struct UIDesignImageMetadata {
|
||||
name: String,
|
||||
role: Option<UIDesignImageRole>,
|
||||
slave_to: UIDesignImageId,
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
use crate::ui_editor::layout::node::Node;
|
||||
use crate::ui_editor::resource::asset_id::{FontAssetId, SpriteAssetId, UIDesignImageId};
|
||||
use crate::ui_editor::resource::font::FontAsset;
|
||||
use crate::ui_editor::resource::sprite::SpriteAsset;
|
||||
use crate::ui_editor::resource::ui_design_image::UIDesignImage;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
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 UITree {
|
||||
src_ui_design: UIDesignImageId,
|
||||
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 {
|
||||
ui_trees: Vec<UITree>,
|
||||
ui_design_images: HashMap<UIDesignImageId, UIDesignImage>,
|
||||
sprite_assets: HashMap<SpriteAssetId, SpriteAsset>,
|
||||
font_assets: HashMap<FontAssetId, FontAsset>,
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
// This file was generated by ts-rs. Do not edit this file manually.
|
||||
|
||||
export type FontAssetId = string;
|
||||
|
||||
export type SpriteAssetId = string;
|
||||
|
||||
export type SpriteBorder = { left: number, right: number, top: number, bottom: number, };
|
||||
|
||||
export type SpriteAsset = { asset_id: SpriteAssetId, pixel_size: [number, number], pixels_per_unit: number, border: SpriteBorder, };
|
||||
|
||||
export type UIRect = { min: [number, number], size: [number, number], };
|
||||
|
||||
export type Transform = { anchor_min: [number, number], anchor_max: [number, number], offset_min: [number, number], offset_max: [number, number], };
|
||||
|
||||
export type HorizontalFillOrigin = "Left" | "Right";
|
||||
|
||||
export type VerticalFillOrigin = "Bottom" | "Top";
|
||||
|
||||
export type Radial90Origin = "BottomLeft" | "TopLeft" | "TopRight" | "BottomRight";
|
||||
|
||||
export type Radial180Origin = "Bottom" | "Left" | "Top" | "Right";
|
||||
|
||||
export type Radial360Origin = "Bottom" | "Right" | "Top" | "Left";
|
||||
|
||||
export type FillMethod = { "Horizontal": HorizontalFillOrigin } | { "Vertical": VerticalFillOrigin } | { "Radial90": { origin: Radial90Origin, clockwise: boolean, } } | { "Radial180": { origin: Radial180Origin, clockwise: boolean, } } | { "Radial360": { origin: Radial360Origin, clockwise: boolean, } };
|
||||
|
||||
export type ImageType = { "Simple": { preserve_aspect: boolean, } } | { "Sliced": { fill_center: boolean, pixels_per_unit_multiplier: number, } } | { "Tiled": { fill_center: boolean, pixels_per_unit_multiplier: number, } } | { "Filled": { preserve_aspect: boolean, method: FillMethod, amount: number, } };
|
||||
|
||||
export type ImageComponent = { target_graphic: SpriteAsset | null, image_type: ImageType, };
|
||||
|
||||
export type FontStyle = "Normal" | "Bold" | "Italic" | "BoldItalic";
|
||||
|
||||
export type TextAlignment = "UpperLeft" | "UpperCenter" | "UpperRight" | "MiddleLeft" | "MiddleCenter" | "MiddleRight" | "LowerLeft" | "LowerCenter" | "LowerRight";
|
||||
|
||||
export type HorizontalTextOverflow = "Wrap" | "Overflow";
|
||||
|
||||
export type VerticalTextOverflow = "Truncate" | "Overflow";
|
||||
|
||||
export type BestFitFontSize = { min: number, max: number, };
|
||||
|
||||
export type FontSizing = { "Fixed": number } | { "BestFit": BestFitFontSize };
|
||||
|
||||
export type TextComponent = { content: string, font: FontAssetId | null, font_style: FontStyle, font_sizing: FontSizing, color: [number, number, number, number], alignment: TextAlignment, horizontal_overflow: HorizontalTextOverflow, vertical_overflow: VerticalTextOverflow, line_spacing: number, };
|
||||
|
||||
export type Component = { "Image": ImageComponent } | { "Text": TextComponent };
|
||||
|
||||
export type Node = { transform: Transform, 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 BestFitFontSize = { min: number, max: number, };
|
||||
@@ -0,0 +1,5 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ImageComponent } from "./ImageComponent";
|
||||
import type { TextComponent } from "./TextComponent";
|
||||
|
||||
export type Component = { "Image": ImageComponent } | { "Text": TextComponent };
|
||||
@@ -0,0 +1,8 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { HorizontalFillOrigin } from "./HorizontalFillOrigin";
|
||||
import type { Radial180Origin } from "./Radial180Origin";
|
||||
import type { Radial360Origin } from "./Radial360Origin";
|
||||
import type { Radial90Origin } from "./Radial90Origin";
|
||||
import type { VerticalFillOrigin } from "./VerticalFillOrigin";
|
||||
|
||||
export type FillMethod = { "Horizontal": HorizontalFillOrigin } | { "Vertical": VerticalFillOrigin } | { "Radial90": { origin: Radial90Origin, clockwise: boolean, } } | { "Radial180": { origin: Radial180Origin, clockwise: boolean, } } | { "Radial360": { origin: Radial360Origin, clockwise: boolean, } };
|
||||
@@ -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 { FontAssetId } from "./FontAssetId";
|
||||
|
||||
export type FontAsset = { asset_id: FontAssetId, };
|
||||
@@ -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 FontAssetId = string;
|
||||
@@ -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 { BestFitFontSize } from "./BestFitFontSize";
|
||||
|
||||
export type FontSizing = { "Fixed": number } | { "BestFit": BestFitFontSize };
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user