85 lines
2.7 KiB
C#
85 lines
2.7 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
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private bool trimTextOnCompletion = true;
|
|
private int NumberOfLinesPrevious = 0;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SamEditor()
|
|
{
|
|
DefaultFontSize = FontSize;
|
|
Text = "";
|
|
TextChanged += SamEditor_TextChanged;
|
|
Completed += SamEditor_Completed;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
|
|
public double DefaultFontSize { get; }
|
|
|
|
public bool TrimText
|
|
{
|
|
get { return trimTextOnCompletion; }
|
|
set
|
|
{
|
|
if (trimTextOnCompletion == value) return;
|
|
trimTextOnCompletion = value;
|
|
}
|
|
}
|
|
|
|
// Native behaviour modified by SamHandler.
|
|
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;
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l E v e n t s
|
|
//-------------------------------------------------------------------
|
|
// 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();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|