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

Random tests. More...

Inheritance diagram for CrabUITest.RandomTest:
CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods CrabUITest.FillMethods

Static Public Member Functions

static void AttachedItemTest (CUIComponent Main)
 
static void CUICommandTest (CUIComponent Main)
 
static void DataFlow (CUIComponent Main)
 
static void DrawFront (CUIComponent Main)
 
static void EventConsumption (CUIComponent Main)
 
static void FramesVsAnchors (CUIComponent Main)
 
static void ImpreciseListPositioning (CUIComponent Main)
 
static void TopMain (CUIComponent Main)
 
static void VanillaSprite (CUIComponent Main)
 
- Static Public Member Functions inherited from CrabUITest.FillMethods
static bool IsTestMethod (MethodInfo mi)
 

Detailed Description

Random tests.

Definition at line 17 of file Weak stuff.cs.

Member Function Documentation

◆ AttachedItemTest()

static void CrabUITest.RandomTest.AttachedItemTest ( CUIComponent Main)
static

Definition at line 96 of file AttachedItemTest.cs.

97 {
98 AttachedItems.ConnectPrefabs("revolver", typeof(RevolverOverlay));
99 AttachedItems.ConnectPrefabs("periscope", typeof(PeriscopeOverlay));
100 CUITest.CloseTestChamber();
101 }

◆ CUICommandTest()

static void CrabUITest.RandomTest.CUICommandTest ( CUIComponent Main)
static

Definition at line 28 of file CUICommand.cs.

29 {
30 CUIFrame frame = new CUIFrame()
31 {
32 Relative = new CUINullRect(0.1f, 0.1f, 0.8f, 0.8f),
33 Anchor = CUIAnchor.Center,
34 };
35
36 CUIComponent lastWrapper = frame.Append(new NestedWrapper()).Append(new NestedWrapper()).Append(new NestedWrapper()).Append(new NestedWrapper()).Append(new NestedWrapper()).Append(new NestedWrapper()).Append(new NestedWrapper()).Append(new NestedWrapper()).Append(new NestedWrapper());
37
38 frame.AddCommand("change color", (o) =>
39 {
40 frame.BackgroundColor = CUIExtensions.RandomColor();
41 });
42
43 lastWrapper.Append(new CUIButton("change color")
44 {
45 Anchor = CUIAnchor.Center,
46 AddOnMouseDown = (e) => lastWrapper.DispatchUp(new CUICommand("change color"))
47 });
48
49 Main.Append(frame);
50 }
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
A button It's derived from CUITextBlock and has all its props.
Definition CUIButton.cs:19
Base class for all components.
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
void AddCommand(string name, Action< object > action)
Manually adds command.
void DispatchUp(CUICommand command)
Dispathes command up the component tree until someone consumes it.
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
record CUICommand(string Name, object Data=null)
Can be dispatched up the component tree to notify parent about something add pass some event data wit...
Rectangle with float?
Definition CUIRect.cs:104

◆ DataFlow()

static void CrabUITest.RandomTest.DataFlow ( CUIComponent Main)
static

Definition at line 21 of file Data flow.cs.

22 {
23 CUIFrame frame = CUIPrefab.NewFrame();
24 frame.Relative = new CUINullRect(0, 0, 0.5f, 0.5f);
25 frame.Anchor = CUIAnchor.Center;
26 frame.Get<CUITextBlock>("caption").Text = "DataFlow";
27 frame["header"]["data"] = new CUITextInput()
28 {
29 Absolute = new CUINullRect(w: 100),
30 Text = "123",
31 };
32 frame["header"]["send"] = new CUIButton("send")
33 {
34 AddOnMouseDown = (e) =>
35 {
36 Stopwatch sw = new Stopwatch();
37 sw.Restart();
38 frame["content"].DispatchDown(new CUIData(frame.Get<CUITextInput>("header.data").Text));
39 sw.Stop();
40 frame.Get<CUITextBlock>("header.took").Text = $"{sw.ElapsedMilliseconds}ms";
41 },
42 };
43 frame["header"]["took"] = new CUITextBlock("took")
44 {
45 Absolute = new CUINullRect(w: 50),
46 TextAlign = CUIAnchor.CenterLeft,
47 };
48 frame["header"]["recieved"] = new CUITextBlock("recieved")
49 {
50 Absolute = new CUINullRect(w: 50),
51 TextAlign = CUIAnchor.CenterLeft,
52 };
53
54 CUIToggleButton spamButton = new CUIToggleButton("spam")
55 {
56 State = true,
57 };
58 frame["header"]["spam"] = spamButton;
59
60 frame.OnAnyCommand += (c) => frame.Get<CUITextBlock>("header.recieved").Text = c.Name;
61
62 for (int i = 0; i < 2000; i++)
63 {
64 CUIButton b = new CUIButton($"Button {i}")
65 {
66 Consumes = $"data {i}",
67 Command = $"hi from button {i}",
68 AKA = $"Button{i}",
69 Palette = PaletteOrder.Secondary,
70 GhostText = true,
71 //Absolute = new CUINullRect(h: 20),
72 };
73 b.OnConsume += (data) => b.TextScale = CUI.Random.NextSingle() * 2.0f; //b.Text = $"{data}";
74 b.OnAnyData += (data) => b.Text = $"lol data:{data}";
75 frame["content"].Append(b);
76 }
77
78 frame.Emits.Add("data 2");
79 frame.OnUpdate += (d) =>
80 {
81 if (spamButton.State)
82 {
83 frame.DispatchDown(new CUIData("data 2", d));
84 }
85 };
86
87 Main.Append(frame);
88 }
virtual CUIComponent Get(string name)
Returns memorized component by name.
void DispatchDown(CUIData data)
Dispathes command down the component tree until someone consumes it.
ObservableCollection< string > Emits
Optimization to data flow If not empty component will search for consumers of the data and pass it ...
In fact a static class managing static things.
Definition CUIErrors.cs:16
Passive block of text.
A button which can be on and off It's derived from CUITextBlock and has all its props.
record CUIData(string Name, object Data=null)
Can be dispatched down the component tree to pass some data to the children without creating a hard l...

◆ DrawFront()

static void CrabUITest.RandomTest.DrawFront ( CUIComponent Main)
static

Definition at line 22 of file DrawFront.cs.

23 {
24 Main["frame1"] = new CUIFrame()
25 {
26 Relative = new CUINullRect(0, 0, 0.4f, 0.4f),
27 BackgroundColor = Color.Black * 0.9f,
28 OutlineThickness = 4f,
29 OutlineColor = Color.White,
30 Border = new CUIBorder(new Color(0, 255, 255), 4),
31 Anchor = new Vector2(0.4f, 0.5f),
32 };
33
34 Main["frame1"].Append(new CUICloseButton()
35 {
36 Anchor = CUIAnchor.TopRight,
37 });
38
39 Main["frame2"] = new CUIFrame()
40 {
41 Relative = new CUINullRect(0, 0, 0.4f, 0.4f),
42 BackgroundColor = Color.Black * 0.9f,
43 OutlineThickness = 4f,
44 OutlineColor = Color.White,
45 Border = new CUIBorder(new Color(255, 0, 255), 4),
46 Anchor = new Vector2(0.6f, 0.5f),
47 };
48 }

◆ EventConsumption()

static void CrabUITest.RandomTest.EventConsumption ( CUIComponent Main)
static

Definition at line 19 of file EventConsumption.cs.

20 {
21 CUIFrame frame = new CUIFrame()
22 {
23 Relative = new CUINullRect(0, 0, 0.6f, 0.6f),
24 Anchor = CUIAnchor.Center,
25 };
26
27 frame["b1"] = new CUIButton("123")
28 {
29 Relative = new CUINullRect(0, 0, 0.6f, 0.1f),
30 Anchor = CUIAnchor.Center,
31 MasterColorOpaque = Color.Red,
32 };
33
34 frame["b2"] = new CUIButton("123")
35 {
36 Relative = new CUINullRect(0, 0, 0.1f, 0.6f),
37 Anchor = CUIAnchor.Center,
38 MasterColorOpaque = Color.Yellow,
39 };
40
41
42 Main.Append(frame);
43 }

◆ FramesVsAnchors()

static void CrabUITest.RandomTest.FramesVsAnchors ( CUIComponent Main)
static

Definition at line 22 of file FramesVsAnchors.cs.

23 {
24 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.TopLeft });
25 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.TopCenter });
26 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.TopRight });
27 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.CenterLeft });
28 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.Center });
29 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.CenterRight });
30 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.BottomLeft });
31 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.BottomCenter });
32 Main.Append(new CUIFrame(null, null, 0.2f, 0.2f) { Anchor = CUIAnchor.BottomRight });
33 }

◆ ImpreciseListPositioning()

static void CrabUITest.RandomTest.ImpreciseListPositioning ( CUIComponent Main)
static

Definition at line 20 of file Imprecise list positioning.cs.

21 {
22 CUIFrame frame = new CUIFrame()
23 {
24 Anchor = CUIAnchor.Center,
25 Absolute = new CUINullRect(0, 0, 500, 500),
26 };
27
28 frame["l"] = new CUIVerticalList()
29 {
30 Absolute = new CUINullRect(0, 0, 40, 200),
31 Border = new CUIBorder(),
32 };
33
34 frame["l"]["h1"] = new CUIHorizontalList()
35 {
36 Absolute = new CUINullRect(0, 0, 40, 40),
37 Border = new CUIBorder(),
38 BackgroundColor = Color.Cyan * 0.5f,
39 CullChildren = false,
40 };
41
42 frame["l"]["h2"] = new CUIHorizontalList()
43 {
44 Absolute = new CUINullRect(0, 0, 40, 40),
45 Border = new CUIBorder(),
46 BackgroundColor = Color.Cyan * 0.5f,
47 CullChildren = false,
48 };
49
50 frame["l"]["h3"] = new CUIHorizontalList()
51 {
52 Absolute = new CUINullRect(0, 0, 40, 40),
53 Border = new CUIBorder(),
54 BackgroundColor = Color.Cyan * 0.5f,
55 //CullChildren = false,
56 };
57
58
59 frame["l"]["h1"]["c"] = new CUIComponent()
60 {
61 Absolute = new CUINullRect(0, 0, 40, 40),
62 BackgroundColor = Color.Blue * 0.5f,
63 Border = new CUIBorder(),
64 };
65
66 frame["l"]["h2"]["c"] = new CUIComponent()
67 {
68 Absolute = new CUINullRect(0, 0, 40, 40),
69 BackgroundColor = Color.Blue * 0.5f,
70 Border = new CUIBorder(),
71 };
72
73 frame["l"]["h3"]["c"] = new CUIComponent()
74 {
75 Absolute = new CUINullRect(0, 0, 40, 40),
76 BackgroundColor = Color.Blue * 0.5f,
77 Border = new CUIBorder(),
78 };
79
80
81
82 Main.Append(frame);
83 }
Resizing components to it's Height and placing them sequentially.
Resizing components to it's Width and placing them sequentially.

◆ TopMain()

static void CrabUITest.RandomTest.TopMain ( CUIComponent Main)
static

Definition at line 21 of file Top Main.cs.

22 {
23 Main["bottomFrame"] = new CUIFrame(0.6f, 0.2f, 0.3f, 0.4f)
24 {
25
26 };
27
28 Main["bottomFrame"]["button"] = new CUIButton("press me")
29 {
30 Anchor = CUIAnchor.Center,
31 };
32
33
34 CUIFrame frame = new CUIFrame(0, 0, 0.3f, 0.4f)
35 {
36 Anchor = CUIAnchor.Center,
37 Border = new CUIBorder(),
38 ConsumeMouseClicks = true,
39 };
40
41 frame["list"] = new CUIVerticalList()
42 {
43 Relative = new CUINullRect(0, 0, 1, 1),
44 };
45
46 frame["list"]["handle"] = new CUIComponent()
47 {
48 Absolute = new CUINullRect(h: 20),
49 };
50
51 frame["list"]["content"] = new CUIWater()
52 {
53 FillEmptySpace = new CUIBool2(false, true),
54 };
55
56 CUI.TopMain.Append(frame);
57 }
static CUIMainComponent TopMain
Orchestrates Drawing and updates, there could be only one CUI.TopMain is located above vanilla GUI.
Definition CUI.cs:89
Just an example of what CUICanvas can be used for.
Definition CUIWater.cs:16
Vector2 but with bools.
Definition CUIBool2.cs:17

◆ VanillaSprite()

static void CrabUITest.RandomTest.VanillaSprite ( CUIComponent Main)
static

Definition at line 20 of file Vanilla Sprite.cs.

21 {
22 CUIFrame frame = new CUIFrame(0.2f, 0.2f, 0.6f, 0.6f);
23
24 frame["img"] = new CUIComponent()
25 {
26 ResizeToSprite = true,
27 Anchor = CUIAnchor.Center,
28 BackgroundSprite = CUISprite.FromId(new Identifier("EyeButton")),
29 //BackgroundSprite = CUISprite.FromVanilla(GUIStyle.PingCircle.Value.Sprite),
30 BackgroundColor = new Color(255, 255, 255, 255),
31 };
32
33 Main.Append(frame);
34 }
Wrapper Containing link to texture and drawing settings, like SourceRedt, DrawMode,...
Definition CUISprite.cs:27

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