Skip to content

Commit

Permalink
Implement Missing mapper (dotnet#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
myroot committed Aug 25, 2022
1 parent fe4ae8c commit 96e5f2d
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 44 deletions.
34 changes: 28 additions & 6 deletions src/Controls/src/Core/HandlerImpl/Button/Button.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.Platform;
using Tizen.NUI;

namespace Microsoft.Maui.Controls
{
Expand All @@ -12,7 +10,31 @@ public static void MapText(ButtonHandler handler, Button button)
handler.PlatformView?.UpdateText(button);
}

[MissingMapper]
public static void MapLineBreakMode(IButtonHandler handler, Button button) { }
public static void MapLineBreakMode(IButtonHandler handler, Button button)
{
switch (button.LineBreakMode)
{
case LineBreakMode.NoWrap:
handler.PlatformView.TextLabel.MultiLine = false;
handler.PlatformView.TextLabel.Ellipsis = false;
break;
case LineBreakMode.WordWrap:
handler.PlatformView.TextLabel.MultiLine = true;
handler.PlatformView.TextLabel.Ellipsis = false;
handler.PlatformView.TextLabel.LineWrapMode = LineWrapMode.Word;
break;
case LineBreakMode.CharacterWrap:
handler.PlatformView.TextLabel.MultiLine = true;
handler.PlatformView.TextLabel.Ellipsis = false;
handler.PlatformView.TextLabel.LineWrapMode = LineWrapMode.Character;
break;
case LineBreakMode.HeadTruncation:
case LineBreakMode.TailTruncation:
case LineBreakMode.MiddleTruncation:
handler.PlatformView.TextLabel.MultiLine = false;
handler.PlatformView.TextLabel.Ellipsis = true;
break;
}
}
}
}
34 changes: 21 additions & 13 deletions src/Core/src/Handlers/Button/ButtonHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,34 @@ public static Task MapImageSourceAsync(IButtonHandler handler, IImage image)
return handler.ImageSourceLoader.UpdateImageSourceAsync();
}

[MissingMapper]
public static void MapCharacterSpacing(IButtonHandler handler, ITextStyle button) { }
public static void MapCharacterSpacing(IButtonHandler handler, ITextStyle button)
{
handler.PlatformView.UpdateCharacterSpacing(button);
}

[MissingMapper]
public static void MapFont(IButtonHandler handler, ITextStyle button) { }
public static void MapFont(IButtonHandler handler, ITextStyle button)
{
var fontManager = handler.GetRequiredService<IFontManager>();
handler.PlatformView.UpdateFont(button, fontManager);
}

[MissingMapper]
public static void MapPadding(IButtonHandler handler, IButton button) { }

[MissingMapper]
public static void MapStrokeColor(IButtonHandler handler, IButtonStroke buttonStroke) { }

[MissingMapper]
public static void MapStrokeThickness(IButtonHandler handler, IButtonStroke buttonStroke) { }
public static void MapStrokeColor(IButtonHandler handler, IButtonStroke buttonStroke)
{
handler.PlatformView.UpdateStrokeColor(buttonStroke);
}

[MissingMapper]
public static void MapCornerRadius(IButtonHandler handler, IButtonStroke buttonStroke) { }
public static void MapStrokeThickness(IButtonHandler handler, IButtonStroke buttonStroke)
{
handler.PlatformView.UpdateStrokeThickness(buttonStroke);
}

[MissingMapper]
public static void MapLineBreakMode(IButtonHandler handler, IButton button) { }
public static void MapCornerRadius(IButtonHandler handler, IButtonStroke buttonStroke)
{
handler.PlatformView.UpdateCornerRadius(buttonStroke);
}

bool OnTouch(object source, View.TouchEventArgs e)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Core/src/Handlers/Editor/EditorHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public static void MapCursorPosition(IEditorHandler handler, ITextInput editor)
public static void MapSelectionLength(IEditorHandler handler, ITextInput editor) =>
handler.PlatformView?.UpdateSelectionLength(editor);

[MissingMapper]
public static void MapCharacterSpacing(IEditorHandler handler, IEditor editor) { }
public static void MapCharacterSpacing(IEditorHandler handler, IEditor editor) =>
handler.PlatformView.UpdateCharacterSpacing(editor);

public static void MapMaxLength(IEditorHandler handler, IEditor editor) =>
handler.PlatformView?.UpdateMaxLength(editor);
Expand All @@ -97,8 +97,8 @@ public static void MapFont(IEditorHandler handler, IEditor editor) =>
public static void MapHorizontalTextAlignment(IEditorHandler handler, IEditor editor) =>
handler.PlatformView?.UpdateHorizontalTextAlignment(editor);

[MissingMapper]
public static void MapVerticalTextAlignment(IEditorHandler handler, IEditor editor) { }
public static void MapVerticalTextAlignment(IEditorHandler handler, IEditor editor) =>
handler.PlatformView.UpdateVerticalTextAlignment(editor);

public static void MapKeyboard(IEditorHandler handler, IEditor editor) =>
handler.PlatformView?.UpdateKeyboard(editor);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/Entry/EntryHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public static void MapKeyboard(IEntryHandler handler, IEntry entry) =>
public static void MapReturnType(IEntryHandler handler, IEntry entry) =>
handler.PlatformView?.UpdateReturnType(entry);

[MissingMapper]
public static void MapCharacterSpacing(IEntryHandler handler, IEntry entry) { }
public static void MapCharacterSpacing(IEntryHandler handler, IEntry entry) =>
handler.PlatformView.UpdateCharacterSpacing(entry);

public static void MapCursorPosition(IEntryHandler handler, IEntry entry) =>
handler.PlatformView?.UpdateCursorPosition(entry);
Expand Down
20 changes: 14 additions & 6 deletions src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ protected override MauiImageButton CreatePlatformView()
};
}

public override bool NeedsContainer => false;

protected override void ConnectHandler(MauiImageButton platformView)
{
platformView.Clicked += OnClicked;
Expand All @@ -28,14 +30,20 @@ protected override void DisconnectHandler(MauiImageButton platformView)
base.DisconnectHandler(platformView);
}

[MissingMapper]
public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke buttonStroke) { }
public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke buttonStroke)
{
handler.PlatformView.UpdateStrokeColor(buttonStroke);
}

[MissingMapper]
public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke) { }
public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke)
{
handler.PlatformView.UpdateStrokeThickness(buttonStroke);
}

[MissingMapper]
public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke) { }
public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke)
{
handler.PlatformView.UpdateCornerRadius(buttonStroke);
}

[MissingMapper]
public static void MapPadding(IImageButtonHandler handler, IImageButton imageButton) { }
Expand Down
12 changes: 8 additions & 4 deletions src/Core/src/Handlers/Label/LabelHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ public static void MapShadow(ILabelHandler handler, ILabel label)
handler.PlatformView?.UpdateShadow(label);
}

[MissingMapper]
public static void MapCharacterSpacing(ILabelHandler handler, ILabel label) { }
public static void MapCharacterSpacing(ILabelHandler handler, ILabel label)
{
handler.PlatformView.UpdateCharacterSpacing(label);
}

[MissingMapper]
public static void MapLineHeight(ILabelHandler handler, ILabel label) { }
public static void MapLineHeight(ILabelHandler handler, ILabel label)
{
handler.PlatformView.UpdateLineHeight(label);
}

[MissingMapper]
public static void MapPadding(ILabelHandler handler, ILabel label) { }
Expand Down
6 changes: 4 additions & 2 deletions src/Core/src/Handlers/Picker/PickerHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ public static void MapSelectedIndex(IPickerHandler handler, IPicker picker)
handler.PlatformView.UpdateSelectedIndex(picker);
}

[MissingMapper]
public static void MapCharacterSpacing(IPickerHandler handler, IPicker picker) { }
public static void MapCharacterSpacing(IPickerHandler handler, IPicker picker)
{
handler.PlatformView.UpdateCharacterSpacing(picker);
}

static void Reload(IPickerHandler handler)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Core/src/Handlers/SearchBar/SearchBarHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public static void MapKeyboard(ISearchBarHandler handler, ISearchBar searchBar)
[MissingMapper]
public static void MapCancelButtonColor(ISearchBarHandler handler, ISearchBar searchBar) { }

[MissingMapper]
public static void MapCharacterSpacing(ISearchBarHandler handler, ISearchBar searchBar) { }
public static void MapCharacterSpacing(ISearchBarHandler handler, ISearchBar searchBar)
{
handler.PlatformView.Entry.UpdateCharacterSpacing(searchBar);
}

void OnTextChanged(object? sender, Tizen.NUI.BaseComponents.TextField.TextChangedEventArgs e)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Core/src/Handlers/TimePicker/TimePickerHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public static void MapTextColor(ITimePickerHandler handler, ITimePicker timePick
handler.PlatformView.UpdateTextColor(timePicker);
}

[MissingMapper]
public static void MapCharacterSpacing(ITimePickerHandler handler, ITimePicker timePicker) { }
public static void MapCharacterSpacing(ITimePickerHandler handler, ITimePicker timePicker)
{
handler.PlatformView.UpdateCharacterSpacing(timePicker);
}

bool OnTouch(object source, Tizen.NUI.BaseComponents.View.TouchEventArgs e)
{
Expand Down
31 changes: 31 additions & 0 deletions src/Core/src/Platform/Tizen/ButtonExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Tizen.UIExtensions.NUI;
using NColor = Tizen.NUI.Color;

namespace Microsoft.Maui.Platform
{
Expand All @@ -13,5 +14,35 @@ public static void UpdateText(this Button platformButton, IText button)
{
platformButton.Text = button.Text ?? "";
}

public static void UpdateCharacterSpacing(this Button platformButton, ITextStyle button)
{
platformButton.TextLabel.CharacterSpacing = button.CharacterSpacing.ToScaledPixel();
}

public static void UpdateFont(this Button platformButton, ITextStyle label, IFontManager fontManager)
{
platformButton.FontSize = label.Font.Size > 0 ? label.Font.Size.ToScaledPoint() : 14d.ToScaledPoint();
platformButton.FontAttributes = label.Font.GetFontAttributes();
platformButton.FontFamily = fontManager.GetFontFamily(label.Font.Family) ?? "";
}

public static void UpdateStrokeColor(this Button platformButton, IButtonStroke button)
{
platformButton.BorderlineColor = button.StrokeColor.ToNUIColor() ?? NColor.Transparent;
}

public static void UpdateStrokeThickness(this Button platformButton, IButtonStroke button)
{
platformButton.BorderlineWidth = button.StrokeThickness.ToScaledPixel();
}

public static void UpdateCornerRadius(this Button platformButton, IButtonStroke button)
{
if (button.CornerRadius != -1)
{
platformButton.CornerRadius = ((double)button.CornerRadius).ToScaledPixel();
}
}
}
}
21 changes: 21 additions & 0 deletions src/Core/src/Platform/Tizen/EditorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ public static void UpdateHorizontalTextAlignment(this Editor platformEditor, ITe
platformEditor.HorizontalTextAlignment = editor.HorizontalTextAlignment.ToPlatform();
}

public static void UpdateVerticalTextAlignment(this Editor platformEditor, ITextAlignment editor)
{
switch (editor.HorizontalTextAlignment)
{
case TextAlignment.Start:
platformEditor.VerticalAlignment = Tizen.NUI.VerticalAlignment.Top;
break;
case TextAlignment.Center:
platformEditor.VerticalAlignment = Tizen.NUI.VerticalAlignment.Center;
break;
case TextAlignment.End:
platformEditor.VerticalAlignment = Tizen.NUI.VerticalAlignment.Bottom;
break;
}
}

public static void UpdateFont(this Editor platformEditor, ITextStyle textStyle, IFontManager fontManager)
{
platformEditor.FontSize = textStyle.Font.Size > 0 ? textStyle.Font.Size.ToScaledPoint() : 25d.ToScaledPoint();
Expand Down Expand Up @@ -82,5 +98,10 @@ public static void UpdateKeyboard(this Editor platformEditor, ITextInput editor)
{
platformEditor.Keyboard = editor.Keyboard.ToPlatform();
}

public static void UpdateCharacterSpacing(this Editor platformEditor, ITextInput editor)
{
platformEditor.CharacterSpacing = editor.CharacterSpacing.ToScaledPixel();
}
}
}
5 changes: 5 additions & 0 deletions src/Core/src/Platform/Tizen/EntryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public static void UpdateSelectionLength(this Entry platformEntry, IEntry entry)
}
}

public static void UpdateCharacterSpacing(this Entry platformEntry, ITextStyle entry)
{
platformEntry.CharacterSpacing = entry.CharacterSpacing.ToScaledPixel();
}

public static TReturnType ToPlatform(this ReturnType returnType)
{
switch (returnType)
Expand Down
10 changes: 10 additions & 0 deletions src/Core/src/Platform/Tizen/LabelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public static void UpdateShadow(this Label platformLabel, IView view)
}
}

public static void UpdateCharacterSpacing(this Label platformLabel, ILabel label)
{
platformLabel.CharacterSpacing = label.CharacterSpacing.ToScaledPixel();
}

public static void UpdateLineHeight(this Label platformLabel, ILabel label)
{
platformLabel.RelativeLineHeight = (float)label.LineHeight;
}

public static FontAttributes GetFontAttributes(this Font font)
{
FontAttributes attributes = font.Weight == FontWeight.Bold ? FontAttributes.Bold : FontAttributes.None;
Expand Down
20 changes: 18 additions & 2 deletions src/Core/src/Platform/Tizen/MauiImageButton.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Tizen.NUI;
using Tizen.UIExtensions.Common;
using NColor = Tizen.NUI.Color;
using TImage = Tizen.UIExtensions.NUI.Image;

namespace Microsoft.Maui.Platform
Expand All @@ -16,6 +16,23 @@ public class MauiImageButton : TImage
public MauiImageButton()
{
TouchEvent += OnTouched;
Border = Border = new Rectangle(0, 0, 0, 0);
}

public void UpdateStrokeColor(IButtonStroke button)
{
BorderlineColor = button.StrokeColor.ToNUIColor() ?? NColor.Transparent;
}

public void UpdateStrokeThickness(IButtonStroke button)
{
BorderlineWidth = button.StrokeThickness.ToScaledPixel();
}

public void UpdateCornerRadius(IButtonStroke button)
{
if (button.CornerRadius != -1)
CornerRadius = ((double)button.CornerRadius).ToScaledPixel();
}

bool OnTouched(object source, TouchEventArgs e)
Expand All @@ -38,7 +55,6 @@ bool OnTouched(object source, TouchEventArgs e)
_isPressed = false;
return true;
}
_isPressed = false;
return false;
}
}
Expand Down
Loading

0 comments on commit 96e5f2d

Please sign in to comment.