зеркало из https://github.com/DeGsoft/maui-linux.git
[C] move the Font proxying into FontElement
This commit is contained in:
Родитель
caf2e81412
Коммит
81058db4f5
|
@ -23,7 +23,7 @@ namespace Xamarin.Forms
|
|||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Button), Color.Default);
|
||||
|
||||
public static readonly BindableProperty FontProperty = BindableProperty.Create("Font", typeof(Font), typeof(Button), default(Font), propertyChanged: FontStructPropertyChanged);
|
||||
public static readonly BindableProperty FontProperty = FontElement.FontProperty;
|
||||
|
||||
public static readonly BindableProperty FontFamilyProperty = FontElement.FontFamilyProperty;
|
||||
|
||||
|
@ -43,8 +43,6 @@ namespace Xamarin.Forms
|
|||
|
||||
readonly Lazy<PlatformConfigurationRegistry<Button>> _platformConfigurationRegistry;
|
||||
|
||||
bool _cancelEvents;
|
||||
|
||||
const double DefaultSpacing = 10;
|
||||
|
||||
public Color BorderColor
|
||||
|
@ -191,47 +189,20 @@ namespace Xamarin.Forms
|
|||
IsEnabledCore = cmd.CanExecute(CommandParameter);
|
||||
}
|
||||
|
||||
static void FontStructPropertyChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
var button = (Button)bindable;
|
||||
|
||||
if (button._cancelEvents)
|
||||
return;
|
||||
|
||||
button.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
|
||||
button._cancelEvents = true;
|
||||
|
||||
if (button.Font == Font.Default)
|
||||
{
|
||||
button.FontFamily = null;
|
||||
button.FontSize = Device.GetNamedSize(NamedSize.Default, button);
|
||||
button.FontAttributes = FontAttributes.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
button.FontFamily = button.Font.FontFamily;
|
||||
if (button.Font.UseNamedSize)
|
||||
button.FontSize = Device.GetNamedSize(button.Font.NamedSize, button.GetType(), true);
|
||||
else
|
||||
button.FontSize = button.Font.FontSize;
|
||||
button.FontAttributes = button.Font.FontAttributes;
|
||||
}
|
||||
|
||||
button._cancelEvents = false;
|
||||
}
|
||||
|
||||
void IFontElement.OnFontFamilyChanged(string oldValue, string newValue) =>
|
||||
SpecificFontPropertyChanged();
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
|
||||
void IFontElement.OnFontSizeChanged(double oldValue, double newValue) =>
|
||||
SpecificFontPropertyChanged();
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
|
||||
double IFontElement.FontSizeDefaultValueCreator() =>
|
||||
Device.GetNamedSize(NamedSize.Default, (Button)this);
|
||||
|
||||
void IFontElement.OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue) =>
|
||||
SpecificFontPropertyChanged();
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
|
||||
void IFontElement.OnFontChanged(Font oldValue, Font newValue) =>
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
|
||||
void OnCommandChanged()
|
||||
{
|
||||
|
@ -266,23 +237,6 @@ namespace Xamarin.Forms
|
|||
oldvalue.SourceChanged -= OnSourceChanged;
|
||||
}
|
||||
|
||||
void SpecificFontPropertyChanged()
|
||||
{
|
||||
if (_cancelEvents)
|
||||
return;
|
||||
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
|
||||
_cancelEvents = true;
|
||||
|
||||
if (FontFamily != null)
|
||||
Font = Font.OfSize(FontFamily, FontSize).WithAttributes(FontAttributes);
|
||||
else
|
||||
Font = Font.SystemFontOfSize(FontSize, FontAttributes);
|
||||
|
||||
_cancelEvents = false;
|
||||
}
|
||||
|
||||
[DebuggerDisplay("Image Position = {Position}, Spacing = {Spacing}")]
|
||||
[TypeConverter(typeof(ButtonContentTypeConverter))]
|
||||
public sealed class ButtonContentLayout
|
||||
|
|
|
@ -61,6 +61,10 @@ namespace Xamarin.Forms
|
|||
{
|
||||
}
|
||||
|
||||
void IFontElement.OnFontChanged(Font oldValue, Font newValue)
|
||||
{
|
||||
}
|
||||
|
||||
double IFontElement.FontSizeDefaultValueCreator() =>
|
||||
Device.GetNamedSize(NamedSize.Default, (Editor)this);
|
||||
|
||||
|
|
|
@ -101,6 +101,10 @@ namespace Xamarin.Forms
|
|||
{
|
||||
}
|
||||
|
||||
void IFontElement.OnFontChanged(Font oldValue, Font newValue)
|
||||
{
|
||||
}
|
||||
|
||||
public event EventHandler Completed;
|
||||
|
||||
public event EventHandler<TextChangedEventArgs> TextChanged;
|
||||
|
|
|
@ -2,6 +2,10 @@ namespace Xamarin.Forms
|
|||
{
|
||||
static class FontElement
|
||||
{
|
||||
public static readonly BindableProperty FontProperty =
|
||||
BindableProperty.Create("Font", typeof(Font), typeof(IFontElement), default(Font),
|
||||
propertyChanged: OnFontPropertyChanged);
|
||||
|
||||
public static readonly BindableProperty FontFamilyProperty =
|
||||
BindableProperty.Create("FontFamily", typeof(string), typeof(IFontElement), default(string),
|
||||
propertyChanged: OnFontFamilyChanged);
|
||||
|
@ -15,13 +19,77 @@ namespace Xamarin.Forms
|
|||
BindableProperty.Create("FontAttributes", typeof(FontAttributes), typeof(IFontElement), FontAttributes.None,
|
||||
propertyChanged: OnFontAttributesChanged);
|
||||
|
||||
static readonly BindableProperty CancelEventsProperty =
|
||||
BindableProperty.Create("CancelEvents", typeof(bool), typeof(FontElement), false);
|
||||
|
||||
static bool GetCancelEvents(BindableObject bindable) => (bool)bindable.GetValue(CancelEventsProperty);
|
||||
static void SetCancelEvents(BindableObject bindable, bool value)
|
||||
{
|
||||
bindable.SetValue(CancelEventsProperty, value);
|
||||
}
|
||||
|
||||
static void OnFontPropertyChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
if (GetCancelEvents(bindable))
|
||||
return;
|
||||
|
||||
SetCancelEvents(bindable, true);
|
||||
|
||||
var font = (Font)newValue;
|
||||
if (font == Font.Default) {
|
||||
bindable.ClearValue(FontFamilyProperty);
|
||||
bindable.ClearValue(FontSizeProperty);
|
||||
bindable.ClearValue(FontAttributesProperty);
|
||||
} else {
|
||||
bindable.SetValue(FontFamilyProperty, font.FontFamily);
|
||||
if (font.UseNamedSize)
|
||||
bindable.SetValue(FontSizeProperty, Device.GetNamedSize(font.NamedSize, bindable.GetType(), true));
|
||||
else
|
||||
bindable.SetValue(FontSizeProperty, font.FontSize);
|
||||
bindable.SetValue(FontAttributesProperty, font.FontAttributes);
|
||||
}
|
||||
SetCancelEvents(bindable, false);
|
||||
}
|
||||
|
||||
static void OnFontFamilyChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
if (GetCancelEvents(bindable))
|
||||
return;
|
||||
|
||||
SetCancelEvents(bindable, true);
|
||||
|
||||
var values = bindable.GetValues(FontSizeProperty, FontAttributesProperty);
|
||||
var fontSize = (double)values[0];
|
||||
var fontAttributes = (FontAttributes)values[1];
|
||||
var fontFamily = (string)newValue;
|
||||
|
||||
if (fontFamily != null)
|
||||
bindable.SetValue(FontProperty, Font.OfSize(fontFamily, fontSize).WithAttributes(fontAttributes));
|
||||
else
|
||||
bindable.SetValue(FontProperty, Font.SystemFontOfSize(fontSize, fontAttributes));
|
||||
|
||||
SetCancelEvents(bindable, false);
|
||||
((IFontElement)bindable).OnFontFamilyChanged((string)oldValue, (string)newValue);
|
||||
}
|
||||
|
||||
static void OnFontSizeChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
if (GetCancelEvents(bindable))
|
||||
return;
|
||||
|
||||
SetCancelEvents(bindable, true);
|
||||
|
||||
var values = bindable.GetValues(FontFamilyProperty, FontAttributesProperty);
|
||||
var fontSize = (double)newValue;
|
||||
var fontAttributes = (FontAttributes)values[1];
|
||||
var fontFamily = (string)values[0];
|
||||
|
||||
if (fontFamily != null)
|
||||
bindable.SetValue(FontProperty, Font.OfSize(fontFamily, fontSize).WithAttributes(fontAttributes));
|
||||
else
|
||||
bindable.SetValue(FontProperty, Font.SystemFontOfSize(fontSize, fontAttributes));
|
||||
|
||||
SetCancelEvents(bindable, false);
|
||||
((IFontElement)bindable).OnFontSizeChanged((double)oldValue, (double)newValue);
|
||||
}
|
||||
|
||||
|
@ -32,6 +100,22 @@ namespace Xamarin.Forms
|
|||
|
||||
static void OnFontAttributesChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
if (GetCancelEvents(bindable))
|
||||
return;
|
||||
|
||||
SetCancelEvents(bindable, true);
|
||||
|
||||
var values = bindable.GetValues(FontFamilyProperty, FontSizeProperty);
|
||||
var fontSize = (double)values[1];
|
||||
var fontAttributes = (FontAttributes)newValue;
|
||||
var fontFamily = (string)values[0];
|
||||
|
||||
if (fontFamily != null)
|
||||
bindable.SetValue(FontProperty, Font.OfSize(fontFamily, fontSize).WithAttributes(fontAttributes));
|
||||
else
|
||||
bindable.SetValue(FontProperty, Font.SystemFontOfSize(fontSize, fontAttributes));
|
||||
|
||||
SetCancelEvents(bindable, false);
|
||||
((IFontElement)bindable).OnFontAttributesChanged((FontAttributes)oldValue, (FontAttributes)newValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,6 @@ namespace Xamarin.Forms
|
|||
void OnFontSizeChanged(double oldValue, double newValue);
|
||||
double FontSizeDefaultValueCreator();
|
||||
void OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue);
|
||||
void OnFontChanged(Font oldValue, Font newValue);
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ namespace Xamarin.Forms
|
|||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Label), Color.Default);
|
||||
|
||||
public static readonly BindableProperty FontProperty = BindableProperty.Create("Font", typeof(Font), typeof(Label), default(Font), propertyChanged: FontStructPropertyChanged);
|
||||
public static readonly BindableProperty FontProperty = FontElement.FontProperty;
|
||||
|
||||
public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(Label), default(string), propertyChanged: OnTextPropertyChanged);
|
||||
|
||||
|
@ -57,8 +57,6 @@ namespace Xamarin.Forms
|
|||
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Label>>(() => new PlatformConfigurationRegistry<Label>(this));
|
||||
}
|
||||
|
||||
bool _cancelEvents;
|
||||
|
||||
[Obsolete("Please use the Font attributes which are on the class itself. Obsoleted in v1.3.0")]
|
||||
public Font Font
|
||||
{
|
||||
|
@ -135,107 +133,20 @@ namespace Xamarin.Forms
|
|||
set { SetValue(FontSizeProperty, value); }
|
||||
}
|
||||
|
||||
static void FontStructPropertyChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
var label = (Label)bindable;
|
||||
if (label._cancelEvents)
|
||||
return;
|
||||
|
||||
label._cancelEvents = true;
|
||||
|
||||
var font = (Font)newValue;
|
||||
if (font == Font.Default)
|
||||
{
|
||||
label.FontFamily = null;
|
||||
label.FontSize = Device.GetNamedSize(NamedSize.Default, label);
|
||||
label.FontAttributes = FontAttributes.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
label.FontFamily = font.FontFamily;
|
||||
if (font.UseNamedSize)
|
||||
{
|
||||
label.FontSize = Device.GetNamedSize(font.NamedSize, label.GetType(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
label.FontSize = font.FontSize;
|
||||
}
|
||||
label.FontAttributes = font.FontAttributes;
|
||||
}
|
||||
|
||||
label._cancelEvents = false;
|
||||
|
||||
label.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
}
|
||||
|
||||
double IFontElement.FontSizeDefaultValueCreator() =>
|
||||
Device.GetNamedSize(NamedSize.Default, (Label)this);
|
||||
|
||||
void IFontElement.OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue)
|
||||
{
|
||||
if (_cancelEvents)
|
||||
return;
|
||||
|
||||
_cancelEvents = true;
|
||||
|
||||
var attributes = newValue;
|
||||
|
||||
#pragma warning disable 0618 // retain until Font removed
|
||||
object[] values = GetValues(FontFamilyProperty, FontSizeProperty);
|
||||
var family = (string)values[0];
|
||||
if (family != null)
|
||||
Font = Font.OfSize(family, (double)values[1]).WithAttributes(attributes);
|
||||
else
|
||||
Font = Font.SystemFontOfSize((double)values[1], attributes);
|
||||
#pragma warning restore 0618
|
||||
|
||||
_cancelEvents = false;
|
||||
|
||||
void IFontElement.OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue) =>
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
}
|
||||
|
||||
void IFontElement.OnFontFamilyChanged(string oldValue, string newValue)
|
||||
{
|
||||
if (_cancelEvents)
|
||||
return;
|
||||
|
||||
_cancelEvents = true;
|
||||
|
||||
#pragma warning disable 0618 // retain until Font removed
|
||||
object[] values = GetValues(FontSizeProperty, FontAttributesProperty);
|
||||
var family = newValue;
|
||||
if (family != null)
|
||||
Font = Font.OfSize(family, (double)values[0]).WithAttributes((FontAttributes)values[1]);
|
||||
else
|
||||
Font = Font.SystemFontOfSize((double)values[0], (FontAttributes)values[1]);
|
||||
#pragma warning restore 0618
|
||||
|
||||
_cancelEvents = false;
|
||||
void IFontElement.OnFontFamilyChanged(string oldValue, string newValue) =>
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
}
|
||||
|
||||
void IFontElement.OnFontSizeChanged(double oldValue, double newValue)
|
||||
{
|
||||
if (_cancelEvents)
|
||||
return;
|
||||
|
||||
_cancelEvents = true;
|
||||
|
||||
#pragma warning disable 0618 // retain until Font removed
|
||||
object[] values = GetValues(FontFamilyProperty, FontAttributesProperty);
|
||||
var size = newValue;
|
||||
var family = (string)values[0];
|
||||
if (family != null)
|
||||
Font = Font.OfSize(family, size).WithAttributes((FontAttributes)values[1]);
|
||||
else
|
||||
Font = Font.SystemFontOfSize(size, (FontAttributes)values[1]);
|
||||
#pragma warning restore 0618
|
||||
|
||||
_cancelEvents = false;
|
||||
|
||||
void IFontElement.OnFontSizeChanged(double oldValue, double newValue) =>
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
}
|
||||
|
||||
void IFontElement.OnFontChanged(Font oldValue, Font newValue) =>
|
||||
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
||||
|
||||
void OnFormattedTextChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
|
|
|
@ -125,6 +125,10 @@ namespace Xamarin.Forms
|
|||
{
|
||||
}
|
||||
|
||||
void IFontElement.OnFontChanged(Font oldValue, Font newValue)
|
||||
{
|
||||
}
|
||||
|
||||
public event EventHandler SearchButtonPressed;
|
||||
|
||||
public event EventHandler<TextChangedEventArgs> TextChanged;
|
||||
|
|
|
@ -171,16 +171,30 @@ namespace Xamarin.Forms
|
|||
|
||||
#pragma warning restore
|
||||
|
||||
void IFontElement.OnFontFamilyChanged(string oldValue, string newValue) =>
|
||||
OnSomeFontPropertyChanged();
|
||||
//Those 4 methods are never used as Span isn't a BO, and doesn't compose with FontElement
|
||||
void IFontElement.OnFontFamilyChanged(string oldValue, string newValue)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IFontElement.OnFontSizeChanged(double oldValue, double newValue) =>
|
||||
OnSomeFontPropertyChanged();
|
||||
void IFontElement.OnFontSizeChanged(double oldValue, double newValue)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
double IFontElement.FontSizeDefaultValueCreator() =>
|
||||
Device.GetNamedSize(NamedSize.Default, typeof(Label));
|
||||
double IFontElement.FontSizeDefaultValueCreator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IFontElement.OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue) =>
|
||||
OnSomeFontPropertyChanged();
|
||||
void IFontElement.OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IFontElement.OnFontChanged(Font oldValue, Font newValue)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче