CrabUI
Loading...
Searching...
No Matches
Ghost.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;
12
13using CrabUI;
14
15namespace CrabUITest
16{
17 public partial class PropTest : FillMethods
18 {
19 public static void Ghost(CUIComponent Main)
20 {
21 CUIFrame frame = new CUIFrame()
22 {
23 Absolute = new CUINullRect(0, 0, 500, 500),
24 Anchor = CUIAnchor.Center,
25 };
26
27 CUIComponent Box(bool x, bool y) => new CUIComponent()
28 {
29 Absolute = new CUINullRect(0, 0, 20, 20),
30 Ghost = new CUIBool2(x, y),
31 BackgroundColor = Color.Lime * 0.7f,
32 };
33
34 float offset = 20;
35 void AddContainer(CUIComponent container, bool x, bool y)
36 {
37 float yOffset = 0;
38 if (!x && !y) yOffset = 0;
39 if (!x && y) yOffset = 1;
40 if (x && !y) yOffset = 2;
41 if (x && y) yOffset = 3;
42
43 container.FitContent = new CUIBool2(true, true);
44 container.BackgroundColor = Color.Yellow;
45 container.Absolute = new CUINullRect(offset, 100 + yOffset * 40);
46 container.AbsoluteMin = new CUINullRect(w: 10, h: 10);
47 container.AKA = $"{container.GetType().Name} [{x},{y}]";
48 container.Append(Box(x, y));
49 frame.Append(container);
50 };
51
52 void AddContainerType(Type type)
53 {
54 frame.Append(new CUITextBlock(type.Name)
55 {
56 Absolute = new CUINullRect(offset, 80),
57 });
58 AddContainer((CUIComponent)Activator.CreateInstance(type), false, false);
59 AddContainer((CUIComponent)Activator.CreateInstance(type), false, true);
60 AddContainer((CUIComponent)Activator.CreateInstance(type), true, false);
61 AddContainer((CUIComponent)Activator.CreateInstance(type), true, true);
62 offset += 120;
63 };
64
65 AddContainerType(typeof(CUIComponent));
66 AddContainerType(typeof(CUIHorizontalList));
67 AddContainerType(typeof(CUIVerticalList));
68 AddContainerType(typeof(CUIGrid));
69
70 Main.Append(frame);
71 }
72 }
73}
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
Base class for all components.
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
A Grid containing children in its cells.
Definition CUIGrid.cs:16
Resizing components to it's Height and placing them sequentially.
Passive block of text.
Resizing components to it's Width and placing them sequentially.
Vector2 but with bools.
Definition CUIBool2.cs:17
Rectangle with float?
Definition CUIRect.cs:104