4
4
using Syncfusion . Maui . Toolkit . NumericUpDown ;
5
5
using Syncfusion . Maui . Toolkit . NumericEntry ;
6
6
using Syncfusion . Maui . Toolkit . Themes ;
7
+ using System ;
7
8
using Path = Microsoft . Maui . Controls . Shapes . Path ;
8
9
9
10
namespace Syncfusion . Maui . Toolkit . TextInputLayout
@@ -1044,7 +1045,7 @@ void UpdateContentPosition()
1044
1045
_viewBounds . X = ( int ) _leadViewWidth ;
1045
1046
UpdatePosition ( ) ;
1046
1047
_viewBounds . Y = 0 ;
1047
- _viewBounds . Width = ( int ) ( Width - _leadViewWidth - _trailViewWidth ) ;
1048
+ _viewBounds . Width = ( int ) Math . Max ( 1 , Width - _leadViewWidth - _trailViewWidth ) ;
1048
1049
_viewBounds . Height = ( int ) Height ;
1049
1050
1050
1051
if ( EnablePasswordVisibilityToggle && ! ShowUpDownButton )
@@ -1061,7 +1062,10 @@ void UpdateContentPosition()
1061
1062
_viewBounds . Width -= ( float ) ( IconSize * ( IsUpDownVerticalAlignment ? 1 : 2 ) ) ;
1062
1063
}
1063
1064
1064
- if ( _viewBounds . Height >= 0 || _viewBounds . Width >= 0 )
1065
+ // Ensure width doesn't become negative after all subtractions
1066
+ _viewBounds . Width = ( float ) Math . Max ( 1 , _viewBounds . Width ) ;
1067
+
1068
+ if ( _viewBounds . Height >= 0 && _viewBounds . Width >= 0 )
1065
1069
{
1066
1070
AbsoluteLayout . SetLayoutBounds ( Content , _viewBounds ) ;
1067
1071
}
@@ -1117,7 +1121,7 @@ void UpdateLeadingViewPosition()
1117
1121
LeadingView . VerticalOptions = LayoutOptions . End ;
1118
1122
}
1119
1123
1120
- if ( _viewBounds . Height >= 0 || _viewBounds . Width >= 0 )
1124
+ if ( _viewBounds . Height >= 0 && _viewBounds . Width >= 0 )
1121
1125
{
1122
1126
AbsoluteLayout . SetLayoutBounds ( LeadingView , _viewBounds ) ;
1123
1127
}
@@ -1151,7 +1155,7 @@ void UpdateTrailingViewPosition()
1151
1155
TrailingView . VerticalOptions = LayoutOptions . End ;
1152
1156
}
1153
1157
1154
- if ( _viewBounds . Height >= 0 || _viewBounds . Width >= 0 )
1158
+ if ( _viewBounds . Height >= 0 && _viewBounds . Width >= 0 )
1155
1159
{
1156
1160
AbsoluteLayout . SetLayoutBounds ( TrailingView , _viewBounds ) ;
1157
1161
}
@@ -1454,7 +1458,7 @@ void UpdateHelperTextPosition()
1454
1458
_helperTextRect . Y = ( int ) ( Height - TotalAssistiveTextHeight ( ) ) ;
1455
1459
}
1456
1460
1457
- _helperTextRect . Width = ( int ) ( Width - startPadding - CounterTextPadding - DefaultAssistiveLabelPadding - ( ( ShowCharCount ) ? CounterTextSize . Width + CounterTextPadding : 0 ) - _trailViewWidth - _leadViewWidth ) ;
1461
+ _helperTextRect . Width = ( int ) Math . Max ( 1 , Width - startPadding - CounterTextPadding - DefaultAssistiveLabelPadding - ( ( ShowCharCount ) ? CounterTextSize . Width + CounterTextPadding : 0 ) - _trailViewWidth - _leadViewWidth ) ;
1458
1462
_helperTextRect . Height = HelperTextSize . Height ;
1459
1463
1460
1464
if ( IsRTL )
@@ -1471,11 +1475,13 @@ double GetAssistiveTextWidth()
1471
1475
1472
1476
if ( Width >= 0 )
1473
1477
{
1474
- return Width - ( IsNone ? 0 : StartX + DefaultAssistiveLabelPadding ) - CounterTextPadding - DefaultAssistiveLabelPadding - ( ( ShowCharCount ) ? CounterTextSize . Width + CounterTextPadding : 0 ) - _trailViewWidth - _leadViewWidth ;
1478
+ var calculatedWidth = Width - ( IsNone ? 0 : StartX + DefaultAssistiveLabelPadding ) - CounterTextPadding - DefaultAssistiveLabelPadding - ( ( ShowCharCount ) ? CounterTextSize . Width + CounterTextPadding : 0 ) - _trailViewWidth - _leadViewWidth ;
1479
+ return Math . Max ( 1 , calculatedWidth ) ;
1475
1480
}
1476
1481
else if ( WidthRequest != - 1 )
1477
1482
{
1478
- return WidthRequest - ( IsNone ? 0 : StartX + DefaultAssistiveLabelPadding ) - CounterTextPadding - DefaultAssistiveLabelPadding - ( ( ShowCharCount ) ? CounterTextSize . Width + CounterTextPadding : 0 ) - _trailViewWidth - _leadViewWidth ;
1483
+ var calculatedWidth = WidthRequest - ( IsNone ? 0 : StartX + DefaultAssistiveLabelPadding ) - CounterTextPadding - DefaultAssistiveLabelPadding - ( ( ShowCharCount ) ? CounterTextSize . Width + CounterTextPadding : 0 ) - _trailViewWidth - _leadViewWidth ;
1484
+ return Math . Max ( 1 , calculatedWidth ) ;
1479
1485
}
1480
1486
else
1481
1487
{
@@ -1495,11 +1501,13 @@ double GetHintTextWidth()
1495
1501
1496
1502
if ( Width >= 0 )
1497
1503
{
1498
- return Width - ( IsNone ? 0 : ( ( 2 * StartX ) + DefaultAssistiveLabelPadding ) ) - _trailViewWidth - _leadViewWidth ;
1504
+ var calculatedWidth = Width - ( IsNone ? 0 : ( ( 2 * StartX ) + DefaultAssistiveLabelPadding ) ) - _trailViewWidth - _leadViewWidth ;
1505
+ return Math . Max ( 1 , calculatedWidth ) ;
1499
1506
}
1500
1507
else if ( WidthRequest != - 1 )
1501
1508
{
1502
- return WidthRequest - ( IsNone ? 0 : 2 * ( StartX + DefaultAssistiveLabelPadding ) ) - _trailViewWidth - _leadViewWidth ;
1509
+ var calculatedWidth = WidthRequest - ( IsNone ? 0 : 2 * ( StartX + DefaultAssistiveLabelPadding ) ) - _trailViewWidth - _leadViewWidth ;
1510
+ return Math . Max ( 1 , calculatedWidth ) ;
1503
1511
}
1504
1512
else
1505
1513
{
@@ -1525,7 +1533,7 @@ void UpdateErrorTextPosition()
1525
1533
_errorTextRect . Y = ( int ) ( Height - TotalAssistiveTextHeight ( ) ) ;
1526
1534
}
1527
1535
1528
- _errorTextRect . Width = ( int ) ( Width - startPadding - CounterTextPadding - DefaultAssistiveLabelPadding - ( ( ShowCharCount ) ? CounterTextSize . Width + CounterTextPadding : 0 ) - _trailViewWidth - _leadViewWidth ) ;
1536
+ _errorTextRect . Width = ( int ) Math . Max ( 1 , Width - startPadding - CounterTextPadding - DefaultAssistiveLabelPadding - ( ( ShowCharCount ) ? CounterTextSize . Width + CounterTextPadding : 0 ) - _trailViewWidth - _leadViewWidth ) ;
1529
1537
_errorTextRect . Height = ErrorTextSize . Height ;
1530
1538
1531
1539
if ( IsRTL )
@@ -1585,11 +1593,11 @@ void UpdateOutlineRectF()
1585
1593
UpdateTrailViewWidthForBorder ( ) ;
1586
1594
if ( BaseLineMaxHeight <= 2 )
1587
1595
{
1588
- _outlineRectF . Width = ( float ) ( ( Width - ( BaseLineMaxHeight * 2 ) ) - _leadViewWidth - _trailViewWidth ) ;
1596
+ _outlineRectF . Width = ( float ) Math . Max ( 1 , ( Width - ( BaseLineMaxHeight * 2 ) ) - _leadViewWidth - _trailViewWidth ) ;
1589
1597
}
1590
1598
else
1591
1599
{
1592
- _outlineRectF . Width = ( float ) ( ( Width - ( BaseLineMaxHeight ) ) - _leadViewWidth - _trailViewWidth ) ;
1600
+ _outlineRectF . Width = ( float ) Math . Max ( 1 , ( Width - ( BaseLineMaxHeight ) ) - _leadViewWidth - _trailViewWidth ) ;
1593
1601
}
1594
1602
1595
1603
_outlineRectF . Height = ( float ) ( Height - _outlineRectF . Y - TotalAssistiveTextHeight ( ) - AssistiveLabelPadding ) ;
@@ -1601,14 +1609,14 @@ void UpdateOutlineBackgroundRectF()
1601
1609
{
1602
1610
_backgroundRectF . X = ( float ) ( _outlineRectF . X + ( FocusedStrokeThickness / 2 ) ) ;
1603
1611
_backgroundRectF . Y = ( float ) ( _outlineRectF . Y + ( FocusedStrokeThickness / 2 ) ) ;
1604
- _backgroundRectF . Width = ( float ) ( _outlineRectF . Width - ( FocusedStrokeThickness ) ) ;
1612
+ _backgroundRectF . Width = ( float ) Math . Max ( 1 , _outlineRectF . Width - FocusedStrokeThickness ) ;
1605
1613
_backgroundRectF . Height = ( float ) ( _outlineRectF . Height - ( FocusedStrokeThickness ) ) ;
1606
1614
}
1607
1615
else
1608
1616
{
1609
1617
_backgroundRectF . X = ( float ) ( _outlineRectF . X + ( UnfocusedStrokeThickness / 2 ) ) ;
1610
1618
_backgroundRectF . Y = ( float ) ( _outlineRectF . Y + ( UnfocusedStrokeThickness / 2 ) ) ;
1611
- _backgroundRectF . Width = ( float ) ( _outlineRectF . Width - ( UnfocusedStrokeThickness ) ) ;
1619
+ _backgroundRectF . Width = ( float ) Math . Max ( 1 , _outlineRectF . Width - UnfocusedStrokeThickness ) ;
1612
1620
_backgroundRectF . Height = ( float ) ( _outlineRectF . Height - ( UnfocusedStrokeThickness ) ) ;
1613
1621
}
1614
1622
@@ -1623,7 +1631,7 @@ void UpdateBackgroundRectF()
1623
1631
UpdateTrailViewWidthForBorder ( ) ;
1624
1632
_backgroundRectF . X = ( float ) _leadViewWidth ;
1625
1633
_backgroundRectF . Y = 0 ;
1626
- _backgroundRectF . Width = ( float ) ( Width - _leadViewWidth - _trailViewWidth ) ;
1634
+ _backgroundRectF . Width = ( float ) Math . Max ( 1 , Width - _leadViewWidth - _trailViewWidth ) ;
1627
1635
if ( BaseLineMaxHeight <= 2 )
1628
1636
{
1629
1637
_backgroundRectF . Height = ( float ) ( Height - TotalAssistiveTextHeight ( ) - AssistiveLabelPadding ) ;
0 commit comments