CrabUI
Loading...
Searching...
No Matches
CrabUITest.SerializationTest Class Reference

Testing Serialization. More...

Inheritance diagram for CrabUITest.SerializationTest:
CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods

Static Public Member Functions

static void Calculated (CUIComponent Main)
 
static void MergeSerialization (CUIComponent Main)
 
static void SaveLoadIntegrity (CUIComponent Main)
 
- Static Public Member Functions inherited from CrabUITest.FillMethods
static bool IsTestMethod (MethodInfo mi)
 

Detailed Description

Testing Serialization.

Definition at line 18 of file SaveLoadIntegrity.cs.

Member Function Documentation

◆ Calculated()

static void CrabUITest.SerializationTest.Calculated ( CUIComponent Main)
static

Definition at line 24 of file Calculated.cs.

25 {
26 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.TopLeft });
27 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.TopCenter });
28 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.TopRight });
29 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.CenterLeft });
30 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.Center });
31 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.CenterRight });
32 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.BottomLeft });
33 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.BottomCenter });
34 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.BottomRight });
35
36 Main.MainComponent.Step();
37
38 string savePath = Path.Combine(CUITest.IgnoredDataPath, "123.xml");
39 Main.SaveToFile(savePath, CUIAttribute.Calculated);
40 }
CUIMainComponent MainComponent
Link to CUIMainComponent, passed to children.
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
void Step()
Forses 1 layout update step, even when Frozen.

◆ MergeSerialization()

static void CrabUITest.SerializationTest.MergeSerialization ( CUIComponent Main)
static

Definition at line 42 of file MergeSerialization.cs.

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 }
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
Base class for all components.
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

◆ SaveLoadIntegrity()

static void CrabUITest.SerializationTest.SaveLoadIntegrity ( CUIComponent Main)
static

Definition at line 21 of file SaveLoadIntegrity.cs.

22 {
23 string savePath = Path.Combine(CUITest.IgnoredDataPath, "123.xml");
24
25 CUIFrame frame;
26 frame = new CUIFrame()
27 {
28 Absolute = new CUINullRect(0, 0, 500, 500),
29 Anchor = CUIAnchor.Center,
30 };
31
32 frame["list"] = new CUIVerticalList()
33 {
34 Relative = new CUINullRect(0, 0, 1, 1),
35 };
36
37 frame["list"]["header"] = new CUIHorizontalList()
38 {
39 FitContent = new CUIBool2(false, true),
40 Direction = CUIDirection.Reverse,
41 };
42 frame["list"]["header"]["close"] = new CUICloseButton()
43 {
44 Absolute = new CUINullRect(0, 0, 15, 15),
45 };
46 frame["list"]["content"] = new CUIVerticalList()
47 {
48 FillEmptySpace = new CUIBool2(false, true),
49 Scrollable = true,
50 };
51
52 CUIComponent AddComponent(Type T)
53 {
54 CUIComponent wrapper = new CUIHorizontalList()
55 {
56 Absolute = new CUINullRect(h: 20),
57 CullChildren = false,
58 };
59
60 wrapper.Append(new CUITextBlock(T.Name)
61 {
62 Absolute = new CUINullRect(w: 130),
63 });
64
65 CUIComponent target = (CUIComponent)Activator.CreateInstance(T);
66 target.FillEmptySpace = new CUIBool2(true, false);
67 wrapper.Append(target);
68
69 frame["list"]["content"].Append(wrapper);
70 return target;
71 }
72
73 AddComponent(typeof(CUIComponent));
74 AddComponent(typeof(CUIButton));
75 AddComponent(typeof(CUIToggleButton));
76 AddComponent(typeof(CUIMultiButton));
77 CUIDropDown dd = (CUIDropDown)AddComponent(typeof(CUIDropDown));
78 dd.Add("123");
79 dd.Add("321");
80 AddComponent(typeof(CUITextBlock));
81 AddComponent(typeof(CUITextInput));
82 AddComponent(typeof(CUIHorizontalList));
83 AddComponent(typeof(CUIVerticalList));
84
85
86
87 frame.SaveToFile(savePath);
88 CUIFrame loaded = CUIComponent.LoadFromFile<CUIFrame>(savePath);
89
90 CUIComponent.DeepCompareVerbose(frame, loaded);
91
92 frame.AddCommand("Close", (o) => frame.RemoveSelf());
93 loaded.AddCommand("Close", (o) => loaded.RemoveSelf());
94
95 Main.Append(frame);
96 Main.Append(loaded);
97 }
A button It's derived from CUITextBlock and has all its props.
Definition CUIButton.cs:19
void AddCommand(string name, Action< object > action)
Manually adds command.
Drop down list, aka Select.
Resizing components to it's Height and placing them sequentially.
Button with multiple options which are rotating when you click.
Passive block of text.
A button which can be on and off It's derived from CUITextBlock and has all its props.
Resizing components to it's Width and placing them sequentially.
Vector2 but with bools.
Definition CUIBool2.cs:17

The documentation for this class was generated from the following files: