Skip to content

Commit

Permalink
feat(Settings): Allow settings Font Size and List Row Height (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic authored Jan 15, 2025
1 parent e0199ba commit 9565525
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/KubeUI/Client/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,10 @@ private void ApplySettings()
Application.Current.RequestedThemeVariant = ThemeVariant.Light;
break;
}

if (App.TopLevel != null)
{
App.TopLevel.FontSize = Convert.ToDouble(Settings.FontSize);
}
}
}
9 changes: 9 additions & 0 deletions src/KubeUI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public sealed partial class Settings : ObservableObject
[ObservableProperty]
public partial ObservableCollection<string> 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;
Expand Down
12 changes: 6 additions & 6 deletions src/KubeUI/ViewModels/Workloads/Pod/PodConsoleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ public sealed partial class PodConsoleViewModel : ViewModelBase, IDisposable
{
private readonly ILogger<PodConsoleViewModel> _logger;

public PodConsoleViewModel(ILogger<PodConsoleViewModel> logger)
private readonly ISettingsService _settingsService;

public PodConsoleViewModel(ILogger<PodConsoleViewModel> logger, ISettingsService settings)
{
_logger = logger;
_settingsService = settings;
Title = Resources.PodConsoleViewModel_Title;
}

Expand Down Expand Up @@ -47,9 +50,6 @@ public PodConsoleViewModel(ILogger<PodConsoleViewModel> logger)
[ObservableProperty]
public partial double Height { get; set; }

[ObservableProperty]
public partial int FontSize { get; set; } = 14;

[ObservableProperty]
public partial int BufferLength { get; set; }

Expand Down Expand Up @@ -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)
Expand All @@ -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.");

Expand Down
16 changes: 14 additions & 2 deletions src/KubeUI/Views/ResourceListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Controls.Templates;
using Avalonia.Styling;
using KubeUI.Client.Informer;
using KubeUI.Client;

namespace KubeUI.Views;

Expand All @@ -14,9 +15,12 @@ namespace KubeUI.Views;

private readonly ILogger<ResourceListView<T>> _logger;

private readonly ISettingsService _settingsService;

public ResourceListView()
{
_logger = Application.Current.GetRequiredService<ILogger<ResourceListView<T>>>();
_settingsService = Application.Current.GetRequiredService<ISettingsService>();
}

private void GenerateGrid()
Expand Down Expand Up @@ -311,15 +315,23 @@ protected override object Build(ResourceListViewModel<T>? vm)
.GridLinesVisibility(DataGridGridLinesVisibility.All)
.IsReadOnly(true)
.MinColumnWidth(90)
.RowHeight(32)
.RowHeight(Convert.ToDouble(_settingsService.Settings.ListRowHeight))
//.OnTapped((x) =>
//{
// if(vm.ViewCommand.CanExecute(_grid.SelectedItem))
// {
// vm.ViewCommand.Execute(_grid.SelectedItem);
// }
//})
,
.Styles([
new Style<DataGridCell>()
.Setter(DataGridCell.FontSizeProperty, Convert.ToDouble(_settingsService.Settings.FontSize))
.Setter(DataGridCell.MinHeightProperty, Convert.ToDouble(_settingsService.Settings.ListRowHeight)),
new Style<DataGridColumnHeader>()
.Setter(DataGridColumnHeader.FontSizeProperty, Convert.ToDouble(_settingsService.Settings.FontSize))
.Setter(DataGridColumnHeader.MinHeightProperty, Convert.ToDouble(_settingsService.Settings.ListRowHeight)),

]),
]);

GenerateGrid();
Expand Down
11 changes: 8 additions & 3 deletions src/KubeUI/Views/ResourceYamlView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
using AvaloniaEdit.Document;
using AvaloniaEdit.Folding;
using AvaloniaEdit.TextMate;
using KubeUI.Client;
using TextMateSharp.Grammars;
using static AvaloniaEdit.TextMate.TextMate;

namespace KubeUI.Views;

public sealed class ResourceYamlView : MyViewBase<ResourceYamlViewModel>
{
private readonly ISettingsService _settingsService;

private Installation _textMateInstallation;

private RegistryOptions _registryOptions;
Expand All @@ -22,8 +25,10 @@ public sealed class ResourceYamlView : MyViewBase<ResourceYamlViewModel>

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;
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions src/KubeUI/Views/SettingsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]),
]);
}
7 changes: 5 additions & 2 deletions src/KubeUI/Views/Workloads/Pod/PodConsoleView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
using Avalonia.Input;
using AvaloniaEdit;
using XtermSharp;
using AvaloniaEdit.Highlighting;
using KubeUI.Client;

namespace KubeUI.Views;

public sealed class PodConsoleView : MyViewBase<PodConsoleViewModel>
{
private readonly ILogger<PodConsoleView> _logger;

private readonly ISettingsService _settingsService;

private TextEditor _textEditor;

public PodConsoleView(ILogger<PodConsoleView> logger)
{
_logger = logger;
_settingsService = Application.Current.GetRequiredService<ISettingsService>();
}

protected override object Build(PodConsoleViewModel? vm)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/KubeUI/Views/Workloads/Pod/PodLogsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
using Avalonia.Markup.Xaml.MarkupExtensions;
using Avalonia.Styling;
using AvaloniaEdit;
using KubeUI.Client;
using TextMateSharp.Grammars;
using static AvaloniaEdit.TextMate.TextMate;

namespace KubeUI.Views;

public sealed class PodLogsView : MyViewBase<PodLogsViewModel>
{
private readonly ISettingsService _settingsService;

private Installation _textMateInstallation;

private RegistryOptions _registryOptions;
Expand All @@ -19,6 +22,8 @@ public sealed class PodLogsView : MyViewBase<PodLogsViewModel>

public PodLogsView()
{
_settingsService = Application.Current.GetRequiredService<ISettingsService>();

_registryOptions = new RegistryOptions(Application.Current.ActualThemeVariant == ThemeVariant.Light ? ThemeName.Light : ThemeName.DarkPlus);

Application.Current.ActualThemeVariantChanged += Current_ActualThemeVariantChanged;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9565525

Please sign in to comment.