85 lines
2.2 KiB
C#
85 lines
2.2 KiB
C#
using Sarand.Net.Mobile.Maui.App;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sarand.Net.Mobile.Maui.Controls
|
|
{
|
|
public class SamEditor : Editor, ISamNativeControlStyle, ISamControl
|
|
{
|
|
// --- Data Members ---
|
|
|
|
private bool trimTextOnCompletion = true;
|
|
private int NumberOfLinesPrevious = 0;
|
|
|
|
// --- Construction ---
|
|
|
|
public SamEditor()
|
|
{
|
|
DefaultFontSize = FontSize;
|
|
Text = "";
|
|
TextChanged += SamEditor_TextChanged;
|
|
Completed += SamEditor_Completed;
|
|
}
|
|
|
|
// --- Component state ---
|
|
|
|
public void SetControlActivity(bool enabled)
|
|
{
|
|
if (IsEnabled != enabled) IsEnabled = enabled;
|
|
}
|
|
|
|
// --- Properties ---
|
|
|
|
|
|
public double DefaultFontSize { get; }
|
|
|
|
public bool TrimText
|
|
{
|
|
get { return trimTextOnCompletion; }
|
|
set
|
|
{
|
|
if (trimTextOnCompletion == value) return;
|
|
trimTextOnCompletion = value;
|
|
}
|
|
}
|
|
|
|
// --- Native styling ---
|
|
public bool NativeNoBorder { get; set; } = Sam.Visuals.Form.Controls.NativeNoBorder;
|
|
public bool NativeNoUnderline { get; set; } = Sam.Visuals.Form.Controls.NativeNoUnderline;
|
|
public bool NativeBackgroundClear { get; set; } = Sam.Visuals.Form.Controls.NativeBackgroundClear;
|
|
|
|
// --- Control events ---
|
|
|
|
// Key Press event is not supported directly in Xamarin.
|
|
// Requires O/S specific implementation.
|
|
// See: Sarand.LogisticsMgr.Mobile.Droid.Forms.Renderers.SlmEditorRenderer
|
|
public void OnKeyPress_Enter()
|
|
{
|
|
// Resize control based on entered text.
|
|
InvalidateMeasure();
|
|
}
|
|
private void SamEditor_TextChanged(object? sender, TextChangedEventArgs e)
|
|
{
|
|
// If the number of lines of text has changed, resize the control.
|
|
int NumberOfLines = StringUtil.EmptyOnNull(Text).Split('\n').Length;
|
|
if (NumberOfLines != NumberOfLinesPrevious)
|
|
// Resize control based on entered text.
|
|
InvalidateMeasure();
|
|
NumberOfLinesPrevious = NumberOfLines;
|
|
}
|
|
private void SamEditor_Completed(object? sender, EventArgs e)
|
|
{
|
|
if (trimTextOnCompletion)
|
|
Text = Text.Trim();
|
|
// Resize control based on entered text.
|
|
InvalidateMeasure();
|
|
}
|
|
|
|
// --- The End ---
|
|
}
|
|
}
|