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

Fixed the issue where ScottPlot could not display CJK (and possibly other) characters by default #512

Merged
merged 6 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions GalaxyBudsClient/Interface/Controls/SettingsSwitchItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using GalaxyBudsClient.Generated.I18N;
using GalaxyBudsClient.Utils.Interface;

namespace GalaxyBudsClient.Interface.Controls;

Expand All @@ -13,38 +15,47 @@ public SettingsSwitchItem()
{
_toggle = new ToggleSwitch();
_toggle.IsCheckedChanged += (_, _) => IsChecked = _toggle.IsChecked;

Click += OnClick;
IsClickEnabled = true;
Footer = _toggle;

Loc.LanguageUpdated += OnLanguageUpdated;
OnLanguageUpdated();
}

private readonly ToggleSwitch _toggle;
public static readonly RoutedEvent<RoutedEventArgs> IsCheckedChangedEvent =

public static readonly RoutedEvent<RoutedEventArgs> IsCheckedChangedEvent =
RoutedEvent.Register<SettingsSwitchItem, RoutedEventArgs>(nameof(IsCheckedChanged), RoutingStrategies.Bubble);

public static readonly StyledProperty<bool?> IsCheckedProperty =
public static readonly StyledProperty<bool?> IsCheckedProperty =
ToggleButton.IsCheckedProperty.AddOwner<SettingsSwitchItem>();

public event EventHandler<RoutedEventArgs>? IsCheckedChanged
{
add => AddHandler(IsCheckedChangedEvent, value);
remove => RemoveHandler(IsCheckedChangedEvent, value);
}

private void OnLanguageUpdated()
{
_toggle.OnContent = Strings.On;
_toggle.OffContent = Strings.Off;
}

public bool? IsChecked
{
get => GetValue(IsCheckedProperty);
set => SetValue(IsCheckedProperty, value);
}

private void OnClick(object? sender, RoutedEventArgs e)
{
IsChecked = !IsChecked;
RaiseEvent(new RoutedEventArgs(IsCheckedChangedEvent));
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
if (change.Property == IsCheckedProperty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using ScottPlot.AxisRules;
using ScottPlot.Plottables;
using ScottPlot.TickGenerators;
using SkiaSharp;

namespace GalaxyBudsClient.Interface.ViewModels.Pages;

Expand Down Expand Up @@ -157,7 +158,9 @@ private async Task UpdatePlotAsync()
}

overlay?.AddNullFrame(DateTimeOffset.Now.DateTime.ToOADate());

var font = SKFontManager.Default.MatchCharacter(Strings.Left[0]).FamilyName;
Plot.Legend.FontName = font;

var plotBatteryL = Plot.Add.Scatter(timestamp, batteryL);
plotBatteryL.MarkerShape = MarkerShape.None;
plotBatteryL.LineWidth = 2;
Expand All @@ -181,7 +184,8 @@ private async Task UpdatePlotAsync()
{
LabelFormatter = value => value is < 0 or > 100 ? string.Empty : NumericAutomatic.DefaultLabelFormatter(value)
};


Plot.Font.Set(font);
Plot.YLabel(Strings.BattHistYAxis);
UpdateLegendVisibility();

Expand Down
21 changes: 10 additions & 11 deletions GalaxyBudsClient/Utils/Interface/WindowIconRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ namespace GalaxyBudsClient.Utils.Interface;
public static class WindowIconRenderer
{
private static readonly WindowIcon DefaultIcon = MakeDefaultIcon();

public static void UpdateDynamicIcon(IBasicStatusUpdate status)
{
var trayIcons = TrayIcon.GetIcons(Application.Current!);
if (trayIcons == null)
if (trayIcons == null)
return;

var batteryLeft = status.BatteryL;
var batteryRight = status.BatteryR;

// Ignore battery level of disconnected earbuds
if (batteryLeft <= 0)
batteryLeft = batteryRight;
if (batteryRight <= 0)
batteryRight = batteryLeft;

int? level = Settings.Data.DynamicTrayIconMode switch
{
DynamicTrayIconModes.BatteryMin => Math.Min(batteryLeft, batteryLeft),
Expand Down Expand Up @@ -67,15 +67,15 @@ private static WindowIcon MakeFromBatteryLevel(int level)
$"{level}",
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
Typeface.Default,
210,
Typeface.Default,
210,
Brushes.Black // This brush does not matter since we use the geometry of the text.
);

// Build the geometry object that represents the text.
var textGeometry = formattedText.BuildGeometry(new Point(0, -30));
var render = new RenderTargetBitmap(new PixelSize(256, 256), new Vector(96, 96));

using (var ctx = render.CreateDrawingContext())
{
ctx.PushRenderOptions(new RenderOptions
Expand All @@ -85,11 +85,10 @@ private static WindowIcon MakeFromBatteryLevel(int level)
EdgeMode = EdgeMode.Antialias,
RequiresFullOpacityHandling = true
});

var fillColor = PlatformUtils.IsOSX ? Brushes.Black : Brushes.White;
ctx.DrawGeometry(fillColor, new Pen(Brushes.Transparent, 0), textGeometry!);

ctx.DrawGeometry(new SolidColorBrush(Settings.Data.AccentColor), new Pen(Brushes.Transparent, 0), textGeometry!);
}

return new WindowIcon(render);
}

Expand Down
Loading