CrabUI
Loading...
Searching...
No Matches
CUIProp.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Diagnostics;
6using System.Runtime.CompilerServices;
7using System.IO;
8
9using Barotrauma;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Input;
12using Microsoft.Xna.Framework.Graphics;
13
14using System.Xml;
15using System.Xml.Linq;
16
17namespace CrabUI
18{
19 /// <summary>
20 /// Wrapper object for prop value, setters, side effects, metadata etc.
21 /// </summary>
22 /// <typeparam name="T"> Type of the prop </typeparam>
23 public class CUIProp<T> : ICUIProp
24 {
25 public void SetHost(CUIComponent host) => Host = host;
26 public void SetName(string name) => Name = name;
27
28 public CUIComponent Host;
29 public string Name = "Unknown";
30 public Action<T, CUIComponent> OnSet;
31 public Func<T, CUIComponent, T> Validate;
32 public bool LayoutProp;
33 public bool DecorProp;
34 public bool AbsoluteProp;
35 public bool ChildProp;
36 public bool ShowInDebug = true;
37
38 public T Value;
39 public void SetValue(T value, [CallerMemberName] string memberName = "")
40 {
41 if (Host == null)
42 {
43 CUI.Log($"{Name} CUIProp doens't have a Host! Type: {typeof(T)} Value: {value} memberName: {memberName}", Color.Red);
44 return;
45 }
46
47 if (Validate == null)
48 {
49 Value = value;
50 }
51 else
52 {
53 Value = Validate.Invoke(value, Host);
54 }
55
56 OnSet?.Invoke(value, Host);
57
58 if (ShowInDebug)
59 {
60 CUIDebug.Capture(null, Host, "SetValue", memberName, Name, Value.ToString());
61 }
62
63
64 if (LayoutProp) Host.OnPropChanged();
65 if (DecorProp) Host.OnDecorPropChanged();
66 if (AbsoluteProp) Host.OnAbsolutePropChanged();
67 if (ChildProp) Host.OnChildrenPropChanged();
68 }
69
70 public CUIProp() { }
71
72 public CUIProp(CUIComponent host, string name)
73 {
74 Name = name;
75 Host = host;
76 }
77
78 }
79}
Base class for all components.
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.
Wrapper object for prop value, setters, side effects, metadata etc.
Definition CUIProp.cs:24