Skip to content

Commit f7f1ada

Browse files
committed
More theming
Also fixed the stop when loading in the installed themes
1 parent 115cdd4 commit f7f1ada

File tree

8 files changed

+84
-20
lines changed

8 files changed

+84
-20
lines changed

MultiRPC/Logging/LoggingPageLogger.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Avalonia.Controls;
4+
using Avalonia.Media;
45
using Avalonia.Threading;
56
using TinyUpdate.Core.Logging;
67

@@ -78,7 +79,8 @@ private static TextBlock MakeTextBlock(string header, string message)
7879
{
7980
return new TextBlock()
8081
{
81-
Text = header + " " + message
82+
Text = header + " " + message,
83+
Foreground = Brushes.White
8284
};
8385
}
8486

MultiRPC/Theming/Theme.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@ public void ReloadAssets()
180180
UnloadAssets();
181181

182182
var fileStream = StreamUtil.SafeOpenRead(_filepath);
183-
_archive = new ZipArchive(fileStream, ZipArchiveMode.Read);
184-
_archiveLoaded = true;
183+
if (fileStream != null)
184+
{
185+
_archive = new ZipArchive(fileStream, ZipArchiveMode.Read);
186+
_archiveLoaded = true;
187+
}
185188
}
186189

187190
public void UnloadAssets()
@@ -214,6 +217,13 @@ public void Apply(IResourceDictionary? resourceDictionary = null)
214217
resourceDictionary["NavButtonSelectedColor"] = Colours.NavButtonSelectedColor;
215218
resourceDictionary["NavButtonSelectedIconColor"] = Colours.NavButtonSelectedIconColor;
216219
resourceDictionary["ThemeForegroundBrush"] = new SolidColorBrush(Colours.TextColour);
220+
221+
resourceDictionary["CheckBoxForegroundUnchecked"] = resourceDictionary["ThemeForegroundBrush"];
222+
resourceDictionary["CheckBoxForegroundChecked"] = resourceDictionary["ThemeForegroundBrush"];
223+
resourceDictionary["CheckBoxForegroundCheckedPointerOver"] = resourceDictionary["ThemeForegroundBrush"];
224+
resourceDictionary["CheckBoxForegroundUncheckedPointerOver"] = resourceDictionary["ThemeForegroundBrush"];
225+
resourceDictionary["CheckBoxForegroundCheckedPressed"] = resourceDictionary["ThemeForegroundBrush"];
226+
resourceDictionary["CheckBoxForegroundUncheckedPressed"] = resourceDictionary["ThemeForegroundBrush"];
217227

218228
AssetManager.FireReloadAssets(this);
219229
}

MultiRPC/UI/App.axaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
namespace MultiRPC.UI;
2222

23+
/*TODO:
24+
* Styling:
25+
* CheckBox (Actual Box)
26+
* Tooltip
27+
* Text on purple RpcView
28+
* Min/Max Buttons*/
2329
public class App : Application
2430
{
2531
public static readonly HttpClient HttpClient = new HttpClient();

MultiRPC/UI/MainWindow.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public MainWindow() : this(new MainPage())
7878
private void DragEnter(object? sender, DragEventArgs e)
7979
{
8080
// Only allow Copy or Link as Drop Operations.
81-
e.DragEffects = e.DragEffects & (DragDropEffects.Copy | DragDropEffects.Link);
81+
e.DragEffects &= DragDropEffects.Copy | DragDropEffects.Link;
8282

8383
// Only allow if the dragged data contains text or filenames.
8484
if (!e.Data.Contains(DataFormats.FileNames))

MultiRPC/UI/Pages/Theme/InstalledThemes.axaml.cs

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
using Avalonia.Layout;
1111
using Avalonia.LogicalTree;
1212
using Avalonia.Media;
13+
using MultiRPC.Extensions;
1314
using MultiRPC.Setting;
1415
using MultiRPC.Setting.Settings;
1516
using MultiRPC.Theming;
1617
using MultiRPC.UI.Controls;
1718

1819
namespace MultiRPC.UI.Pages.Theme;
1920

21+
//TODO: Make it faster when loading in the theme
2022
//TODO: Add Showing/Active/Editing Text
2123
//TODO: Disable Remove button on active theme
2224
//TODO: Add Edit button when theme editor has progress
@@ -41,9 +43,11 @@ public void Initialize(bool loadXaml)
4143
return;
4244
}
4345

44-
wppThemes.Children.AddRange(
45-
Directory.EnumerateFiles(_themeLocation)
46-
.Select(MakePreviewUI));
46+
_ = Task.Run(() =>
47+
{
48+
var files = Directory.GetFiles(_themeLocation);
49+
MakePreviewUIs(files);
50+
});
4751
}
4852

4953
private void OnAttachedToLogicalTree(object? sender, LogicalTreeAttachmentEventArgs e)
@@ -64,7 +68,22 @@ private void OnDetachedFromLogicalTree(object? sender, LogicalTreeAttachmentEven
6468
private async void BtnAdd_OnClick(object? sender, RoutedEventArgs e) => await GetTheme(false);
6569
private async void BtnAddAndApply_OnClick(object? sender, RoutedEventArgs e) => await GetTheme(true);
6670

67-
private Control MakePreviewUI(string file) => MakePreviewUI(Theming.Theme.Load(file), file);
71+
private async void MakePreviewUIs(string[] files)
72+
{
73+
foreach (var file in files)
74+
{
75+
/*Funnily enough, if we load in things too
76+
fast then it'll make the whole UI unresponsive*/
77+
await Task.Delay(50);
78+
var theme = Theming.Theme.Load(file);
79+
this.RunUILogic(() =>
80+
{
81+
var control = MakePreviewUI(theme, file);
82+
wppThemes.Children.Add(control);
83+
});
84+
}
85+
}
86+
6887
private Control MakePreviewUI(Theming.Theme? theme, string? file = null)
6988
{
7089
if (theme == null)
@@ -90,7 +109,7 @@ private Control MakePreviewUI(Theming.Theme? theme, string? file = null)
90109
{
91110
DataContext = Language.GetLanguage("Remove"),
92111
[!ContentProperty] = new Binding("TextObservable^"),
93-
IsEnabled = editButton.IsEnabled,
112+
IsEnabled = false,//editButton.IsEnabled,
94113
Tag = theme,
95114
};
96115
removeButton.Click += RemoveButtonOnClick;
@@ -123,10 +142,14 @@ private Control MakePreviewUI(Theming.Theme? theme, string? file = null)
123142
};
124143

125144
var themeUI = new ThemePreview(theme)
126-
{ Margin = new Thickness(0, 0, 15, 15) };
145+
{
146+
Margin = new Thickness(0, 0, 15, 15)
147+
};
127148
themeUI.PointerEnter += ThemeUIOnPointerEnter;
128149
themeUI.PointerLeave += ThemeUIOnPointerLeave;
129150
themeUI.DoubleTapped += ThemeUIOnDoubleTapped;
151+
themeUI.AttachedToLogicalTree += (sender, args) => _ = Task.Run(theme.ReloadAssets);
152+
themeUI.DetachedFromLogicalTree += (sender, args) => _ = Task.Run(theme.UnloadAssets);
130153
return new StackPanel
131154
{
132155
Children =
@@ -137,25 +160,33 @@ private Control MakePreviewUI(Theming.Theme? theme, string? file = null)
137160
};
138161
}
139162

163+
private Theming.Theme? _tmpTheme;
140164
private void ThemeUIOnPointerLeave(object? sender, PointerEventArgs e)
141165
{
142166
//We want to restore the old theme if it didn't become the new active theme
143167
var th = (ThemePreview)sender!;
144-
if (_activeTheme != th.Theme)
168+
if (_tmpTheme != null
169+
&& _activeTheme != th.Theme)
145170
{
146171
_activeTheme?.Apply();
172+
_tmpTheme = null;
147173
}
148174
}
149175

150176
private async void ThemeUIOnPointerEnter(object? sender, PointerEventArgs e)
151177
{
152-
await Task.Delay(1000);
178+
await Task.Delay(500);
153179
var th = (ThemePreview)sender!;
154-
if (_activeTheme != th.Theme
155-
&& th.IsPointerOver)
180+
181+
this.RunUILogic(() =>
156182
{
157-
th.Theme.Apply();
158-
}
183+
if (_activeTheme != th.Theme
184+
&& th.IsPointerOver)
185+
{
186+
_tmpTheme = th.Theme;
187+
th.Theme.Apply();
188+
}
189+
});
159190
}
160191

161192
private readonly GeneralSettings _generalSettings = SettingManager<GeneralSettings>.Setting;

MultiRPC/UI/Pages/Theme/MasterThemeEditorPage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public override void Initialize(bool loadXaml)
1414
var tabPage = new TabsPage
1515
{
1616
MinWidth = 675,
17-
MinHeight = 520
17+
MaxWidth = 997.5,
18+
MaxHeight = 520
1819
};
1920
ContentPadding = new Thickness(0);
2021
tabPage.AddTabs(new ThemeEditorPage()

MultiRPC/UI/Pages/Theme/ThemePreview.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</Style>
1616
</UserControl.Styles>
1717
<UserControl.Resources>
18+
<SolidColorBrush x:Key="ThemeForegroundBrush" Color="White" />
1819
<SolidColorBrush x:Key="ComboBoxDropDownBackground" Color="{DynamicResource ThemeAccentColor2}" />
1920
<SolidColorBrush x:Key="ThemeAccentBrush" Color="{DynamicResource ThemeAccentColor}"/>
2021
<SolidColorBrush x:Key="ThemeAccentBrush2" Color="{DynamicResource ThemeAccentColor2}"/>

MultiRPC/UI/Styling.axaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Styles xmlns="https://github.com/avaloniaui"
1+
<Styles xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:multirpc="clr-namespace:MultiRPC">
44
<Design.PreviewWith>
@@ -41,8 +41,8 @@
4141
<Style Selector="ComboBox /template/ Path#DropDownGlyph">
4242
<Setter Property="Fill" Value="{DynamicResource ThemeAccentBrush4}" />
4343
</Style>
44-
<Style Selector="ComboBox /template/ ContentControl#ContentPresenter">
45-
<Setter Property="TextBlock.Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
44+
<Style Selector="ComboBox:pointerover /template/ Path#DropDownGlyph">
45+
<Setter Property="Fill" Value="{DynamicResource ThemeAccentBrush5}" />
4646
</Style>
4747
<Style Selector="ComboBox">
4848
<Setter Property="Height" Value="{TemplateBinding MinHeight}" />
@@ -74,6 +74,17 @@
7474
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush}" />
7575
<Setter Property="BorderBrush" Value="{DynamicResource ThemeAccentBrush4}" />
7676
</Style>
77+
78+
<Style Selector="TextBox:focus">
79+
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
80+
</Style>
81+
<Style Selector="TextBox:focus /template/ TextBlock#PART_Watermark, TextBox:focus /template/ TextBlock#PART_FloatingWatermark">
82+
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
83+
</Style>
84+
<Style Selector="TextBox:pointerover /template/ TextBlock#PART_Watermark, TextBox:focus /template/ TextBlock#PART_FloatingWatermark">
85+
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
86+
</Style>
87+
7788
<Style Selector="TextBox:pointerover /template/ Border">
7889
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush}" />
7990
<Setter Property="BorderBrush" Value="{DynamicResource ThemeAccentBrush5}" />
@@ -131,9 +142,11 @@
131142
<Setter Property="BorderThickness" Value="1" />
132143
</Style>
133144
<Style Selector="Button:pointerover /template/ ContentPresenter">
145+
<Setter Property="TextBlock.Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
134146
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2Hover}" />
135147
</Style>
136148
<Style Selector="Button:pressed /template/ ContentPresenter">
149+
<Setter Property="TextBlock.Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
137150
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush}" />
138151
</Style>
139152
<Style Selector="Button:disabled /template/ ContentPresenter">

0 commit comments

Comments
 (0)