88 lines
1.7 KiB
C#
88 lines
1.7 KiB
C#
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sarand.Net.Mobile.Maui.Controls
|
|
{
|
|
public class SamLabel : Label, ISamControl
|
|
{
|
|
// --- Data Members ---
|
|
|
|
private double fontSize;
|
|
private double fontSizeProportion = 1.0;
|
|
private bool applyingFontSize;
|
|
|
|
// --- Construction ---
|
|
|
|
public SamLabel()
|
|
{
|
|
fontSize = base.FontSize;
|
|
FontSizeDefault = fontSize;
|
|
Text = "";
|
|
}
|
|
|
|
// --- Properties ---
|
|
|
|
|
|
/// <summary>Default (initial) font size.</summary>
|
|
public double FontSizeDefault { get; private set; }
|
|
|
|
public new double FontSize
|
|
{
|
|
get { return fontSize; }
|
|
set
|
|
{
|
|
if (fontSize == value) return;
|
|
fontSize = value;
|
|
ApplyFontSize();
|
|
}
|
|
}
|
|
|
|
/// <summary>Font size proportion.</summary>
|
|
public double FontSizeProportion
|
|
{
|
|
get { return fontSizeProportion; }
|
|
set
|
|
{
|
|
if (fontSizeProportion == value) return;
|
|
fontSizeProportion = value;
|
|
ApplyFontSize();
|
|
}
|
|
}
|
|
|
|
// --- Font sizing ---
|
|
|
|
private void ApplyFontSize()
|
|
{
|
|
applyingFontSize = true;
|
|
base.FontSize = fontSize * fontSizeProportion;
|
|
applyingFontSize = false;
|
|
}
|
|
|
|
protected override void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
|
{
|
|
base.OnPropertyChanged(propertyName);
|
|
if (propertyName.EqualsCI("FontSize") && !applyingFontSize)
|
|
{
|
|
if (FontSizeDefault <= 0)
|
|
FontSizeDefault = base.FontSize;
|
|
if (fontSizeProportion != 0)
|
|
fontSize = base.FontSize / fontSizeProportion;
|
|
}
|
|
}
|
|
|
|
// --- Component state ---
|
|
|
|
public void SetControlActivity(bool enabled)
|
|
{
|
|
if (IsEnabled != enabled) IsEnabled = enabled;
|
|
}
|
|
|
|
// --- The End ---
|
|
}
|
|
}
|