CrabUI
Loading...
Searching...
No Matches
Data flow.cs
1using System;
2using System.Reflection;
3using System.Runtime.CompilerServices;
4using System.Collections.Generic;
5using System.Collections.Immutable;
6using System.Linq;
7using System.Diagnostics;
8
9using Barotrauma;
10using HarmonyLib;
11using Microsoft.Xna.Framework;
12using Microsoft.Xna.Framework.Graphics;
13
14using CrabUI;
15
16namespace CrabUITest
17{
18 public partial class RandomTest : FillMethods
19 {
20 [HideFromAutoTestRunner]
21 public static void DataFlow(CUIComponent Main)
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 }
89
90
91 }
92}
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 Get(string name)
Returns memorized component by name.
void DispatchDown(CUIData data)
Dispathes command down the component tree until someone consumes it.
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
ObservableCollection< string > Emits
Optimization to data flow If not empty component will search for consumers of the data and pass it ...
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
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...
Rectangle with float?
Definition CUIRect.cs:104