Skip to content

Commit

Permalink
Allow to build with simple theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattias1 committed Dec 27, 2024
1 parent 3d83dac commit b1687be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
24 changes: 21 additions & 3 deletions AvaloniaExtensions/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Declarative;
using Avalonia.Themes.Fluent;
using Avalonia.Styling;
using System;
using System.Linq;

#if SIMPLE_THEME
using Avalonia.Themes.Simple;
#else
using Avalonia.Themes.Fluent;
#endif

namespace AvaloniaExtensions;

public static class AvaloniaExtensionsApp {
Expand Down Expand Up @@ -40,6 +46,14 @@ public static AppBuilder WithSettingsFile<T>(this AppBuilder builder, string pat
return builder;
}

public static AppBuilder WithTheme(this AppBuilder builder, IStyle style) {
if (builder.Instance is null) {
throw new InvalidOperationException("No builder instance found for some reason.");
}
builder.Instance.Styles.Add(style);
return builder;
}

public static Application StartDesktopApp(this AppBuilder builder, string windowTitle, Func<ViewBase> contentFunc) {
return builder.StartDesktopApp(() => ExtendedWindow.Init(windowTitle, contentFunc()));
}
Expand All @@ -60,10 +74,14 @@ public static Application StartDesktopApp(this AppBuilder builder, Func<Window>
builder.SetupWithLifetime(lifetime);

if (!builder.Instance?.Styles.Any() ?? false) {
// builder.Instance.Styles.Add(new StyleInclude(new Uri("avares://Semi.Avalonia/Themes/")) {
// builder.WithTheme(new StyleInclude(new Uri("avares://Semi.Avalonia/Themes/")) {
// Source = new Uri("avares://Semi.Avalonia/Themes/Index.axaml")
// });
builder.Instance.Styles.Add(new FluentTheme());
#if SIMPLE_THEME
builder.WithTheme(new SimpleTheme());
#else
builder.WithTheme(new FluentTheme());
#endif
}

lifetime.MainWindow = windowFunc();
Expand Down
5 changes: 4 additions & 1 deletion AvaloniaExtensions/AvaloniaExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/Mattias1/avalonia-extensions</RepositoryUrl>
<PackageTags>avaloniaui;avalonia;gui</PackageTags>

<DefineConstants Condition=" '$(SIMPLE_THEME)'!='' ">SIMPLE_THEME</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,7 +32,8 @@
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
<PackageReference Include="Avalonia.Markup.Declarative" Version="11.1.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.3" Condition=" '$(Configuration)'=='Debug' OR '$(SIMPLE_THEME)'=='' " />
<PackageReference Include="Avalonia.Themes.Simple" Version="11.2.3" Condition=" '$(Configuration)'=='Debug' OR '$(SIMPLE_THEME)'!='' " />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ For a more elaborate example, you can take a look at the

Setup development environment
------------------------------
- Start the example app with `cd ExampleApp/ && dotnet run`
You can build and run the example app with: `cd ExampleApp/ && dotnet run`

If you want to run with the simple theme to create a minimised version, you can run something like
this: `cd ExampleApp/ && dotnet run -c Release -p SIMPLE_THEME=true ; cd ../`


Publish release
Expand Down

0 comments on commit b1687be

Please sign in to comment.