A game about forced loneliness, made by TACStudios
1using UnityEditor;
2using UnityEngine;
3
4namespace Unity.VisualScripting
5{
6 [Widget(typeof(Literal))]
7 public sealed class LiteralWidget : UnitWidget<Literal>
8 {
9 public LiteralWidget(FlowCanvas canvas, Literal unit) : base(canvas, unit) { }
10
11 protected override bool showHeaderAddon => unit.isDefined;
12
13 public override bool foregroundRequiresInput => true;
14
15 protected override float GetHeaderAddonWidth()
16 {
17 var adaptiveWidthAttribute = unit.type.GetAttribute<InspectorAdaptiveWidthAttribute>();
18
19 return Mathf.Min(metadata.Inspector().GetAdaptiveWidth(), adaptiveWidthAttribute?.width ?? Styles.maxSettingsWidth);
20 }
21
22 protected override float GetHeaderAddonHeight(float width)
23 {
24 return LudiqGUI.GetInspectorHeight(null, metadata, width, GUIContent.none);
25 }
26
27 public override void BeforeFrame()
28 {
29 base.BeforeFrame();
30
31 if (showHeaderAddon &&
32 GetHeaderAddonWidth() != headerAddonPosition.width ||
33 GetHeaderAddonHeight(headerAddonPosition.width) != headerAddonPosition.height)
34 {
35 Reposition();
36 }
37 }
38
39 protected override void DrawHeaderAddon()
40 {
41 using (LudiqGUIUtility.labelWidth.Override(75)) // For reflected inspectors / custom property drawers
42 using (Inspector.adaptiveWidth.Override(true))
43 {
44 EditorGUI.BeginChangeCheck();
45
46 LudiqGUI.Inspector(metadata, headerAddonPosition, GUIContent.none);
47
48 if (EditorGUI.EndChangeCheck())
49 {
50 unit.EnsureDefined();
51 Reposition();
52 }
53 }
54 }
55 }
56}