Skip to content

Commit 3fbaae8

Browse files
committed
Updated template graph and template code viewer
1 parent 52c43ce commit 3fbaae8

File tree

6 files changed

+277
-437
lines changed

6 files changed

+277
-437
lines changed
Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,15 @@
1-
TemplateItemElement
2-
{
3-
margin: 3px;
4-
5-
flex-shrink: 0;
6-
flex-grow: 0;
7-
}
8-
.graph
9-
{
10-
background-color: #202020;
11-
}
12-
131
.node-header-queue
142
{
153
-unity-font-style: italic;
164
color: grey;
175
-unity-text-align: middle-right;
186
flex-grow: 1;
7+
margin-right: 6px;
198
}
20-
21-
.node-header
22-
{
23-
background-color: #383838;
24-
flex-direction: row;
25-
padding: 8px;
26-
border-color: black;
27-
border-width: 2px;
28-
border-top-left-radius: 6px;
29-
border-top-right-radius: 6px;
30-
}
31-
32-
.node-header-name
33-
{
34-
color: #C4C4C4;
35-
}
36-
379
.node-header-id
3810
{
39-
color: #C4C4C4;
40-
font-size: 9px;
11+
font-size: 8px;
4112
-unity-font-style: italic;
4213
align-self: center;
43-
}
44-
45-
.node-body
46-
{
47-
background-color: #383838;
48-
flex-direction: row;
49-
border-bottom-width: 2px;
50-
border-left-width: 2px;
51-
border-right-width: 2px;
52-
border-color: black;
53-
border-bottom-left-radius: 6px;
54-
border-bottom-right-radius: 6px;
55-
56-
}
57-
.node-body>VisualElement
58-
{
59-
padding: 8px;
60-
flex-grow: 1;
61-
}
62-
63-
.node-body.divider>VisualElement
64-
{
65-
border-color: black;
66-
border-left-width: 2px;
67-
}
68-
69-
.node-body>Label
70-
{
71-
padding: 8px;
72-
margin-right: 20px;
73-
-unity-text-align: middle-left;
74-
color: #C4C4C4;
75-
}
76-
77-
.node-body>VisualElement>Label
78-
{
79-
color: #C4C4C4;
80-
flex-grow: 1;
81-
-unity-text-align: middle-right;
82-
}
83-
84-
TemplateRow
85-
{
86-
margin-left: 50px;
87-
}
88-
89-
PopupField
90-
{
91-
margin-top: 10px;
92-
margin-bottom: 10px;
93-
width: 500px;
14+
margin-left: 2px;
9415
}
84.9 KB
Binary file not shown.

Editor/Resources/MSS/RobotoMono-Regular.ttf.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Windows/FunctionTimeline.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -513,27 +513,22 @@ public string SelectedItem
513513
set
514514
{
515515
_selectedItem = value;
516-
_templateLabel.text = _selectedItem;
516+
_viewer.Text = _selectedItem;
517517
}
518518
}
519519

520-
private Label _templateLabel;
520+
private CodeViewElement _viewer;
521521
private string _selectedItem;
522522

523523
public FunctionTemplateViewer()
524524
{
525-
ScrollView s = new ScrollView(ScrollViewMode.VerticalAndHorizontal);
526-
_templateLabel = new Label(SelectedItem);
527-
s.AddToClassList("unity-base-text-field__input");
528-
s.AddToClassList("unity-text-field__input");
529-
s.AddToClassList("unity-base-field__input");
530-
s.Add(_templateLabel);
525+
_viewer = new CodeViewElement();
531526

532527
var title = new Label("Function code template");
533528
title.AddToClassList("area-title");
534529

535530
Add(title);
536-
Add(s);
531+
Add(_viewer);
537532
}
538533
}
539534

@@ -619,15 +614,14 @@ public TimelineContainer(ModularShader shader)
619614
};
620615
_roots.Add(root);
621616
}
622-
617+
618+
var timelineContent = new VisualElement();
623619
if (_roots.Count == 0)
624620
{
625621
Label label = new Label("No roots found");
626622
left.Add(label);
627623
return;
628624
}
629-
var timelineContent = new VisualElement();
630-
631625
timelineContent.Add(_roots[0]);
632626

633627
var timelineScroll = new ScrollView(ScrollViewMode.Vertical);
@@ -661,5 +655,4 @@ public TimelineContainer(ModularShader shader)
661655
bot.Add(moduleViewer);
662656
}
663657
}
664-
665658
}

Editor/Windows/ModularShaderDebugger.cs

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ public static void ShowExample()
5151
ModularShaderDebugger wnd = GetWindow<ModularShaderDebugger>();
5252
wnd.titleContent = new GUIContent("Modular Shader Debugger");
5353

54-
if (wnd.position.width < 300 || wnd.position.height < 300)
54+
if (wnd.position.width < 400 || wnd.position.height < 400)
5555
{
5656
Rect size = wnd.position;
5757
size.width = 1280;
5858
size.height = 720;
5959
wnd.position = size;
6060
}
61-
6261
}
6362

6463
private ObjectField _modularShaderField;
@@ -167,4 +166,101 @@ private void UpdateTabs()
167166
}
168167
}
169168
}
169+
170+
public class CodeViewElement : VisualElement
171+
{
172+
private class LineItem : VisualElement
173+
{
174+
private static Font TextFont
175+
{
176+
get
177+
{
178+
if (_font == null)
179+
_font = Resources.Load<Font>(MSSConstants.RESOURCES_FOLDER + "/RobotoMono-Regular");
180+
return _font;
181+
}
182+
}
183+
184+
private static Font _font;
185+
private Label _lineNumber;
186+
private Label _line;
187+
public string Text { get; }
188+
189+
public LineItem() : this(0, "") {}
190+
191+
public LineItem(int number, string text, int digits = 0)
192+
{
193+
Text = text;
194+
_lineNumber = new Label("" + number);
195+
_lineNumber.style.color = Color.gray;
196+
_lineNumber.style.width = digits == 0 ? 30 : digits * 8;
197+
_lineNumber.style.unityTextAlign = TextAnchor.MiddleRight;
198+
_lineNumber.style.unityFont = TextFont;
199+
_lineNumber.style.marginRight = 4;
200+
_lineNumber.style.marginLeft = 4;
201+
202+
_line = new Label(text);
203+
_line.style.flexGrow = 1;
204+
_line.style.unityFont = TextFont;
205+
206+
style.flexDirection = FlexDirection.Row;
207+
Add(_lineNumber);
208+
Add(_line);
209+
}
210+
211+
public void SetText(int i, string textLine, int digits)
212+
{
213+
_lineNumber.text = "" + i;
214+
_lineNumber.style.width = digits == 0 ? 30 : digits * 8;
215+
_line.text = textLine;
216+
_line.MeasureTextSize(textLine, 0, MeasureMode.Exactly, 0, MeasureMode.Exactly);
217+
}
218+
}
219+
220+
public string Text
221+
{
222+
get => string.Join("\n", _textLines);
223+
set
224+
{
225+
_textLines = value == null ? Array.Empty<string>() : value.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
226+
_digits = (int)Math.Floor(Math.Log10(_textLines.Length) + 1);
227+
_listView.itemsSource = _textLines;
228+
229+
float width =((_textLines.Length == 0 ? 0 : _textLines.Max(x => x.Length)) + _digits + 1) * 10;
230+
_listView.contentContainer.style.width = width;
231+
}
232+
}
233+
234+
public int LineCount => _textLines.Length;
235+
236+
private Label _templateLabel;
237+
private string[] _textLines;
238+
private ListView _listView;
239+
private int _digits;
240+
241+
public CodeViewElement()
242+
{
243+
ScrollView s = new ScrollView(ScrollViewMode.Horizontal);
244+
_listView = new ListView();
245+
_listView.itemHeight = 15;
246+
_listView.AddToClassList("unity-base-text-field__input");
247+
_listView.AddToClassList("unity-text-field__input");
248+
_listView.AddToClassList("unity-base-field__input");
249+
_listView.style.flexGrow = 1;
250+
_listView.contentContainer.style.flexGrow = 1;
251+
252+
Func<VisualElement> makeItem = () => new LineItem();
253+
Action<VisualElement, int> bindItem = (e, i) => (e as LineItem).SetText(i+1, _textLines[i], _digits);
254+
255+
_listView.makeItem = makeItem;
256+
_listView.bindItem = bindItem;
257+
_listView.selectionType = SelectionType.None;
258+
s.Add(_listView);
259+
Add(s);
260+
s.style.flexGrow = 1;
261+
s.contentContainer.style.flexGrow = 1;
262+
263+
style.flexGrow = 1;
264+
}
265+
}
170266
}

0 commit comments

Comments
 (0)