From 9565525184cb8a9db2f3dfe5639b16403508d941 Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Tue, 14 Jan 2025 21:38:19 -0800 Subject: [PATCH] feat(Settings): Allow settings Font Size and List Row Height (#867) --- src/KubeUI/Client/SettingsService.cs | 5 +++ src/KubeUI/Settings.cs | 9 +++++ .../Workloads/Pod/PodConsoleViewModel.cs | 12 +++---- src/KubeUI/Views/ResourceListView.cs | 16 +++++++-- src/KubeUI/Views/ResourceYamlView.cs | 11 +++++-- src/KubeUI/Views/SettingsView.cs | 33 +++++++++++++++++++ .../Views/Workloads/Pod/PodConsoleView.cs | 7 ++-- src/KubeUI/Views/Workloads/Pod/PodLogsView.cs | 7 +++- 8 files changed, 86 insertions(+), 14 deletions(-) diff --git a/src/KubeUI/Client/SettingsService.cs b/src/KubeUI/Client/SettingsService.cs index fa0a65b7..e850bae2 100644 --- a/src/KubeUI/Client/SettingsService.cs +++ b/src/KubeUI/Client/SettingsService.cs @@ -109,5 +109,10 @@ private void ApplySettings() Application.Current.RequestedThemeVariant = ThemeVariant.Light; break; } + + if (App.TopLevel != null) + { + App.TopLevel.FontSize = Convert.ToDouble(Settings.FontSize); + } } } diff --git a/src/KubeUI/Settings.cs b/src/KubeUI/Settings.cs index 603fc9b6..3b19dfab 100644 --- a/src/KubeUI/Settings.cs +++ b/src/KubeUI/Settings.cs @@ -29,6 +29,15 @@ public sealed partial class Settings : ObservableObject [ObservableProperty] public partial ObservableCollection KubeConfigs { get; set; } = []; + [ObservableProperty] + public partial decimal FontSize { get; set; } = 13; + + [ObservableProperty] + public partial decimal ConsoleFontSize { get; set; } = 12; + + [ObservableProperty] + public partial decimal ListRowHeight { get; set; } = 30; + public ClusterSettings GetClusterSettings(ICluster cluster) { var _key = cluster.KubeConfigPath + " " + cluster.Name; diff --git a/src/KubeUI/ViewModels/Workloads/Pod/PodConsoleViewModel.cs b/src/KubeUI/ViewModels/Workloads/Pod/PodConsoleViewModel.cs index 013e47e3..a9dd1376 100644 --- a/src/KubeUI/ViewModels/Workloads/Pod/PodConsoleViewModel.cs +++ b/src/KubeUI/ViewModels/Workloads/Pod/PodConsoleViewModel.cs @@ -17,9 +17,12 @@ public sealed partial class PodConsoleViewModel : ViewModelBase, IDisposable { private readonly ILogger _logger; - public PodConsoleViewModel(ILogger logger) + private readonly ISettingsService _settingsService; + + public PodConsoleViewModel(ILogger logger, ISettingsService settings) { _logger = logger; + _settingsService = settings; Title = Resources.PodConsoleViewModel_Title; } @@ -47,9 +50,6 @@ public PodConsoleViewModel(ILogger logger) [ObservableProperty] public partial double Height { get; set; } - [ObservableProperty] - public partial int FontSize { get; set; } = 14; - [ObservableProperty] public partial int BufferLength { get; set; } @@ -119,7 +119,7 @@ public void Resize(double width, double height) Height = height; if (Width > 0 && Height > 0) { - var size = CalculateTextSize("a", FontFamily, FontSize); + var size = CalculateTextSize("a", FontFamily, Convert.ToDouble(_settingsService.Settings.ConsoleFontSize)); var cols = (int)((width) / size.Width); var rows = (int)((height) / (size.Height * 1.17)); if (Terminal.Cols != cols || Terminal.Rows != rows) @@ -131,7 +131,7 @@ public void Resize(double width, double height) } } - public static Size CalculateTextSize(string text, string fontName, int myFontSize) + public static Size CalculateTextSize(string text, string fontName, double myFontSize) { var myFont = Avalonia.Media.FontFamily.Parse(fontName) ?? throw new ArgumentException($"The resource {fontName} is not a FontFamily."); diff --git a/src/KubeUI/Views/ResourceListView.cs b/src/KubeUI/Views/ResourceListView.cs index d1a1eee2..aba75a00 100644 --- a/src/KubeUI/Views/ResourceListView.cs +++ b/src/KubeUI/Views/ResourceListView.cs @@ -5,6 +5,7 @@ using Avalonia.Controls.Templates; using Avalonia.Styling; using KubeUI.Client.Informer; +using KubeUI.Client; namespace KubeUI.Views; @@ -14,9 +15,12 @@ namespace KubeUI.Views; private readonly ILogger> _logger; + private readonly ISettingsService _settingsService; + public ResourceListView() { _logger = Application.Current.GetRequiredService>>(); + _settingsService = Application.Current.GetRequiredService(); } private void GenerateGrid() @@ -311,7 +315,7 @@ protected override object Build(ResourceListViewModel? vm) .GridLinesVisibility(DataGridGridLinesVisibility.All) .IsReadOnly(true) .MinColumnWidth(90) - .RowHeight(32) + .RowHeight(Convert.ToDouble(_settingsService.Settings.ListRowHeight)) //.OnTapped((x) => //{ // if(vm.ViewCommand.CanExecute(_grid.SelectedItem)) @@ -319,7 +323,15 @@ protected override object Build(ResourceListViewModel? vm) // vm.ViewCommand.Execute(_grid.SelectedItem); // } //}) - , + .Styles([ + new Style() + .Setter(DataGridCell.FontSizeProperty, Convert.ToDouble(_settingsService.Settings.FontSize)) + .Setter(DataGridCell.MinHeightProperty, Convert.ToDouble(_settingsService.Settings.ListRowHeight)), + new Style() + .Setter(DataGridColumnHeader.FontSizeProperty, Convert.ToDouble(_settingsService.Settings.FontSize)) + .Setter(DataGridColumnHeader.MinHeightProperty, Convert.ToDouble(_settingsService.Settings.ListRowHeight)), + + ]), ]); GenerateGrid(); diff --git a/src/KubeUI/Views/ResourceYamlView.cs b/src/KubeUI/Views/ResourceYamlView.cs index 6a5dc5b4..96a3fdf3 100644 --- a/src/KubeUI/Views/ResourceYamlView.cs +++ b/src/KubeUI/Views/ResourceYamlView.cs @@ -7,6 +7,7 @@ using AvaloniaEdit.Document; using AvaloniaEdit.Folding; using AvaloniaEdit.TextMate; +using KubeUI.Client; using TextMateSharp.Grammars; using static AvaloniaEdit.TextMate.TextMate; @@ -14,6 +15,8 @@ namespace KubeUI.Views; public sealed class ResourceYamlView : MyViewBase { + private readonly ISettingsService _settingsService; + private Installation _textMateInstallation; private RegistryOptions _registryOptions; @@ -22,8 +25,10 @@ public sealed class ResourceYamlView : MyViewBase private TextEditor _textEditor; - public ResourceYamlView() + public ResourceYamlView(ISettingsService settingsService) { + _settingsService = settingsService; + _registryOptions = new RegistryOptions(Application.Current.ActualThemeVariant == ThemeVariant.Light ? ThemeName.Light : ThemeName.DarkPlus); Application.Current.ActualThemeVariantChanged += Current_ActualThemeVariantChanged; @@ -108,8 +113,8 @@ protected override object Build(ResourceYamlViewModel? vm) .OnTextChanged((x) => { YamlFoldingStrategy.UpdateFoldings(_foldingManager, _textEditor.Document); }) - .FontFamily(new FontFamily("Consolas,Menlo,Monospace")) - .FontSize(14.0) + .FontFamily(new FontFamily("Cascadia Mono")) + .FontSize(Convert.ToDouble(_settingsService.Settings.ConsoleFontSize)) .FontWeight(FontWeight.Normal) .IsReadOnly(@vm.EditMode, converter: Utilities.InverseBooleanConverter) .ShowLineNumbers(true) diff --git a/src/KubeUI/Views/SettingsView.cs b/src/KubeUI/Views/SettingsView.cs index 55f727e7..b54c690d 100644 --- a/src/KubeUI/Views/SettingsView.cs +++ b/src/KubeUI/Views/SettingsView.cs @@ -67,5 +67,38 @@ protected override object Build(SettingsViewModel? vm) => .IsEnabled(false) .IsChecked(@vm.SettingsService.Settings.PreReleaseChannel), ]), + new Grid() + .Cols("*,2*") + .ToolTip("Font Size") + .Children([ + new Label() + .Col(0) + .Content("Font Size"), + new NumericUpDown() + .Col(1) + .Value(@vm.SettingsService.Settings.FontSize), + ]), + new Grid() + .Cols("*,2*") + .ToolTip("Console/Logs/Yaml Font Size") + .Children([ + new Label() + .Col(0) + .Content("Console/Logs/Yaml Font Size"), + new NumericUpDown() + .Col(1) + .Value(@vm.SettingsService.Settings.ConsoleFontSize), + ]), + new Grid() + .Cols("*,2*") + .ToolTip("List Row Height") + .Children([ + new Label() + .Col(0) + .Content("List Row Height"), + new NumericUpDown() + .Col(1) + .Value(@vm.SettingsService.Settings.ListRowHeight), + ]), ]); } diff --git a/src/KubeUI/Views/Workloads/Pod/PodConsoleView.cs b/src/KubeUI/Views/Workloads/Pod/PodConsoleView.cs index bf04d872..ad7e3bea 100644 --- a/src/KubeUI/Views/Workloads/Pod/PodConsoleView.cs +++ b/src/KubeUI/Views/Workloads/Pod/PodConsoleView.cs @@ -2,7 +2,7 @@ using Avalonia.Input; using AvaloniaEdit; using XtermSharp; -using AvaloniaEdit.Highlighting; +using KubeUI.Client; namespace KubeUI.Views; @@ -10,11 +10,14 @@ public sealed class PodConsoleView : MyViewBase { private readonly ILogger _logger; + private readonly ISettingsService _settingsService; + private TextEditor _textEditor; public PodConsoleView(ILogger logger) { _logger = logger; + _settingsService = Application.Current.GetRequiredService(); } protected override object Build(PodConsoleViewModel? vm) @@ -328,7 +331,7 @@ protected override object Build(PodConsoleViewModel? vm) }) .Document(@vm.Console, BindingMode.OneWay) .FontFamily(@vm.FontFamily) - .FontSize(@vm.FontSize) + .FontSize(Convert.ToDouble(_settingsService.Settings.ConsoleFontSize)) .IsReadOnly(true) .ShowLineNumbers(false) .Background(Brushes.Black) diff --git a/src/KubeUI/Views/Workloads/Pod/PodLogsView.cs b/src/KubeUI/Views/Workloads/Pod/PodLogsView.cs index adb73068..aa802ffb 100644 --- a/src/KubeUI/Views/Workloads/Pod/PodLogsView.cs +++ b/src/KubeUI/Views/Workloads/Pod/PodLogsView.cs @@ -4,6 +4,7 @@ using Avalonia.Markup.Xaml.MarkupExtensions; using Avalonia.Styling; using AvaloniaEdit; +using KubeUI.Client; using TextMateSharp.Grammars; using static AvaloniaEdit.TextMate.TextMate; @@ -11,6 +12,8 @@ namespace KubeUI.Views; public sealed class PodLogsView : MyViewBase { + private readonly ISettingsService _settingsService; + private Installation _textMateInstallation; private RegistryOptions _registryOptions; @@ -19,6 +22,8 @@ public sealed class PodLogsView : MyViewBase public PodLogsView() { + _settingsService = Application.Current.GetRequiredService(); + _registryOptions = new RegistryOptions(Application.Current.ActualThemeVariant == ThemeVariant.Light ? ThemeName.Light : ThemeName.DarkPlus); Application.Current.ActualThemeVariantChanged += Current_ActualThemeVariantChanged; @@ -95,7 +100,7 @@ protected override object Build(PodLogsViewModel? vm) }) .Document(@vm.Logs, BindingMode.OneWay) .FontFamily(new FontFamily("Cascadia Mono")) - .FontSize(14.0) + .FontSize(Convert.ToDouble(_settingsService.Settings.ConsoleFontSize)) .FontWeight(FontWeight.Normal) .IsReadOnly(true) .ShowLineNumbers(false)