CrabUI
Loading...
Searching...
No Matches
MergeSerialization.cs
1using System;
2using System.Reflection;
3using System.Runtime.CompilerServices;
4using System.Collections.Generic;
5using System.Collections.Immutable;
6using System.Linq;
7
8using Barotrauma;
9using HarmonyLib;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Graphics;
12using System.IO;
13
14using CrabUI;
15
16namespace CrabUITest
17{
18 public partial class SerializationTest : FillMethods
19 {
20 public class CustomWrapper : CUIComponent
21 {
22 public CustomWrapper()
23 {
24 Relative = new CUINullRect(0, 0, 0.5f, 0.5f);
25 Anchor = CUIAnchor.Center;
26 BackgroundColor = Color.Green;
27
28 this["B"] = new CUIComponent()
29 {
30 Relative = new CUINullRect(0, 0, 0.5f, 0.5f),
31 Anchor = CUIAnchor.Center,
32 BackgroundColor = Color.Yellow,
33 MergeSerialization = true,
34 };
35
36 this["B"].OnMouseEnter += (e) => this["B"].BackgroundColor = Color.Blue;
37 this["B"].OnMouseLeave += (e) => this["B"].BackgroundColor = Color.Yellow;
38 }
39 }
40
41 [HideFromAutoTestRunner]
42 public static void MergeSerialization(CUIComponent Main)
43 {
44 CUIFrame frame = new CUIFrame()
45 {
46 Relative = new CUINullRect(0, 0, 0.5f, 0.5f),
47 Anchor = CUIAnchor.Center,
48 };
49
50 frame["A"] = new CustomWrapper();
51 frame["A"]["B"]["C"] = new CUIComponent()
52 {
53 Relative = new CUINullRect(0, 0, 0.5f, 0.5f),
54 Anchor = CUIAnchor.Center,
55 BackgroundColor = Color.Magenta,
56 };
57
58 string s = frame.Serialize();
59 CUI.Log(s);
60 frame = (CUIFrame)CUIComponent.Deserialize(s);
61 CUI.Log(" ");
62 CUI.Log(frame.Serialize());
63
64 Main.Append(frame);
65 }
66
67
68 }
69}
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
Base class for all components.
CUINullRect Relative
Relative to parent size and position, [0..1].
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
Color BackgroundColor
Color of BackgroundSprite, default is black If you're using custom sprite and don't see it make sur...
Vector2 Anchor
this point of this component
bool MergeSerialization
If true it won't be deserialized, Instead its children will be detached and attached to the compone...
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
In fact a static class managing static things.
Definition CUIErrors.cs:16
static void Log(object msg, Color? color=null, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
Prints a message to console.
Rectangle with float?
Definition CUIRect.cs:104