-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
302 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Eto.Mac.Forms; | ||
|
||
public class ThemeHandler : WidgetHandler<NSAppearance, Theme>, Theme.IHandler | ||
{ | ||
public ThemeHandler(NSAppearance appearance) | ||
{ | ||
Control = appearance; | ||
} | ||
|
||
public string Name | ||
{ | ||
get | ||
{ | ||
var name = Control?.Name.ToString() ?? Application.Instance.Localize(Widget, "System"); | ||
if (name.StartsWith("NSAppearanceName")) | ||
return name.Substring("NSAppearanceName".Length); | ||
return name; | ||
} | ||
} | ||
|
||
public ThemeStyle Style => Control.Name.ToString().ToLowerInvariant().Contains("dark") ? ThemeStyle.Dark : ThemeStyle.Light; | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (obj is ThemeHandler themeHandler) | ||
{ | ||
if (Control == null && themeHandler.Control == null) | ||
return true; | ||
return Control.Equals(themeHandler.Control); | ||
} | ||
return base.Equals(obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Control?.GetHashCode() ?? 0; | ||
} | ||
} | ||
|
||
public class ThemesHandler : Themes.IHandler | ||
{ | ||
public Theme System => new Theme(new ThemeHandler(null)); | ||
public Theme Light => new Theme(new ThemeHandler(NSAppearance.GetAppearance(NSAppearance.NameAqua))); | ||
public Theme Dark => new Theme(new ThemeHandler(NSAppearance.GetAppearance(NSAppearance.NameDarkAqua))); | ||
public Theme None => System; | ||
|
||
public IEnumerable<Theme> GetThemes() | ||
{ | ||
yield return new Theme(new ThemeHandler(null)); | ||
yield return new Theme(new ThemeHandler(NSAppearance.GetAppearance(NSAppearance.NameAqua))); | ||
yield return new Theme(new ThemeHandler(NSAppearance.GetAppearance(NSAppearance.NameDarkAqua))); | ||
yield return new Theme(new ThemeHandler(NSAppearance.GetAppearance(NSAppearance.NameVibrantLight))); | ||
yield return new Theme(new ThemeHandler(NSAppearance.GetAppearance(NSAppearance.NameVibrantDark))); | ||
} | ||
} |
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
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,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Eto.Wpf.Forms; | ||
|
||
#if NET9_0_OR_GREATER | ||
|
||
public class ThemeHandler : WidgetHandler<sw.ThemeMode, Theme, Theme.ICallback>, Theme.IHandler | ||
{ | ||
public ThemeHandler(sw.ThemeMode mode) | ||
{ | ||
Control = mode; | ||
} | ||
|
||
public string Name => Control.ToString(); | ||
|
||
public ThemeStyle Style | ||
{ | ||
get | ||
{ | ||
if (Control == sw.ThemeMode.System) | ||
return ThemeStyle.System; | ||
if (Control == sw.ThemeMode.Light) | ||
return ThemeStyle.Light; | ||
if (Control == sw.ThemeMode.Dark) | ||
return ThemeStyle.Dark; | ||
return ThemeStyle.Light; | ||
} | ||
} | ||
} | ||
|
||
public class ThemesHandler : Themes.IHandler | ||
{ | ||
public Theme Light => new Theme(new ThemeHandler(sw.ThemeMode.Light)); | ||
public Theme Dark => new Theme(new ThemeHandler(sw.ThemeMode.Dark)); | ||
public Theme System => new Theme(new ThemeHandler(sw.ThemeMode.System)); | ||
public Theme None => new Theme(new ThemeHandler(sw.ThemeMode.None)); | ||
|
||
public IEnumerable<Theme> GetThemes() | ||
{ | ||
yield return new Theme(new ThemeHandler(sw.ThemeMode.System)); | ||
yield return new Theme(new ThemeHandler(sw.ThemeMode.Light)); | ||
yield return new Theme(new ThemeHandler(sw.ThemeMode.Dark)); | ||
yield return new Theme(new ThemeHandler(sw.ThemeMode.None)); | ||
} | ||
} | ||
|
||
#endif |
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
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
Oops, something went wrong.