версия 2.0.9: размер шрифта/текста (масштаб интерфейса) в Настройках
- Настройки: выпадающий список «Размер шрифта / текста» (90/100/115/130/150%) - масштаб применяется ко всему главному окну (LayoutTransform), сохраняется и восстанавливается при старте Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
c808d62188
commit
60ab620608
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#define MyAppName "Электронная Фармация"
|
#define MyAppName "Электронная Фармация"
|
||||||
#define MyAppBrand "ЭльФиСА"
|
#define MyAppBrand "ЭльФиСА"
|
||||||
#define MyAppVersion "2.0.8"
|
#define MyAppVersion "2.0.9"
|
||||||
#define MyAppPublisher "PharmData"
|
#define MyAppPublisher "PharmData"
|
||||||
#define MyAppURL "https://cdn.24pharmdata.ru"
|
#define MyAppURL "https://cdn.24pharmdata.ru"
|
||||||
#define MyAppSupportURL "https://24pharmdata.ru"
|
#define MyAppSupportURL "https://24pharmdata.ru"
|
||||||
|
|||||||
@ -28,6 +28,14 @@ public partial class App : Application
|
|||||||
app.Resources["AppFontFamily"] = new FontFamily(family);
|
app.Resources["AppFontFamily"] = new FontFamily(family);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Применяет масштаб интерфейса (размер шрифта/текста) к главному окну.</summary>
|
||||||
|
public static void ApplyScale(double scale)
|
||||||
|
{
|
||||||
|
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime d
|
||||||
|
&& d.MainWindow is MainWindow mw)
|
||||||
|
mw.ApplyScale(scale);
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
{
|
{
|
||||||
RequestedThemeVariant = Elfisa.Core.SettingsStore.Current.Theme == "Dark"
|
RequestedThemeVariant = Elfisa.Core.SettingsStore.Current.Theme == "Dark"
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||||
<Version>2.0.8</Version>
|
<Version>2.0.9</Version>
|
||||||
<AssemblyVersion>2.0.8.0</AssemblyVersion>
|
<AssemblyVersion>2.0.9.0</AssemblyVersion>
|
||||||
<FileVersion>2.0.8.0</FileVersion>
|
<FileVersion>2.0.9.0</FileVersion>
|
||||||
<Product>ЭльФиСА — Электронная Фармация</Product>
|
<Product>ЭльФиСА — Электронная Фармация</Product>
|
||||||
<Company>PharmData</Company>
|
<Company>PharmData</Company>
|
||||||
<!-- Кросс-платформенная публикация задаётся флагами CLI (RID + self-contained). -->
|
<!-- Кросс-платформенная публикация задаётся флагами CLI (RID + self-contained). -->
|
||||||
|
|||||||
@ -19,6 +19,12 @@ public partial class SettingsViewModel : ViewModelBase
|
|||||||
public string[] Themes { get; } = { "Светлая", "Тёмная" };
|
public string[] Themes { get; } = { "Светлая", "Тёмная" };
|
||||||
[ObservableProperty] private int _themeIndex;
|
[ObservableProperty] private int _themeIndex;
|
||||||
|
|
||||||
|
/// <summary>Размер шрифта/текста — масштаб интерфейса.</summary>
|
||||||
|
public string[] FontSizes { get; } = { "Мелкий (90%)", "Обычный (100%)", "Крупный (115%)", "Очень крупный (130%)", "Огромный (150%)" };
|
||||||
|
private static readonly double[] ScaleValues = { 0.9, 1.0, 1.15, 1.3, 1.5 };
|
||||||
|
[ObservableProperty] private int _fontSizeIndex = 1;
|
||||||
|
public double SelectedScale => ScaleValues[Math.Clamp(FontSizeIndex, 0, ScaleValues.Length - 1)];
|
||||||
|
|
||||||
/// <summary>Все системные шрифты + «По умолчанию» первым.</summary>
|
/// <summary>Все системные шрифты + «По умолчанию» первым.</summary>
|
||||||
public ObservableCollection<string> Fonts { get; } = new();
|
public ObservableCollection<string> Fonts { get; } = new();
|
||||||
[ObservableProperty] private string _selectedFont = DefaultFontLabel;
|
[ObservableProperty] private string _selectedFont = DefaultFontLabel;
|
||||||
@ -32,6 +38,12 @@ public partial class SettingsViewModel : ViewModelBase
|
|||||||
ApiBaseUrl = SettingsStore.Current.ApiBaseUrl ?? AppConfig.DefaultApiBaseUrl;
|
ApiBaseUrl = SettingsStore.Current.ApiBaseUrl ?? AppConfig.DefaultApiBaseUrl;
|
||||||
ThemeIndex = SettingsStore.Current.Theme == "Dark" ? 1 : 0;
|
ThemeIndex = SettingsStore.Current.Theme == "Dark" ? 1 : 0;
|
||||||
|
|
||||||
|
var scale = SettingsStore.Current.UiScale;
|
||||||
|
var best = 1;
|
||||||
|
for (int i = 0; i < ScaleValues.Length; i++)
|
||||||
|
if (Math.Abs(ScaleValues[i] - scale) < Math.Abs(ScaleValues[best] - scale)) best = i;
|
||||||
|
FontSizeIndex = best;
|
||||||
|
|
||||||
Fonts.Add(DefaultFontLabel);
|
Fonts.Add(DefaultFontLabel);
|
||||||
foreach (var f in FontManager.Current.SystemFonts
|
foreach (var f in FontManager.Current.SystemFonts
|
||||||
.Select(x => x.Name)
|
.Select(x => x.Name)
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
Background="{DynamicResource Bg}"
|
Background="{DynamicResource Bg}"
|
||||||
Title="ЭльФиСА">
|
Title="ЭльФиСА">
|
||||||
|
|
||||||
|
<!-- Масштаб интерфейса (размер шрифта/текста) — зум всего содержимого. -->
|
||||||
|
<LayoutTransformControl x:Name="ScaleHost">
|
||||||
<ContentControl Content="{Binding Current}"/>
|
<ContentControl Content="{Binding Current}"/>
|
||||||
|
</LayoutTransformControl>
|
||||||
|
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using Elfisa.Core;
|
||||||
|
|
||||||
namespace Elfisa.Avalonia.Views;
|
namespace Elfisa.Avalonia.Views;
|
||||||
|
|
||||||
@ -7,5 +9,14 @@ public partial class MainWindow : Window
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
ApplyScale(SettingsStore.Current.UiScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Масштабирует всё содержимое окна (размер шрифта/текста и элементов).</summary>
|
||||||
|
public void ApplyScale(double scale)
|
||||||
|
{
|
||||||
|
var host = this.FindControl<LayoutTransformControl>("ScaleHost");
|
||||||
|
if (host is null) return;
|
||||||
|
host.LayoutTransform = scale == 1.0 ? null : new ScaleTransform(scale, scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,7 +3,7 @@
|
|||||||
xmlns:vm="using:Elfisa.Avalonia.ViewModels"
|
xmlns:vm="using:Elfisa.Avalonia.ViewModels"
|
||||||
x:Class="Elfisa.Avalonia.Views.SettingsWindow"
|
x:Class="Elfisa.Avalonia.Views.SettingsWindow"
|
||||||
x:DataType="vm:SettingsViewModel"
|
x:DataType="vm:SettingsViewModel"
|
||||||
Width="460" Height="520" CanResize="False"
|
Width="460" Height="590" CanResize="False"
|
||||||
WindowStartupLocation="CenterOwner"
|
WindowStartupLocation="CenterOwner"
|
||||||
Background="{DynamicResource Bg}"
|
Background="{DynamicResource Bg}"
|
||||||
Title="Настройки">
|
Title="Настройки">
|
||||||
@ -33,6 +33,11 @@
|
|||||||
</ComboBox>
|
</ComboBox>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Spacing="6">
|
||||||
|
<TextBlock Text="Размер шрифта / текста" Classes="label"/>
|
||||||
|
<ComboBox ItemsSource="{Binding FontSizes}" SelectedIndex="{Binding FontSizeIndex}" HorizontalAlignment="Stretch"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Spacing="6">
|
<StackPanel Spacing="6">
|
||||||
<TextBlock Text="Грузополучатель по умолчанию" Classes="label"/>
|
<TextBlock Text="Грузополучатель по умолчанию" Classes="label"/>
|
||||||
<ComboBox ItemsSource="{Binding Locations}" SelectedItem="{Binding SelectedLocation}" HorizontalAlignment="Stretch"/>
|
<ComboBox ItemsSource="{Binding Locations}" SelectedItem="{Binding SelectedLocation}" HorizontalAlignment="Stretch"/>
|
||||||
|
|||||||
@ -44,12 +44,14 @@ public partial class SettingsWindow : Window
|
|||||||
SettingsStore.Current.Theme = vm.ThemeIndex == 1 ? "Dark" : "Light";
|
SettingsStore.Current.Theme = vm.ThemeIndex == 1 ? "Dark" : "Light";
|
||||||
var font = vm.SelectedFont == SettingsViewModel.DefaultFontLabel ? null : vm.SelectedFont;
|
var font = vm.SelectedFont == SettingsViewModel.DefaultFontLabel ? null : vm.SelectedFont;
|
||||||
SettingsStore.Current.FontFamily = font;
|
SettingsStore.Current.FontFamily = font;
|
||||||
|
SettingsStore.Current.UiScale = vm.SelectedScale;
|
||||||
SettingsStore.Current.DefaultLocationId = vm.SelectedLocation?.BuyerLocationId;
|
SettingsStore.Current.DefaultLocationId = vm.SelectedLocation?.BuyerLocationId;
|
||||||
SettingsStore.Save();
|
SettingsStore.Save();
|
||||||
|
|
||||||
if (Application.Current is { } app)
|
if (Application.Current is { } app)
|
||||||
app.RequestedThemeVariant = vm.ThemeIndex == 1 ? ThemeVariant.Dark : ThemeVariant.Light;
|
app.RequestedThemeVariant = vm.ThemeIndex == 1 ? ThemeVariant.Dark : ThemeVariant.Light;
|
||||||
App.ApplyFont(font); // применяем сразу ко всем окнам
|
App.ApplyFont(font); // шрифт — сразу ко всем окнам
|
||||||
|
App.ApplyScale(vm.SelectedScale); // масштаб — к главному окну
|
||||||
}
|
}
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ public sealed class AppSettings
|
|||||||
public string? ApiBaseUrl { get; set; }
|
public string? ApiBaseUrl { get; set; }
|
||||||
public string Theme { get; set; } = "Light"; // Light | Dark
|
public string Theme { get; set; } = "Light"; // Light | Dark
|
||||||
public string? FontFamily { get; set; } // шрифт интерфейса (null = по умолчанию)
|
public string? FontFamily { get; set; } // шрифт интерфейса (null = по умолчанию)
|
||||||
|
public double UiScale { get; set; } = 1.0; // масштаб интерфейса (размер шрифта/текста)
|
||||||
public string? DefaultLocationId { get; set; }
|
public string? DefaultLocationId { get; set; }
|
||||||
public string? Token { get; set; } // сохранённая сессия
|
public string? Token { get; set; } // сохранённая сессия
|
||||||
public string? Role { get; set; }
|
public string? Role { get; set; }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user