Skip to content

Commit c476875

Browse files
committed
Add new extension methods for VisualElements
1 parent b045c48 commit c476875

File tree

5 files changed

+316
-97
lines changed

5 files changed

+316
-97
lines changed

Aspid.UnityFastTools/Assets/Plugins/Aspid/UnityFastTools/Source/Runtime/VisualElements/Extensions/IStyleExtensions.cs

Lines changed: 137 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,6 @@ public static T SetPadding<T>(this T style,
3838
return style;
3939
}
4040

41-
public static T SetBorderRadius<T>(this T style,
42-
StyleLength? topLeft = null,
43-
StyleLength? topRight = null,
44-
StyleLength? bottomLeft = null,
45-
StyleLength? bottomRight = null)
46-
where T : IStyle
47-
{
48-
if (topLeft is not null) style.borderTopLeftRadius = topLeft.Value;
49-
if (topRight is not null) style.borderTopRightRadius = topRight.Value;
50-
51-
if (bottomLeft is not null) style.borderBottomLeftRadius = bottomLeft.Value;
52-
if (bottomRight is not null) style.borderBottomRightRadius = bottomRight.Value;
53-
54-
return style;
55-
}
56-
5741
#region Font
5842
public static T SetFontSize<T>(this T style, StyleLength size)
5943
where T : IStyle
@@ -84,119 +68,220 @@ public static T SetUnityFontStyleAndWeight<T>(this T style, StyleEnum<FontStyle>
8468
}
8569
#endregion
8670

87-
#region Align
88-
public static T SetAlignSelf<T>(this T style, StyleEnum<Align> align)
71+
#region Flex
72+
public static T SetFlexGrow<T>(this T style, StyleFloat flexGrow)
8973
where T : IStyle
9074
{
91-
style.alignSelf = align;
75+
style.flexGrow = flexGrow;
9276
return style;
9377
}
9478

95-
public static T SetAlignItems<T>(this T style, StyleEnum<Align> align)
79+
public static T SetFlexBasis<T>(this T style, StyleLength flexBasis)
9680
where T : IStyle
9781
{
98-
style.alignItems = align;
82+
style.flexBasis = flexBasis;
9983
return style;
10084
}
10185

102-
public static T SetAlignContent<T>(this T style, StyleEnum<Align> align)
86+
public static T SetFlexShrink<T>(this T style, StyleFloat flexShrink)
10387
where T : IStyle
10488
{
105-
style.alignContent = align;
89+
style.flexShrink = flexShrink;
90+
return style;
91+
}
92+
93+
public static T SetFlexWrap<T>(this T style, StyleEnum<Wrap> flexWrap)
94+
where T : IStyle
95+
{
96+
style.flexWrap = flexWrap;
97+
return style;
98+
}
99+
100+
101+
public static T SetFlexDirection<T>(this T style, FlexDirection flexDirection)
102+
where T : IStyle
103+
{
104+
style.flexDirection = flexDirection;
106105
return style;
107106
}
108107
#endregion
109108

110-
#region Color
111-
public static T SetColor<T>(this T style, StyleColor color)
109+
#region Size
110+
public static T SetSize<T>(this T style, StyleLength? width = null, StyleLength? height = null)
112111
where T : IStyle
113112
{
114-
style.color = color;
113+
if (width is not null) style.width = width.Value;
114+
if (height is not null) style.height = height.Value;
115+
115116
return style;
116117
}
117118

118-
public static T SetBackgroundColor<T>(this T style, StyleColor color)
119+
public static T SetMinSize<T>(this T style, StyleLength? width = null, StyleLength? height = null)
119120
where T : IStyle
120121
{
121-
style.backgroundColor = color;
122+
if (width is not null) style.minWidth = width.Value;
123+
if (height is not null) style.minHeight = height.Value;
124+
122125
return style;
123126
}
124127
#endregion
128+
129+
#region Text
130+
public static T SetUnityTextAlign<T>(this T style, TextAnchor textAnchor)
131+
where T : IStyle
132+
{
133+
style.unityTextAlign = textAnchor;
134+
return style;
135+
}
125136

126-
#region Flex
127-
public static T SetFlexGrow<T>(this T style, StyleFloat flexGrow)
137+
public static T SetTextShadow<T>(this T style, StyleTextShadow textShadow)
128138
where T : IStyle
129139
{
130-
style.flexGrow = flexGrow;
140+
style.textShadow = textShadow;
131141
return style;
132142
}
133143

134-
public static T SetFlexBasis<T>(this T style, StyleLength flexBasis)
144+
public static T SetUnityTextOutlineColor<T>(this T style, StyleColor color)
135145
where T : IStyle
136146
{
137-
style.flexBasis = flexBasis;
147+
style.unityTextOutlineColor = color;
138148
return style;
139149
}
140150

141-
public static T SetFlexShrink<T>(this T style, StyleFloat flexShrink)
151+
public static T SetUnityTextAutoSize<T>(this T style, StyleTextAutoSize textAutoSize)
142152
where T : IStyle
143153
{
144-
style.flexShrink = flexShrink;
154+
style.unityTextAutoSize = textAutoSize;
145155
return style;
146156
}
147157

148-
public static T SetFlexWrap<T>(this T style, StyleEnum<Wrap> flexWrap)
158+
public static T SetTextOverflow<T>(this T style, StyleEnum<TextOverflow> textOverflow)
149159
where T : IStyle
150160
{
151-
style.flexWrap = flexWrap;
161+
style.textOverflow = textOverflow;
152162
return style;
153-
}
163+
}
154164

165+
public static T SetUnityTextGenerator<T>(this T style, TextGeneratorType textGeneratorType)
166+
where T : IStyle
167+
{
168+
style.unityTextGenerator = textGeneratorType;
169+
return style;
170+
}
155171

156-
public static T SetFlexDirection<T>(this T style, FlexDirection flexDirection)
172+
public static T SetUnityTextOutlineWidth<T>(this T style, StyleFloat unityTextOutlineWidth)
157173
where T : IStyle
158174
{
159-
style.flexDirection = flexDirection;
175+
style.unityTextOutlineWidth = unityTextOutlineWidth;
176+
return style;
177+
}
178+
179+
public static T SetUnityTextOverflowPosition<T>(this T style, TextOverflowPosition unityTextOutlineWidth)
180+
where T : IStyle
181+
{
182+
style.unityTextOverflowPosition = unityTextOutlineWidth;
183+
return style;
184+
}
185+
186+
public static T SetUnityEditorTextRenderingMode<T>(this T style, EditorTextRenderingMode editorTextRenderingMode)
187+
where T : IStyle
188+
{
189+
style.unityEditorTextRenderingMode = editorTextRenderingMode;
160190
return style;
161191
}
162192
#endregion
163193

164-
#region Overflow
165-
public static T SetOverflow<T>(this T style, StyleEnum<Overflow> overflow)
194+
#region Align
195+
public static T SetAlignSelf<T>(this T style, StyleEnum<Align> align)
166196
where T : IStyle
167197
{
168-
style.overflow = overflow;
198+
style.alignSelf = align;
169199
return style;
170200
}
171201

172-
public static T SetTextOverflow<T>(this T style, StyleEnum<TextOverflow> textOverflow)
202+
public static T SetAlignItems<T>(this T style, StyleEnum<Align> align)
173203
where T : IStyle
174204
{
175-
style.textOverflow = textOverflow;
205+
style.alignItems = align;
176206
return style;
177-
}
207+
}
208+
209+
public static T SetAlignContent<T>(this T style, StyleEnum<Align> align)
210+
where T : IStyle
211+
{
212+
style.alignContent = align;
213+
return style;
214+
}
178215
#endregion
179216

180-
public static T SetWhiteSpace<T>(this T style, StyleEnum<WhiteSpace> whiteSpace)
217+
#region Color
218+
public static T SetColor<T>(this T style, StyleColor color)
181219
where T : IStyle
182220
{
183-
style.whiteSpace = whiteSpace;
221+
style.color = color;
222+
return style;
223+
}
224+
225+
public static T SetBackgroundColor<T>(this T style, StyleColor color)
226+
where T : IStyle
227+
{
228+
style.backgroundColor = color;
229+
return style;
230+
}
231+
#endregion
232+
233+
#region Border
234+
public static T SetBorderWidth<T>(this T style,
235+
StyleFloat? top = null,
236+
StyleFloat? bottom = null,
237+
StyleFloat? left = null,
238+
StyleFloat? right = null)
239+
where T : IStyle
240+
{
241+
if (top is not null) style.borderTopWidth = top.Value;
242+
if (bottom is not null) style.borderBottomWidth = bottom.Value;
243+
244+
if (left is not null) style.borderLeftWidth = left.Value;
245+
if (right is not null) style.borderRightWidth = right.Value;
246+
184247
return style;
185248
}
186249

250+
public static T SetBorderRadius<T>(this T style,
251+
StyleLength? topLeft = null,
252+
StyleLength? topRight = null,
253+
StyleLength? bottomLeft = null,
254+
StyleLength? bottomRight = null)
255+
where T : IStyle
256+
{
257+
if (topLeft is not null) style.borderTopLeftRadius = topLeft.Value;
258+
if (topRight is not null) style.borderTopRightRadius = topRight.Value;
259+
260+
if (bottomLeft is not null) style.borderBottomLeftRadius = bottomLeft.Value;
261+
if (bottomRight is not null) style.borderBottomRightRadius = bottomRight.Value;
262+
263+
return style;
264+
}
265+
#endregion
266+
187267
public static T SetDisplay<T>(this T style, DisplayStyle display)
188268
where T : IStyle
189269
{
190270
style.display = display;
191271
return style;
192272
}
193273

194-
public static T SetSize<T>(this T style, StyleLength? width = null, StyleLength? height = null)
274+
public static T SetOverflow<T>(this T style, StyleEnum<Overflow> overflow)
195275
where T : IStyle
196276
{
197-
if (width is not null) style.width = width.Value;
198-
if (height is not null) style.height = height.Value;
199-
277+
style.overflow = overflow;
278+
return style;
279+
}
280+
281+
public static T SetWhiteSpace<T>(this T style, StyleEnum<WhiteSpace> whiteSpace)
282+
where T : IStyle
283+
{
284+
style.whiteSpace = whiteSpace;
200285
return style;
201286
}
202287
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using UnityEngine.UIElements;
3+
4+
// ReSharper disable once CheckNamespace
5+
namespace Aspid.UnityFastTools
6+
{
7+
public static class ListViewExtensions
8+
{
9+
public static T SetBindItem<T>(this T element, Action<VisualElement, int> bindItem)
10+
where T : ListView
11+
{
12+
element.bindItem = bindItem;
13+
return element;
14+
}
15+
16+
#region Make
17+
public static T SetMakeItem<T>(this T element, Func<VisualElement> makeItem)
18+
where T : ListView
19+
{
20+
element.makeItem = makeItem;
21+
return element;
22+
}
23+
24+
public static T SetMakeFooter<T>(this T element, Func<VisualElement> makeFooter)
25+
where T : ListView
26+
{
27+
element.makeFooter = makeFooter;
28+
return element;
29+
}
30+
31+
public static T SetMakeHeader<T>(this T element, Func<VisualElement> makeHeader)
32+
where T : ListView
33+
{
34+
element.makeHeader = makeHeader;
35+
return element;
36+
}
37+
38+
public static T SetMakeNoneElement<T>(this T element, Func<VisualElement> makeNoneElement)
39+
where T : ListView
40+
{
41+
element.makeNoneElement = makeNoneElement;
42+
return element;
43+
}
44+
#endregion
45+
}
46+
}

Aspid.UnityFastTools/Assets/Plugins/Aspid/UnityFastTools/Source/Runtime/VisualElements/Extensions/ListViewExtensions.cs.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.

0 commit comments

Comments
 (0)