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

Testing the overall behavior of a component. More...

Inheritance diagram for CrabUITest.ComponentTest:
CrabUITest.FillMethods 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 PrintCoverage ()
 
static void CUIMessageBoxTest (CUIComponent Host)
 
static void CUICanvas (CUIComponent Host)
 
static void CUICanvas2 (CUIComponent Host)
 
static void CUIDropDown (CUIComponent Host)
 
static void CUIMultiButton (CUIComponent Host)
 
static void CUIRadialMenu (CUIComponent Host)
 
static void CUISlider (CUIComponent Host)
 
static void CUITextBlock (CUIComponent Host)
 
static void CUITextInput (CUIComponent Host)
 
static void CUITickBox (CUIComponent Host)
 
static void CUIWater (CUIComponent Host)
 
- Static Public Member Functions inherited from CrabUITest.FillMethods
static bool IsTestMethod (MethodInfo mi)
 

Detailed Description

Testing the overall behavior of a component.

Definition at line 18 of file CUIWater.cs.

Member Function Documentation

◆ CUICanvas()

static void CrabUITest.ComponentTest.CUICanvas ( CUIComponent Host)
static

Definition at line 20 of file CUICanvas.cs.

21 {
22 CUIFrame frame = new CUIFrame(0, 0, 0.3f, 0.4f)
23 {
24 Anchor = CUIAnchor.Center,
25 Border = new CUIBorder(),
26 };
27
28 CUICanvas canvas = new CUICanvas()
29 {
30 Relative = new CUINullRect(0, 0, 1, 1),
31 Anchor = CUIAnchor.Center,
32 Border = new CUIBorder(Color.Black),
33 };
34
35 float d = 0;
36 canvas.OnUpdate += (totalTime) =>
37 {
38 for (int x = 0; x < canvas.Size.X; x++)
39 {
40 for (int y = 0; y < canvas.Size.Y; y++)
41 {
42 int v = (int)((x * x + y * y - x * y) + d) % 255;
43 canvas.SetPixel(x, y, new Color(0, 0, v));
44 }
45 }
46 canvas.SetData();
47 d += 1f;
48 };
49
50 frame.Append(canvas);
51
52 Host.Append(frame);
53 }
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
Allows you to manipulate pixel data of its texture.
Definition CUICanvas.cs:17
void SetData()
Call this method to transfer values from Data array into texture.
Definition CUICanvas.cs:66
virtual Point Size
Size of the internal texture Will automatically resize the texture and data array of set.
Definition CUICanvas.cs:28
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
Rectangle with float?
Definition CUIRect.cs:104

◆ CUICanvas2()

static void CrabUITest.ComponentTest.CUICanvas2 ( CUIComponent Host)
static

Definition at line 55 of file CUICanvas.cs.

56 {
57 CUIFrame frame = new CUIFrame(0, 0, 0.3f, 0.4f)
58 {
59 Anchor = CUIAnchor.Center,
60 Border = new CUIBorder(),
61 };
62
63 CUICanvas canvas = new CUICanvas()
64 {
65 Relative = new CUINullRect(0, 0, 1, 1),
66 Anchor = CUIAnchor.Center,
67 Border = new CUIBorder(Color.Black),
68 };
69
70 canvas.Render((sb) =>
71 {
72 GUI.DrawButton(sb, new Rectangle(10, 10, 80, 40), "button lol", Color.Blue);
73 });
74
75 frame.Append(canvas);
76
77 Host.Append(frame);
78 }
void Render(Action< SpriteBatch > renderFunc)
Uses renderFunc to render stuff directy onto Canvas.Texture You can for example use GUI "Draw" method...
Definition CUICanvas.cs:76

◆ CUIDropDown()

static void CrabUITest.ComponentTest.CUIDropDown ( CUIComponent Host)
static

Definition at line 19 of file CUIDropDownTest.cs.

20 {
21 CUIFrame frame = new CUIFrame(0.2f, 0.2f, 0.6f, 0.6f);
22
23 frame["dd"] = new CUIDropDown()
24 {
25 Absolute = new CUINullRect(x: 100, y: 100),
26 Options = new string[]{
27 "123", "bebebe", "321"
28 },
29 Selected = "bebebe",
30 };
31
33 {
34 Relative = new CUINullRect(w: 0.3f),
35 Absolute = new CUINullRect(300, 100, null, 40),
36 HideChildrenOutsideFrame = false,
37 Style = new CUIStyle(){
38 {"BackgroundColor", "White"},
39 }
40 };
41
42 hl["dd1"] = new CUIDropDown()
43 {
44 FillEmptySpace = new CUIBool2(true, false),
45 Options = new string[]{
46 "123", "bebebe", "321"
47 },
48 Selected = "bebebe",
49 };
50
51 hl["dd2"] = new CUIDropDown()
52 {
53 Absolute = new CUINullRect(x: 100, y: 100),
54 Options = new string[]{
55 "123", "bebebe", "321"
56 },
57 Selected = "bebebe",
58 };
59
60
61
62 frame.Append(hl);
63
64 Host.Append(frame);
65 }
Drop down list, aka Select.
Resizing components to it's Height and placing them sequentially.
In Fact just an observable dict.
Definition CUIStyle.cs:21
Vector2 but with bools.
Definition CUIBool2.cs:17

◆ CUIMessageBoxTest()

static void CrabUITest.ComponentTest.CUIMessageBoxTest ( CUIComponent Host)
static

Definition at line 21 of file CUIAlert.cs.

22 {
23 CUIMessageBox.Open("Lorem ipsum dolor sit amet consectetur adipisicing elit. Quas, ratione. Sit molestiae nihil eligendi modi, dolor voluptate, eius deleniti porro quo voluptatum ut repellat veniam vel accusantium aut quaerat repellendus. Lorem ipsum dolor sit amet consectetur adipisicing elit. Quas, ratione. Sit molestiae nihil eligendi modi, dolor voluptate, eius deleniti porro quo voluptatum ut repellat veniam vel accusantium aut quaerat repellendus.");
24 }
Simple dialog box with a message and ok button use public static void Open(string msg) to open it.

◆ CUIMultiButton()

static void CrabUITest.ComponentTest.CUIMultiButton ( CUIComponent Host)
static

Definition at line 20 of file CUIMultiButtonTest.cs.

21 {
22 CUIFrame frame = new CUIFrame(0.6f, 0.2f, 0.3f, 0.4f);
23
25 {
26 Absolute = new CUINullRect(x: 100, y: 100),
27 Options = new string[]{
28 "bebebe", "jujuju", "123", "321"
29 },
30 Selected = "bebebe",
31 };
32
33 frame.Append(mb);
34
35 Host.Append(frame);
36 }
Button with multiple options which are rotating when you click.

◆ CUIRadialMenu()

static void CrabUITest.ComponentTest.CUIRadialMenu ( CUIComponent Host)
static

Definition at line 20 of file CUIRadialMenu.cs.

21 {
22 CUIRadialMenu menu = new CUIRadialMenu()
23 {
24 OptionTemplate = new CUIRadialMenuOption()
25 {
26 BackgroundSprite = new CUISprite("RadialMenuOption.png"),
27 }
28 };
29
30 menu.OptionTemplate.Animations["hover"].Interpolate = (d) => ToolBox.GradientLerp(d,
31 new Color(0, 0, 32, 255),
32 new Color(0, 0, 255, 255),
33 new Color(0, 32, 255, 255)
34 );
35
36 menu.AddOption("1", () => CUI.Log("1"));
37 menu.AddOption("2", () => CUI.Log("2"));
38 menu.AddOption("3", () => CUI.Log("3"));
39 menu.AddOption("4", () => CUI.Log("4"));
40 menu.AddOption("5", () => CUI.Log("5"));
41 menu.AddOption("6", () => CUI.Log("6"));
42 menu.AddOption("7", () => CUI.Log("7"));
43 menu.AddOption("8", () => CUI.Log("8"));
44
45
46 Host.Append(menu);
47 }
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.
Unfinished crap, don't use.
Unfinished crap, don't use.
Wrapper Containing link to texture and drawing settings, like SourceRedt, DrawMode,...
Definition CUISprite.cs:27

◆ CUISlider()

static void CrabUITest.ComponentTest.CUISlider ( CUIComponent Host)
static

Definition at line 20 of file CUISlider.cs.

21 {
22 CUIFrame frame = new CUIFrame(0, 0, 0.3f, 0.4f)
23 {
24 Anchor = CUIAnchor.Center,
25 Border = new CUIBorder(),
26 };
27
28 CUISlider slider = new CUISlider()
29 {
30 Relative = new CUINullRect(w: 0.8f),
31 Absolute = new CUINullRect(h: 30),
32 Anchor = CUIAnchor.Center,
33 Command = "onslide",
34 };
35 slider.Lambda = 0.3f;
36
37
38 frame.AddCommand("onslide", (o) => CUI.Log(o));
39 frame.Append(slider);
40
41
42
43 Host.Append(frame);
44 }
void AddCommand(string name, Action< object > action)
Manually adds command.
Horizontal range input.
Definition CUISlider.cs:16

◆ CUITextBlock()

static void CrabUITest.ComponentTest.CUITextBlock ( CUIComponent Host)
static

Definition at line 20 of file CUITextBlock.cs.

21 {
22 CUIFrame frame = new CUIFrame()
23 {
24 Absolute = new CUINullRect(0, 0, 500, 500),
25 Anchor = CUIAnchor.Center,
26 };
27
28 frame["t1"] = new CUITextBlock("text")
29 {
30 Absolute = new CUINullRect(10, 10),
31 BackgroundColor = new Color(0, 0, 64),
32 };
33
34 frame["t2"] = new CUITextBlock("100px no wrap 100px no wrap 100px no wrap 100px no wrap")
35 {
36 Absolute = new CUINullRect(10, 40, 100),
37 BackgroundColor = new Color(0, 0, 64),
38 };
39
40 frame["t3"] = new CUITextBlock("100px wrap 100px wrap 100px wrap 100px wrap 100px wrap 100px wrap")
41 {
42 Absolute = new CUINullRect(10, 60, 100),
43 BackgroundColor = new Color(0, 0, 64),
44 Wrap = true,
45 };
46
47 frame["t4"] = new CUITextBlock("Vertical")
48 {
49 Absolute = new CUINullRect(120, 60),
50 BackgroundColor = new Color(0, 0, 64),
51 Vertical = true,
52 };
53
54 frame["t5"] = new CUITextBlock("Vertical Wrap")
55 {
56 Absolute = new CUINullRect(150, 60),
57 BackgroundColor = new Color(0, 0, 64),
58 Vertical = true,
59 Wrap = true,
60 };
61
62 frame["t6"] = new CUITextBlock("Vertical padding")
63 {
64 Absolute = new CUINullRect(190, 60),
65 BackgroundColor = new Color(0, 0, 64),
66 Vertical = true,
67 Padding = new Vector2(10, 10),
68 };
69
70 frame["t7"] = new CUITextBlock("Vertical scale")
71 {
72 Absolute = new CUINullRect(220, 60),
73 BackgroundColor = new Color(0, 0, 64),
74 Vertical = true,
75 TextScale = 1.5f,
76 };
77
78 frame["t8"] = new CUITextBlock("align bottom")
79 {
80 Absolute = new CUINullRect(250, 60, 100, 300),
81 BackgroundColor = new Color(0, 0, 64),
82 TextAlign = CUIAnchor.BottomCenter,
83 };
84
85 Host.Append(frame);
86 }
Passive block of text.

◆ CUITextInput()

static void CrabUITest.ComponentTest.CUITextInput ( CUIComponent Host)
static

Definition at line 20 of file CUITextInputTest.cs.

21 {
22 CUIFrame frame = new CUIFrame(0.6f, 0.2f, 0.3f, 0.4f);
23
25 {
26 Absolute = new CUINullRect(x: 50, y: 50),
27 });
28
30 {
31 Absolute = new CUINullRect(x: 50, y: 75, w: 200),
32 FitContent = new CUIBool2(false, true),
33 });
34
36 {
37 Absolute = new CUINullRect(x: 50, y: 100),
38 Relative = new CUINullRect(w: 0.75f),
39 FitContent = new CUIBool2(false, true),
40 });
41
42 CUITextInput t4 = (CUITextInput)frame.Append(new CUITextInput("bebebebebebebe")
43 {
44 Absolute = new CUINullRect(x: 50, y: 125),
45 Relative = new CUINullRect(w: 0.75f),
46 FitContent = new CUIBool2(false, true),
47 Disabled = true,
48 });
49
50 t3.OnTextChanged += (t) => t2.Text = t;
51 t1.OnTextAdded += (t) => CUI.Log(t);
52
53 Host.Append(frame);
54 }

◆ CUITickBox()

static void CrabUITest.ComponentTest.CUITickBox ( CUIComponent Host)
static

Definition at line 20 of file CUITickBoxTest.cs.

21 {
22 CUIFrame frame = new CUIFrame(0.6f, 0.2f, 0.3f, 0.4f);
23
24 frame["tickbox1"] = new CUITickBox()
25 {
26 Absolute = new CUINullRect(100, 100, 20, 20),
27 };
28
29 frame["tickbox2"] = new CUITickBox()
30 {
31 Absolute = new CUINullRect(150, 100, 50, 50),
32 Disabled = true,
33 };
34
35
36
37 Host.Append(frame);
38 }
Just a tick box.
Definition CUITickBox.cs:17

◆ CUIWater()

static void CrabUITest.ComponentTest.CUIWater ( CUIComponent Host)
static

Definition at line 20 of file CUIWater.cs.

21 {
22 CUIFrame frame = new CUIFrame(0, 0, 0.3f, 0.4f)
23 {
24 Anchor = CUIAnchor.Center,
25 Border = new CUIBorder(),
26 };
27
28 frame["list"] = new CUIVerticalList()
29 {
30 Relative = new CUINullRect(0, 0, 1, 1),
31 };
32
33 frame["list"]["handle"] = new CUIComponent()
34 {
35 Absolute = new CUINullRect(h: 20),
36 };
37
38 frame["list"]["content"] = new CUIWater()
39 {
40 FillEmptySpace = new CUIBool2(false, true),
41 };
42
43 Host.Append(frame);
44 }
Base class for all components.
Resizing components to it's Width and placing them sequentially.
Just an example of what CUICanvas can be used for.
Definition CUIWater.cs:16

◆ PrintCoverage()

static void CrabUITest.ComponentTest.PrintCoverage ( )
static

Definition at line 24 of file ComponentTest.cs.

25 {
26 Assembly targetAssembly = Assembly.GetAssembly(typeof(ComponentTest));
27
28 IEnumerable<Type> componentTypes = targetAssembly.GetTypes().Where(T => T.IsSubclassOf(typeof(CUIComponent)) && T.DeclaringType == null);
29
30 IEnumerable<MethodInfo> testMethods = typeof(ComponentTest).GetMethods().Where(mi => FillMethods.IsTestMethod(mi));
31
32 Dictionary<string, bool> IsCovered = new Dictionary<string, bool>();
33
34 foreach (MethodInfo mi in testMethods)
35 {
36 IsCovered[mi.Name] = true;
37 }
38
39 foreach (Type T in componentTypes)
40 {
41 bool covered = IsCovered.GetValueOrDefault(T.Name);
42 Color cl = covered ? Color.Lime : Color.Red;
43 CUITest.Log(T, cl);
44 }
45 }

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