Skip to content

Commit a5038db

Browse files
committed
feat: details tab
1 parent cfcfa9c commit a5038db

File tree

3 files changed

+56
-50
lines changed

3 files changed

+56
-50
lines changed

Editor/EditorMessageUtility.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ namespace GBG.EditorMessages.Editor
99
public static class EditorMessageUtility
1010
{
1111
#region Style
12-
13-
public static int GlobalIconSize = 16;
1412

15-
// alpha : 50
13+
public static int GlobalIconSize = 16;
14+
15+
public static Color ActiveColor => EditorGUIUtility.isProSkin
16+
? new Color(0.22f, 0.22f, 0.22f, 1f)
17+
: new Color(0.76f, 0.76f, 0.76f, 1f);
18+
public static Color InactiveColor => EditorGUIUtility.isProSkin
19+
? new Color(1f, 1f, 1f, 0.15f)
20+
: new Color(1f, 1f, 1f, 0.26f);
1621

1722
#endregion
1823

24+
1925
//private static Font _monospaceFont;
2026
private static FontAsset _monospaceFontAsset;
2127

Editor/MessageDetailsElement.cs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using UnityEditor;
2-
using UnityEngine;
3-
using UnityEngine.UIElements;
1+
using UnityEngine.UIElements;
42

53
namespace GBG.EditorMessages.Editor
64
{
75
public class MessageDetailsElement : VisualElement
86
{
97
private readonly VisualElement _typeToggleContainer;
10-
private readonly Image _messageToggle;
8+
private readonly MessageDetailsTabElement _messageTab;
9+
private readonly MessageDetailsTabElement _contextTab;
10+
private readonly MessageDetailsTabElement _customDataTab;
1111
private readonly Label _detailsLabel;
1212

1313

@@ -22,14 +22,12 @@ public MessageDetailsElement()
2222

2323
#region Details Type Toggle
2424

25-
Color inactiveColor = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.15f) : new Color(1f, 1f, 1f, 0.26f);
26-
2725
// Type Toggle Container
2826
_typeToggleContainer = new VisualElement
2927
{
3028
style =
3129
{
32-
backgroundColor = inactiveColor,
30+
backgroundColor = EditorMessageUtility.InactiveColor,
3331
width = iconSize + 2,
3432
paddingLeft = 1,
3533
//paddingRight = 1,
@@ -39,33 +37,17 @@ public MessageDetailsElement()
3937
};
4038
Add(_typeToggleContainer);
4139

42-
MessageDetailsTabElement toggle1 = new MessageDetailsTabElement
43-
{
44-
style =
45-
{
46-
height = iconSize,
47-
}
48-
};
49-
_typeToggleContainer.Add(toggle1);
40+
_messageTab = new MessageDetailsTabElement(EditorMessageUtility.GetInfoIcon(),
41+
"Message", OnClickMessageTab);
42+
_typeToggleContainer.Add(_messageTab);
5043

51-
MessageDetailsTabElement toggle2 = new MessageDetailsTabElement
52-
{
53-
style =
54-
{
55-
height = iconSize,
56-
backgroundColor = EditorGUIUtility.isProSkin ? new Color(0.22f, 0.22f, 0.22f, 1f) : new Color(0.76f, 0.76f, 0.76f, 1f),
57-
}
58-
};
59-
_typeToggleContainer.Add(toggle2);
44+
_contextTab = new MessageDetailsTabElement(EditorMessageUtility.GetContextIcon(),
45+
"Context", OnClickContextTab);
46+
_typeToggleContainer.Add(_contextTab);
6047

61-
MessageDetailsTabElement toggle3 = new MessageDetailsTabElement
62-
{
63-
style =
64-
{
65-
height = iconSize,
66-
}
67-
};
68-
_typeToggleContainer.Add(toggle3);
48+
_customDataTab = new MessageDetailsTabElement(EditorMessageUtility.GetCustomDataIcon(),
49+
"Custom Data", OnClickCustomDataTab);
50+
_typeToggleContainer.Add(_customDataTab);
6951

7052
#endregion
7153

@@ -83,13 +65,7 @@ public MessageDetailsElement()
8365
Add(detailsContainer);
8466

8567
// Message Details Scroll
86-
ScrollView detailsScrollView = new ScrollView(ScrollViewMode.Vertical)
87-
{
88-
style =
89-
{
90-
//flexGrow = 1,
91-
}
92-
};
68+
ScrollView detailsScrollView = new ScrollView(ScrollViewMode.Vertical);
9369
detailsContainer.Add(detailsScrollView);
9470

9571
// Message Details Label
@@ -112,5 +88,27 @@ public void SetMessage(Message message)
11288
{
11389
_detailsLabel.text = message?.Content;
11490
}
91+
92+
93+
private void OnClickMessageTab()
94+
{
95+
_messageTab.style.backgroundColor = EditorMessageUtility.ActiveColor;
96+
_contextTab.style.backgroundColor = EditorMessageUtility.InactiveColor;
97+
_customDataTab.style.backgroundColor = EditorMessageUtility.InactiveColor;
98+
}
99+
100+
private void OnClickContextTab()
101+
{
102+
_messageTab.style.backgroundColor = EditorMessageUtility.InactiveColor;
103+
_contextTab.style.backgroundColor = EditorMessageUtility.ActiveColor;
104+
_customDataTab.style.backgroundColor = EditorMessageUtility.InactiveColor;
105+
}
106+
107+
private void OnClickCustomDataTab()
108+
{
109+
_messageTab.style.backgroundColor = EditorMessageUtility.InactiveColor;
110+
_contextTab.style.backgroundColor = EditorMessageUtility.InactiveColor;
111+
_customDataTab.style.backgroundColor = EditorMessageUtility.ActiveColor;
112+
}
115113
}
116114
}

Editor/MessageDetailsTabElement.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using UnityEditor;
1+
using System;
22
using UnityEngine;
33
using UnityEngine.UIElements;
44

@@ -8,27 +8,29 @@ public class MessageDetailsTabElement : VisualElement
88
{
99
public Image Icon { get; }
1010

11-
public MessageDetailsTabElement()
11+
12+
public MessageDetailsTabElement(Texture texture, string tooltip, Action onClick)
1213
{
1314
float iconSize = EditorMessageUtility.GlobalIconSize;
14-
//Color inactiveColor = EditorGUIUtility.isProSkin
15-
// ? new Color(1f, 1f, 1f, 0.15f)
16-
// : new Color(1f, 1f, 1f, 0.26f);
15+
style.height = iconSize;
16+
this.tooltip = tooltip;
1717

1818
Icon = new Image
1919
{
20-
image = EditorMessageUtility.GetInfoIcon(), // todo : test
20+
image = texture,
2121
style =
2222
{
2323
alignSelf = Align.Center,
24-
//minWidth = iconSize,
25-
//maxWidth = iconSize,
24+
minWidth = iconSize,
25+
maxWidth = iconSize,
2626
minHeight = iconSize,
2727
maxHeight = iconSize,
2828
//backgroundColor = inactiveColor,
2929
}
3030
};
3131
Add(Icon);
32+
33+
RegisterCallback<ClickEvent>(evt => onClick?.Invoke());
3234
}
3335
}
3436
}

0 commit comments

Comments
 (0)