forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NUI] Implement Editor/Entry handler (dotnet#335)
* Implement Editor/Entry handler * Fix measure issue * Update paramer name * Fix if statement
- Loading branch information
Showing
4 changed files
with
278 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,110 @@ | ||
using NView = Tizen.NUI.BaseComponents.View; | ||
using System; | ||
using Tizen.NUI.BaseComponents; | ||
using Tizen.UIExtensions.Common; | ||
using Tizen.UIExtensions.NUI; | ||
using TSize = Tizen.UIExtensions.Common.Size; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class EditorHandler : ViewHandler<IEditor, NView> | ||
public partial class EditorHandler : ViewHandler<IEditor, Editor> | ||
{ | ||
// TODO Need to implement | ||
protected override NView CreatePlatformView() => new NView() | ||
class MauiEditor : Editor, IMeasurable | ||
{ | ||
BackgroundColor = Tizen.NUI.Color.Red | ||
}; | ||
TSize IMeasurable.Measure(double availableWidth, double availableHeight) | ||
{ | ||
if (!string.IsNullOrEmpty(Text)) | ||
{ | ||
if (availableWidth < NaturalSize.Width) | ||
{ | ||
return new TSize(availableWidth, NaturalSize.Height); | ||
} | ||
else if (NaturalSize.Width > 0) | ||
{ | ||
return new TSize(NaturalSize.Width, NaturalSize.Height); | ||
} | ||
else | ||
{ | ||
// even though text but natural size is zero. it is abnormal state | ||
return new TSize(Math.Max(Text.Length * PixelSize + 10, availableWidth), PixelSize + 10); | ||
} | ||
} | ||
else | ||
{ | ||
return new TSize(Math.Max(PixelSize + 10, availableWidth), PixelSize + 10); | ||
}; | ||
} | ||
} | ||
|
||
protected override Editor CreatePlatformView() => new MauiEditor(); | ||
|
||
public static void MapBackground(IEditorHandler handler, IEditor editor) | ||
protected override void ConnectHandler(Editor nativeView) | ||
{ | ||
handler.UpdateValue(nameof(handler.ContainerView)); | ||
handler.ToPlatform()?.UpdateBackground(editor); | ||
nativeView.TextChanged += OnTextChanged; | ||
nativeView.FocusLost += OnFocusLost; | ||
base.ConnectHandler(nativeView); | ||
} | ||
|
||
public static void MapText(IEditorHandler handler, IEditor editor) | ||
protected override void DisconnectHandler(Editor nativeView) | ||
{ | ||
nativeView.TextChanged -= OnTextChanged; | ||
nativeView.FocusLost -= OnFocusLost; | ||
base.DisconnectHandler(nativeView); | ||
} | ||
|
||
public static void MapTextColor(IEditorHandler handler, IEditor editor) | ||
public static void MapBackground(EditorHandler handler, IEditor editor) | ||
{ | ||
handler.UpdateValue(nameof(handler.ContainerView)); | ||
handler.GetWrappedNativeView()?.UpdateBackground(editor); | ||
} | ||
public static void MapText(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdateText(editor); | ||
|
||
public static void MapPlaceholder(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
public static void MapTextColor(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdateTextColor(editor); | ||
|
||
public static void MapPlaceholderColor(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
public static void MapPlaceholder(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdatePlaceholder(editor); | ||
|
||
public static void MapMaxLength(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
public static void MapPlaceholderColor(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdatePlaceholderColor(editor); | ||
|
||
public static void MapIsReadOnly(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
[MissingMapper] | ||
public static void MapCharacterSpacing(EditorHandler handler, IEditor editor) { } | ||
|
||
public static void MapIsTextPredictionEnabled(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
public static void MapMaxLength(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdateMaxLength(editor); | ||
|
||
public static void MapFont(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
public static void MapIsReadOnly(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdateIsReadOnly(editor); | ||
|
||
public static void MapFormatting(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
public static void MapIsTextPredictionEnabled(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdateIsTextPredictionEnabled(editor); | ||
|
||
public static void MapKeyboard(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
public static void MapFont(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdateFont(editor, handler.GetRequiredService<IFontManager>()); | ||
|
||
public static void MapHorizontalTextAlignment(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
public static void MapHorizontalTextAlignment(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdateHorizontalTextAlignment(editor); | ||
|
||
public static void MapVerticalTextAlignment(IEditorHandler handler, IEditor editor) | ||
{ | ||
} | ||
[MissingMapper] | ||
public static void MapVerticalTextAlignment(EditorHandler handler, IEditor editor) { } | ||
|
||
public static void MapKeyboard(IEditorHandler handler, IEditor editor) | ||
{ | ||
public static void MapKeyboard(EditorHandler handler, IEditor editor) => | ||
handler.PlatformView?.UpdateKeyboard(editor); | ||
} | ||
|
||
public static void MapHorizontalTextAlignment(IEditorHandler handler, IEditor editor) | ||
void OnTextChanged(object? sender, TextEditor.TextChangedEventArgs e) | ||
{ | ||
handler.PlatformView?.UpdateHorizontalTextAlignment(editor); | ||
} | ||
if (VirtualView == null || PlatformView == null) | ||
return; | ||
|
||
public static void MapVerticalTextAlignment(IEditorHandler handler, IEditor editor) | ||
{ | ||
handler.PlatformView?.UpdateVerticalTextAlignment(editor); | ||
VirtualView.Text = PlatformView.Text; | ||
} | ||
|
||
public static void MapCursorPosition(IEditorHandler handler, ITextInput editor) | ||
void OnFocusLost(object? sender, System.EventArgs e) | ||
{ | ||
handler.PlatformView?.UpdateSelectionLength(editor); | ||
} | ||
if (VirtualView == null || PlatformView == null) | ||
return; | ||
|
||
public static void MapSelectionLength(IEditorHandler handler, ITextInput editor) | ||
{ | ||
handler.PlatformView?.UpdateSelectionLength(editor); | ||
VirtualView.Completed(); | ||
} | ||
|
||
[MissingMapper] | ||
public static void MapCharacterSpacing(EditorHandler handler, IEditor editor) { } | ||
} | ||
} |
Oops, something went wrong.