CrabUI
Loading...
Searching...
No Matches
CrabUI.CUIComponent Class Reference

Base class for all components. More...

Inheritance diagram for CrabUI.CUIComponent:
CrabUI.ICUIComponent CrabUI.ISimpleProps CrabUI.IListProps CrabUI.ISerializationProps CrabUI.CUICanvas CrabUI.CUIDropDown CrabUI.CUIFrame CrabUI.CUIGrid CrabUI.CUIHorizontalList CrabUI.CUIMainComponent CrabUI.CUIMap CrabUI.CUIMenuOption CrabUI.CUIPages CrabUI.CUIRadialMenu CrabUI.CUIRadialMenuOption CrabUI.CUISlider CrabUI.CUITextBlock CrabUI.CUITextInput CrabUI.CUITickBox CrabUI.CUIVerticalList

Public Member Functions

void AddAnimation (string name, CUIAnimation animation)
 
void BlockChildrenAnimations ()
 
void AttachTo (Item item, Action< Item, CUIComponent > callback=null)
 
void AddCommand (string name, Action< object > action)
 Manually adds command.
 
void RemoveCommand (string name)
 
void DispatchUp (CUICommand command)
 Dispathes command up the component tree until someone consumes it.
 
void DispatchDown (CUIData data)
 Dispathes command down the component tree until someone consumes it.
 
void Execute (CUICommand command)
 Will execute action corresponding to this command.
 
virtual partial void Draw (SpriteBatch spriteBatch)
 Here component should be drawn.
 
virtual partial void DrawFront (SpriteBatch spriteBatch)
 Method for drawing something that should always be on top, e.g. resize handles.
 
virtual partial void Draw (SpriteBatch spriteBatch)
 
virtual partial void DrawFront (SpriteBatch spriteBatch)
 
 CUIComponent (float? x=null, float? y=null, float? w=null, float? h=null)
 
void Dispose ()
 
virtual void CleanUp ()
 
override string ToString ()
 
void PrintTree (string offset="")
 
void Info (object msg, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
 Prints component and then message.
 
CUIComponent Remember (CUIComponent c, string name)
 
CUIComponent Remember (CUIComponent c)
 If it already has AKA.
 
CUIComponent Forget (string name)
 
CUIComponent Forget (CUIComponent c)
 If it already has AKA.
 
virtual CUIComponent Get (string name)
 Returns memorized component by name.
 
Get< T > (string name)
 
void CascadeRefresh ()
 
virtual bool IsPointOnTransparentPixel (Vector2 point)
 
virtual bool ShouldInvoke (CUIInput e)
 
void InvokeOnLayoutUpdated ()
 
record CompareResult (bool equal, string firstMismatch="")
 
CUIComponent Clone ()
 
void SaveStateAs (string name)
 
void LoadState (string name)
 
void ForgetState (string name)
 
void ApplyState (CUIComponent state)
 
virtual XElement ToXML (CUIAttribute propAttribute=CUIAttribute.CUISerializable)
 
virtual void FromXML (XElement element, string baseFolder=null)
 
string Serialize (CUIAttribute propAttribute=CUIAttribute.CUISerializable)
 
void LoadSelfFromFile (string path, bool searchForSpritesInTheSameFolder=true, bool saveAfterLoad=false)
 
void LoadFromTheSameFile ()
 
void SaveToTheSamePath ()
 
void SaveToFile (string path, CUIAttribute propAttribute=CUIAttribute.CUISerializable)
 
virtual void Hydrate ()
 Experimental method
Here you can add data/ callbacks/ save stuff to variables
after loading a xml skeletom.
 
virtual CUIComponent Append (CUIComponent child, string name=null, [CallerMemberName] string memberName="")
 Adds children to the end of the list.
 
virtual CUIComponent Prepend (CUIComponent child, string name=null, [CallerMemberName] string memberName="")
 Adds children to the begining of the list.
 
virtual CUIComponent Insert (CUIComponent child, int index, string name=null, [CallerMemberName] string memberName="")
 
void RemoveSelf ()
 
CUIComponent RemoveChild (CUIComponent child, [CallerMemberName] string memberName="")
 
void RemoveAllChildren ([CallerMemberName] string memberName="")
 
void MoveToFront ()
 Moves component to front in Parent.Children which makes it render after other childs.
 

Static Public Member Functions

static void RunRecursiveOn (CUIComponent component, Action< CUIComponent > action)
 designed to be versatile, in fact never used
 
static void ForEach (Action< CUIComponent > action)
 
static IEnumerable< Type > GetClassHierarchy (Type type)
 
static IEnumerable< Type > GetReverseClassHierarchy (Type type)
 
static bool DeepCompareVerbose (CUIComponent a, CUIComponent b)
 
static CompareResult DeepCompare (CUIComponent a, CUIComponent b)
 
static CUIComponent Deserialize (string raw, string baseFolder=null)
 
static CUIComponent Deserialize (XElement e, string baseFolder=null)
 
static CUIComponent LoadFromFile (string path, bool searchForSpritesInTheSameFolder=true, bool saveAfterLoad=false)
 
static T LoadFromFile< T > (string path, bool searchForSpritesInTheSameFolder=true, bool saveAfterLoad=false)
 

Public Attributes

Indexer< string, CUIAnimationAnimations
 
Dictionary< string, List< CUIComponent > > DataTargets = new()
 Consumers of emmited data, updates on tree change.
 
bool Disposed
 
bool ignoreDebug
 For debug frame itself.
 
CUIResizeHandle LeftResizeHandle = new CUIResizeHandle(new Vector2(0, 1), new CUIBool2(false, false))
 
CUIResizeHandle RightResizeHandle = new CUIResizeHandle(new Vector2(1, 1), new CUIBool2(true, false))
 

Static Public Attributes

static Dictionary< int, WeakReference< CUIComponent > > ComponentsById = new()
 
static WeakCatalog< Type, CUIComponentComponentsByType = new()
 
static GUIButton dummyComponent
 This is used to trick vanilla GUI into believing that mouse is hovering some component and block clicks.
 

Protected Member Functions

void ExtractProps (XElement element, string baseFolder=null)
 
void PackProps (XElement element, CUIAttribute propAttribute=CUIAttribute.CUISerializable)
 
virtual void PassPropsToChild (CUIComponent child)
 Pass props like ZIndex, Visible to a new child.
 

Protected Attributes

CUILayout layout
 
CUINullVector2 forsedSize
 
float scale = 1f
 
Color[] TextureData
 Buffer for texture data, for IgnoreTransparent checks.
 
bool disabled
 

Properties

AttachedItemHandle AttachedItemHandle [get, set]
 
string Command [get, set]
 This command will be dispatched up when some component specific event happens.
 
string Consumes [get, set]
 Will consume data with this name.
 
bool ReflectCommands [get, set]
 
bool RetranslateCommands [get, set]
 
ObservableCollection< string > Emits [get, set]
 Optimization to data flow
If not empty component will search for consumers of the data and pass it directly to them instead of broadcasting it.
 
Dictionary< string, Action< object > > Commands = new() [get, set]
 All commands.
 
static IEnumerable< CUIComponentAllComponents [get]
 
bool Debug [get, set]
 
bool IgnoreDebug [get, set]
 
string AKA [get, set]
 Parent can memorize it's children by their names, AKA.
 
Dictionary< string, CUIComponentNamedComponents = new() [get, set]
 All memorized components.
 
CUIComponent this[string name] [get, set]
 You can access NamedComponents with this indexer.
 
bool ConsumeMouseClicks [get, set]
 
bool ConsumeDragAndDrop [get, set]
 
bool ConsumeSwipe [get, set]
 
bool ConsumeMouseScroll [get, set]
 
Action< double > AddOnUpdate [set]
 
Action< CUIInputAddOnMouseLeave [set]
 
Action< CUIInputAddOnMouseEnter [set]
 
Action< CUIInputAddOnMouseDown [set]
 
Action< CUIInputAddOnMouseUp [set]
 
Action< CUIInputAddOnMouseMove [set]
 
Action< CUIInputAddOnMouseOn [set]
 
Action< CUIInputAddOnMouseOff [set]
 
Action< CUIInputAddOnClick [set]
 
Action< CUIInputAddOnDClick [set]
 
Action< CUIInputAddOnScroll [set]
 
Action< float, float > AddOnDrag [set]
 
Action< float, float > AddOnSwipe [set]
 
Action< CUIInputAddOnKeyDown [set]
 
Action< CUIInputAddOnKeyUp [set]
 
Action< CUIInputAddOnTextInput [set]
 
Action AddOnFocus [set]
 
Action AddOnFocusLost [set]
 
bool Draggable [get, set]
 
bool Focusable [get, set]
 
bool Resizible [get, set]
 
bool ResizibleLeft [get, set]
 
bool ResizibleRight [get, set]
 
CUIBool2 ResizeDirection [get, set]
 
bool Swipeable [get, set]
 
virtual CUILayout Layout [get, set]
 
Dictionary< string, CUIComponentStates = new() [get, set]
 State is just a clone component with copies of all props.
 
string SavePath [get, set]
 
int ID [get, set]
 Global ID, unique for component.
 
CUIMainComponent MainComponent [get, set]
 Link to CUIMainComponent, passed to children.
 
bool Focused [get, set]
 
bool BackgroundVisible [get, set]
 BackgroundColor != Color.Transparent.
 
bool OutlineVisible [get, set]
 
bool MouseOver [get, set]
 
bool MousePressed [get, set]
 
CUINullVector2 ForcedMinSize [get, set]
 This is used by text to prevent resizing beyond that and works as AbsoluteMin.
 
float Scale [get, set]
 This is set by ChildrenOffset when zooming, and iirc consumed by text to adjust text scale.
 
CUIRect BorderBox [get, set]
 Calculated Prop, Real + BorderThickness.
 
CUIRect OutlineBox [get, set]
 
CUIRect Real [get, set]
 Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent.Update.
 
CUIStyle Style [get, set]
 Allows you to assing parsable string or link to CUIPalette to any prop
It's indexable, so you can access it like this: component.Style["BackgroundColor"] = "cyan"
if value starts with "CUIPalette." it will extract the value from palette
e.g. component.Style["BackgroundColor"] = "CUIPalette.DarkBlue.Secondary.On"

 
CUIStyle ResolvedStyle [get, set]
 
List< CUIComponentChildren = new() [get, set]
 
CUIComponentParent [get, set]
 
IEnumerable< CUIComponentAddChildren [set]
 Allows you to add array of children.
 
CUIComponentProps CUIProps = new() [get, set]
 Just a wrapper for CUIProps idk how to separate them better.
 
Vector2 Padding [get, set]
 Used for text, should be in CUITextBlock really.
 
CUISprite BorderSprite = CUISprite.Default [get, set]
 Should be one texture, not sprite sheet
Or there would be no way to wrap it
Top side will always point outwards.
 
CUIBorder Border = new CUIBorder() [get, set]
 Container for Color and Thickness
Border is drawn inside the component and will eat space from content
If "by side" border prop != null then it'll take presidence.
 
CUIBorder TopBorder [get, set]
 
CUIBorder RigthBorder [get, set]
 
CUIBorder BottomBorder [get, set]
 
CUIBorder LeftBorder [get, set]
 
float OutlineThickness = 1f [get, set]
 
Color OutlineColor [get, set]
 Outline is like a border, but on the outside of the component.
 
CUISprite BackgroundSprite [get, set]
 Will be drawn in background with BackgroundColor
Default is solid white 1x1 texture.
 
bool IgnoreTransparent [get, set]
 If true, mouse events on transparent pixels will be ignored
Note: this will buffer texture data and potentially consume a lot of memory so use wisely.
 
Color BackgroundColor [get, set]
 Color of BackgroundSprite, default is black
If you're using custom sprite and don't see it make sure this color is not black.
 
float Transparency [get, set]
 
PaletteOrder Palette [get, set]
 This palette will be used to resolve palette styles
Primary, Secondary, Tertiary, Quaternary.
 
PaletteOrder DeepPalette [set]
 
Color ResizeHandleColor = Color.White [get, set]
 Had to expose resize handle props, because it's not a real component and can't really use styles.
 
Color ResizeHandleGrabbedColor = Color.Cyan [get, set]
 
SamplerState SamplerState [get, set]
 don't
 
bool HideChildrenOutsideFrame [get, set]
 Should children be cut off by scissor rect, this is just visual, it's not the same as culling.
 
bool CullChildren [get, set]
 if child rect doesn't intersect with parent it won't be drawn and won't consume fps
It also sets HideChildrenOutsideFrame
 
bool UnCullable [get, set]
 It shouldn't be culled off even outside of parent bounds and even if parent demands so.
 
CUI3DOffset ChildrenOffset [get, set]
 Will shift all children by this much, e.g. this is how scroll works It's also 3D.
 
Func< CUIRect, CUIBoundariesChildrenBoundaries [get, set]
 Limits to children positions.
 
bool Fixed [get, set]
 Should it ignore child offset?
 
Vector2 Anchor [get, set]
 this point of this component
 
Vector2? ParentAnchor [get, set]
 will be attached to this point of parent
 
CUIBool2 Ghost [get, set]
 Ghost components don't affect layout.
 
int? ZIndex [get, set]
 Components are drawn in order of their ZIndex
Normally it's derived from component position in the tree, but this will override it.
 
bool ResizeToSprite [get, set]
 If true component will set it's Absolute size to sprite texture size.
 
CUIBool2 FillEmptySpace [get, set]
 Will be resized to fill empty space in list components.
 
CUIBool2 FitContent [get, set]
 Will resize itself to fit components with absolute size, e.g. text.
 
CUINullRect Absolute [get, set]
 Absolute size and position in pixels.
 
CUINullRect AbsoluteMin [get, set]
 
CUINullRect AbsoluteMax [get, set]
 
CUINullRect Relative [get, set]
 Relative to parent size and position, [0..1].
 
CUINullRect RelativeMin [get, set]
 
CUINullRect RelativeMax [get, set]
 
CUINullRect CrossRelative [get, set]
 It's like Relative, but to the opposite dimension
E.g. Real.Width = CrossRelative.Width * Parent.Real.Height
Handy for creating square things.
 
string GridTemplateRows [get, set]
 Used in Grid, space separated Row sizes, either in pixels (123) or in % (123%)
 
string GridTemplateColumns [get, set]
 Used in Grid, space separated Columns sizes, either in pixels (123) or in % (123%)
 
Point? GridStartCell [get, set]
 Component will be placed in this cell in the grid component.
 
Point? GridEndCell [get, set]
 And resized to fit cells from GridStartCell to GridEndCell.
 
Point? GridCell [get, set]
 Sets both GridStartCell and GridEndCell at once.
 
object Data [get, set]
 Arbitrary data.
 
virtual bool Disabled [get, set]
 Usually means - non interactable, e.g. unclickable gray button.
 
bool ShouldPassPropsToChildren = true [get, set]
 Some props (like visible) are autopassed to all new childs see PassPropsToChild.
 
bool IgnoreParentVisibility [get, set]
 Don't inherit parent Visibility.
 
bool IgnoreParentEventIgnorance [get, set]
 Don't inherit parent IgnoreEvents.
 
bool IgnoreParentZIndex [get, set]
 Don't inherit parent ZIndex.
 
bool IgnoreParentTransparency [get, set]
 
bool Visible [get, set]
 Invisible components are not drawn, but still can be interacted with.
 
bool IgnoreEvents [get, set]
 Won't react to mouse events.
 
bool Revealed [get, set]
 Visible + !IgnoreEvents.
 
bool Serializable = true [get, set]
 If false then this component and its children won't be serialized.
 
bool SerializeChildren = true [get, set]
 Is this a serialization cutoff point
Parent will serialize children down to this component and stop.
 
bool MergeSerialization = false [get, set]
 If true it won't be deserialized,
Instead its children will be detached and attached to the component with matching AKA on the parent.
 
bool ReplaceSerialization = false [get, set]
 If true, deserialized component will replace existing component with the same AKA instead of creating a duplicate.
 
static bool ForceSaveAllProps = false [get, set]
 
- Properties inherited from CrabUI.ISimpleProps
- Properties inherited from CrabUI.IListProps
- Properties inherited from CrabUI.ISerializationProps

Events

Action< CUICommandOnAnyCommand
 this will be executed on any command
 
Action< CUIDataOnAnyData
 Will be executed when receiving any data.
 
Action< Object > OnConsume
 Happens when appropriate data is received.
 
Action OnTreeChanged
 
Action< double > OnUpdate
 
Action< CUIInputOnMouseLeave
 
Action< CUIInputOnMouseEnter
 
Action< CUIInputOnMouseDown
 
Action< CUIInputOnMouseUp
 
Action< CUIInputOnMouseMove
 
Action< CUIInputOnMouseOn
 
Action< CUIInputOnMouseOff
 
Action< CUIInputOnClick
 
Action< CUIInputOnDClick
 
Action< CUIInputOnScroll
 
Action< float, float > OnDrag
 
Action< float, float > OnSwipe
 
Action< CUIInputOnKeyDown
 
Action< CUIInputOnKeyUp
 
Action< CUIInputOnTextInput
 
Action OnFocus
 
Action OnFocusLost
 
Action OnLayoutUpdated
 
Action OnStyleApplied
 Use it to e.g. update component color.
 
Action< CUIComponentOnChildAdded
 
Action< CUIComponentOnChildRemoved
 

Detailed Description

Base class for all components.

Definition at line 19 of file Serialization Props.cs.

Constructor & Destructor Documentation

◆ CUIComponent() [1/2]

CrabUI.CUIComponent.CUIComponent ( )

Definition at line 208 of file CUIComponent.cs.

209 {
210 if (CUI.Disposed)
211 {
212 Disposed = true;
213 return;
214 }
215
216 ID = MaxID++;
217
218 ComponentsById[ID] = new WeakReference<CUIComponent>(this);
219 ComponentsByType.Add(this.GetType(), this);
220
221 Vitalize();
222 VitalizeProps();
223
224 SetupCommands();
225
226 Layout = new CUILayoutSimple();
227
228 SetupStyles();
229 SetupAnimations();
230 }
int ID
Global ID, unique for component.

◆ CUIComponent() [2/2]

CrabUI.CUIComponent.CUIComponent ( float? x = null,
float? y = null,
float? w = null,
float? h = null )

Definition at line 232 of file CUIComponent.cs.

232 : this()
233 {
234 Relative = new CUINullRect(x, y, w, h);
235 }
CUINullRect Relative
Relative to parent size and position, [0..1].

Member Function Documentation

◆ AddAnimation()

void CrabUI.CUIComponent.AddAnimation ( string name,
CUIAnimation animation )

Definition at line 31 of file CUIComponent.Animations.cs.

32 {
33 animation.Target = this;
34 animations[name] = animation;
35 }

◆ AddCommand()

void CrabUI.CUIComponent.AddCommand ( string name,
Action< object > action )

Manually adds command.

Parameters
name
action

◆ Append()

virtual CUIComponent CrabUI.CUIComponent.Append ( CUIComponent child,
string name = null,
[CallerMemberName] string memberName = "" )
virtual

Adds children to the end of the list.

Parameters
child
nameAKA
Returns
child

Definition at line 93 of file CUIComponent.Tree.cs.

94 {
95 if (child == null) return child;
96
97 child.Parent = this;
98 Children.Add(child);
99 if (name != null) Remember(child, name);
100
101 return child;
102 }

◆ ApplyState()

void CrabUI.CUIComponent.ApplyState ( CUIComponent state)

Definition at line 85 of file CUIComponent.Serialization.cs.

86 {
87 Stopwatch sw = Stopwatch.StartNew();
88 if (state == null) return;
89
90 //TODO why not closest relative?
91 Type targetType = state.GetType() == GetType() ? GetType() : typeof(CUIComponent);
92
93 CUITypeMetaData meta = CUITypeMetaData.Get(targetType);
94
95 //TODO Megacringe, fix it
96 foreach (PropertyInfo pi in meta.Serializable.Values)
97 {
98 if (pi.PropertyType.IsValueType || pi.PropertyType == typeof(string))
99 {
100 pi.SetValue(this, pi.GetValue(state));
101 }
102 else
103 {
104 object value = pi.GetValue(state);
105 if (value == null)
106 {
107 pi.SetValue(this, null);
108 continue;
109 }
110
111 if (pi.PropertyType.IsAssignableTo(typeof(ICloneable)))
112 {
113 ICloneable cloneable = (ICloneable)pi.GetValue(state);
114 object clone = cloneable.Clone();
115 pi.SetValue(this, clone);
116 }
117 else
118 {
119 CUI.Info($"Ekhem, can't copy {pi} prop from {state} to {this} because it's not cloneable");
120 }
121 }
122 }
123
124 //TODO Megacringe, fix it
125 foreach (PropertyInfo pi in meta.Serializable.Values)
126 {
127 if (pi.PropertyType.IsValueType && !object.Equals(pi.GetValue(state), pi.GetValue(this)))
128 {
129 pi.SetValue(this, pi.GetValue(state));
130 }
131 }
132
133 }

◆ BlockChildrenAnimations()

void CrabUI.CUIComponent.BlockChildrenAnimations ( )

Definition at line 37 of file CUIComponent.Animations.cs.

38 {
39 foreach (CUIComponent child in Children)
40 {
41 foreach (CUIAnimation animation in child.animations.Values)
42 {
43 animation.Stop();
44 animation.Blocked = true;
45 }
46 child.BlockChildrenAnimations();
47 }
48 }

◆ CascadeRefresh()

void CrabUI.CUIComponent.CascadeRefresh ( )

Definition at line 29 of file CUIComponent.Events.cs.

30 {
31 if (this is IRefreshable refreshable) refreshable.Refresh();
32 Children.ForEach(c => c.CascadeRefresh());
33 }

◆ CleanUp()

virtual void CrabUI.CUIComponent.CleanUp ( )
virtual

Definition at line 244 of file CUIComponent.cs.

244{ }

◆ Clone()

CUIComponent CrabUI.CUIComponent.Clone ( )

Definition at line 70 of file CUIComponent.Serialization.cs.

71 {
72 CUIComponent clone = new CUIComponent()
73 {
74 Unreal = true,
75 };
76 clone.ApplyState(this);
77 return clone;
78 }

◆ CompareResult()

record CrabUI.CUIComponent.CompareResult ( bool equal,
string firstMismatch = "" )

Definition at line 22 of file CUIComponent.Serialization.cs.

23 {
24 public static implicit operator bool(CompareResult r) => r.equal;
25 }

◆ DeepCompare()

static CompareResult CrabUI.CUIComponent.DeepCompare ( CUIComponent a,
CUIComponent b )
static

Definition at line 34 of file CUIComponent.Serialization.cs.

35 {
36 if (a.GetType() != b.GetType()) return new CompareResult(false, $"type mismatch: {a} | {b}");
37
38 Type T = a.GetType();
39 CUITypeMetaData meta = CUITypeMetaData.Get(T);
40
41 foreach (var (key, pi) in meta.Serializable)
42 {
43 if (!object.Equals(pi.GetValue(a), pi.GetValue(b)))
44 {
45 return new CompareResult(false, $"{pi}: {a}{pi.GetValue(a)} | {b}{pi.GetValue(b)}");
46 }
47 }
48
49 if (a.Children.Count != b.Children.Count)
50 {
51 return new CompareResult(false, $"child count mismatch: {a}{CUI.ArrayToString(a.Children)} | {b}{CUI.ArrayToString(b.Children)}");
52 }
53
54 for (int i = 0; i < a.Children.Count; i++)
55 {
56 CompareResult sub = DeepCompare(a.Children[i], b.Children[i]);
57 if (!sub.equal) return sub;
58 }
59
60 return new CompareResult(true);
61 }

◆ DeepCompareVerbose()

static bool CrabUI.CUIComponent.DeepCompareVerbose ( CUIComponent a,
CUIComponent b )
static

Definition at line 27 of file CUIComponent.Serialization.cs.

28 {
29 CompareResult result = DeepCompare(a, b);
30 if (result.equal) CUI.Log($"{a} == {b}");
31 else CUI.Log($"{result.firstMismatch}");
32 return result.equal;
33 }

◆ Deserialize() [1/2]

static CUIComponent CrabUI.CUIComponent.Deserialize ( string raw,
string baseFolder = null )
static

Definition at line 312 of file CUIComponent.Serialization.cs.

313 {
314 return Deserialize(XElement.Parse(raw));
315 }

◆ Deserialize() [2/2]

static CUIComponent CrabUI.CUIComponent.Deserialize ( XElement e,
string baseFolder = null )
static

Definition at line 317 of file CUIComponent.Serialization.cs.

318 {
319 try
320 {
321 Type type = CUIReflection.GetComponentTypeByName(e.Name.ToString());
322 if (type == null) return null;
323
324 CUIComponent c = (CUIComponent)Activator.CreateInstance(type);
325 // c.RemoveAllChildren();
326 c.FromXML(e, baseFolder);
327 CUIComponent.RunRecursiveOn(c, (component) => component.Hydrate());
328
329 return c;
330 }
331 catch (Exception ex)
332 {
333 CUIDebug.Error(ex);
334 return null;
335 }
336 }

◆ DispatchDown()

void CrabUI.CUIComponent.DispatchDown ( CUIData data)

Dispathes command down the component tree until someone consumes it.

Definition at line 195 of file CUIComponent.Commands.cs.

196 {
197 if (Emits.Contains(data.Name))
198 {
199 if (DataTargets.ContainsKey(data.Name))
200 {
201 foreach (CUIComponent target in DataTargets[data.Name])
202 {
203 target.OnConsume?.Invoke(data.Data);
204 }
205 }
206 }
207 else
208 {
209 if (Consumes == data.Name) OnConsume?.Invoke(data.Data);
210 else if (OnAnyData != null) OnAnyData.Invoke(data);
211 else
212 {
213 foreach (CUIComponent child in Children) child.DispatchDown(data);
214 }
215 }
216 }
string Consumes
Will consume data with this name.
Dictionary< string, List< CUIComponent > > DataTargets
Consumers of emmited data, updates on tree change.
ObservableCollection< string > Emits
Optimization to data flow If not empty component will search for consumers of the data and pass it ...
Action< Object > OnConsume
Happens when appropriate data is received.
Action< CUIData > OnAnyData
Will be executed when receiving any data.

◆ DispatchUp()

void CrabUI.CUIComponent.DispatchUp ( CUICommand command)

Dispathes command up the component tree until someone consumes it.

Parameters
command

Definition at line 185 of file CUIComponent.Commands.cs.

186 {
187 if (OnAnyCommand != null) OnAnyCommand?.Invoke(command);
188 else if (Commands.ContainsKey(command.Name)) Execute(command);
189 else Parent?.DispatchUp(command);
190 }
Dictionary< string, Action< object > > Commands
All commands.
Action< CUICommand > OnAnyCommand
this will be executed on any command
void Execute(CUICommand command)
Will execute action corresponding to this command.
void DispatchUp(CUICommand command)
Dispathes command up the component tree until someone consumes it.

◆ Dispose()

void CrabUI.CUIComponent.Dispose ( )

Definition at line 238 of file CUIComponent.cs.

239 {
240 if (Disposed) return;
241 CleanUp();
242 Disposed = true;
243 }

◆ Draw() [1/2]

virtual partial void CrabUI.CUIComponent.Draw ( SpriteBatch spriteBatch)
virtual

◆ Draw() [2/2]

virtual partial void CrabUI.CUIComponent.Draw ( SpriteBatch spriteBatch)
virtual

Reimplemented in CrabUI.CUIButton, CrabUI.CUIMagnifyingGlass, CrabUI.CUIMainComponent, CrabUI.CUISlider, CrabUI.CUITextBlock, CrabUI.CUITextInput, and CrabUI.CUIToggleButton.

Definition at line 145 of file CUIComponent.cs.

146 {
147 if (BackgroundVisible) CUI.DrawRectangle(spriteBatch, Real, BackgroundColor * Transparency, BackgroundSprite);
148
149 CUI.DrawBorders(spriteBatch, this);
150 // if (Border.Visible) GUI.DrawRectangle(spriteBatch, BorderBox.Position, BorderBox.Size, Border.Color, thickness: Border.Thickness);
151
152 if (OutlineVisible) GUI.DrawRectangle(spriteBatch, OutlineBox.Position, OutlineBox.Size, OutlineColor, thickness: OutlineThickness);
153 }
bool BackgroundVisible
BackgroundColor != Color.Transparent.
Color BackgroundColor
Color of BackgroundSprite, default is black If you're using custom sprite and don't see it make sur...
CUIRect Real
Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent....
Color OutlineColor
Outline is like a border, but on the outside of the component.
CUISprite BackgroundSprite
Will be drawn in background with BackgroundColor Default is solid white 1x1 texture.

◆ DrawFront() [1/2]

virtual partial void CrabUI.CUIComponent.DrawFront ( SpriteBatch spriteBatch)
virtual

Method for drawing something that should always be on top, e.g. resize handles.

Parameters
spriteBatch

◆ DrawFront() [2/2]

virtual partial void CrabUI.CUIComponent.DrawFront ( SpriteBatch spriteBatch)
virtual

Definition at line 155 of file CUIComponent.cs.

156 {
157 LeftResizeHandle.Draw(spriteBatch);
158 RightResizeHandle.Draw(spriteBatch);
159
160 if (DebugHighlight)
161 {
162 CUI.DrawTexture(spriteBatch, Real, CUITextureManager.Checkers, Color.White * 0.5f, CUISpriteDrawMode.Static);
163 }
164 }

◆ Execute()

void CrabUI.CUIComponent.Execute ( CUICommand command)

Will execute action corresponding to this command.

Parameters
commandName

Definition at line 222 of file CUIComponent.Commands.cs.

223 {
224 Commands.GetValueOrDefault(command.Name)?.Invoke(command.Data);
225 }

◆ ExtractProps()

void CrabUI.CUIComponent.ExtractProps ( XElement element,
string baseFolder = null )
protected

Definition at line 230 of file CUIComponent.Serialization.cs.

231 {
232 Type type = GetType();
233
234 CUITypeMetaData meta = CUITypeMetaData.Get(type);
235
236 foreach (XAttribute attribute in element.Attributes())
237 {
238 if (!meta.Serializable.ContainsKey(attribute.Name.ToString()))
239 {
240 CUI.Warning($"Can't parse prop {attribute.Name} in {type.Name} because type metadata doesn't contain that prop (is it a property? fields aren't supported yet)");
241 continue;
242 }
243
244 PropertyInfo prop = meta.Serializable[attribute.Name.ToString()];
245
246 try
247 {
248 if (prop.PropertyType == typeof(CUISprite) && baseFolder != null)
249 {
250 prop.SetValue(this, CUISprite.ParseWithContext(attribute.Value, baseFolder));
251 }
252 else
253 {
254 prop.SetValue(this, CUIParser.Parse(attribute.Value, prop.PropertyType, false));
255 }
256 }
257 catch (Exception e)
258 {
259 CUI.Warning($"Can't parse {attribute.Value} into {prop.PropertyType.Name}\n{e}");
260 }
261 }
262 }

◆ ForEach()

static void CrabUI.CUIComponent.ForEach ( Action< CUIComponent > action)
static

Definition at line 84 of file CUIComponent.cs.

85 {
86 foreach (int id in ComponentsById.Keys)
87 {
88 CUIComponent component = null;
89 ComponentsById[id].TryGetTarget(out component);
90 if (component is not null) action(component);
91 }
92 }

◆ Forget() [1/2]

CUIComponent CrabUI.CUIComponent.Forget ( CUIComponent c)

If it already has AKA.

Definition at line 109 of file CUIComponent.Debug.cs.

110 {
111 if (c?.AKA != null) NamedComponents.Remove(c.AKA);
112 return c;
113 }
Dictionary< string, CUIComponent > NamedComponents
All memorized components.
string AKA
Parent can memorize it's children by their names, AKA.

◆ Forget() [2/2]

CUIComponent CrabUI.CUIComponent.Forget ( string name)

Definition at line 99 of file CUIComponent.Debug.cs.

100 {
101 if (name == null) return null;
102 CUIComponent c = NamedComponents.GetValueOrDefault(name);
103 NamedComponents.Remove(name);
104 return c;
105 }

◆ FromXML()

virtual void CrabUI.CUIComponent.FromXML ( XElement element,
string baseFolder = null )
virtual

Definition at line 170 of file CUIComponent.Serialization.cs.

171 {
172 //RemoveAllChildren();
173
174 foreach (XElement childElement in element.Elements())
175 {
176 Type childType = CUIReflection.GetComponentTypeByName(childElement.Name.ToString());
177 if (childType == null) continue;
178
179 CUIComponent child = (CUIComponent)Activator.CreateInstance(childType);
180 child.FromXML(childElement, baseFolder);
181
182 if (child.MergeSerialization)
183 {
184 try
185 {
186 if (child.AKA == null || !this.NamedComponents.ContainsKey(child.AKA))
187 {
188 CUI.Warning($"Can't merge {child} into {this}");
189 CUI.Warning($"Merge deserialization requre matching AKA");
190 this.Append(child, child.AKA);
191 }
192 else
193 {
194 List<CUIComponent> children = new List<CUIComponent>(child.Children);
195 foreach (CUIComponent c in children)
196 {
197 this[child.AKA].Append(c);
198 }
199 }
200 }
201 catch (Exception e)
202 {
203 CUI.Warning($"Merge deserialization of {child} into {this}[{child.AKA}] failed");
204 CUI.Warning(e.Message);
205 }
206 }
207 else
208 {
209 if (child.AKA != null && this.NamedComponents.ContainsKey(child.AKA))
210 {
211 if (child.ReplaceSerialization)
212 {
213 this.RemoveChild(this[child.AKA]);
214 }
215 else
216 {
217 CUI.Warning($"{this} already contains {child.AKA}, so deserialization will create a duplicate\nTry using ReplaceSerialization or MergeSerialization");
218 }
219 }
220
221 this.Append(child, child.AKA);
222 }
223
224 //CUI.Log($"{this}[{child.AKA}] = {child} ");
225 }
226
227 ExtractProps(element, baseFolder);
228 }
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.

◆ Get()

virtual CUIComponent CrabUI.CUIComponent.Get ( string name)
virtual

Returns memorized component by name.

Parameters
name
Returns

Definition at line 135 of file CUIComponent.Debug.cs.

136 {
137 if (name == null) return null;
138 if (NamedComponents.ContainsKey(name)) return NamedComponents[name];
139
140 CUIComponent component = this;
141 string[] names = name.Split('.');
142
143 foreach (string n in names)
144 {
145 component = component.NamedComponents.GetValueOrDefault(n);
146
147 if (component == null)
148 {
149 CUI.Warning($"Failed to Get {name} from {this}, there's no {n}");
150 break;
151 }
152 }
153
154 return component;
155 }

◆ Get< T >()

T CrabUI.CUIComponent.Get< T > ( string name)
Type Constraints
T :CUIComponent 

◆ GetClassHierarchy()

static IEnumerable< Type > CrabUI.CUIComponent.GetClassHierarchy ( Type type)
static

Definition at line 94 of file CUIComponent.cs.

95 {
96 while (type != typeof(Object) && type != null)
97 {
98 yield return type;
99 type = type.BaseType;
100 }
101 }

◆ Hydrate()

virtual void CrabUI.CUIComponent.Hydrate ( )
virtual

Experimental method
Here you can add data/ callbacks/ save stuff to variables
after loading a xml skeletom.

Definition at line 449 of file CUIComponent.Serialization.cs.

450 {
451
452 }

◆ Info()

void CrabUI.CUIComponent.Info ( object msg,
[CallerFilePath] string source = "",
[CallerLineNumber] int lineNumber = 0 )

Prints component and then message.

Parameters
msg
source
lineNumber

Definition at line 64 of file CUIComponent.Debug.cs.

65 {
66 var fi = new FileInfo(source);
67
68 CUI.Log($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", Color.Yellow * 0.5f);
69 CUI.Log($"{this} {msg ?? "null"}", Color.Yellow);
70 }

◆ Insert()

virtual CUIComponent CrabUI.CUIComponent.Insert ( CUIComponent child,
int index,
string name = null,
[CallerMemberName] string memberName = "" )
virtual

Definition at line 121 of file CUIComponent.Tree.cs.

122 {
123 if (child == null) return child;
124
125 child.Parent = this;
126 index = Math.Clamp(index, 0, Children.Count);
127 Children.Insert(index, child);
128 if (name != null) Remember(child, name);
129
130 return child;
131 }

◆ IsPointOnTransparentPixel()

virtual bool CrabUI.CUIComponent.IsPointOnTransparentPixel ( Vector2 point)
virtual

Definition at line 76 of file CUIComponent.Events.cs.

77 {
78 if (BackgroundSprite.DrawMode != CUISpriteDrawMode.Resize) return true;
79
80 //TODO hangle case where offset != sprite.origin
81 Vector2 RotationCenter = new Vector2(
84 );
85
86 Vector2 v = (point - Real.Position - RotationCenter).Rotate(-BackgroundSprite.Rotation) + RotationCenter;
87
88 float x = v.X / Real.Width;
89 float y = v.Y / Real.Height;
90
91 Rectangle bounds = BackgroundSprite.Texture.Bounds;
92 Rectangle SourceRect = BackgroundSprite.SourceRect;
93
94 int textureX = (int)Math.Round(SourceRect.X + x * SourceRect.Width);
95 int textureY = (int)Math.Round(SourceRect.Y + y * SourceRect.Height);
96
97 if (textureX < SourceRect.X || (SourceRect.X + SourceRect.Width - 1) < textureX) return true;
98 if (textureY < SourceRect.Y || (SourceRect.Y + SourceRect.Height - 1) < textureY) return true;
99
100 Color cl = TextureData[textureY * bounds.Width + textureX];
101
102 return cl.A == 0;
103 }
Color[] TextureData
Buffer for texture data, for IgnoreTransparent checks.
Vector2 Offset
Draw offset from CUIComponent Position For your convenience also sets origin.
Definition CUISprite.cs:103
float Rotation
In radians.
Definition CUISprite.cs:73
Rectangle SourceRect
Part of the texture that is drawn Won't work in Wrap mode becase it will loop the whole texture.
Definition CUISprite.cs:55
CUISpriteDrawMode DrawMode
Resize - will resize the sprite to component Wrap - will loop the texture Static - sprite ignores...
Definition CUISprite.cs:50
Texture2D Texture
The link to the texture Multiple sprites can use the same texture.
Definition CUISprite.cs:62

◆ LoadFromFile()

static CUIComponent CrabUI.CUIComponent.LoadFromFile ( string path,
bool searchForSpritesInTheSameFolder = true,
bool saveAfterLoad = false )
static

Definition at line 359 of file CUIComponent.Serialization.cs.

360 {
361 try
362 {
363 XDocument xdoc = XDocument.Load(path);
364 CUIComponent result;
365 if (searchForSpritesInTheSameFolder)
366 {
367 result = Deserialize(xdoc.Root, Path.GetDirectoryName(path));
368 }
369 else result = Deserialize(xdoc.Root);
370
371 result.SavePath = path;
372
373 if (saveAfterLoad) result.SaveToTheSamePath();
374
375 return result;
376 }
377 catch (Exception ex)
378 {
379 CUIDebug.Error(ex);
380 return null;
381 }
382 }

◆ LoadFromFile< T >()

static T CrabUI.CUIComponent.LoadFromFile< T > ( string path,
bool searchForSpritesInTheSameFolder = true,
bool saveAfterLoad = false )
static
Type Constraints
T :CUIComponent 

Definition at line 384 of file CUIComponent.Serialization.cs.

384 : CUIComponent
385 {
386 try
387 {
388 XDocument xdoc = XDocument.Load(path);
389 T result;
390 if (searchForSpritesInTheSameFolder)
391 {
392 result = (T)Deserialize(xdoc.Root, Path.GetDirectoryName(path));
393 }
394 else result = (T)Deserialize(xdoc.Root);
395
396 result.SavePath = path;
397
398 if (saveAfterLoad) result.SaveToTheSamePath();
399
400 return result;
401 }
402 catch (Exception ex)
403 {
404 CUIDebug.Error(ex);
405 return null;
406 }
407 }

◆ LoadFromTheSameFile()

void CrabUI.CUIComponent.LoadFromTheSameFile ( )

Definition at line 409 of file CUIComponent.Serialization.cs.

410 {
411 if (SavePath == null)
412 {
413 CUI.Warning($"Can't load {this} from The Same Path, SavePath is null");
414 return;
415 }
416 LoadSelfFromFile(SavePath);
417 }

◆ LoadSelfFromFile()

void CrabUI.CUIComponent.LoadSelfFromFile ( string path,
bool searchForSpritesInTheSameFolder = true,
bool saveAfterLoad = false )

Definition at line 338 of file CUIComponent.Serialization.cs.

339 {
340 try
341 {
342 XDocument xdoc = XDocument.Load(path);
343
344 RemoveAllChildren();
345 if (searchForSpritesInTheSameFolder) FromXML(xdoc.Root, Path.GetDirectoryName(path));
346 else FromXML(xdoc.Root);
347
348 CUIComponent.RunRecursiveOn(this, (component) => component.Hydrate());
349 SavePath = path;
350
351 if (saveAfterLoad) SaveToTheSamePath();
352 }
353 catch (Exception ex)
354 {
355 CUI.Warning(ex);
356 }
357 }

◆ MoveToFront()

void CrabUI.CUIComponent.MoveToFront ( )

Moves component to front in Parent.Children which makes it render after other childs.

Definition at line 201 of file CUIComponent.Tree.cs.

202 {
203 if (Parent == null) return;
204
205 Parent.Children.Remove(this);
206 Parent.Children.Add(this);
207 TreeChanged = true;
208 }

◆ PackProps()

void CrabUI.CUIComponent.PackProps ( XElement element,
CUIAttribute propAttribute = CUIAttribute::CUISerializable )
protected

Definition at line 265 of file CUIComponent.Serialization.cs.

266 {
267 Type type = GetType();
268 CUITypeMetaData meta = CUITypeMetaData.Get(type);
269
270 SortedDictionary<string, PropertyInfo> props = propAttribute switch
271 {
272 CUIAttribute.CUISerializable => meta.Serializable,
273 CUIAttribute.Calculated => meta.Calculated,
274 _ => meta.Serializable,
275 };
276
277 foreach (string key in props.Keys)
278 {
279 try
280 {
281 object value = props[key].GetValue(this);
282 // it's default value for this prop
283 if (!ForceSaveAllProps && meta.Default != null && Object.Equals(value, CUIReflection.GetNestedValue(meta.Default, key)))
284 {
285 continue;
286 }
287
288 element?.SetAttributeValue(key, CUIParser.Serialize(value, false));
289 }
290 catch (Exception e)
291 {
292 CUI.Warning($"Failed to serialize prop: {e.Message}");
293 CUI.Warning($"{key} in {this}");
294 }
295 }
296 }

◆ PassPropsToChild()

virtual void CrabUI.CUIComponent.PassPropsToChild ( CUIComponent child)
protectedvirtual

Pass props like ZIndex, Visible to a new child.

Parameters
child

Definition at line 187 of file CUIComponent.Tree.cs.

188 {
189 if (!ShouldPassPropsToChildren) return;
190
191 //child.Palette = Palette;
192 if (ZIndex.HasValue && !child.IgnoreParentZIndex) child.ZIndex = ZIndex.Value + 1;
193 if (IgnoreEvents && !child.IgnoreParentEventIgnorance) child.IgnoreEvents = true;
194 if (!Visible && !child.IgnoreParentVisibility) child.Visible = false;
195 }
int? ZIndex
Components are drawn in order of their ZIndex Normally it's derived from component position in the ...
bool Visible
Invisible components are not drawn, but still can be interacted with.
bool IgnoreEvents
Won't react to mouse events.
bool ShouldPassPropsToChildren
Some props (like visible) are autopassed to all new childs see PassPropsToChild.

◆ Prepend()

virtual CUIComponent CrabUI.CUIComponent.Prepend ( CUIComponent child,
string name = null,
[CallerMemberName] string memberName = "" )
virtual

Adds children to the begining of the list.

Parameters
child
nameAKA
Returns
child

Definition at line 110 of file CUIComponent.Tree.cs.

111 {
112 if (child == null) return child;
113
114 child.Parent = this;
115 Children.Insert(0, child);
116 if (name != null) Remember(child, name);
117
118 return child;
119 }

◆ PrintTree()

void CrabUI.CUIComponent.PrintTree ( string offset = "")

Definition at line 49 of file CUIComponent.Debug.cs.

50 {
51 CUI.Log($"{offset}{this}");
52 foreach (CUIComponent child in Children)
53 {
54 child.PrintTree(offset + "| ");
55 }
56 }

◆ Remember() [1/2]

CUIComponent CrabUI.CUIComponent.Remember ( CUIComponent c)

If it already has AKA.

Definition at line 93 of file CUIComponent.Debug.cs.

94 {
95 if (c.AKA != null) NamedComponents[c.AKA] = c;
96 return c;
97 }

◆ Remember() [2/2]

CUIComponent CrabUI.CUIComponent.Remember ( CUIComponent c,
string name )

Definition at line 84 of file CUIComponent.Debug.cs.

85 {
86 NamedComponents[name] = c;
87 c.AKA = name;
88 return c;
89 }

◆ RemoveAllChildren()

void CrabUI.CUIComponent.RemoveAllChildren ( [CallerMemberName] string memberName = "")

Definition at line 160 of file CUIComponent.Tree.cs.

161 {
162 foreach (CUIComponent c in Children)
163 {
164 if (this != null) // kek
165 {
166 c.TreeChanged = true;
167 c.OnPropChanged();
168 //Forget(c);
169 //Children.Remove(c);
170 OnChildRemoved?.Invoke(c);
171 }
172
173 c.parent = null;
174
175 CUIDebug.Capture(null, this, "RemoveAllChildren", memberName, "child", $"{c}");
176 }
177
178 NamedComponents.Clear();
179 Children.Clear();
180 }

◆ RemoveChild()

CUIComponent CrabUI.CUIComponent.RemoveChild ( CUIComponent child,
[CallerMemberName] string memberName = "" )

Definition at line 135 of file CUIComponent.Tree.cs.

136 {
137 if (child == null || !Children.Contains(child)) return child;
138
139 if (this != null) // kek
140 {
141 child.TreeChanged = true;
142 child.OnPropChanged();
143 //HACK i'm sure it doesn't belong here, find a better place
144 forsedSize = new CUINullVector2();
145 OnAbsolutePropChanged();
146 // Forget(child);
147 Children.Remove(child);
148 OnChildRemoved?.Invoke(child);
149 }
150
151 child.parent = null;
152
153 CUIDebug.Capture(null, this, "RemoveChild", memberName, "child", $"{child}");
154
155 return child;
156 }

◆ RunRecursiveOn()

static void CrabUI.CUIComponent.RunRecursiveOn ( CUIComponent component,
Action< CUIComponent > action )
static

designed to be versatile, in fact never used

Definition at line 74 of file CUIComponent.cs.

75 {
76 action(component);
77 foreach (CUIComponent child in component.Children)
78 {
79 RunRecursiveOn(child, action);
80 }
81 }
static void RunRecursiveOn(CUIComponent component, Action< CUIComponent > action)
designed to be versatile, in fact never used

◆ SaveToFile()

void CrabUI.CUIComponent.SaveToFile ( string path,
CUIAttribute propAttribute = CUIAttribute::CUISerializable )

Definition at line 429 of file CUIComponent.Serialization.cs.

430 {
431 try
432 {
433 XDocument xdoc = new XDocument();
434 xdoc.Add(this.ToXML(propAttribute));
435 xdoc.Save(path);
436 SavePath = path;
437 }
438 catch (Exception e)
439 {
440 CUI.Warning(e);
441 }
442 }

◆ SaveToTheSamePath()

void CrabUI.CUIComponent.SaveToTheSamePath ( )

Definition at line 419 of file CUIComponent.Serialization.cs.

420 {
421 if (SavePath == null)
422 {
423 CUI.Warning($"Can't save {this} To The Same Path, SavePath is null");
424 return;
425 }
426 SaveToFile(SavePath);
427 }

◆ Serialize()

string CrabUI.CUIComponent.Serialize ( CUIAttribute propAttribute = CUIAttribute::CUISerializable)

Definition at line 299 of file CUIComponent.Serialization.cs.

300 {
301 try
302 {
303 XElement e = this.ToXML(propAttribute);
304 return e.ToString();
305 }
306 catch (Exception e)
307 {
308 CUI.Error(e);
309 return e.Message;
310 }
311 }

◆ ShouldInvoke()

virtual bool CrabUI.CUIComponent.ShouldInvoke ( CUIInput e)
virtual

Definition at line 106 of file CUIComponent.Events.cs.

107 {
109 {
110 return !IsPointOnTransparentPixel(e.MousePosition);
111 }
112
113 return true;
114 }
bool IgnoreTransparent
If true, mouse events on transparent pixels will be ignored Note: this will buffer texture data and...

◆ ToXML()

virtual XElement CrabUI.CUIComponent.ToXML ( CUIAttribute propAttribute = CUIAttribute::CUISerializable)
virtual

Definition at line 140 of file CUIComponent.Serialization.cs.

141 {
142 try
143 {
144 if (!Serializable) return null;
145
146 Type type = GetType();
147
148 XElement e = new XElement(type.Name);
149
150 PackProps(e, propAttribute);
151
152 foreach (CUIComponent child in Children)
153 {
154 if (this.SerializeChildren)
155 {
156 e.Add(child.ToXML(propAttribute));
157 }
158 }
159
160 return e;
161 }
162 catch (Exception e)
163 {
164 CUI.Warning(e);
165 return new XElement("Error", e.Message);
166 }
167 }
bool SerializeChildren
Is this a serialization cutoff point Parent will serialize children down to this component and stop...
bool Serializable
If false then this component and its children won't be serialized.

Member Data Documentation

◆ Animations

Indexer<string, CUIAnimation> CrabUI.CUIComponent.Animations

Definition at line 30 of file CUIComponent.Animations.cs.

◆ ComponentsById

Dictionary<int, WeakReference<CUIComponent> > CrabUI.CUIComponent.ComponentsById = new()
static

Definition at line 52 of file CUIComponent.cs.

◆ ComponentsByType

WeakCatalog<Type, CUIComponent> CrabUI.CUIComponent.ComponentsByType = new()
static

Definition at line 61 of file CUIComponent.cs.

◆ DataTargets

Dictionary<string, List<CUIComponent> > CrabUI.CUIComponent.DataTargets = new()

Consumers of emmited data, updates on tree change.

Definition at line 138 of file CUIComponent.Commands.cs.

◆ disabled

bool CrabUI.CUIComponent.disabled
protected

Definition at line 26 of file Other Props.cs.

◆ Disposed

bool CrabUI.CUIComponent.Disposed

Definition at line 237 of file CUIComponent.cs.

◆ dummyComponent

GUIButton CrabUI.CUIComponent.dummyComponent
static
Initial value:
= new GUIButton(new RectTransform(new Point(0, 0)))
{
Text = "DUMMY",
}

This is used to trick vanilla GUI into believing that mouse is hovering some component and block clicks.

Definition at line 67 of file CUIComponent.cs.

68 {
69 Text = "DUMMY",
70 };

◆ forsedSize

CUINullVector2 CrabUI.CUIComponent.forsedSize
protected

Definition at line 85 of file CUIComponent.State.cs.

◆ ignoreDebug

bool CrabUI.CUIComponent.ignoreDebug

For debug frame itself.

Definition at line 39 of file CUIComponent.Debug.cs.

◆ layout

CUILayout CrabUI.CUIComponent.layout
protected

Definition at line 23 of file CUIComponent.Layout.cs.

◆ LeftResizeHandle

CUIResizeHandle CrabUI.CUIComponent.LeftResizeHandle = new CUIResizeHandle(new Vector2(0, 1), new CUIBool2(false, false))

Definition at line 153 of file CUIComponent.Events.cs.

◆ RightResizeHandle

CUIResizeHandle CrabUI.CUIComponent.RightResizeHandle = new CUIResizeHandle(new Vector2(1, 1), new CUIBool2(true, false))

Definition at line 154 of file CUIComponent.Events.cs.

◆ scale

float CrabUI.CUIComponent.scale = 1f
protected

Definition at line 103 of file CUIComponent.State.cs.

◆ TextureData

Color [] CrabUI.CUIComponent.TextureData
protected

Buffer for texture data, for IgnoreTransparent checks.

Definition at line 119 of file CUIComponent.State.cs.

Property Documentation

◆ Absolute

CUINullRect CrabUI.CUIComponent.Absolute
getset

Absolute size and position in pixels.

Implements CrabUI.ISimpleProps.

Definition at line 123 of file Layout Props.cs.

124 {
125 get => CUIProps.Absolute.Value;
126 set => CUIProps.Absolute.SetValue(value);
127 }
CUIComponentProps CUIProps
Just a wrapper for CUIProps idk how to separate them better.
Definition CUIProps.cs:27

◆ AbsoluteMax

CUINullRect CrabUI.CUIComponent.AbsoluteMax
getset

Implements CrabUI.ISimpleProps.

Definition at line 135 of file Layout Props.cs.

136 {
137 get => CUIProps.AbsoluteMax.Value;
138 set => CUIProps.AbsoluteMax.SetValue(value);
139 }

◆ AbsoluteMin

CUINullRect CrabUI.CUIComponent.AbsoluteMin
getset

Implements CrabUI.ISimpleProps.

Definition at line 129 of file Layout Props.cs.

130 {
131 get => CUIProps.AbsoluteMin.Value;
132 set => CUIProps.AbsoluteMin.SetValue(value);
133 }

◆ AddChildren

IEnumerable<CUIComponent> CrabUI.CUIComponent.AddChildren
set

Allows you to add array of children.

Definition at line 80 of file CUIComponent.Tree.cs.

80{ set { foreach (CUIComponent c in value) { Append(c); } } }

◆ AddOnClick

Action<CUIInput> CrabUI.CUIComponent.AddOnClick
set

Definition at line 64 of file CUIComponent.Events.cs.

64{ set { OnClick += value; } }

◆ AddOnDClick

Action<CUIInput> CrabUI.CUIComponent.AddOnDClick
set

Definition at line 65 of file CUIComponent.Events.cs.

65{ set { OnDClick += value; } }

◆ AddOnDrag

Action<float, float> CrabUI.CUIComponent.AddOnDrag
set

Definition at line 67 of file CUIComponent.Events.cs.

67{ set { OnDrag += value; } }

◆ AddOnFocus

Action CrabUI.CUIComponent.AddOnFocus
set

Definition at line 72 of file CUIComponent.Events.cs.

72{ set { OnFocus += value; } }

◆ AddOnFocusLost

Action CrabUI.CUIComponent.AddOnFocusLost
set

Definition at line 73 of file CUIComponent.Events.cs.

73{ set { OnFocusLost += value; } }

◆ AddOnKeyDown

Action<CUIInput> CrabUI.CUIComponent.AddOnKeyDown
set

Definition at line 69 of file CUIComponent.Events.cs.

69{ set { OnKeyDown += value; } }

◆ AddOnKeyUp

Action<CUIInput> CrabUI.CUIComponent.AddOnKeyUp
set

Definition at line 70 of file CUIComponent.Events.cs.

70{ set { OnKeyUp += value; } }

◆ AddOnMouseDown

Action<CUIInput> CrabUI.CUIComponent.AddOnMouseDown
set

Definition at line 59 of file CUIComponent.Events.cs.

59{ set { OnMouseDown += value; } }

◆ AddOnMouseEnter

Action<CUIInput> CrabUI.CUIComponent.AddOnMouseEnter
set

Definition at line 58 of file CUIComponent.Events.cs.

58{ set { OnMouseEnter += value; } }

◆ AddOnMouseLeave

Action<CUIInput> CrabUI.CUIComponent.AddOnMouseLeave
set

Definition at line 57 of file CUIComponent.Events.cs.

57{ set { OnMouseLeave += value; } }

◆ AddOnMouseMove

Action<CUIInput> CrabUI.CUIComponent.AddOnMouseMove
set

Definition at line 61 of file CUIComponent.Events.cs.

61{ set { OnMouseMove += value; } }

◆ AddOnMouseOff

Action<CUIInput> CrabUI.CUIComponent.AddOnMouseOff
set

Definition at line 63 of file CUIComponent.Events.cs.

63{ set { OnMouseOff += value; } }

◆ AddOnMouseOn

Action<CUIInput> CrabUI.CUIComponent.AddOnMouseOn
set

Definition at line 62 of file CUIComponent.Events.cs.

62{ set { OnMouseOn += value; } }

◆ AddOnMouseUp

Action<CUIInput> CrabUI.CUIComponent.AddOnMouseUp
set

Definition at line 60 of file CUIComponent.Events.cs.

60{ set { OnMouseUp += value; } }

◆ AddOnScroll

Action<CUIInput> CrabUI.CUIComponent.AddOnScroll
set

Definition at line 66 of file CUIComponent.Events.cs.

66{ set { OnScroll += value; } }

◆ AddOnSwipe

Action<float, float> CrabUI.CUIComponent.AddOnSwipe
set

Definition at line 68 of file CUIComponent.Events.cs.

68{ set { OnSwipe += value; } }

◆ AddOnTextInput

Action<CUIInput> CrabUI.CUIComponent.AddOnTextInput
set

Definition at line 71 of file CUIComponent.Events.cs.

71{ set { OnTextInput += value; } }

◆ AddOnUpdate

Action<double> CrabUI.CUIComponent.AddOnUpdate
set

Definition at line 56 of file CUIComponent.Events.cs.

56{ set { OnUpdate += value; } }

◆ AKA

string CrabUI.CUIComponent.AKA
getset

Parent can memorize it's children by their names, AKA.

Definition at line 78 of file CUIComponent.Debug.cs.

78{ get; set; }

◆ AllComponents

IEnumerable<CUIComponent> CrabUI.CUIComponent.AllComponents
staticget

Definition at line 53 of file CUIComponent.cs.

◆ Anchor

Vector2 CrabUI.CUIComponent.Anchor
getset

this point of this component

Definition at line 63 of file Layout Props.cs.

63{ get; set; }

◆ AttachedItemHandle

AttachedItemHandle CrabUI.CUIComponent.AttachedItemHandle
getset

Definition at line 23 of file CUIComponent.Attached Item.cs.

23{ get; set; }

◆ BackgroundColor

Color CrabUI.CUIComponent.BackgroundColor
getset

Color of BackgroundSprite, default is black
If you're using custom sprite and don't see it make sure this color is not black.

Definition at line 89 of file Graphic Props.cs.

90 {
91 get => CUIProps.BackgroundColor.Value;
92 set => CUIProps.BackgroundColor.SetValue(value);
93 }

◆ BackgroundSprite

CUISprite CrabUI.CUIComponent.BackgroundSprite
getset

Will be drawn in background with BackgroundColor
Default is solid white 1x1 texture.

Definition at line 66 of file Graphic Props.cs.

67 {
68 get => CUIProps.BackgroundSprite.Value;
69 set => CUIProps.BackgroundSprite.SetValue(value);
70 }

◆ BackgroundVisible

bool CrabUI.CUIComponent.BackgroundVisible
getsetprotected

BackgroundColor != Color.Transparent.

Definition at line 56 of file CUIComponent.State.cs.

56{ get; set; }

◆ Border

CUIBorder CrabUI.CUIComponent.Border = new CUIBorder()
getset

Container for Color and Thickness
Border is drawn inside the component and will eat space from content
If "by side" border prop != null then it'll take presidence.

Definition at line 43 of file Graphic Props.cs.

43{ get; set; } = new CUIBorder();

◆ BorderBox

CUIRect CrabUI.CUIComponent.BorderBox
getsetprotected

Calculated Prop, Real + BorderThickness.

Definition at line 113 of file CUIComponent.State.cs.

113{ get; set; }

◆ BorderSprite

CUISprite CrabUI.CUIComponent.BorderSprite = CUISprite.Default
getset

Should be one texture, not sprite sheet
Or there would be no way to wrap it
Top side will always point outwards.

Definition at line 36 of file Graphic Props.cs.

36{ get; set; } = CUISprite.Default;

◆ BottomBorder

CUIBorder CrabUI.CUIComponent.BottomBorder
getset

Definition at line 46 of file Graphic Props.cs.

46{ get; set; }

◆ Children

List<CUIComponent> CrabUI.CUIComponent.Children = new()
getset

Definition at line 23 of file CUIComponent.Tree.cs.

23{ get; set; } = new();

◆ ChildrenBoundaries

Func<CUIRect, CUIBoundaries> CrabUI.CUIComponent.ChildrenBoundaries
getset

Limits to children positions.

Definition at line 54 of file Layout Props.cs.

54{ get; set; }

◆ ChildrenOffset

CUI3DOffset CrabUI.CUIComponent.ChildrenOffset
getset

Will shift all children by this much, e.g. this is how scroll works It's also 3D.

Definition at line 45 of file Layout Props.cs.

46 {
47 get => CUIProps.ChildrenOffset.Value;
48 set => CUIProps.ChildrenOffset.SetValue(value);
49 }

◆ Command

string CrabUI.CUIComponent.Command
getset

This command will be dispatched up when some component specific event happens.

Definition at line 49 of file CUIComponent.Commands.cs.

49{ get; set; }

◆ Commands

Dictionary<string, Action<object> > CrabUI.CUIComponent.Commands = new()
getset

All commands.

Definition at line 144 of file CUIComponent.Commands.cs.

144{ get; set; } = new();

◆ ConsumeDragAndDrop

bool CrabUI.CUIComponent.ConsumeDragAndDrop
getset

Definition at line 24 of file CUIComponent.Events.cs.

24{ get; set; }

◆ ConsumeMouseClicks

bool CrabUI.CUIComponent.ConsumeMouseClicks
getset

Definition at line 23 of file CUIComponent.Events.cs.

23{ get; set; }

◆ ConsumeMouseScroll

bool CrabUI.CUIComponent.ConsumeMouseScroll
getset

Definition at line 26 of file CUIComponent.Events.cs.

26{ get; set; }

◆ Consumes

string CrabUI.CUIComponent.Consumes
getset

Will consume data with this name.

Definition at line 65 of file CUIComponent.Commands.cs.

65{ get; set; }

◆ ConsumeSwipe

bool CrabUI.CUIComponent.ConsumeSwipe
getset

Definition at line 25 of file CUIComponent.Events.cs.

25{ get; set; }

◆ CrossRelative

CUINullRect CrabUI.CUIComponent.CrossRelative
getset

It's like Relative, but to the opposite dimension
E.g. Real.Width = CrossRelative.Width * Parent.Real.Height
Handy for creating square things.

Implements CrabUI.ISimpleProps.

Definition at line 167 of file Layout Props.cs.

168 {
169 get => CUIProps.CrossRelative.Value;
170 set => CUIProps.CrossRelative.SetValue(value);
171 }

◆ CUIProps

CUIComponentProps CrabUI.CUIComponent.CUIProps = new()
getset

Just a wrapper for CUIProps idk how to separate them better.

Definition at line 27 of file CUIProps.cs.

27{ get; set; } = new();

◆ CullChildren

bool CrabUI.CUIComponent.CullChildren
getset

if child rect doesn't intersect with parent it won't be drawn and won't consume fps
It also sets HideChildrenOutsideFrame

Definition at line 30 of file Layout Props.cs.

31 {
32 get => CUIProps.CullChildren.Value;
33 set => CUIProps.CullChildren.SetValue(value);
34 }

◆ Data

object CrabUI.CUIComponent.Data
getset

Arbitrary data.

Definition at line 25 of file Other Props.cs.

25{ get; set; }

◆ Debug

bool CrabUI.CUIComponent.Debug
getset

Definition at line 26 of file CUIComponent.Debug.cs.

27 {
28 get => debug;
29 set
30 {
31 debug = value;
32 //foreach (CUIComponent c in Children) { c.Debug = value; }
33 }
34 }

◆ DeepPalette

PaletteOrder CrabUI.CUIComponent.DeepPalette
set

Definition at line 118 of file Graphic Props.cs.

119 {
120 set
121 {
122 Palette = value;
123 foreach (var child in Children)
124 {
125 child.DeepPalette = value;
126 }
127 }
128 }
PaletteOrder Palette
This palette will be used to resolve palette styles Primary, Secondary, Tertiary,...

◆ Disabled

virtual bool CrabUI.CUIComponent.Disabled
getset

Usually means - non interactable, e.g. unclickable gray button.

Definition at line 31 of file Other Props.cs.

32 {
33 get => disabled;
34 set => disabled = value;
35 }

◆ Draggable

bool CrabUI.CUIComponent.Draggable
getset

Definition at line 140 of file CUIComponent.Events.cs.

141 {
142 get => DragHandle.Draggable;
143 set => DragHandle.Draggable = value;
144 }

◆ Emits

ObservableCollection<string> CrabUI.CUIComponent.Emits
getset

Optimization to data flow
If not empty component will search for consumers of the data and pass it directly to them instead of broadcasting it.

Definition at line 106 of file CUIComponent.Commands.cs.

107 {
108 get => emits;
109 set
110 {
111 emits = value;
112 emits.CollectionChanged += (o, e) => UpdateDataTargets();
113 UpdateDataTargets();
114 }
115 }

◆ FillEmptySpace

CUIBool2 CrabUI.CUIComponent.FillEmptySpace
getset

Will be resized to fill empty space in list components.

Implements CrabUI.IListProps.

Definition at line 105 of file Layout Props.cs.

106 {
107 get => CUIProps.FillEmptySpace.Value;
108 set => CUIProps.FillEmptySpace.SetValue(value);
109 }

◆ FitContent

CUIBool2 CrabUI.CUIComponent.FitContent
getset

Will resize itself to fit components with absolute size, e.g. text.

Implements CrabUI.ISimpleProps.

Definition at line 114 of file Layout Props.cs.

115 {
116 get => CUIProps.FitContent.Value;
117 set => CUIProps.FitContent.SetValue(value);
118 }

◆ Fixed

bool CrabUI.CUIComponent.Fixed
getset

Should it ignore child offset?

Definition at line 59 of file Layout Props.cs.

59{ get; set; }

◆ Focusable

bool CrabUI.CUIComponent.Focusable
getset

Definition at line 148 of file CUIComponent.Events.cs.

149 {
150 get => FocusHandle.Focusable;
151 set => FocusHandle.Focusable = value;
152 }

◆ Focused

bool CrabUI.CUIComponent.Focused
getset

Definition at line 46 of file CUIComponent.State.cs.

46{ get; set; }

◆ ForcedMinSize

CUINullVector2 CrabUI.CUIComponent.ForcedMinSize
getset

This is used by text to prevent resizing beyond that and works as AbsoluteMin.

Definition at line 80 of file CUIComponent.State.cs.

81 {
82 get => forsedSize;
83 set => SetForcedMinSize(value);
84 }

◆ ForceSaveAllProps

bool CrabUI.CUIComponent.ForceSaveAllProps = false
staticgetset

Implements CrabUI.ISerializationProps.

Definition at line 41 of file Serialization Props.cs.

41{ get; set; } = false;

◆ Ghost

CUIBool2 CrabUI.CUIComponent.Ghost
getset

Ghost components don't affect layout.

Implements CrabUI.ISimpleProps.

Definition at line 73 of file Layout Props.cs.

74 {
75 get => CUIProps.Ghost.Value;
76 set => CUIProps.Ghost.SetValue(value);
77 }

◆ GridCell

Point? CrabUI.CUIComponent.GridCell
getset

Sets both GridStartCell and GridEndCell at once.

Definition at line 192 of file Layout Props.cs.

193 {
194 get => GridStartCell;
195 set
196 {
197 GridStartCell = value;
198 GridEndCell = value;
199 }
200 }
Point? GridStartCell
Component will be placed in this cell in the grid component.
Point? GridEndCell
And resized to fit cells from GridStartCell to GridEndCell.

◆ GridEndCell

Point? CrabUI.CUIComponent.GridEndCell
getset

And resized to fit cells from GridStartCell to GridEndCell.

Definition at line 188 of file Layout Props.cs.

188{ get; set; }

◆ GridStartCell

Point? CrabUI.CUIComponent.GridStartCell
getset

Component will be placed in this cell in the grid component.

Definition at line 184 of file Layout Props.cs.

184{ get; set; }

◆ GridTemplateColumns

string CrabUI.CUIComponent.GridTemplateColumns
getset

Used in Grid, space separated Columns sizes, either in pixels (123) or in % (123%)

Definition at line 180 of file Layout Props.cs.

180{ get; set; }

◆ GridTemplateRows

string CrabUI.CUIComponent.GridTemplateRows
getset

Used in Grid, space separated Row sizes, either in pixels (123) or in % (123%)

Definition at line 176 of file Layout Props.cs.

176{ get; set; }

◆ HideChildrenOutsideFrame

bool CrabUI.CUIComponent.HideChildrenOutsideFrame
getset

Should children be cut off by scissor rect, this is just visual, it's not the same as culling.

Definition at line 24 of file Layout Props.cs.

24{ get; set; }

◆ ID

int CrabUI.CUIComponent.ID
getset

Global ID, unique for component.

Definition at line 25 of file CUIComponent.State.cs.

25{ get; set; }

◆ IgnoreDebug

bool CrabUI.CUIComponent.IgnoreDebug
getset

Definition at line 39 of file CUIComponent.Debug.cs.

40 {
41 get => ignoreDebug || Unreal;
42 set
43 {
44 ignoreDebug = value;
45 foreach (CUIComponent c in Children) { c.IgnoreDebug = value; }
46 }
47 }
bool ignoreDebug
For debug frame itself.

◆ IgnoreEvents

bool CrabUI.CUIComponent.IgnoreEvents
getset

Won't react to mouse events.

Definition at line 68 of file Other Props.cs.

69 {
70 get => CUIProps.IgnoreEvents.Value;
71 set => CUIProps.IgnoreEvents.SetValue(value);
72 }

◆ IgnoreParentEventIgnorance

bool CrabUI.CUIComponent.IgnoreParentEventIgnorance
getset

Don't inherit parent IgnoreEvents.

Definition at line 48 of file Other Props.cs.

48{ get; set; }

◆ IgnoreParentTransparency

bool CrabUI.CUIComponent.IgnoreParentTransparency
getset

Definition at line 53 of file Other Props.cs.

53{ get; set; }

◆ IgnoreParentVisibility

bool CrabUI.CUIComponent.IgnoreParentVisibility
getset

Don't inherit parent Visibility.

Definition at line 44 of file Other Props.cs.

44{ get; set; }

◆ IgnoreParentZIndex

bool CrabUI.CUIComponent.IgnoreParentZIndex
getset

Don't inherit parent ZIndex.

Definition at line 52 of file Other Props.cs.

52{ get; set; }

◆ IgnoreTransparent

bool CrabUI.CUIComponent.IgnoreTransparent
getset

If true, mouse events on transparent pixels will be ignored
Note: this will buffer texture data and potentially consume a lot of memory so use wisely.

Definition at line 77 of file Graphic Props.cs.

78 {
79 get => CUIProps.IgnoreTransparent.Value;
80 set => CUIProps.IgnoreTransparent.SetValue(value);
81 }

◆ Layout

virtual CUILayout CrabUI.CUIComponent.Layout
getset

Definition at line 25 of file CUIComponent.Layout.cs.

26 {
27 get => layout;
28 set { layout = value; layout.Host = this; }
29 }

◆ LeftBorder

CUIBorder CrabUI.CUIComponent.LeftBorder
getset

Definition at line 47 of file Graphic Props.cs.

47{ get; set; }

◆ MainComponent

CUIMainComponent CrabUI.CUIComponent.MainComponent
getset

Link to CUIMainComponent, passed to children.

Definition at line 33 of file CUIComponent.State.cs.

34 {
35 get => mainComponent;
36 set
37 {
38 mainComponent = value;
39 foreach (var child in Children) { child.MainComponent = value; }
40 }
41 }

◆ MergeSerialization

bool CrabUI.CUIComponent.MergeSerialization = false
getset

If true it won't be deserialized,
Instead its children will be detached and attached to the component with matching AKA on the parent.

Implements CrabUI.ISerializationProps.

Definition at line 35 of file Serialization Props.cs.

35{ get; set; } = false;

◆ MouseOver

bool CrabUI.CUIComponent.MouseOver
getset

Definition at line 72 of file CUIComponent.State.cs.

72{ get; set; }

◆ MousePressed

bool CrabUI.CUIComponent.MousePressed
getset

Definition at line 73 of file CUIComponent.State.cs.

73{ get; set; }

◆ NamedComponents

Dictionary<string, CUIComponent> CrabUI.CUIComponent.NamedComponents = new()
getset

All memorized components.

Definition at line 82 of file CUIComponent.Debug.cs.

82{ get; set; } = new();

◆ OutlineBox

CUIRect CrabUI.CUIComponent.OutlineBox
getsetprotected

Definition at line 114 of file CUIComponent.State.cs.

114{ get; set; }

◆ OutlineColor

Color CrabUI.CUIComponent.OutlineColor
getset

Outline is like a border, but on the outside of the component.

Definition at line 56 of file Graphic Props.cs.

57 {
58 get => CUIProps.OutlineColor.Value;
59 set => CUIProps.OutlineColor.SetValue(value);
60 }

◆ OutlineThickness

float CrabUI.CUIComponent.OutlineThickness = 1f
getset

Definition at line 51 of file Graphic Props.cs.

51{ get; set; } = 1f;

◆ OutlineVisible

bool CrabUI.CUIComponent.OutlineVisible
getsetprotected

Definition at line 58 of file CUIComponent.State.cs.

58{ get; set; }

◆ Padding

Vector2 CrabUI.CUIComponent.Padding
getsetadd

Used for text, should be in CUITextBlock really.

Definition at line 25 of file Graphic Props.cs.

26 {
27 get => CUIProps.Padding.Value;
28 set => CUIProps.Padding.SetValue(value);
29 }

◆ Palette

PaletteOrder CrabUI.CUIComponent.Palette
getset

This palette will be used to resolve palette styles
Primary, Secondary, Tertiary, Quaternary.

Definition at line 113 of file Graphic Props.cs.

114 {
115 get => CUIProps.Palette.Value;
116 set => CUIProps.Palette.SetValue(value);
117 }

◆ Parent

CUIComponent? CrabUI.CUIComponent.Parent
getset

Definition at line 25 of file CUIComponent.Tree.cs.

26 {
27 get => parent;
28 set => SetParent(value);
29 }

◆ ParentAnchor

Vector2? CrabUI.CUIComponent.ParentAnchor
getset

will be attached to this point of parent

Definition at line 67 of file Layout Props.cs.

67{ get; set; }

◆ Real

CUIRect CrabUI.CUIComponent.Real
getset

Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent.Update.

Definition at line 125 of file CUIComponent.State.cs.

126 {
127 get => real;
128 set => SetReal(value);
129 }

◆ ReflectCommands

bool CrabUI.CUIComponent.ReflectCommands
getset

Definition at line 69 of file CUIComponent.Commands.cs.

70 {
71 get => reflectCommands;
72 set
73 {
74 reflectCommands = value;
75 OnAnyCommand += (command) =>
76 {
77 foreach (CUIComponent child in Children)
78 {
79 child.DispatchDown(new CUIData(command.Name, command.Data));
80 }
81 };
82 }
83 }
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...

◆ Relative

CUINullRect CrabUI.CUIComponent.Relative
getset

Relative to parent size and position, [0..1].

Implements CrabUI.ISimpleProps.

Definition at line 144 of file Layout Props.cs.

145 {
146 get => CUIProps.Relative.Value;
147 set => CUIProps.Relative.SetValue(value);
148 }

◆ RelativeMax

CUINullRect CrabUI.CUIComponent.RelativeMax
getset

Implements CrabUI.ISimpleProps.

Definition at line 156 of file Layout Props.cs.

157 {
158 get => CUIProps.RelativeMax.Value;
159 set => CUIProps.RelativeMax.SetValue(value);
160 }

◆ RelativeMin

CUINullRect CrabUI.CUIComponent.RelativeMin
getset

Implements CrabUI.ISimpleProps.

Definition at line 150 of file Layout Props.cs.

151 {
152 get => CUIProps.RelativeMin.Value;
153 set => CUIProps.RelativeMin.SetValue(value);
154 }

◆ ReplaceSerialization

bool CrabUI.CUIComponent.ReplaceSerialization = false
getset

If true, deserialized component will replace existing component with the same AKA instead of creating a duplicate.

Implements CrabUI.ISerializationProps.

Definition at line 40 of file Serialization Props.cs.

40{ get; set; } = false;

◆ ResizeDirection

CUIBool2 CrabUI.CUIComponent.ResizeDirection
getset

Definition at line 176 of file CUIComponent.Events.cs.

177 {
178 get => RightResizeHandle.Direction;
179 set
180 {
181 LeftResizeHandle.Direction = value;
182 RightResizeHandle.Direction = value;
183 }
184 }

◆ ResizeHandleColor

Color CrabUI.CUIComponent.ResizeHandleColor = Color.White
getset

Had to expose resize handle props, because it's not a real component and can't really use styles.

Definition at line 134 of file Graphic Props.cs.

134{ get; set; } = Color.White;

◆ ResizeHandleGrabbedColor

Color CrabUI.CUIComponent.ResizeHandleGrabbedColor = Color.Cyan
getset

Definition at line 136 of file Graphic Props.cs.

136{ get; set; } = Color.Cyan;

◆ ResizeToSprite

bool CrabUI.CUIComponent.ResizeToSprite
getset

If true component will set it's Absolute size to sprite texture size.

Definition at line 95 of file Layout Props.cs.

96 {
97 get => CUIProps.ResizeToSprite.Value;
98 set => CUIProps.ResizeToSprite.SetValue(value);
99 }

◆ Resizible

bool CrabUI.CUIComponent.Resizible
getset

Definition at line 155 of file CUIComponent.Events.cs.

156 {
157 get => ResizibleLeft || ResizibleRight;
158 set { ResizibleLeft = value; ResizibleRight = value; }
159 }

◆ ResizibleLeft

bool CrabUI.CUIComponent.ResizibleLeft
getset

Definition at line 162 of file CUIComponent.Events.cs.

163 {
164 get => LeftResizeHandle.Visible;
165 set => LeftResizeHandle.Visible = value;
166 }

◆ ResizibleRight

bool CrabUI.CUIComponent.ResizibleRight
getset

Definition at line 169 of file CUIComponent.Events.cs.

170 {
171 get => RightResizeHandle.Visible;
172 set => RightResizeHandle.Visible = value;
173 }

◆ ResolvedStyle

CUIStyle CrabUI.CUIComponent.ResolvedStyle
getset

Definition at line 75 of file CUIComponent.Style.cs.

75{ get; set; }

◆ RetranslateCommands

bool CrabUI.CUIComponent.RetranslateCommands
getset

Definition at line 87 of file CUIComponent.Commands.cs.

88 {
89 get => retranslateCommands;
90 set
91 {
92 retranslateCommands = value;
93 OnAnyCommand += (command) =>
94 {
95 Parent?.DispatchUp(command);
96 };
97 }
98 }

◆ Revealed

bool CrabUI.CUIComponent.Revealed
getset

Visible + !IgnoreEvents.

Definition at line 77 of file Other Props.cs.

78 {
79 get => CUIProps.Revealed.Value;
80 set => CUIProps.Revealed.SetValue(value);
81 }

◆ RigthBorder

CUIBorder CrabUI.CUIComponent.RigthBorder
getset

Definition at line 45 of file Graphic Props.cs.

45{ get; set; }

◆ SamplerState

SamplerState CrabUI.CUIComponent.SamplerState
getset

don't

Definition at line 141 of file Graphic Props.cs.

141{ get; set; }

◆ SavePath

string CrabUI.CUIComponent.SavePath
getset

Definition at line 138 of file CUIComponent.Serialization.cs.

138{ get; set; }

◆ Scale

float CrabUI.CUIComponent.Scale
getset

This is set by ChildrenOffset when zooming, and iirc consumed by text to adjust text scale.

Definition at line 98 of file CUIComponent.State.cs.

99 {
100 get => scale;
101 set => SetScale(value);
102 }

◆ Serializable

bool CrabUI.CUIComponent.Serializable = true
getset

If false then this component and its children won't be serialized.

Implements CrabUI.ISerializationProps.

Definition at line 24 of file Serialization Props.cs.

24{ get; set; } = true;

◆ SerializeChildren

bool CrabUI.CUIComponent.SerializeChildren = true
getset

Is this a serialization cutoff point
Parent will serialize children down to this component and stop.

Implements CrabUI.ISerializationProps.

Definition at line 29 of file Serialization Props.cs.

29{ get; set; } = true;

◆ ShouldPassPropsToChildren

bool CrabUI.CUIComponent.ShouldPassPropsToChildren = true
getset

Some props (like visible) are autopassed to all new childs see PassPropsToChild.

Definition at line 40 of file Other Props.cs.

40{ get; set; } = true;

◆ States

Dictionary<string, CUIComponent> CrabUI.CUIComponent.States = new()
getset

State is just a clone component with copies of all props.

Definition at line 68 of file CUIComponent.Serialization.cs.

68{ get; set; } = new();

◆ Style

CUIStyle CrabUI.CUIComponent.Style
getset

Allows you to assing parsable string or link to CUIPalette to any prop
It's indexable, so you can access it like this: component.Style["BackgroundColor"] = "cyan"
if value starts with "CUIPalette." it will extract the value from palette
e.g. component.Style["BackgroundColor"] = "CUIPalette.DarkBlue.Secondary.On"

Definition at line 50 of file CUIComponent.Style.cs.

51 {
52 get => style;
53 set
54 {
55 if (style == value) return;
56
57 if (style != null)
58 {
59 style.OnUse -= HandleStyleChange;
60 style.OnPropChanged -= HandleStylePropChange;
61 }
62
63 style = value;
64
65 if (style != null)
66 {
67 style.OnUse += HandleStyleChange;
68 style.OnPropChanged += HandleStylePropChange;
69 }
70
71 HandleStyleChange(style);
72 }
73 }

◆ Swipeable

bool CrabUI.CUIComponent.Swipeable
getset

Definition at line 188 of file CUIComponent.Events.cs.

189 {
190 get => SwipeHandle.Swipeable;
191 set => SwipeHandle.Swipeable = value;
192 }

◆ this[string name]

CUIComponent CrabUI.CUIComponent.this[string name]
getset

You can access NamedComponents with this indexer.

Parameters
name
Returns

Definition at line 120 of file CUIComponent.Debug.cs.

121 {
122 get => Get(name);
123 set
124 {
125 if (value.Parent != null) Remember(value, name);
126 else Append(value, name);
127 }
128 }
virtual CUIComponent Get(string name)
Returns memorized component by name.

◆ TopBorder

CUIBorder CrabUI.CUIComponent.TopBorder
getset

Definition at line 44 of file Graphic Props.cs.

44{ get; set; }

◆ Transparency

float CrabUI.CUIComponent.Transparency
getset

Definition at line 96 of file Graphic Props.cs.

97 {
98 get => transparency;
99 set
100 {
101 transparency = value;
102 foreach (CUIComponent child in Children)
103 {
104 if (!child.IgnoreParentTransparency) child.Transparency = value;
105 }
106 }
107 }

◆ UnCullable

bool CrabUI.CUIComponent.UnCullable
getset

It shouldn't be culled off even outside of parent bounds and even if parent demands so.

Definition at line 39 of file Layout Props.cs.

39{ get; set; }

◆ Visible

bool CrabUI.CUIComponent.Visible
getset

Invisible components are not drawn, but still can be interacted with.

Definition at line 59 of file Other Props.cs.

60 {
61 get => CUIProps.Visible.Value;
62 set => CUIProps.Visible.SetValue(value);
63 }

◆ ZIndex

int? CrabUI.CUIComponent.ZIndex
getset

Components are drawn in order of their ZIndex
Normally it's derived from component position in the tree, but this will override it.

Definition at line 84 of file Layout Props.cs.

85 {
86 get => CUIProps.ZIndex.Value;
87 set => CUIProps.ZIndex.SetValue(value);
88 }

Event Documentation

◆ OnAnyCommand

Action<CUICommand> CrabUI.CUIComponent.OnAnyCommand

this will be executed on any command

Definition at line 53 of file CUIComponent.Commands.cs.

◆ OnAnyData

Action<CUIData> CrabUI.CUIComponent.OnAnyData

Will be executed when receiving any data.

Definition at line 57 of file CUIComponent.Commands.cs.

◆ OnChildAdded

Action<CUIComponent> CrabUI.CUIComponent.OnChildAdded

Definition at line 82 of file CUIComponent.Tree.cs.

◆ OnChildRemoved

Action<CUIComponent> CrabUI.CUIComponent.OnChildRemoved

Definition at line 83 of file CUIComponent.Tree.cs.

◆ OnClick

Action<CUIInput> CrabUI.CUIComponent.OnClick

Definition at line 44 of file CUIComponent.Events.cs.

◆ OnConsume

Action<Object> CrabUI.CUIComponent.OnConsume

Happens when appropriate data is received.

Definition at line 61 of file CUIComponent.Commands.cs.

◆ OnDClick

Action<CUIInput> CrabUI.CUIComponent.OnDClick

Definition at line 45 of file CUIComponent.Events.cs.

◆ OnDrag

Action<float, float> CrabUI.CUIComponent.OnDrag

Definition at line 47 of file CUIComponent.Events.cs.

◆ OnFocus

Action CrabUI.CUIComponent.OnFocus

Definition at line 52 of file CUIComponent.Events.cs.

◆ OnFocusLost

Action CrabUI.CUIComponent.OnFocusLost

Definition at line 53 of file CUIComponent.Events.cs.

◆ OnKeyDown

Action<CUIInput> CrabUI.CUIComponent.OnKeyDown

Definition at line 49 of file CUIComponent.Events.cs.

◆ OnKeyUp

Action<CUIInput> CrabUI.CUIComponent.OnKeyUp

Definition at line 50 of file CUIComponent.Events.cs.

◆ OnLayoutUpdated

Action CrabUI.CUIComponent.OnLayoutUpdated

Definition at line 31 of file CUIComponent.Layout.cs.

◆ OnMouseDown

Action<CUIInput> CrabUI.CUIComponent.OnMouseDown

Definition at line 39 of file CUIComponent.Events.cs.

◆ OnMouseEnter

Action<CUIInput> CrabUI.CUIComponent.OnMouseEnter

Definition at line 38 of file CUIComponent.Events.cs.

◆ OnMouseLeave

Action<CUIInput> CrabUI.CUIComponent.OnMouseLeave

Definition at line 37 of file CUIComponent.Events.cs.

◆ OnMouseMove

Action<CUIInput> CrabUI.CUIComponent.OnMouseMove

Definition at line 41 of file CUIComponent.Events.cs.

◆ OnMouseOff

Action<CUIInput> CrabUI.CUIComponent.OnMouseOff

Definition at line 43 of file CUIComponent.Events.cs.

◆ OnMouseOn

Action<CUIInput> CrabUI.CUIComponent.OnMouseOn

Definition at line 42 of file CUIComponent.Events.cs.

◆ OnMouseUp

Action<CUIInput> CrabUI.CUIComponent.OnMouseUp

Definition at line 40 of file CUIComponent.Events.cs.

◆ OnScroll

Action<CUIInput> CrabUI.CUIComponent.OnScroll

Definition at line 46 of file CUIComponent.Events.cs.

◆ OnStyleApplied

Action CrabUI.CUIComponent.OnStyleApplied

Use it to e.g. update component color.

Definition at line 30 of file CUIComponent.Style.cs.

◆ OnSwipe

Action<float, float> CrabUI.CUIComponent.OnSwipe

Definition at line 48 of file CUIComponent.Events.cs.

◆ OnTextInput

Action<CUIInput> CrabUI.CUIComponent.OnTextInput

Definition at line 51 of file CUIComponent.Events.cs.

◆ OnTreeChanged

Action CrabUI.CUIComponent.OnTreeChanged

Definition at line 35 of file CUIComponent.Events.cs.

◆ OnUpdate

Action<double> CrabUI.CUIComponent.OnUpdate

Definition at line 36 of file CUIComponent.Events.cs.


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