Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rel 4.2 radiobutton checkbox enhancements #350

Merged
5 changes: 5 additions & 0 deletions src/InputKit.Maui/Shared/Configuration/GlobalSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public class GlobalSetting
/// Label position of control.
/// </summary>
public LabelPosition LabelPosition { get; set; }

/// <summary>
/// The line break mode for the text displayed by the control.
/// </summary>
public LineBreakMode LineBreakMode { get; set; }
}
33 changes: 30 additions & 3 deletions src/InputKit.Maui/Shared/Controls/CheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public partial class CheckBox : StatefulStackLayout, IValidatable
Size = 25,
CornerRadius = 2,
FontSize = 14,
LabelPosition = LabelPosition.After
LabelPosition = LabelPosition.After,
LineBreakMode = LineBreakMode.WordWrap
};

#region Constants
Expand Down Expand Up @@ -56,6 +57,7 @@ public partial class CheckBox : StatefulStackLayout, IValidatable
};
protected internal Label lblOption = new Label
{
LineBreakMode = GlobalSetting.LineBreakMode,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Start,
FontSize = GlobalSetting.FontSize,
Expand Down Expand Up @@ -86,6 +88,7 @@ public CheckBox()
MinimumWidthRequest = GlobalSetting.Size,
HeightRequest = GlobalSetting.Size,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
outlineBox,
Expand Down Expand Up @@ -256,6 +259,20 @@ public Color ValidationColor
set => SetValue(ValidationColorProperty, value);
}

/// <summary>
/// Gets or sets the line break mode for the label.
/// </summary>
public LineBreakMode LineBreakMode { get => (LineBreakMode)GetValue(LineBreakModeProperty); set => SetValue(LineBreakModeProperty, value); }

/// <summary>
/// Gets or sets the vertical options for the icon.
/// </summary>
public LayoutOptions IconVerticalOptions { get => (LayoutOptions)GetValue(IconVerticalOptionsProperty); set => SetValue(IconVerticalOptionsProperty, value); }

/// <summary>
/// Gets or sets the horizontal options for the icon.
/// </summary>
public LayoutOptions IconHorizontalOptions { get => (LayoutOptions)GetValue(IconHorizontalOptionsProperty); set => SetValue(IconHorizontalOptionsProperty, value); }
#endregion

#region Validation
Expand Down Expand Up @@ -335,6 +352,16 @@ public void DisplayValidation()

public static readonly BindableProperty TypeProperty = BindableProperty.Create(nameof(Type), typeof(CheckType), typeof(CheckBox), defaultValue: CheckType.Regular,
propertyChanged: (bindable, oldValue, newValue) => (bindable as CheckBox).UpdateType());

public static readonly BindableProperty LineBreakModeProperty = BindableProperty.Create(nameof(LineBreakMode), typeof(LineBreakMode), typeof(CheckBox), defaultValue: GlobalSetting.LineBreakMode,
propertyChanged: (bindable, oldValue, newValue) => (bindable as CheckBox).lblOption.LineBreakMode = (LineBreakMode)newValue);

public static readonly BindableProperty IconVerticalOptionsProperty = BindableProperty.Create(nameof(IconVerticalOptions), typeof(LayoutOptions), typeof(CheckBox), defaultValue: LayoutOptions.Center,
propertyChanged: (bindable, oldValue, newValue) => (bindable as CheckBox).IconLayout.VerticalOptions = (LayoutOptions)newValue);

public static readonly BindableProperty IconHorizontalOptionsProperty = BindableProperty.Create(nameof(IconHorizontalOptions), typeof(LayoutOptions), typeof(CheckBox), defaultValue: LayoutOptions.Center,
propertyChanged: ( bindable, oldValue, newValue ) => (bindable as CheckBox).IconLayout.HorizontalOptions = (LayoutOptions)newValue);

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#endregion

Expand Down Expand Up @@ -369,7 +396,7 @@ protected override async void OnSizeAllocated(double width, double height)
#endif
if (IconLayout.Width != -1 && lblOption.Width > this.Width)
{
lblOption.MaximumWidthRequest = this.Width - IconLayout.Width;
lblOption.MaximumWidthRequest = this.Width - this.Spacing - IconLayout.Width;
}
}

Expand Down Expand Up @@ -514,4 +541,4 @@ public enum CheckType
Filled,
Material,
}
}
}
57 changes: 51 additions & 6 deletions src/InputKit.Maui/Shared/Controls/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class RadioButton : StatefulStackLayout
Size = 25,
CornerRadius = -1,
FontSize = 14,
LabelPosition = LabelPosition.After
LabelPosition = LabelPosition.After,
LineBreakMode = LineBreakMode.WordWrap
};
#endregion

Expand All @@ -52,14 +53,13 @@ public class RadioButton : StatefulStackLayout
};
protected internal Label lblText = new Label
{
VerticalTextAlignment = TextAlignment.Center,
LineBreakMode = GlobalSetting.LineBreakMode,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Start,
TextColor = GlobalSetting.TextColor,
FontSize = GlobalSetting.FontSize,
TextColor = GlobalSetting.TextColor,
FontFamily = GlobalSetting.FontFamily,
MaxLines = 3,
LineBreakMode = LineBreakMode.WordWrap
IsVisible = false
};
private bool _isDisabled;
protected const double DOT_FULL_SCALE = .65;
Expand All @@ -82,6 +82,7 @@ public RadioButton()
IconLayout = new Grid
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
iconCircle,
Expand Down Expand Up @@ -143,7 +144,7 @@ public RadioButton()
/// <summary>
/// Value to keep inside of Radio Button
/// </summary>
public object Value { get; set; }
public object Value { get => GetValue(ValueProperty); set => SetValue(ValueProperty, value); }

/// <summary>
/// Gets or Sets, is that Radio Button selected/choosed/Checked
Expand Down Expand Up @@ -215,6 +216,22 @@ public LabelPosition LabelPosition
get => (LabelPosition)GetValue(LabelPositionProperty);
set => SetValue(LabelPositionProperty, value);
}

/// <summary>
/// Gets or sets the line break mode for the label.
/// </summary>
public LineBreakMode LineBreakMode { get => (LineBreakMode)GetValue(LineBreakModeProperty); set => SetValue(LineBreakModeProperty, value); }

/// <summary>
/// Gets or sets the vertical options for the icon.
/// </summary>
public LayoutOptions IconVerticalOptions { get => (LayoutOptions)GetValue(IconVerticalOptionsProperty); set => SetValue(IconVerticalOptionsProperty, value); }

/// <summary>
/// Gets or sets the horizontal options for the icon.
/// </summary>
public LayoutOptions IconHorizontalOptions { get => (LayoutOptions)GetValue(IconHorizontalOptionsProperty); set => SetValue(IconHorizontalOptionsProperty, value); }

#endregion

#region BindableProperties
Expand All @@ -236,6 +253,18 @@ public LabelPosition LabelPosition
returnType: typeof(LabelPosition), defaultBindingMode: BindingMode.TwoWay,
defaultValue: GlobalSetting.LabelPosition,
propertyChanged: (bo, ov, nv) => (bo as RadioButton).ApplyLabelPosition((LabelPosition)nv));


public static readonly BindableProperty LineBreakModeProperty = BindableProperty.Create(nameof(LineBreakMode), typeof(LineBreakMode), typeof(RadioButton), defaultValue: GlobalSetting.LineBreakMode,
propertyChanged: ( bindable, oldValue, newValue ) => (bindable as RadioButton).lblText.LineBreakMode = (LineBreakMode)newValue);

public static readonly BindableProperty IconVerticalOptionsProperty = BindableProperty.Create(nameof(IconVerticalOptions), typeof(LayoutOptions), typeof(RadioButton), defaultValue: LayoutOptions.Center,
propertyChanged: ( bindable, oldValue, newValue ) => (bindable as RadioButton).IconLayout.VerticalOptions = (LayoutOptions)newValue);

public static readonly BindableProperty IconHorizontalOptionsProperty = BindableProperty.Create(nameof(IconHorizontalOptions), typeof(LayoutOptions), typeof(RadioButton), defaultValue: LayoutOptions.Center,
propertyChanged: ( bindable, oldValue, newValue ) => (bindable as RadioButton).IconLayout.HorizontalOptions = (LayoutOptions)newValue);

public static readonly BindableProperty ValueProperty = BindableProperty.Create(nameof(Value), typeof(object), typeof(RadioButton), defaultBindingMode: BindingMode.OneTime);
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#endregion

Expand All @@ -257,6 +286,22 @@ private void ApplyLabelPosition(LabelPosition position)
}
}

protected override async void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);

// TODO: Remove this logic after resolution of https://github.com/dotnet/maui/issues/8873
// This is a workaround.

#if ANDROID
await Task.Delay(1);
#endif
if (IconLayout.Width != -1 && lblText.Width > this.Width)
{
lblText.MaximumWidthRequest = this.Width - this.Spacing - IconLayout.Width;
}
}

private protected virtual void UpdateShape()
{
iconChecked.Data = SelectedIconGeomerty;
Expand Down