CrabUI
Loading...
Searching...
No Matches
ResizeToContent.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 /// <summary>
20 /// FitContent in simple layout
21 /// </summary>
22 /// <param name="Main"></param>
23 public static void ResizeToContent(CUIComponent Main)
24 {
25 CUIFrame frame = new CUIFrame(0.6f, 0.2f, 0.2f, 0.6f);
26
27 frame["line"] = new CUIComponent()
28 {
29 Relative = new CUINullRect(w: 1),
30 FitContent = new CUIBool2(false, true),
31 Anchor = new Vector2(0.5f, 0.5f),
32 BackgroundColor = Color.Blue,
33 };
34
35 frame["content"] = frame["line"].Append(new CUIComponent()
36 {
37 BackgroundColor = Color.Lime,
38 Relative = new CUINullRect(w: 0.25f),
39 Absolute = new CUINullRect(h: 50),
40 Anchor = new Vector2(0.5f, 0.5f),
41 });
42
43 Main.Append(frame);
44 }
45
46 /// <summary>
47 /// FitContent in list
48 /// </summary>
49 /// <param name="Main"></param>
50 public static void ResizeToContent2(CUIComponent Main)
51 {
52 CUIFrame frame = new CUIFrame(0.6f, 0.2f, 0.2f, 0.6f);
53
54 frame["list"] = new CUIVerticalList()
55 {
56 Relative = new CUINullRect(w: 1, h: 1),
57 BackgroundColor = Color.Blue,
58 };
59
60 frame["list"].Append(new CUIComponent() { Absolute = new CUINullRect(h: 50), });
61 frame["list"]["center"] = new CUIComponent()
62 {
63 BackgroundColor = Color.Lime,
64 FitContent = new CUIBool2(false, true),
65 };
66 frame["list"].Append(new CUIComponent() { Absolute = new CUINullRect(h: 50), });
67
68
69 frame["list"]["center"].Append(new CUITextBlock("bebebe")
70 {
71 BackgroundColor = Color.Red,
72 Anchor = new Vector2(0.5f, 0.5f),
73 TextScale = 2f,
74 });
75
76
77
78
79 Main.Append(frame);
80 }
81
82 /// <summary>
83 /// FitContent of List itself
84 /// </summary>
85 /// <param name="Main"></param>
86 public static void ResizeToContent3(CUIComponent Main)
87 {
88 CUIFrame frame = new CUIFrame(0.6f, 0.2f, 0.2f, 0.6f);
89
90 frame["vlist"] = new CUIVerticalList()
91 {
92 FitContent = new CUIBool2(true, true),
93 Anchor = new Vector2(0.0f, 0.5f),
94 BackgroundColor = Color.Blue,
95 };
96
97 frame["vlist"].Append(new CUIComponent()
98 {
99 BackgroundColor = new Color(255, 0, 0, 100),
100 Absolute = new CUINullRect(w: 50, h: 50),
101 });
102
103 frame["hlist"] = new CUIHorizontalList()
104 {
105 FitContent = new CUIBool2(true, true),
106 Anchor = new Vector2(1.0f, 0.5f),
107 BackgroundColor = Color.Blue,
108 };
109
110 frame["hlist"].Append(new CUIComponent()
111 {
112 BackgroundColor = new Color(255, 0, 0, 100),
113 Absolute = new CUINullRect(w: 50, h: 50),
114 });
115
116 Main.Append(frame);
117 }
118
119
120
121
122 }
123}
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
Resizing components to it's Height and placing them sequentially.
Passive block of text.
Resizing components to it's Width and placing them sequentially.
static void ResizeToContent2(CUIComponent Main)
FitContent in list.
static void ResizeToContent3(CUIComponent Main)
FitContent of List itself.
static void ResizeToContent(CUIComponent Main)
FitContent in simple layout.
Vector2 but with bools.
Definition CUIBool2.cs:17
Rectangle with float?
Definition CUIRect.cs:104