Skip to content

Commit 1ac7ff7

Browse files
committed
improvements in numericupdown
1 parent 3ea964f commit 1ac7ff7

File tree

7 files changed

+380
-111
lines changed

7 files changed

+380
-111
lines changed

maui/src/NumericEntry/Event/ValueChangedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Provides event data for the <see cref="SfNumericEntry.ValueChanged"/> event.
55
/// </summary>
6-
public class NumericEntryValueChangedEventArgs
6+
public class NumericEntryValueChangedEventArgs : EventArgs
77
{
88
/// <summary>
99
/// Initializes a new instance of the <see cref="NumericEntryValueChangedEventArgs"/> class.

maui/src/NumericEntry/SfNumericEntry.Methods.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ void SetBinding()
344344
_textBox.SetBinding(SfEntryView.IsVisibleProperty, "IsVisible");
345345
_textBox.SetBinding(SfEntryView.CursorPositionProperty, "CursorPosition", BindingMode.TwoWay);
346346
_textBox.SetBinding(SfEntryView.SelectionLengthProperty, "SelectionLength", BindingMode.TwoWay);
347+
348+
#if WINDOWS
349+
if(_textBox.Text != null)
350+
{
351+
_textBox.CursorPosition = _textBox.Text.Length;
352+
}
353+
#endif
347354
}
348355
}
349356

@@ -2360,6 +2367,13 @@ private void UpdateTextBoxCursorPosition(string displayText, int caretPosition)
23602367
}
23612368

23622369
_textBox.Text = displayText;
2370+
if (ValueChangeMode == ValueChangeMode.OnKeyFocus && _textBox.Text != null && _textBox.Text != displayText)
2371+
{
2372+
if (Parse(_textBox.Text) == Maximum)
2373+
{
2374+
caretPosition = _textBox.Text.Length;
2375+
}
2376+
}
23632377
if (_textBox.Text != null)
23642378
{
23652379
_textBox.CursorPosition = caretPosition >= 0 ? (caretPosition <= _textBox.Text.Length) ? caretPosition : _textBox.Text.Length : 0;
@@ -2541,7 +2555,11 @@ internal void UpdateDisplayText(double? value, bool resetCursor = true)
25412555
}
25422556
}
25432557

2558+
#if WINDOWS
2559+
if ((resetCursor || _isFirst) && _textBox.Text != null)
2560+
#else
25442561
if (resetCursor && _textBox.Text != null)
2562+
#endif
25452563
{
25462564
_textBox.CursorPosition = _textBox.Text.Length;
25472565
}

maui/src/NumericEntry/SfNumericEntry.cs

Lines changed: 114 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,72 @@ public partial class SfNumericEntry : SfView, ITextElement, ITouchListener, IKey
172172
/// Another separator string for UI layout.
173173
/// </summary>
174174
string? _anotherSeparator;
175+
176+
/// <summary>
177+
/// Height of the toolbar in points.
178+
/// </summary>
179+
const float ToolbarHeight = 50.0f;
180+
181+
/// <summary>
182+
/// Thickness of separator lines in points.
183+
/// </summary>
184+
const float LineThickness = 0.5f;
185+
186+
/// <summary>
187+
/// Width threshold for small screens in points.
188+
/// </summary>
189+
const float SmallScreenWidth = 320.0f;
190+
191+
/// <summary>
192+
/// Width threshold for medium screens in points.
193+
/// </summary>
194+
const float LargeScreenWidth = 667.0f;
195+
196+
/// <summary>
197+
/// Divisor used to calculate button width.
198+
/// </summary>
199+
const int ButtonDivider = 3;
200+
201+
/// <summary>
202+
/// Button spacing for small landscape screens.
203+
/// </summary>
204+
const float SmallLandscapeButtonSpacing = 2.5f;
205+
206+
/// <summary>
207+
/// Separator spacing for small landscape screens.
208+
/// </summary>
209+
const float SmallLandscapeSeparatorSpacing = 5.0f;
210+
211+
/// <summary>
212+
/// Button spacing for large landscape screens.
213+
/// </summary>
214+
const float LargeLandscapeButtonSpacing = 3.1f;
215+
216+
/// <summary>
217+
/// Separator spacing for large landscape screens.
218+
/// </summary>
219+
const float LargeLandscapeSeparatorSpacing = 6.1f;
220+
221+
/// <summary>
222+
/// Button spacing for medium portrait screens.
223+
/// </summary>
224+
const float MediumPortraitButtonSpacing = 2.0f;
225+
226+
/// <summary>
227+
/// Separator spacing for medium portrait screens.
228+
/// </summary>
229+
const float MediumPortraitSeparatorSpacing = 4.0f;
230+
231+
/// <summary>
232+
/// Button spacing for small portrait screens.
233+
/// </summary>
234+
const float SmallPortraitButtonSpacing = 1.5f;
235+
236+
/// <summary>
237+
/// Separator spacing for small portrait screens.
238+
/// </summary>
239+
const float SmallPortraitSeparatorSpacing = 3.0f;
240+
175241
#endif
176242
#elif WINDOWS
177243
/// <summary>
@@ -403,7 +469,7 @@ protected override List<SemanticsNode> GetSemanticsNodesCore(double width, doubl
403469
{
404470
// Ensure any necessary size updates are performed
405471
UpdateSemanticsSizes();
406-
if (SemanticsDataIsCurrent())
472+
if (SemanticsDataIsCurrent() && IsTextInputLayout)
407473
{
408474
return _numericEntrySemanticsNodes;
409475
}
@@ -849,11 +915,11 @@ void DeviceRotated(NSNotification notification)
849915
/// Determines whether the current device orientation is portrait or not.
850916
/// </summary>
851917
/// <returns>True if the orientation is portrait or face up/down; otherwise, false.</returns>
852-
static bool IsPortraitOrientation()
918+
static bool IsLandscapeOrientation()
853919
{
854-
return UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.Portrait || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown ||
855-
UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.FaceUp || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.FaceDown;
856-
}
920+
return UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight;
921+
922+
}
857923

858924
/// <summary>
859925
/// Configures the frames for minus, separator, and return buttons based on the screen width and provided adjustments.
@@ -878,56 +944,54 @@ void SetButtonFrames(nfloat adjustment, nfloat extraAdjustment)
878944
}
879945
}
880946

881-
/// <summary>
882-
/// Updates the frames and layout of toolbar buttons, adjusting based on screen orientation and size.
883-
/// Ensures the components maintain appropriate spacing and sizing for touch interactions.
884-
/// </summary>
885-
void UpdateFrames()
947+
/// <summary>
948+
/// Updates the frames and layout of toolbar buttons, adjusting based on screen orientation and size.
949+
/// Ensures the components maintain appropriate spacing and sizing for touch interactions.
950+
/// </summary>
951+
void UpdateFrames()
886952
{
887-
if (UIDevice.CurrentDevice.Orientation != UIDeviceOrientation.Unknown)
888-
{
889-
if (_toolbarView == null || _minusButton == null || _separatorButton == null || _returnButton == null
953+
954+
if (_toolbarView == null || _minusButton == null || _separatorButton == null || _returnButton == null
890955
|| _lineView1 == null || _lineView2 == null || _lineView3 == null || _lineView4 == null)
956+
{
957+
return;
958+
}
959+
960+
961+
if (IsLandscapeOrientation())
962+
{
963+
nfloat width = (nfloat)Math.Max((double)UIScreen.MainScreen.Bounds.Height, (double)UIScreen.MainScreen.Bounds.Width);
964+
_buttonWidth = width / ButtonDivider;
965+
_toolbarView.Frame = new CGRect(0.0f, 0.0f, (float)width, ToolbarHeight);
966+
if (width <= LargeScreenWidth)
967+
{
968+
SetButtonFrames(SmallLandscapeButtonSpacing, SmallLandscapeSeparatorSpacing);
969+
}
970+
else if (width > LargeScreenWidth)
971+
{
972+
SetButtonFrames(LargeLandscapeButtonSpacing, LargeLandscapeSeparatorSpacing);
973+
}
974+
}
975+
else
976+
{
977+
nfloat width = (nfloat)Math.Min((double)UIScreen.MainScreen.Bounds.Height, (double)UIScreen.MainScreen.Bounds.Width);
978+
_buttonWidth = width / ButtonDivider;
979+
_toolbarView.Frame = new CGRect(0.0f, 0.0f, (float)width, ToolbarHeight);
980+
if (width > SmallScreenWidth)
891981
{
892-
return;
982+
SetButtonFrames(MediumPortraitButtonSpacing, MediumPortraitSeparatorSpacing);
893983
}
984+
else if (width <= SmallScreenWidth)
985+
{
986+
SetButtonFrames(SmallPortraitButtonSpacing, SmallPortraitSeparatorSpacing);
894987

895-
nfloat width = UIScreen.MainScreen.Bounds.Width;
896-
_buttonWidth = width / 3;
897-
_toolbarView.Frame = new CGRect(0.0f, 0.0f, (float)width, 50.0f);
898-
if (IsPortraitOrientation())
899-
{
900-
if (width <= 375 && width > 320)
901-
{
902-
SetButtonFrames(2, 4);
903-
}
904-
else if (width <= 320)
905-
{
906-
SetButtonFrames((nfloat)1.5, 3);
907-
908-
}
909-
else if (width > 375)
910-
{
911-
SetButtonFrames(2, 4);
912-
}
913-
}
914-
else if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight)
915-
{
916-
if (width <= 667)
917-
{
918-
SetButtonFrames((nfloat)2.5, 5);
919-
}
920-
else if (width > 667)
921-
{
922-
SetButtonFrames((nfloat)3.1, (nfloat)6.1);
923-
}
924-
}
925-
_lineView1.Frame = new CGRect(0, 0, _toolbarView.Frame.Size.Width, 0.5f);
926-
_lineView2.Frame = new CGRect(0, _toolbarView.Frame.Size.Height - 0.5f, _toolbarView.Frame.Size.Width, 0.5f);
927-
_lineView3.Frame = new CGRect(_minusButton.Frame.Right - 0.5f, 0, 0.5, _minusButton.Frame.Size.Height);
928-
_lineView4.Frame = new CGRect(_returnButton.Frame.Left, 0, 0.5, _minusButton.Frame.Size.Height);
929-
}
930-
}
988+
}
989+
}
990+
_lineView1.Frame = new CGRect(0, 0, _toolbarView.Frame.Size.Width, LineThickness);
991+
_lineView2.Frame = new CGRect(0, _toolbarView.Frame.Size.Height - LineThickness, _toolbarView.Frame.Size.Width, LineThickness);
992+
_lineView3.Frame = new CGRect(_minusButton.Frame.Right - LineThickness, 0, LineThickness, _minusButton.Frame.Size.Height);
993+
_lineView4.Frame = new CGRect(_returnButton.Frame.Left, 0, LineThickness, _minusButton.Frame.Size.Height);
994+
}
931995
#endif
932996
#endregion
933997
}

0 commit comments

Comments
 (0)