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

In Fact just an observable dict. More...

Public Member Functions

void Add (string key, string value)
 
void Clear ()
 
object Clone ()
 
void Use (CUIStyle source)
 
void UseString (string raw)
 
void UseXML (XElement element)
 
override string ToString ()
 
override bool Equals (object obj)
 

Static Public Member Functions

static CUIStyle DefaultFor (Type T)
 
static CUIStyle DefaultFor< T > ()
 
static CUIStyle Merge (CUIStyle baseStyle, CUIStyle addedStyle)
 
static CUIStyle FromXML (XElement element)
 
static CUIStyle Parse (string raw)
 
static CUIStyle operator+ (CUIStyle styleA, CUIStyle styleB)
 
static bool operator== (CUIStyle styleA, CUIStyle styleB)
 
static bool operator!= (CUIStyle styleA, CUIStyle styleB)
 

Public Attributes

Dictionary< string, string > Props = new()
 Prop name -> value.
 

Properties

virtual string this[string name] [get, set]
 

Events

Action< string, string > OnPropChanged
 
Action< CUIStyleOnUse
 

Detailed Description

In Fact just an observable dict.

Definition at line 20 of file CUIStyle.cs.

Member Function Documentation

◆ Add()

void CrabUI.CUIStyle.Add ( string key,
string value )

Definition at line 31 of file CUIStyle.cs.

32 {
33 Props[key] = value;
34 OnPropChanged?.Invoke(key, value);
35 }
Dictionary< string, string > Props
Prop name -> value.
Definition CUIStyle.cs:42

◆ Clone()

object CrabUI.CUIStyle.Clone ( )

Definition at line 53 of file CUIStyle.cs.

54 {
55 CUIStyle style = new CUIStyle();
56 style.Props = new Dictionary<string, string>(Props);
57 return style;
58 }

◆ DefaultFor< T >()

static CUIStyle CrabUI.CUIStyle.DefaultFor< T > ( )
static
Type Constraints
T :CUIComponent 

◆ Equals()

override bool CrabUI.CUIStyle.Equals ( object obj)

Definition at line 137 of file CUIStyle.cs.

138 {
139 if (!(obj is CUIStyle styleB)) return false;
140 CUIStyle styleA = this;
141 if (styleA is null && styleB is null) return true;
142 if (styleA is null || styleB is null) return false;
143 if (styleA.Props is null || styleB.Props is null) return false;
144 if (styleA.Props.Count != styleB.Props.Count) return false;
145 foreach (var (key, value) in styleA.Props)
146 {
147 if (!styleB.Props.ContainsKey(key)) return false;
148 if (styleA[key] != styleB[key]) return false;
149 }
150 return true;
151 }

◆ FromXML()

static CUIStyle CrabUI.CUIStyle.FromXML ( XElement element)
static

Definition at line 118 of file CUIStyle.cs.

119 {
120 CUIStyle style = new CUIStyle();
121 style.UseXML(element);
122 return style;
123 }

◆ Merge()

static CUIStyle CrabUI.CUIStyle.Merge ( CUIStyle baseStyle,
CUIStyle addedStyle )
static

Definition at line 60 of file CUIStyle.cs.

61 {
62 CUIStyle result = new CUIStyle();
63
64 if (baseStyle != null)
65 {
66 foreach (string key in baseStyle.Props.Keys)
67 {
68 result[key] = baseStyle.Props[key];
69 }
70 }
71
72 if (addedStyle != null)
73 {
74 foreach (string key in addedStyle.Props.Keys)
75 {
76 result[key] = addedStyle.Props[key];
77 }
78 }
79
80 return result;
81 }

◆ operator!=()

static bool CrabUI.CUIStyle.operator!= ( CUIStyle styleA,
CUIStyle styleB )
static

Definition at line 169 of file CUIStyle.cs.

170 {
171 if (styleA is null && styleB is null) return false;
172 if (styleA is null || styleB is null) return true;
173 if (styleA.Props is null || styleB.Props is null) return true;
174 if (styleA.Props.Count != styleB.Props.Count) return true;
175 foreach (var (key, value) in styleA.Props)
176 {
177 if (!styleB.Props.ContainsKey(key)) return true;
178 if (styleA[key] != styleB[key]) return true;
179 }
180 return false;
181 }

◆ operator==()

static bool CrabUI.CUIStyle.operator== ( CUIStyle styleA,
CUIStyle styleB )
static

Definition at line 155 of file CUIStyle.cs.

156 {
157 if (styleA is null && styleB is null) return true;
158 if (styleA is null || styleB is null) return false;
159 if (styleA.Props is null || styleB.Props is null) return false;
160 if (styleA.Props.Count != styleB.Props.Count) return false;
161 foreach (var (key, value) in styleA.Props)
162 {
163 if (!styleB.Props.ContainsKey(key)) return false;
164 if (styleA[key] != styleB[key]) return false;
165 }
166 return true;
167 }

◆ Parse()

static CUIStyle CrabUI.CUIStyle.Parse ( string raw)
static

Definition at line 130 of file CUIStyle.cs.

131 {
132 CUIStyle style = new CUIStyle();
133 style.UseString(raw);
134 return style;
135 }

◆ ToString()

override string CrabUI.CUIStyle.ToString ( )

Definition at line 125 of file CUIStyle.cs.

126 {
127 return "{ " + String.Join(", ", Props.Select(kvp => $"{kvp.Key} : {kvp.Value}")) + " }";
128 }

◆ Use()

void CrabUI.CUIStyle.Use ( CUIStyle source)

Definition at line 83 of file CUIStyle.cs.

84 {
85 Props = new Dictionary<string, string>(source.Props);
86 OnUse?.Invoke(this);
87 }

◆ UseString()

void CrabUI.CUIStyle.UseString ( string raw)

Definition at line 89 of file CUIStyle.cs.

90 {
91 Clear();
92
93 try
94 {
95 string content = raw.Split('{', '}')[1];
96 if (content.Trim() == "") return;
97 var pairs = content.Split(',').Select(s => s.Split(':').Select(sub => sub.Trim()).ToArray());
98
99 foreach (var pair in pairs)
100 {
101 Props[pair[0]] = pair[1];
102 }
103 }
104 catch (Exception e) { CUI.Warning($"Style.UseString failed: {e.Message}"); }
105 OnUse?.Invoke(this);
106 }

◆ UseXML()

void CrabUI.CUIStyle.UseXML ( XElement element)

Definition at line 108 of file CUIStyle.cs.

109 {
110 Clear();
111 foreach (XElement prop in element.Elements())
112 {
113 Props[prop.Name.ToString()] = prop.Value;
114 }
115 OnUse?.Invoke(this);
116 }

Member Data Documentation

◆ Props

Dictionary<string, string> CrabUI.CUIStyle.Props = new()

Prop name -> value.

Definition at line 42 of file CUIStyle.cs.

Property Documentation

◆ this[string name]

virtual string CrabUI.CUIStyle.this[string name]
getset

Definition at line 47 of file CUIStyle.cs.

48 {
49 get => Props.ContainsKey(name) ? Props[name] : "";
50 set => Add(name, value);
51 }

Event Documentation

◆ OnPropChanged

Action<string, string> CrabUI.CUIStyle.OnPropChanged

Definition at line 44 of file CUIStyle.cs.

◆ OnUse

Action<CUIStyle> CrabUI.CUIStyle.OnUse

Definition at line 45 of file CUIStyle.cs.


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