-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from XanatosX/feature/add-theme-switching
Add Theme Switching
- Loading branch information
Showing
27 changed files
with
688 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/ModularToolManager/Converters/Serialization/ColorConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using Avalonia.Media; | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ModularToolManager.Converters.Serialization; | ||
|
||
/// <summary> | ||
/// Converter class to get avalonia colors correctly laoded/saved into a json | ||
/// </summary> | ||
internal class ColorConverter : JsonConverter<Color> | ||
{ | ||
/// <summary> | ||
/// The current color mode for reading | ||
/// </summary> | ||
internal enum CurrentColorMode | ||
{ | ||
Unknown, | ||
Alpha, | ||
Red, | ||
Green, | ||
Blue | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Color Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
|
||
byte alpha = 0; | ||
byte red = 0; | ||
byte green = 0; | ||
byte blue = 0; | ||
CurrentColorMode currentColorMode = CurrentColorMode.Unknown; | ||
|
||
|
||
while (reader.Read()) | ||
{ | ||
if (reader.TokenType == JsonTokenType.EndObject) | ||
{ | ||
break; | ||
} | ||
if (reader.TokenType == JsonTokenType.PropertyName) | ||
{ | ||
currentColorMode = reader.GetString() switch | ||
{ | ||
"A" => CurrentColorMode.Alpha, | ||
"R" => CurrentColorMode.Red, | ||
"G" => CurrentColorMode.Green, | ||
"B" => CurrentColorMode.Blue, | ||
_ => CurrentColorMode.Unknown, | ||
}; | ||
} | ||
if (reader.TokenType == JsonTokenType.Number) | ||
{ | ||
byte number = reader.GetByte(); | ||
switch (currentColorMode) | ||
{ | ||
case CurrentColorMode.Unknown: | ||
break; | ||
case CurrentColorMode.Alpha: | ||
alpha = number; | ||
break; | ||
case CurrentColorMode.Red: | ||
red = number; | ||
break; | ||
case CurrentColorMode.Green: | ||
green = number; | ||
break; | ||
case CurrentColorMode.Blue: | ||
blue = number; | ||
break; | ||
default: break; | ||
} | ||
} | ||
} | ||
|
||
return new Color(alpha, red, green, blue); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void Write(Utf8JsonWriter writer, Color value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteNumber("A", value.A); | ||
writer.WriteNumber("R", value.R); | ||
writer.WriteNumber("G", value.G); | ||
writer.WriteNumber("B", value.B); | ||
writer.WriteEndObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Avalonia.Media; | ||
using Avalonia.Themes.Fluent; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ModularToolManager.Models; | ||
|
||
/// <summary> | ||
/// Style information for the application | ||
/// </summary> | ||
public class ApplicationStyle | ||
{ | ||
/// <summary> | ||
/// The id of the style | ||
/// </summary> | ||
[JsonPropertyName("id")] | ||
public int Id { get; init; } | ||
|
||
/// <summary> | ||
/// IS this a dark or light style variant | ||
/// </summary> | ||
[JsonPropertyName("mode")] | ||
public FluentThemeMode Mode { get; init; } | ||
|
||
/// <summary> | ||
/// The name of the translation key which is getting used for the name | ||
/// </summary> | ||
[JsonPropertyName("name_translation_key")] | ||
public string? NameTranslationKey { get; init; } | ||
|
||
/// <summary> | ||
/// The name of the translation key which is getting used for the description | ||
/// </summary> | ||
[JsonPropertyName("description_translation_key")] | ||
public string? DescriptionTranslationKey { get; init; } | ||
|
||
/// <summary> | ||
/// The translated name for the application style | ||
/// </summary> | ||
[JsonIgnore] | ||
public string? Name { get; set; } | ||
|
||
/// <summary> | ||
/// The translated description for the application style | ||
/// </summary> | ||
[JsonIgnore] | ||
public string? Description { get; set; } | ||
|
||
/// <summary> | ||
/// The tint color for the material | ||
/// </summary> | ||
[JsonPropertyName("tint_color")] | ||
public Color? TintColor { get; init; } | ||
|
||
/// <summary> | ||
/// The opacity of the material | ||
/// </summary> | ||
[JsonPropertyName("material_opacity")] | ||
public float MaterialOpacity { get; init; } | ||
|
||
/// <summary> | ||
/// The opacity of the tint | ||
/// </summary> | ||
[JsonPropertyName("tint_opacity")] | ||
public float TintOpacity { get; init; } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/ModularToolManager/Models/Messages/ApplicationThemeUpdated.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using CommunityToolkit.Mvvm.Messaging.Messages; | ||
|
||
namespace ModularToolManager.Models.Messages; | ||
|
||
/// <summary> | ||
/// Mesage that the application theme got changed | ||
/// </summary> | ||
internal class ApplicationThemeUpdated : ValueChangedMessage<int> | ||
{ | ||
/// <summary> | ||
/// Create a new instance of this class | ||
/// </summary> | ||
/// <param name="value">The theme id the application got updated to</param> | ||
public ApplicationThemeUpdated(int value) : base(value) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
|
||
namespace ModularToolManager.Models; | ||
|
||
/// <summary> | ||
/// Record to save internal data for showing a modal | ||
/// </summary> | ||
/// <param name="ThemeId">The id of the theme to use</param> | ||
/// <param name="Title"> The title to show on the modal</param> | ||
/// <param name="modalContent">The content of the modal</param> | ||
/// <param name="IconName">The name of the icon to load</param> | ||
/// <param name="CanResize">Can the modal be resized</param> | ||
public record ModalWindowInformation(int ThemeId, string Title, ObservableObject modalContent, string? IconName, bool CanResize = true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[ | ||
{ | ||
"id": 0, | ||
"mode": 1, | ||
"name_translation_key": "App_Dark_Theme", | ||
"description_translation_key": "App_Dark_Theme_Description", | ||
"tint_color": { | ||
"A": 255, | ||
"R": 0, | ||
"G": 0, | ||
"B": 0 | ||
}, | ||
"material_opacity": 0.65, | ||
"tint_opacity": 1 | ||
}, | ||
{ | ||
"id": 1, | ||
"mode": 0, | ||
"name_translation_key": "App_Light_Theme", | ||
"description_translation_key": "App_Light_Theme_Description", | ||
"tint_color": { | ||
"A": 255, | ||
"R": 255, | ||
"G": 255, | ||
"B": 255 | ||
}, | ||
"material_opacity": 0.65, | ||
"tint_opacity": 1 | ||
} | ||
] |
Oops, something went wrong.