Skip to content

Commit b41a829

Browse files
committed
Updates from version 1.5 of Pinwheel
1 parent 4913d58 commit b41a829

14 files changed

+459
-17
lines changed

pinwheel/schema/pinwheel.xsd

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@
4949
<xs:choice minOccurs="0" maxOccurs="unbounded">
5050
<xs:element name="colorSet" type="ColorSetType" />
5151
<xs:element name="colorItem" type="ColorItemType" />
52-
<xs:element name="alias" type="AliasType" />
52+
<xs:element name="alias" type="SetAliasType" />
5353
<xs:element name="group" type="GroupType" />
5454
<xs:element name="numberItem" type="NumberItemType" />
5555
<xs:element name="numberAlias" type="NumberAliasType" />
5656
<xs:element name="booleanItem" type="BooleanItemType" />
5757
<xs:element name="booleanAlias" type="BooleanAliasType" />
5858
<xs:element name="stringItem" type="StringItemType" />
5959
<xs:element name="stringAlias" type="StringAliasType" />
60+
<xs:element name="shadowItem" type="ShadowItemType" />
61+
<xs:element name="shadowSet" type="ShadowSetType" />
62+
<xs:element name="shadowAlias" type="SetAliasType" />
6063
</xs:choice>
6164
</xs:complexType>
6265

@@ -95,7 +98,21 @@
9598
</xs:sequence>
9699
</xs:complexType>
97100

98-
<xs:complexType name="AliasType">
101+
<xs:complexType name="ShadowItemType">
102+
<xs:sequence>
103+
<xs:element name="id" type="xs:string" />
104+
<xs:element name="name" type="xs:string" />
105+
<xs:element name="profile" type="xs:string" />
106+
<xs:element name="appearance" type="AppearanceValues" minOccurs="0" maxOccurs="1" />
107+
<xs:element name="autoContrast" type="xs:decimal" minOccurs="0" maxOccurs="1" />
108+
<xs:element name="shadow" type="ItemShadowType" />
109+
<xs:element name="buildGroupId" type="xs:string" minOccurs="0" maxOccurs="1" />
110+
<xs:element name="testGroupId" type="xs:string" minOccurs="0" maxOccurs="1" />
111+
<xs:element name="testPosition" type="xs:string" minOccurs="0" maxOccurs="1" />
112+
</xs:sequence>
113+
</xs:complexType>
114+
115+
<xs:complexType name="SetAliasType">
99116
<xs:sequence>
100117
<xs:element name="name" type="xs:string" />
101118
<xs:element name="type" type="xs:integer" />
@@ -145,12 +162,12 @@
145162
<xs:element name="referencedItemId" type="xs:string" minOccurs="0" maxOccurs="1" />
146163
<xs:element name="referencedItemIdLightHighContrast" type="xs:string" minOccurs="0" maxOccurs="1" />
147164
<xs:element name="referencedItemIdDark" type="xs:string" minOccurs="0" maxOccurs="1" />
148-
<xs:element name="referencedItemIdDarkHighContrast" type="xs:string" minOccurs="0" maxOccurs="1" />
165+
<xs:element name="referencedItemIdDarkHighContrast" type="xs:string" minOccurs="0" maxOccurs="1" />
149166
<xs:element name="buildGroupId" type="xs:string" minOccurs="0" maxOccurs="1" />
150167
</xs:sequence>
151168
</xs:complexType>
152169

153-
<xs:complexType name="StringAliasType">
170+
<xs:complexType name="StringAliasType">
154171
<xs:sequence>
155172
<xs:element name="name" type="xs:string" />
156173
<xs:element name="type" type="xs:integer" />
@@ -161,11 +178,32 @@
161178
<xs:element name="referencedItemId" type="xs:string" minOccurs="0" maxOccurs="1" />
162179
<xs:element name="referencedItemIdLightHighContrast" type="xs:string" minOccurs="0" maxOccurs="1" />
163180
<xs:element name="referencedItemIdDark" type="xs:string" minOccurs="0" maxOccurs="1" />
164-
<xs:element name="referencedItemIdDarkHighContrast" type="xs:string" minOccurs="0" maxOccurs="1" />
181+
<xs:element name="referencedItemIdDarkHighContrast" type="xs:string" minOccurs="0" maxOccurs="1" />
165182
<xs:element name="buildGroupId" type="xs:string" minOccurs="0" maxOccurs="1" />
166183
</xs:sequence>
167184
</xs:complexType>
168185

186+
<xs:complexType name="ShadowSetType">
187+
<xs:sequence>
188+
<xs:element name="id" type="xs:string" />
189+
<xs:element name="name" type="xs:string" />
190+
<xs:element name="profile" type="xs:string" />
191+
<xs:element name="appearance" type="AppearanceValues" minOccurs="0" maxOccurs="1" />
192+
<xs:element name="autoContrast" type="xs:decimal" minOccurs="0" maxOccurs="1" />
193+
<xs:element name="steps" type="xs:integer" />
194+
<xs:element name="interpolation" type="xs:integer" />
195+
<xs:element name="curve" type="xs:integer" minOccurs="0" maxOccurs="1" />
196+
<xs:element name="curveAmount" type="xs:decimal" minOccurs="0" maxOccurs="1" />
197+
<xs:element name="type" type="xs:integer" />
198+
<xs:element name="middle" type="xs:decimal" />
199+
<xs:element name="naming" type="xs:integer" />
200+
<xs:element name="shadows" type="ShadowsType" />
201+
<xs:element name="buildGroupId" type="xs:string" minOccurs="0" maxOccurs="1" />
202+
<xs:element name="testGroupId" type="xs:string" minOccurs="0" maxOccurs="1" />
203+
<xs:element name="testPosition" type="xs:string" minOccurs="0" maxOccurs="1" />
204+
</xs:sequence>
205+
</xs:complexType>
206+
169207
<xs:complexType name="GroupType">
170208
<xs:sequence>
171209
<xs:element name="id" type="xs:string" />
@@ -175,10 +213,17 @@
175213
<xs:choice minOccurs="0" maxOccurs="unbounded">
176214
<xs:element name="colorSet" type="ColorSetType" />
177215
<xs:element name="colorItem" type="ColorItemType" />
178-
<xs:element name="alias" type="AliasType" />
216+
<xs:element name="alias" type="SetAliasType" />
179217
<xs:element name="group" type="GroupType" />
180218
<xs:element name="numberItem" type="NumberItemType" />
181219
<xs:element name="numberAlias" type="NumberAliasType" />
220+
<xs:element name="booleanItem" type="BooleanItemType" />
221+
<xs:element name="booleanAlias" type="BooleanAliasType" />
222+
<xs:element name="stringItem" type="StringItemType" />
223+
<xs:element name="stringAlias" type="StringAliasType" />
224+
<xs:element name="shadowItem" type="ShadowItemType" />
225+
<xs:element name="shadowSet" type="ShadowSetType" />
226+
<xs:element name="shadowAlias" type="SetAliasType" />
182227
</xs:choice>
183228
<xs:element name="buildGroupId" type="xs:string" minOccurs="0" maxOccurs="1" />
184229
<xs:element name="testGroupId" type="xs:string" minOccurs="0" maxOccurs="1" />
@@ -230,6 +275,19 @@
230275
</xs:sequence>
231276
</xs:complexType>
232277

278+
<xs:complexType name="ShadowsType">
279+
<xs:sequence>
280+
<xs:element name="shadow" type="ShadowType" maxOccurs="unbounded" />
281+
</xs:sequence>
282+
</xs:complexType>
283+
284+
<xs:complexType name="ShadowType">
285+
<xs:sequence>
286+
<xs:element name="name" type="xs:string" />
287+
<xs:element name="variants" type="VariantsType" />
288+
</xs:sequence>
289+
</xs:complexType>
290+
233291
<xs:complexType name="ColorsType">
234292
<xs:sequence>
235293
<xs:element name="color" type="ColorType" maxOccurs="unbounded" />
@@ -259,6 +317,17 @@
259317
</xs:simpleContent>
260318
</xs:complexType>
261319
</xs:element>
320+
<xs:element name="shadowDetails" maxOccurs="unbounded">
321+
<xs:complexType>
322+
<xs:sequence>
323+
<xs:element name="x" type="xs:decimal" />
324+
<xs:element name="y" type="xs:decimal" />
325+
<xs:element name="blur" type="xs:decimal" />
326+
<xs:element name="spread" type="xs:decimal" />
327+
<xs:element name="colorRgba" type="xs:string" />
328+
</xs:sequence>
329+
</xs:complexType>
330+
</xs:element>
262331
</xs:choice>
263332
<xs:attribute name="type" type="xs:string" use="optional" />
264333
</xs:complexType>
@@ -273,6 +342,12 @@
273342
</xs:sequence>
274343
</xs:complexType>
275344

345+
<xs:complexType name="ItemShadowType">
346+
<xs:sequence>
347+
<xs:element name="variants" type="VariantsType" />
348+
</xs:sequence>
349+
</xs:complexType>
350+
276351
<xs:complexType name="ItemNumberType">
277352
<xs:sequence>
278353
<xs:element name="variants" type="VariantsType" />

pinwheel/templates/Pinwheel Built In Examples/AndroidCompose.stencil

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,45 @@ val {{ item.name }}HighContrast = "{{ item.string.value.highContrast }}"
5858
{% if item.string.value.darkHighContrast %}
5959
val {{ item.name }}DarkHighContrast = "{{ item.string.value.darkHighContrast }}"
6060
{% endif %}
61+
{% elif item.shadowItem %}
62+
val {{ item.name }} = {%+ shadowAsKotlinPinwheelShadow item.shadowItem.shadow.light +%}
63+
{% if item.shadowItem.shadow.dark %}
64+
val {{ item.name }}Dark = {%+ shadowAsKotlinPinwheelShadow item.shadowItem.shadow.dark +%}
65+
{% endif %}
66+
{% if item.shadowItem.shadow.highContrast %}
67+
val {{ item.name }}HighContrast = {%+ shadowAsKotlinPinwheelShadow item.shadowItem.shadow.highContrast +%}
68+
{% endif %}
69+
{% if item.shadowItem.shadow.darkHighContrast %}
70+
val {{ item.name }}DarkHighContrast = {%+ shadowAsKotlinPinwheelShadow item.shadowItem.shadow.darkHighContrast +%}
71+
{% endif %}
72+
{% elif item.shadowSet %}
73+
{% for shadow in item.shadowSet.shadows %}
74+
val {{ item.name }}{{ shadow.name }} = {%+ shadowAsKotlinPinwheelShadow shadow.light +%}
75+
{% if shadow.dark %}
76+
val {{ item.name }}{{ shadow.name }}Dark = {%+ shadowAsKotlinPinwheelShadow shadow.dark +%}
77+
{% endif %}
78+
{% if shadow.highContrast %}
79+
val {{ item.name }}{{ shadow.name }}HighContrast = {%+ shadowAsKotlinPinwheelShadow shadow.highContrast +%}
80+
{% endif %}
81+
{% if shadow.darkHighContrast %}
82+
val {{ item.name }}{{ shadow.name }}DarkHighContrast = {%+ shadowAsKotlinPinwheelShadow shadow.darkHighContrast +%}
83+
{% endif %}
84+
{% endfor %}
6185
{% endif %}
6286
{% endfor %}
87+
88+
data class PinwheelShadow(
89+
val x: Double,
90+
val y: Double,
91+
val blur: Double,
92+
val spread: Double,
93+
val color: Color
94+
) {
95+
companion object {
96+
// if using a call like asFrameworkPaint().setShadowLayer(blur,x,y,color) this is the scale factor to use
97+
const val BLUR_SCALE_FACTOR = 0.85
98+
}
99+
100+
val scaledBlur: Double
101+
get() = blur * BLUR_SCALE_FACTOR
102+
}

pinwheel/templates/Pinwheel Built In Examples/Metal.stencil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,32 @@ const char* {{ item.name }}HighContrast = "{{ item.string.value.highContrast }}"
5656
{% if item.string.value.darkHighContrast %}
5757
const char* {{ item.name }}DarkHighContrast = "{{ item.string.value.darkHighContrast }}";
5858
{% endif %}
59+
{% elif item.shadowItem %}
60+
constant constexpr auto {{ item.name }}XOffset = {{ item.shadowItem.shadow.light.x }};
61+
constant constexpr auto {{ item.name }}YOffset = {{ item.shadowItem.shadow.light.y }};
62+
constant constexpr auto {{ item.name }}Blur = {{ item.shadowItem.shadow.light.blur }};
63+
constant constexpr auto {{ item.name }}Spread = {{ item.shadowItem.shadow.light.spread }};
64+
constant constexpr auto {{ item.name }}Color = float4({{ item.shadowItem.shadow.light.color.red }}, {{ item.shadowItem.shadow.light.color.green }}, {{ item.shadowItem.shadow.light.color.blue}}, {{ item.shadowItem.shadow.light.color.alpha}});
65+
{% if item.shadowItem.shadow.dark %}
66+
constant constexpr auto {{ item.name }}DarkXOffset = {{ item.shadowItem.shadow.dark.x }};
67+
constant constexpr auto {{ item.name }}DarkYOffset = {{ item.shadowItem.shadow.dark.y }};
68+
constant constexpr auto {{ item.name }}DarkBlur = {{ item.shadowItem.shadow.dark.blur }};
69+
constant constexpr auto {{ item.name }}DarkSpread = {{ item.shadowItem.shadow.dark.spread }};
70+
constant constexpr auto {{ item.name }}DarkColor = float4({{ item.shadowItem.shadow.dark.color.red }}, {{ item.shadowItem.shadow.dark.color.green }}, {{ item.shadowItem.shadow.dark.color.blue}}, {{ item.shadowItem.shadow.dark.color.alpha}});
71+
{% endif %}
72+
{% if item.shadowItem.shadow.highContrast %}
73+
constant constexpr auto {{ item.name }}HighContrastXOffset = {{ item.shadowItem.shadow.highContrast.x }};
74+
constant constexpr auto {{ item.name }}HighContrastYOffset = {{ item.shadowItem.shadow.highContrast.y }};
75+
constant constexpr auto {{ item.name }}HighContrastBlur = {{ item.shadowItem.shadow.highContrast.blur }};
76+
constant constexpr auto {{ item.name }}HighContrastSpread = {{ item.shadowItem.shadow.highContrast.spread }};
77+
constant constexpr auto {{ item.name }}HighContrastColor = float4({{ item.shadowItem.shadow.highContrast.color.red }}, {{ item.shadowItem.shadow.highContrast.color.green }}, {{ item.shadowItem.shadow.highContrast.color.blue}}, {{ item.shadowItem.shadow.highContrast.color.alpha}});
78+
{% endif %}
79+
{% if item.shadowItem.shadow.darkHighContrast %}
80+
constant constexpr auto {{ item.name }}DarkHighContrastXOffset = {{ item.shadowItem.shadow.darkHighContrast.x }};
81+
constant constexpr auto {{ item.name }}DarkHighContrastYOffset = {{ item.shadowItem.shadow.darkHighContrast.y }};
82+
constant constexpr auto {{ item.name }}DarkHighContrastBlur = {{ item.shadowItem.shadow.darkHighContrast.blur }};
83+
constant constexpr auto {{ item.name }}DarkHighContrastSpread = {{ item.shadowItem.shadow.darkHighContrast.spread }};
84+
constant constexpr auto {{ item.name }}DarkHighContrastColor = float4({{ item.shadowItem.shadow.darkHighContrast.color.red }}, {{ item.shadowItem.shadow.darkHighContrast.color.green }}, {{ item.shadowItem.shadow.darkHighContrast.color.blue}}, {{ item.shadowItem.shadow.darkHighContrast.color.alpha}});
85+
{% endif %}
5986
{% endif %}
6087
{% endfor %}

pinwheel/templates/Pinwheel Built In Examples/OpenGL.stencil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,32 @@ const char* {{ item.name }}HighContrast = "{{ item.string.value.highContrast }}"
5656
{% if item.string.value.darkHighContrast %}
5757
const char* {{ item.name }}DarkHighContrast = "{{ item.string.value.darkHighContrast }}";
5858
{% endif %}
59+
{% elif item.shadowItem %}
60+
const float {{ item.name }}XOffset = {{ item.shadowItem.shadow.light.x }};
61+
const float {{ item.name }}YOffset = {{ item.shadowItem.shadow.light.y }};
62+
const float {{ item.name }}Blur = {{ item.shadowItem.shadow.light.blur }};
63+
const float {{ item.name }}Spread = {{ item.shadowItem.shadow.light.spread }};
64+
const vec4 {{ item.name }}Color = float4({{ item.shadowItem.shadow.light.color.red }}, {{ item.shadowItem.shadow.light.color.green }}, {{ item.shadowItem.shadow.light.color.blue}}, {{ item.shadowItem.shadow.light.color.alpha}});
65+
{% if item.shadowItem.shadow.dark %}
66+
const float {{ item.name }}DarkXOffset = {{ item.shadowItem.shadow.dark.x }};
67+
const float {{ item.name }}DarkYOffset = {{ item.shadowItem.shadow.dark.y }};
68+
const float {{ item.name }}DarkBlur = {{ item.shadowItem.shadow.dark.blur }};
69+
const float {{ item.name }}DarkSpread = {{ item.shadowItem.shadow.dark.spread }};
70+
const vec4 {{ item.name }}DarkColor = float4({{ item.shadowItem.shadow.dark.color.red }}, {{ item.shadowItem.shadow.dark.color.green }}, {{ item.shadowItem.shadow.dark.color.blue}}, {{ item.shadowItem.shadow.dark.color.alpha}});
71+
{% endif %}
72+
{% if item.shadowItem.shadow.highContrast %}
73+
const float {{ item.name }}HighContrastXOffset = {{ item.shadowItem.shadow.highContrast.x }};
74+
const float {{ item.name }}HighContrastYOffset = {{ item.shadowItem.shadow.highContrast.y }};
75+
const float {{ item.name }}HighContrastBlur = {{ item.shadowItem.shadow.highContrast.blur }};
76+
const float {{ item.name }}HighContrastSpread = {{ item.shadowItem.shadow.highContrast.spread }};
77+
const vec4 {{ item.name }}HighContrastColor = float4({{ item.shadowItem.shadow.highContrast.color.red }}, {{ item.shadowItem.shadow.highContrast.color.green }}, {{ item.shadowItem.shadow.highContrast.color.blue}}, {{ item.shadowItem.shadow.highContrast.color.alpha}});
78+
{% endif %}
79+
{% if item.shadowItem.shadow.darkHighContrast %}
80+
const float {{ item.name }}DarkHighContrastXOffset = {{ item.shadowItem.shadow.darkHighContrast.x }};
81+
const float {{ item.name }}DarkHighContrastYOffset = {{ item.shadowItem.shadow.darkHighContrast.y }};
82+
const float {{ item.name }}DarkHighContrastBlur = {{ item.shadowItem.shadow.darkHighContrast.blur }};
83+
const float {{ item.name }}DarkHighContrastSpread = {{ item.shadowItem.shadow.darkHighContrast.spread }};
84+
const vec4 {{ item.name }}DarkHighContrastColor = float4({{ item.shadowItem.shadow.darkHighContrast.color.red }}, {{ item.shadowItem.shadow.darkHighContrast.color.green }}, {{ item.shadowItem.shadow.darkHighContrast.color.blue}}, {{ item.shadowItem.shadow.darkHighContrast.color.alpha}});
85+
{% endif %}
5986
{% endif %}
6087
{% endfor %}

pinwheel/templates/Pinwheel Built In Examples/SwiftAppKitEnum.stencil

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ enum {{ exportFileName|capitalize }} {
1919
{% for color in item.colorSet.colors %}
2020
static let {%+ codeSafeName color.name +%} = {%+ colorAsSwiftAppKitColor color.light +%}
2121
{% if color.dark %}
22-
static let {%+ codeSafeName color.name +%} = {%+ colorAsSwiftAppKitColor color.dark +%}
22+
static let {%+ codeSafeName color.name +%}Dark = {%+ colorAsSwiftAppKitColor color.dark +%}
2323
{% endif %}
2424
{% if color.highContrast %}
25-
static let {%+ codeSafeName color.name +%} = {%+ colorAsSwiftAppKitColor color.highContrast +%}
25+
static let {%+ codeSafeName color.name +%}HighContrast = {%+ colorAsSwiftAppKitColor color.highContrast +%}
2626
{% endif %}
2727
{% if color.darkHighContrast %}
28-
static let {%+ codeSafeName color.name +%} = {%+ colorAsSwiftAppKitColor color.darkHighContrast +%}
28+
static let {%+ codeSafeName color.name +%}DarkHighContrast = {%+ colorAsSwiftAppKitColor color.darkHighContrast +%}
2929
{% endif %}
3030
{% endfor %}
3131
}
@@ -62,6 +62,46 @@ enum {{ exportFileName|capitalize }} {
6262
{% if item.string.value.darkHighContrast %}
6363
static let {%+ codeSafeName item.name %}DarkHighContrast = "{{ item.string.value.darkHighContrast }}"
6464
{% endif %}
65+
{% elif item.shadowItem %}
66+
static let {{ item.name }} = {%+ shadowAsSwiftAppKitPinwheelShadow item.shadowItem.shadow.light +%}
67+
{% if item.shadowItem.shadow.dark %}
68+
static let {{ item.name }}Dark = {%+ shadowAsSwiftAppKitPinwheelShadow item.shadowItem.shadow.dark +%}
69+
{% endif %}
70+
{% if item.shadowItem.shadow.highContrast %}
71+
static let {{ item.name }}HighContrast = {%+ shadowAsSwiftAppKitPinwheelShadow item.shadowItem.shadow.highContrast +%}
72+
{% endif %}
73+
{% if item.shadowItem.shadow.darkHighContrast %}
74+
static let {{ item.name }}DarkHighContrast = {%+ shadowAsSwiftAppKitPinwheelShadow item.shadowItem.shadow.darkHighContrast +%}
75+
{% endif %}
76+
{% elif item.shadowSet %}
77+
enum {{ item.name|capitalize }} {
78+
{% for shadow in item.shadowSet.shadows %}
79+
static let {%+ codeSafeName shadow.name +%} = {%+ shadowAsSwiftAppKitPinwheelShadow shadow.light +%}
80+
{% if shadow.dark %}
81+
static let {%+ codeSafeName shadow.name +%}Dark = {%+ shadowAsSwiftAppKitPinwheelShadow shadow.dark +%}
82+
{% endif %}
83+
{% if shadow.highContrast %}
84+
static let {%+ codeSafeName shadow.name +%}HighContrast = {%+ shadowAsSwiftAppKitPinwheelShadow shadow.highContrast +%}
85+
{% endif %}
86+
{% if shadow.darkHighContrast %}
87+
static let {%+ codeSafeName shadow.name +%}DarkHighContrast = {%+ shadowAsSwiftAppKitPinwheelShadow shadow.darkHighContrast +%}
88+
{% endif %}
89+
{% endfor %}
90+
}
6591
{% endif %}
6692
{% endfor %}
6793
}
94+
95+
struct PinwheelShadow {
96+
static let blurCGScaleFactor = 0.5 // CoreGraphics shadows, scale factor so the blur matches CSS box shadows and Pinwheel previews
97+
98+
let x: Double
99+
let y: Double
100+
let blur: Double
101+
let spread: Double
102+
let color: NSColor
103+
104+
var cgScaledBlured: Double {
105+
blur * Self.blurCGScaleFactor
106+
}
107+
}

0 commit comments

Comments
 (0)