CrabUI
Loading...
Searching...
No Matches
CUIComponent.Style.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;
16using HarmonyLib;
17
18namespace CrabUI
19{
20 public partial class CUIComponent : IDisposable
21 {
22 private void SetupStyles()
23 {
24 Style = new CUIStyle();
25 }
26
27 /// <summary>
28 /// Use it to e.g. update component color
29 /// </summary>
30 public event Action OnStyleApplied;
31 internal void InvokeOnStyleApplied() => OnStyleApplied?.Invoke();
32
33 private void HandleStylePropChange(string key, string value)
34 {
35 CUIGlobalStyleResolver.OnComponentStylePropChanged(this, key);
36 }
37 private void HandleStyleChange(CUIStyle s)
38 {
39 CUIGlobalStyleResolver.OnComponentStyleChanged(this);
40 }
41
42 private CUIStyle style;
43 /// <summary>
44 /// Allows you to assing parsable string or link to CUIPalette to any prop
45 /// It's indexable, so you can access it like this: component.Style["BackgroundColor"] = "cyan"
46 /// if value starts with "CUIPalette." it will extract the value from palette
47 /// e.g. component.Style["BackgroundColor"] = "CUIPalette.DarkBlue.Secondary.On"
48 /// </summary>
49 [CUISerializable]
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 }
74
75 public CUIStyle ResolvedStyle { get; set; }
76 }
77}
CUIStyle Style
Allows you to assing parsable string or link to CUIPalette to any prop It's indexable,...
Action OnStyleApplied
Use it to e.g. update component color.
Contains all logic for resolving styles in the framework.
In Fact just an observable dict.
Definition CUIStyle.cs:21