CrabUI
Loading...
Searching...
No Matches
CUICommand.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 RandomTest : FillMethods
18 {
19 public class NestedWrapper : CUIComponent
20 {
21 public NestedWrapper()
22 {
23 Relative = new CUINullRect(0.1f, 0.1f, 0.8f, 0.8f);
24 }
25 }
26
27
28 public static void CUICommandTest(CUIComponent Main)
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 }
51
52
53 }
54}
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.
CUINullRect Relative
Relative to parent size and position, [0..1].
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