Skip to content

Commit 9391e9f

Browse files
Merge pull request 59720 from feature/160310-backgroundStyle into master
1 parent dd90a2c commit 9391e9f

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

Editor/FigmaParser.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Xml;
88
using UnityEngine;
99
using Trackman;
10+
using UnityEngine.UIElements;
1011

1112
// ReSharper disable UnusedMember.Local
1213
// ReSharper disable UnusedParameter.Local
@@ -131,13 +132,6 @@ enum FontStyle
131132
BoldAndItalic
132133
}
133134

134-
enum ScaleMode
135-
{
136-
StretchToFill,
137-
ScaleAndCrop,
138-
ScaleToFit
139-
}
140-
141135
enum TextAlign
142136
{
143137
UpperLeft,
@@ -588,7 +582,10 @@ struct CursorProperty
588582
// Background
589583
ColorProperty backgroundColor { get => Get("background-color"); set => Set("background-color", value); }
590584
AssetProperty backgroundImage { get => Get("background-image"); set => Set("background-image", value); }
591-
EnumProperty<ScaleMode> unityBackgroundScaleMode { get => Get("-unity-background-scale-mode"); set => Set("-unity-background-scale-mode", value); }
585+
EnumProperty<BackgroundPositionKeyword> unityBackgroundPositionX { get => Get("background-position-x"); set => Set("background-position-x", value); }
586+
EnumProperty<BackgroundPositionKeyword> unityBackgroundPositionY { get => Get("background-position-y"); set => Set("background-position-y", value); }
587+
EnumProperty<Repeat> unityBackgroundRepeat { get => Get("background-repeat"); set => Set("background-repeat", value); }
588+
EnumProperty<BackgroundSizeType> unityBackgroundSize { get => Get("background-size"); set => Set("background-size", value); }
592589
ColorProperty unityBackgroundImageTintColor { get => Get("-unity-background-image-tint-color"); set => Set("-unity-background-image-tint-color", value); }
593590
// Slicing
594591
IntegerProperty unitySliceLeft { get => Get("-unity-slice-left"); set => Set("-unity-slice-left", value); }
@@ -642,6 +639,9 @@ public UssStyle(string name)
642639
unityFontDefinition = Unit.Initial;
643640
justifyContent = JustifyContent.Center;
644641
alignItems = Align.Center;
642+
unityBackgroundPositionX = BackgroundPositionKeyword.Center;
643+
unityBackgroundPositionY = BackgroundPositionKeyword.Center;
644+
unityBackgroundRepeat = Repeat.NoRepeat;
645645
break;
646646

647647
case viewportClass:
@@ -1408,12 +1408,12 @@ void AddFillStyle(IEnumerable<Paint> fills)
14081408

14091409
switch (image.scaleMode)
14101410
{
1411-
case global.ScaleMode.FILL:
1412-
unityBackgroundScaleMode = ScaleMode.ScaleAndCrop;
1411+
case ScaleMode.FILL:
1412+
unityBackgroundSize = BackgroundSizeType.Cover;
14131413
break;
14141414

1415-
case global.ScaleMode.FIT:
1416-
unityBackgroundScaleMode = ScaleMode.ScaleToFit;
1415+
case ScaleMode.FIT:
1416+
unityBackgroundSize = BackgroundSizeType.Contain;
14171417
break;
14181418
}
14191419
}

Runtime/Extensions/NodeExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,10 @@ public static void CopyResolvedStyle(this VisualElement value, VisualElement sou
320320
if (valueResolvedStyle.opacity != sourceResolvedStyle.opacity) style.opacity = sourceResolvedStyle.opacity;
321321
if (valueResolvedStyle.visibility != sourceResolvedStyle.visibility) style.visibility = sourceResolvedStyle.visibility;
322322
if (valueResolvedStyle.unityBackgroundImageTintColor != sourceResolvedStyle.unityBackgroundImageTintColor) style.unityBackgroundImageTintColor = sourceResolvedStyle.unityBackgroundImageTintColor;
323-
if (valueResolvedStyle.unityBackgroundScaleMode != sourceResolvedStyle.unityBackgroundScaleMode) style.unityBackgroundScaleMode = sourceResolvedStyle.unityBackgroundScaleMode;
323+
if (valueResolvedStyle.backgroundPositionX != sourceResolvedStyle.backgroundPositionX) style.backgroundPositionX = sourceResolvedStyle.backgroundPositionX;
324+
if (valueResolvedStyle.backgroundPositionY != sourceResolvedStyle.backgroundPositionY) style.backgroundPositionY = sourceResolvedStyle.backgroundPositionY;
325+
if (valueResolvedStyle.backgroundRepeat != sourceResolvedStyle.backgroundRepeat) style.backgroundRepeat = sourceResolvedStyle.backgroundRepeat;
326+
if (valueResolvedStyle.backgroundSize != sourceResolvedStyle.backgroundSize) style.backgroundSize = sourceResolvedStyle.backgroundSize;
324327
if (valueResolvedStyle.backgroundImage != sourceResolvedStyle.backgroundImage) style.backgroundImage = sourceResolvedStyle.backgroundImage;
325328
if (valueResolvedStyle.backgroundColor != sourceResolvedStyle.backgroundColor) style.backgroundColor = sourceResolvedStyle.backgroundColor;
326329
if (valueResolvedStyle.color != sourceResolvedStyle.color) style.color = sourceResolvedStyle.color;
@@ -438,7 +441,10 @@ public static void CopyStyle(this VisualElement value, VisualElement source, Cop
438441
if (sourceStyle.backgroundImage.keyword != StyleKeyword.Null && valueStyle.backgroundImage != sourceStyle.backgroundImage) valueStyle.backgroundImage = sourceStyle.backgroundImage;
439442
if (sourceStyle.backgroundColor.keyword != StyleKeyword.Null && valueStyle.backgroundColor != sourceStyle.backgroundColor) valueStyle.backgroundColor = sourceStyle.backgroundColor;
440443
if (sourceStyle.unityBackgroundImageTintColor.keyword != StyleKeyword.Null && valueStyle.unityBackgroundImageTintColor != sourceStyle.unityBackgroundImageTintColor) valueStyle.unityBackgroundImageTintColor = sourceStyle.unityBackgroundImageTintColor;
441-
if (sourceStyle.unityBackgroundScaleMode.keyword != StyleKeyword.Null && valueStyle.unityBackgroundScaleMode != sourceStyle.unityBackgroundScaleMode) valueStyle.unityBackgroundScaleMode = sourceStyle.unityBackgroundScaleMode;
444+
if (sourceStyle.backgroundPositionX.keyword != StyleKeyword.Null && valueStyle.backgroundPositionX != sourceStyle.backgroundPositionX) valueStyle.backgroundPositionX = sourceStyle.backgroundPositionX;
445+
if (sourceStyle.backgroundPositionY.keyword != StyleKeyword.Null && valueStyle.backgroundPositionY != sourceStyle.backgroundPositionY) valueStyle.backgroundPositionY = sourceStyle.backgroundPositionY;
446+
if (sourceStyle.backgroundRepeat.keyword != StyleKeyword.Null && valueStyle.backgroundRepeat != sourceStyle.backgroundRepeat) valueStyle.backgroundRepeat = sourceStyle.backgroundRepeat;
447+
if (sourceStyle.backgroundSize.keyword != StyleKeyword.Null && valueStyle.backgroundSize != sourceStyle.backgroundSize) valueStyle.backgroundSize = sourceStyle.backgroundSize;
442448
}
443449

444450
if (copyMask.HasFlag(CopyStyleMask.Padding))

0 commit comments

Comments
 (0)