Skip to content

Commit 571c2cf

Browse files
authored
Merge pull request #102 from FmgLib/101-new-features
101 new features
2 parents 808f458 + 646186c commit 571c2cf

15 files changed

+949
-171
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace FmgLib.MauiMarkup.Core;
2+
3+
public static class ColorExtension
4+
{
5+
public static Color ToColorFromArgb(this string code)
6+
=> Color.FromArgb(code);
7+
8+
public static Color ToColorFromRgba(this string code)
9+
=> Color.FromRgba(code);
10+
11+
public static Color ToColor(this string code)
12+
=> Color.Parse(code);
13+
}

libs/FmgLib.MauiMarkup/Core/Extensions/IEnumerableExtension.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System.Collections;
2+
using System.Linq.Expressions;
3+
using System.Reflection;
24

35
namespace FmgLib.MauiMarkup.Core;
46

@@ -15,4 +17,33 @@ public static void Add<T>(this T self, Action<T> configure)
1517
{
1618
configure(self);
1719
}
20+
21+
public static TModel AddRangeMarkup<TModel, TCollection, TItem>(this TModel self, Expression<Func<TModel, TCollection>> propertyExpression, params TItem[] items) where TCollection : ICollection<TItem>
22+
=> AddRangeMarkup(self, propertyExpression, items);
23+
24+
public static TModel AddRangeMarkup<TModel, TCollection, TItem>(this TModel self, Expression<Func<TModel, TCollection>> propertyExpression, IEnumerable<TItem> items) where TCollection : ICollection<TItem>
25+
{
26+
try
27+
{
28+
var property = propertyExpression.Compile()(self);
29+
30+
if (property == null)
31+
{
32+
property = (TCollection)Activator.CreateInstance(typeof(TCollection));
33+
34+
var memberExpression = (MemberExpression)propertyExpression.Body;
35+
var propertyInfo = (PropertyInfo)memberExpression.Member;
36+
propertyInfo.SetValue(self, property);
37+
}
38+
39+
foreach (var item in items)
40+
property.Add(item);
41+
42+
return self;
43+
}
44+
catch (Exception)
45+
{
46+
return self;
47+
}
48+
}
1849
}

libs/FmgLib.MauiMarkup/Extensions/BoxViewExtension.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,18 @@ public static SettersContext<T> CornerRadius<T>(this SettersContext<T> self, Fun
9393
return self;
9494
}
9595

96+
97+
public static Microsoft.Maui.Controls.BoxView CornerRadius(this Microsoft.Maui.Controls.BoxView self,
98+
double topLeft, double topRight, double bottomLeft, double bottomRight)
99+
{
100+
self.SetValue(Microsoft.Maui.Controls.BoxView.CornerRadiusProperty, new CornerRadius(topLeft, topRight, bottomLeft, bottomRight));
101+
return self;
102+
}
103+
104+
public static SettersContext<Microsoft.Maui.Controls.BoxView> CornerRadius(this SettersContext<Microsoft.Maui.Controls.BoxView> self,
105+
double topLeft, double topRight, double bottomLeft, double bottomRight)
106+
{
107+
self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.BoxView.CornerRadiusProperty, Value = new CornerRadius(topLeft, topRight, bottomLeft, bottomRight) });
108+
return self;
109+
}
96110
}

libs/FmgLib.MauiMarkup/Extensions/EditorExtension.cs

Lines changed: 133 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -346,20 +346,50 @@ public static T OnCompleted<T>(this T self, Action<T> action)
346346
}
347347

348348

349+
public static T AlignText<T>(this T self, TextAlignment vertical, TextAlignment horizontal)
350+
where T : Editor
351+
{
352+
self.SetValue(Editor.VerticalTextAlignmentProperty, vertical);
353+
self.SetValue(Editor.HorizontalTextAlignmentProperty, horizontal);
354+
return self;
355+
}
356+
357+
public static SettersContext<T> AlignText<T>(this SettersContext<T> self, TextAlignment vertical, TextAlignment horizontal)
358+
where T : Editor
359+
{
360+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = vertical });
361+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = horizontal });
362+
return self;
363+
}
364+
349365
public static T TextCenterHorizontal<T>(this T self)
350366
where T : Editor
351367
{
352368
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.Center);
353369
return self;
354370
}
355371

372+
public static SettersContext<T> TextCenterHorizontal<T>(this SettersContext<T> self)
373+
where T : Editor
374+
{
375+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.Center });
376+
return self;
377+
}
378+
356379
public static T TextCenterVertical<T>(this T self)
357380
where T : Editor
358381
{
359382
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.Center);
360383
return self;
361384
}
362385

386+
public static SettersContext<T> TextCenterVertical<T>(this SettersContext<T> self)
387+
where T : Editor
388+
{
389+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.Center });
390+
return self;
391+
}
392+
363393
public static T TextCenter<T>(this T self)
364394
where T : Editor
365395
{
@@ -368,112 +398,195 @@ public static T TextCenter<T>(this T self)
368398
return self;
369399
}
370400

401+
public static SettersContext<T> TextCenter<T>(this SettersContext<T> self)
402+
where T : Editor
403+
{
404+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.Center });
405+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.Center });
406+
return self;
407+
}
408+
371409
public static T TextTop<T>(this T self)
372410
where T : Editor
373411
{
374412
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.Start);
375413
return self;
376414
}
377415

416+
public static SettersContext<T> TextTop<T>(this SettersContext<T> self)
417+
where T : Editor
418+
{
419+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.Start });
420+
return self;
421+
}
422+
378423
public static T TextBottom<T>(this T self)
379-
where T : Editor, Microsoft.Maui.ITextAlignment
424+
where T : Editor
380425
{
381426
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.End);
382427
return self;
383428
}
384429

385-
public static T TextTopStart<T>(this T self)
430+
public static SettersContext<T> TextBottom<T>(this SettersContext<T> self)
431+
where T : Editor
432+
{
433+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.End });
434+
return self;
435+
}
436+
437+
public static T TextTopLeft<T>(this T self)
386438
where T : Editor
387439
{
388440
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.Start);
389441
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.Start);
390442
return self;
391443
}
392444

393-
public static T TextBottomStart<T>(this T self)
445+
public static SettersContext<T> TextTopLeft<T>(this SettersContext<T> self)
446+
where T : Editor
447+
{
448+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.Start });
449+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.Start });
450+
return self;
451+
}
452+
453+
public static T TextBottomLeft<T>(this T self)
394454
where T : Editor
395455
{
396456
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.End);
397457
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.Start);
398458
return self;
399459
}
400460

401-
public static T TextTopCenterH<T>(this T self)
461+
public static SettersContext<T> TextBottomLeft<T>(this SettersContext<T> self)
462+
where T : Editor
463+
{
464+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.End });
465+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.Start });
466+
return self;
467+
}
468+
469+
public static T TextTopCenter<T>(this T self)
402470
where T : Editor
403471
{
404472
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.Start);
405473
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.Center);
406474
return self;
407475
}
408476

409-
public static T TextBottomCenterH<T>(this T self)
477+
public static SettersContext<T> TextTopCenter<T>(this SettersContext<T> self)
478+
where T : Editor
479+
{
480+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.Start });
481+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.Center });
482+
return self;
483+
}
484+
485+
public static T TextBottomCenter<T>(this T self)
410486
where T : Editor
411487
{
412488
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.End);
413489
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.Center);
414490
return self;
415491
}
416492

417-
public static T TextCenterVEnd<T>(this T self)
493+
public static SettersContext<T> TextBottomCenter<T>(this SettersContext<T> self)
418494
where T : Editor
419495
{
420-
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.Start);
421-
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.End);
496+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.End });
497+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.Center });
422498
return self;
423499
}
424500

425-
public static T TextCenterVStart<T>(this T self)
501+
public static T TextCenterRight<T>(this T self)
426502
where T : Editor
427503
{
428-
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.End);
504+
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.Center);
429505
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.End);
430506
return self;
431507
}
432508

433-
public static T AlignText<T>(this T self, TextAlignment vertical, TextAlignment horizontal)
509+
public static SettersContext<T> TextCenterRight<T>(this SettersContext<T> self)
434510
where T : Editor
435511
{
436-
self.SetValue(Editor.VerticalTextAlignmentProperty, vertical);
437-
self.SetValue(Editor.HorizontalTextAlignmentProperty, horizontal);
512+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.Center });
513+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.End });
438514
return self;
439515
}
440516

441-
public static SettersContext<T> AlignText<T>(this SettersContext<T> self, TextAlignment vertical, TextAlignment horizontal)
517+
public static T TextCenterLeft<T>(this T self)
442518
where T : Editor
443519
{
444-
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = vertical });
445-
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = horizontal });
520+
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.Center);
521+
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.Start);
522+
return self;
523+
}
524+
525+
public static SettersContext<T> TextCenterLeft<T>(this SettersContext<T> self)
526+
where T : Editor
527+
{
528+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.Center });
529+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.Start });
446530
return self;
447531
}
448532

449-
public static T TextTopEnd<T>(this T self)
533+
public static T TextTopRight<T>(this T self)
450534
where T : Editor
451535
{
452536
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.Start);
453537
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.End);
454538
return self;
455539
}
456540

457-
public static T TextBottomEnd<T>(this T self)
541+
public static SettersContext<T> TextTopRight<T>(this SettersContext<T> self)
542+
where T : Editor
543+
{
544+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.Start });
545+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.End });
546+
return self;
547+
}
548+
549+
public static T TextBottomRight<T>(this T self)
458550
where T : Editor
459551
{
460552
self.SetValue(Editor.VerticalTextAlignmentProperty, TextAlignment.End);
461553
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.End);
462554
return self;
463555
}
464556

465-
public static T TextStart<T>(this T self)
557+
public static SettersContext<T> TextBottomRight<T>(this SettersContext<T> self)
558+
where T : Editor
559+
{
560+
self.XamlSetters.Add(new Setter { Property = Editor.VerticalTextAlignmentProperty, Value = TextAlignment.End });
561+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.End });
562+
return self;
563+
}
564+
565+
public static T TextLeft<T>(this T self)
466566
where T : Editor
467567
{
468568
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.Start);
469569
return self;
470570
}
471571

472-
public static T TextEnd<T>(this T self)
572+
public static SettersContext<T> TextLeft<T>(this SettersContext<T> self)
573+
where T : Editor
574+
{
575+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.Start });
576+
return self;
577+
}
578+
579+
public static T TextRight<T>(this T self)
473580
where T : Editor
474581
{
475582
self.SetValue(Editor.HorizontalTextAlignmentProperty, TextAlignment.End);
476583
return self;
477584
}
478585

586+
public static SettersContext<T> TextRight<T>(this SettersContext<T> self)
587+
where T : Editor
588+
{
589+
self.XamlSetters.Add(new Setter { Property = Editor.HorizontalTextAlignmentProperty, Value = TextAlignment.End });
590+
return self;
591+
}
479592
}

0 commit comments

Comments
 (0)