diff --git a/Alchemy/Assets/Alchemy/Editor/BuiltinAttributeDrawers.cs b/Alchemy/Assets/Alchemy/Editor/BuiltinAttributeDrawers.cs index f523cac..42fc4a2 100644 --- a/Alchemy/Assets/Alchemy/Editor/BuiltinAttributeDrawers.cs +++ b/Alchemy/Assets/Alchemy/Editor/BuiltinAttributeDrawers.cs @@ -242,35 +242,19 @@ public override void OnCreateElement() [CustomAttributeDrawer(typeof(PreviewAttribute))] public sealed class PreviewDrawer : TrackSerializedObjectAttributeDrawer { + private readonly StyleSheet _styleSheet = Resources.Load("Elements/PreviewDrawer-Styles"); private Image image; - private const float PreviewSize = 40f; - private const float BorderWidth = 1f; - private static readonly Color borderColor = new Color(0f, 0f, 0f, 0.3f); public override void OnCreateElement() { if (SerializedProperty.propertyType != SerializedPropertyType.ObjectReference) return; - image = new Image - { - scaleMode = ScaleMode.ScaleToFit, - style = { - width = PreviewSize, - height = PreviewSize, - marginTop = EditorGUIUtility.standardVerticalSpacing, - marginBottom = EditorGUIUtility.standardVerticalSpacing * 4f, - alignSelf = Align.FlexEnd, - borderTopWidth = BorderWidth, - borderBottomWidth = BorderWidth, - borderLeftWidth = BorderWidth, - borderRightWidth = BorderWidth, - borderBottomColor = borderColor, - borderTopColor = borderColor, - borderLeftColor = borderColor, - borderRightColor = borderColor, - } - }; + image = new Image(); + image.styleSheets.Add(_styleSheet); + image.AddToClassList("preview-attribute__image"); + image.AddToClassList("preview-attribute__image--align-right"); + image.RegisterCallback(x => { using var mouseDownEvent = MouseDownEvent.GetPooled(x); @@ -317,34 +301,26 @@ public override void OnCreateElement() [CustomAttributeDrawer(typeof(TitleAttribute))] public sealed class TitleDrawer : AlchemyAttributeDrawer { + private readonly StyleSheet _styleSheet = Resources.Load("Elements/TitleDrawer-Attribute-Styles"); + public override void OnCreateElement() { var att = (TitleAttribute)Attribute; var parent = TargetElement.parent; - var title = new Label(att.TitleText) - { - style = { - unityFontStyleAndWeight = FontStyle.Bold, - paddingLeft = 3f, - marginTop = 4f, - marginBottom = -2f - } - }; + var title = new Label(att.TitleText); + + title.styleSheets.Add(_styleSheet); + title.AddToClassList("title-attribute__title"); + parent.Insert(parent.IndexOf(TargetElement), title); if (att.SubtitleText != null) { - var subtitle = new Label(att.SubtitleText) - { - style = { - fontSize = 10f, - paddingLeft = 4.5f, - marginTop = 1.5f, - color = GUIHelper.SubtitleColor, - unityTextAlign = TextAnchor.MiddleLeft - } - }; + var subtitle = new Label(att.SubtitleText); + + subtitle.styleSheets.Add(_styleSheet); + subtitle.AddToClassList("title-attribute__subtitle"); parent.Insert(parent.IndexOf(TargetElement), subtitle); } diff --git a/Alchemy/Assets/Alchemy/Editor/BuiltinGroupDrawers.cs b/Alchemy/Assets/Alchemy/Editor/BuiltinGroupDrawers.cs index 0e59596..4cfdce3 100644 --- a/Alchemy/Assets/Alchemy/Editor/BuiltinGroupDrawers.cs +++ b/Alchemy/Assets/Alchemy/Editor/BuiltinGroupDrawers.cs @@ -1,59 +1,46 @@ using System; using System.Collections.Generic; using System.Linq; -using UnityEngine; -using UnityEngine.UIElements; +using Alchemy.Editor.Elements; +using Alchemy.Inspector; using UnityEditor; using UnityEditor.UIElements; -using Alchemy.Inspector; -using Alchemy.Editor.Elements; +using UnityEngine; +using UnityEngine.UIElements; namespace Alchemy.Editor.Drawers { [CustomGroupDrawer(typeof(GroupAttribute))] public sealed class GroupDrawer : AlchemyGroupDrawer { + private readonly StyleSheet _styleSheet = Resources.Load("Elements/GroupDrawer-Styles"); + public override VisualElement CreateRootElement(string label) { - return new Box() - { - style = { - width = Length.Percent(100f), - marginTop = 3f, - paddingBottom = 2f, - paddingRight = 1f, - paddingLeft = 1f, - } - }; + Box box = new(); + box.styleSheets.Add(_styleSheet); + box.AddToClassList("group__box"); + + GUIHelper.ModifyChildFoldouts(box, "group__box__child-foldout"); + + return box; } } [CustomGroupDrawer(typeof(BoxGroupAttribute))] public sealed class BoxGroupDrawer : AlchemyGroupDrawer { + private readonly StyleSheet _styleSheet = Resources.Load("Elements/BoxGroupDrawer-Styles"); + public override VisualElement CreateRootElement(string label) { - var helpBox = new HelpBox() - { - text = label, - style = { - flexDirection = FlexDirection.Column, - width = Length.Percent(100f), - marginTop = 3f, - paddingBottom = 3f, - paddingRight = 3f, - paddingLeft = 3f, - } - }; - - var labelElement = helpBox.Q