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

I was trying to make a calculator
But failed miserably because i have no idea how calculator works. More...

Public Member Functions

void Initialize (CUIComponent FakeMain)
 
void Dispose ()
 

Public Attributes

Calculator calculator
 

Detailed Description

I was trying to make a calculator
But failed miserably because i have no idea how calculator works.

Definition at line 22 of file Calc.cs.

Member Function Documentation

◆ Dispose()

void CrabUITest.CalculatorMod.Dispose ( )

Definition at line 130 of file Calc.cs.

131 {
132
133 }

◆ Initialize()

void CrabUITest.CalculatorMod.Initialize ( CUIComponent FakeMain)

Definition at line 46 of file Calc.cs.

47 {
48 calculator = new Calculator();
49
50 CUIComponent Header;
51 CUIGrid ButtonGrid;
52 CUITextBlock tb;
53
54
55 CUIFrame mainframe = new CUIFrame()
56 {
57 Absolute = new CUINullRect(700, 200, 300, 400),
58 AbsoluteMin = new CUINullRect(w: 100, h: 100),
59
60 //Anchor = CUIAnchor.Center,
61 };
62
63 mainframe["list"] = new CUIVerticalList()
64 {
65 Relative = new CUINullRect(0, 0, 1, 1),
66 BackgroundColor = Color.Blue,
67 };
68
69 mainframe["list"]["Header"] = Header = new CUIComponent()
70 {
71 BackgroundColor = Color.Green,
72 FitContent = new CUIBool2(false, true),
73 };
74
75 mainframe["list"]["ButtonGrid"] = ButtonGrid = new CUIGrid()
76 {
77 FillEmptySpace = new CUIBool2(false, true),
78 BackgroundColor = Color.Brown,
79 GridTemplateColumns = "25% 25% 25% 25%",
80 GridTemplateRows = "25% 25% 25% 25%",
81 };
82
83
84 Header["tb"] = tb = new CUITextBlock("Value");
85
86
87 calculator.OnValueChange += (value) =>
88 {
89 tb.Text = value.ToString();
90 };
91
92 void addNumButton(int i, int x, int y)
93 {
94 ButtonGrid.Append(new CUIButton($"{i}")
95 {
96 GridCell = new Point(x, y),
97 AddOnClick = (e) => calculator.SetDigit(i),
98 });
99 }
100
101 addNumButton(1, 0, 0);
102 addNumButton(2, 1, 0);
103 addNumButton(3, 2, 0);
104 addNumButton(4, 0, 1);
105 addNumButton(5, 1, 1);
106 addNumButton(6, 2, 1);
107 addNumButton(7, 0, 2);
108 addNumButton(8, 1, 2);
109 addNumButton(9, 2, 2);
110
111 ButtonGrid.Append(new CUIButton($"+")
112 {
113 GridCell = new Point(3, 2),
114 });
115
116 ButtonGrid.Append(new CUIButton($"-")
117 {
118 GridCell = new Point(3, 1),
119 });
120
121 ButtonGrid.Append(new CUIButton($"=")
122 {
123 GridStartCell = new Point(2, 3),
124 GridEndCell = new Point(3, 3),
125 });
126
127 FakeMain.Append(mainframe);
128 }
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.
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
A Grid containing children in its cells.
Definition CUIGrid.cs:16
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

Member Data Documentation

◆ calculator

Calculator CrabUITest.CalculatorMod.calculator

Definition at line 44 of file Calc.cs.


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