refactor set theme
This commit is contained in:
26
src/SharpIDE.Godot/Features/Settings/SetTheme.cs
Normal file
26
src/SharpIDE.Godot/Features/Settings/SetTheme.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace SharpIDE.Godot.Features.Settings;
|
||||||
|
|
||||||
|
public static class SetTheme
|
||||||
|
{
|
||||||
|
private static readonly Theme LightTheme = ResourceLoader.Load<Theme>("uid://dc7l6bjhn61i5");
|
||||||
|
private static readonly Color LightThemeClearColor = new Color("fdfdfd");
|
||||||
|
private static readonly Theme DarkTheme = ResourceLoader.Load<Theme>("uid://epmt8kq6efrs");
|
||||||
|
private static readonly Color DarkThemeClearColor = new Color("4d4d4d");
|
||||||
|
|
||||||
|
public static void SetIdeTheme(this Node node, string theme)
|
||||||
|
{
|
||||||
|
var rootWindow = node.GetTree().GetRoot();
|
||||||
|
if (theme is "Light")
|
||||||
|
{
|
||||||
|
RenderingServer.Singleton.SetDefaultClearColor(LightThemeClearColor);
|
||||||
|
rootWindow.Theme = LightTheme;
|
||||||
|
}
|
||||||
|
else if (theme is "Dark")
|
||||||
|
{
|
||||||
|
RenderingServer.Singleton.SetDefaultClearColor(DarkThemeClearColor);
|
||||||
|
rootWindow.Theme = DarkTheme;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,11 +9,6 @@ public partial class SettingsWindow : Window
|
|||||||
private CheckButton _debuggerUseSharpDbgCheckButton = null!;
|
private CheckButton _debuggerUseSharpDbgCheckButton = null!;
|
||||||
private OptionButton _themeOptionButton = null!;
|
private OptionButton _themeOptionButton = null!;
|
||||||
|
|
||||||
private Theme _lightTheme = ResourceLoader.Load<Theme>("uid://dc7l6bjhn61i5");
|
|
||||||
private Color _lightThemeClearColor = new Color("fdfdfd");
|
|
||||||
private Theme _darkTheme = ResourceLoader.Load<Theme>("uid://epmt8kq6efrs");
|
|
||||||
private Color _darkThemeClearColor = new Color("4d4d4d");
|
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
CloseRequested += Hide;
|
CloseRequested += Hide;
|
||||||
@@ -57,16 +52,6 @@ public partial class SettingsWindow : Window
|
|||||||
private void OnThemeItemSelected(long index)
|
private void OnThemeItemSelected(long index)
|
||||||
{
|
{
|
||||||
var selectedTheme = _themeOptionButton.GetItemText((int)index);
|
var selectedTheme = _themeOptionButton.GetItemText((int)index);
|
||||||
var rootWindow = GetTree().GetRoot();
|
this.SetIdeTheme(selectedTheme);
|
||||||
if (selectedTheme is "Light")
|
|
||||||
{
|
|
||||||
RenderingServer.Singleton.SetDefaultClearColor(_lightThemeClearColor);
|
|
||||||
rootWindow.Theme = _lightTheme;
|
|
||||||
}
|
|
||||||
else if (selectedTheme is "Dark")
|
|
||||||
{
|
|
||||||
RenderingServer.Singleton.SetDefaultClearColor(_darkThemeClearColor);
|
|
||||||
rootWindow.Theme = _darkTheme;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user