Skip to content

Commit

Permalink
Split IText into IText and ITextStyle and a good couple of bugs (#668)
Browse files Browse the repository at this point in the history
Co-authored-by: Shane Neuville <[email protected]>
  • Loading branch information
mattleibow and PureWeen authored Apr 7, 2021
1 parent 1e55dd9 commit 0736879
Show file tree
Hide file tree
Showing 115 changed files with 618 additions and 548 deletions.
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public static class AppHostBuilderExtensions
typeof(ContentPage),
typeof(Page),
typeof(Label),
typeof(CheckBox),
#if !WINDOWS
typeof(ActivityIndicator),
typeof(CheckBox),
typeof(DatePicker),
typeof(Editor),
typeof(Entry),
Expand Down
10 changes: 7 additions & 3 deletions src/Compatibility/Core/src/Windows/EntryRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,16 @@ void UpdateTextColor()

void UpdateMaxLength()
{
Control.MaxLength = Element.MaxLength;
var maxLength = Element.MaxLength;
if (maxLength == -1)
maxLength = int.MaxValue;

Control.MaxLength = maxLength;

var currentControlText = Control.Text;

if (currentControlText.Length > Element.MaxLength)
Control.Text = currentControlText.Substring(0, Element.MaxLength);
if (currentControlText.Length > maxLength)
Control.Text = currentControlText.Substring(0, maxLength);
}

void UpdateDetectReadingOrderFromContent()
Expand Down
9 changes: 7 additions & 2 deletions src/Controls/samples/Controls.Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ void SetupMauiLayout()
verticalStack.Add(new Button { Text = "CharacterSpacing" });
verticalStack.Add(new Button { CharacterSpacing = 8, Text = "CharacterSpacing" });

verticalStack.Add(new CheckBox());
var checkbox = new CheckBox();
checkbox.CheckedChanged += (sender, e) =>
{
Debug.WriteLine($"Checked Changed to '{e.Value}'");
};
verticalStack.Add(checkbox);
verticalStack.Add(new CheckBox { BackgroundColor = Color.LightPink });
verticalStack.Add(new CheckBox { IsChecked = true, Color = Color.Aquamarine });

Expand All @@ -133,7 +138,7 @@ void SetupMauiLayout()
};

verticalStack.Add(entry);
verticalStack.Add(new Entry { Text = "Entry", TextColor = Color.DarkRed, FontFamily = "Dokdo" });
verticalStack.Add(new Entry { Text = "Entry", TextColor = Color.DarkRed, FontFamily = "Dokdo", MaxLength = -1 });
verticalStack.Add(new Entry { IsPassword = true, TextColor = Color.Black });
verticalStack.Add(new Entry { IsTextPredictionEnabled = false });
verticalStack.Add(new Entry { Placeholder = "This should be placeholder text" });
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/HandlerImpl/Button.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ void IButton.Released()
(this as IButtonController).SendReleased();
}

Font IText.Font => Font;
Font ITextStyle.Font => Font;
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/HandlerImpl/DatePicker.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public partial class DatePicker : IDatePicker
{
Font? _font;

Font IDatePicker.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
Font ITextStyle.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/HandlerImpl/Editor.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public partial class Editor : IEditor
{
Font? _font;

Font IText.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
Font ITextStyle.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/HandlerImpl/Entry.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public partial class Entry : IEntry
{
Font? _font;

Font IText.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
Font ITextStyle.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
}
}
13 changes: 1 addition & 12 deletions src/Controls/src/Core/HandlerImpl/Label.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ public partial class Label : ILabel
{
Font? _font;

Font IText.Font
{
get
{
if (_font == null)
{
_font = Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
}

return _font.Value;
}
}
Font ITextStyle.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
}
}
2 changes: 2 additions & 0 deletions src/Controls/src/Core/HandlerImpl/Picker.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
public partial class Picker : IPicker
{
Font? _font;

Font ITextStyle.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/HandlerImpl/SearchBar.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public partial class SearchBar : ISearchBar
{
Font? _font;

Font IText.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
Font ITextStyle.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);

bool ITextInput.IsTextPredictionEnabled => true;
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/HandlerImpl/TimePicker.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public partial class TimePicker : ITimePicker
{
Font? _font;

Font ITimePicker.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
Font ITextStyle.Font => _font ??= Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
}
}
13 changes: 10 additions & 3 deletions src/Controls/src/Core/Picker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,26 @@ public virtual string UpdateFormsText(string source, TextTransform textTransform
=> TextTransformUtilites.GetTransformedText(source, textTransform);

void IFontElement.OnFontFamilyChanged(string oldValue, string newValue) =>
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
HandleFontChanged();

void IFontElement.OnFontSizeChanged(double oldValue, double newValue) =>
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
HandleFontChanged();

void IFontElement.OnFontChanged(Font oldValue, Font newValue) =>
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
HandleFontChanged();

double IFontElement.FontSizeDefaultValueCreator() =>
Device.GetNamedSize(NamedSize.Default, (Picker)this);

void IFontElement.OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue) =>
HandleFontChanged();

void HandleFontChanged()
{
// Null out the Maui font value so it will be recreated next time it's accessed
_font = null;
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

void ITextElement.OnTextTransformChanged(TextTransform oldValue, TextTransform newValue) =>
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
Expand Down
20 changes: 20 additions & 0 deletions src/Core/src/Attributes/MissingMapperAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace Microsoft.Maui
{
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class MissingMapperAttribute : Attribute
{
public MissingMapperAttribute()
{

}

public MissingMapperAttribute(string description)
{
Description = description;
}

public string? Description { get; set; }
}
}
File renamed without changes.
12 changes: 1 addition & 11 deletions src/Core/src/Core/IDatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Maui
/// <summary>
/// Represents a View that allows the user to select a date.
/// </summary>
public interface IDatePicker : IView
public interface IDatePicker : IView, ITextStyle
{
/// <summary>
/// Gets the format of the date to display to the user.
Expand All @@ -26,15 +26,5 @@ public interface IDatePicker : IView
/// Gets the maximum DateTime selectable.
/// </summary>
DateTime MaximumDate { get; }

/// <summary>
/// Gets the spacing between characters of the text.
/// </summary>
double CharacterSpacing { get; }

/// <summary>
/// Gets the font family, style and size of the font.
/// </summary>
Font Font { get; }
}
}
5 changes: 0 additions & 5 deletions src/Core/src/Core/IEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@ public interface IEditor : IView, ITextInput
/// Gets or sets the placeholder text color.
/// </summary>
Color PlaceholderColor { get; set; }

/// <summary>
/// Gets a value that controls whether text prediction and automatic text correction is on or off.
/// </summary>
bool IsTextPredictionEnabled { get; }
}
}
7 changes: 1 addition & 6 deletions src/Core/src/Core/IEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
/// <summary>
/// Represents a View that is used for single-line text input.
/// </summary>
public interface IEntry : IView, IText, ITextInput, ITextAlignment
public interface IEntry : IView, ITextInput, ITextAlignment
{
/// <summary>
/// Gets a value that indicates if the entry should visually obscure typed text.
/// </summary>
bool IsPassword { get; }

/// <summary>
/// Gets a value that controls whether text prediction and automatic text correction is on or off.
/// </summary>
bool IsTextPredictionEnabled { get; }

/// <summary>
/// Gets an enumeration value that controls the appearance of the return button.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Core/src/Core/ILabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface ILabel : IView, IText, ITextAlignment, IPadding
/// Underline and strike-through text decorations can be applied.
/// </summary>
TextDecorations TextDecorations { get; }

/// <summary>
/// Gets the line height applied to the Label.
/// Underline and strike-through text decorations can be applied.
Expand Down
7 changes: 1 addition & 6 deletions src/Core/src/Core/IPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.Maui
/// <summary>
/// Represents a View for selecting a text item from a list of data.
/// </summary>
public interface IPicker : IView
public interface IPicker : IView, ITextStyle
{
/// <summary>
/// Gets the title for the Picker.
Expand All @@ -32,10 +32,5 @@ public interface IPicker : IView
/// Gets the selected item.
/// </summary>
object? SelectedItem { get; set; }

/// <summary>
/// Gets the character spacing.
/// </summary>
double CharacterSpacing { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Core/ISearchBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Represents a View used to initiating a search.
/// </summary>
public interface ISearchBar : IView, IText, IPlaceholder, ITextAlignment
public interface ISearchBar : IView, ITextInput, ITextAlignment
{

}
Expand Down
17 changes: 1 addition & 16 deletions src/Core/src/Core/IText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@ namespace Microsoft.Maui
/// <summary>
/// Provides functionality to be able to customize Text.
/// </summary>
public interface IText
public interface IText : ITextStyle
{
/// <summary>
/// Gets the text.
/// </summary>
string Text { get; }

/// <summary>
/// Gets the text color.
/// </summary>
Color TextColor { get; }

/// <summary>
/// Gets the font family, style and size of the font.
/// </summary>
Font Font { get; }

/// <summary>
/// Gets the spacing between characters of the text.
/// </summary>
double CharacterSpacing { get; }
}
}
5 changes: 5 additions & 0 deletions src/Core/src/Core/ITextInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public interface ITextInput : IText, IPlaceholder
/// </summary>
new string Text { get; set; }

/// <summary>
/// Gets a value that controls whether text prediction and automatic text correction is on or off.
/// </summary>
bool IsTextPredictionEnabled { get; }

/// <summary>
/// Gets a value indicating whether or not the view is read-only.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions src/Core/src/Core/ITextStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Microsoft.Maui
{
/// <summary>
/// Provides functionality to be able to customize the appearance of text.
/// </summary>
public interface ITextStyle
{
/// <summary>
/// Gets the text color.
/// </summary>
Color TextColor { get; }

/// <summary>
/// Gets the font family, style and size of the font.
/// </summary>
Font Font { get; }

/// <summary>
/// Gets the spacing between characters of the text.
/// </summary>
double CharacterSpacing { get; }
}
}
12 changes: 1 addition & 11 deletions src/Core/src/Core/ITimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Maui
/// <summary>
/// Represents a View that allows the user to select a time.
/// </summary>
public interface ITimePicker : IView
public interface ITimePicker : IView, ITextStyle
{
/// <summary>
/// The format of the time to display to the user.
Expand All @@ -16,15 +16,5 @@ public interface ITimePicker : IView
/// Gets the displayed time.
/// </summary>
TimeSpan Time { get; set; }

/// <summary>
/// Gets the spacing between characters of the text.
/// </summary>
double CharacterSpacing { get; }

/// <summary>
/// Gets the font family, style and size of the font.
/// </summary>
Font Font { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@ namespace Microsoft.Maui.Handlers
public partial class ActivityIndicatorHandler : ViewHandler<IActivityIndicator, ProgressBar>
{
protected override ProgressBar CreateNativeView() => new ProgressBar(Context) { Indeterminate = true };

public static void MapIsRunning(ActivityIndicatorHandler handler, IActivityIndicator activityIndicator)
{
handler.NativeView?.UpdateIsRunning(activityIndicator);
}

public static void MapColor(ActivityIndicatorHandler handler, IActivityIndicator activityIndicator)
{
handler.NativeView?.UpdateColor(activityIndicator);
}
}
}
Loading

0 comments on commit 0736879

Please sign in to comment.