Archived
1
Fork 0

Add detection for light/dark theme

This commit is contained in:
redstrate 2020-09-22 12:27:41 -04:00
parent 827ce8bec6
commit 807cf7ba86
3 changed files with 64 additions and 34 deletions

View file

@ -58,10 +58,19 @@ enum class PlatformFeature {
Windowing
};
/// On platforms that has a GUI with a seperate light/dark mode.
enum class PlatformTheme {
Light,
Dark
};
namespace platform {
/// Returns a human readable platform name, e.g. Linux.
const char* get_name();
/// Returns the current platform theme.
PlatformTheme get_theme();
/// Queries whether or not the platform supports a certain feature.
bool supports_feature(const PlatformFeature feature);

View file

@ -47,6 +47,13 @@ ImGuiLayer::ImGuiLayer() {
for (auto& [im, pl] : imToPl)
io.KeyMap[im] = platform::get_keycode(pl);
const auto theme = platform::get_theme();
switch(theme) {
case PlatformTheme::Light:
ImGui::StyleColorsLight();
break;
case PlatformTheme::Dark:
{
ImGui::StyleColorsDark();
auto& style = ImGui::GetStyle();
@ -80,6 +87,9 @@ ImGuiLayer::ImGuiLayer() {
colors[ImGuiCol_Tab] = ImVec4(0.22f, 0.27f, 0.33f, 0.86f);
colors[ImGuiCol_TabActive] = ImVec4(0.33f, 0.51f, 0.75f, 1.00f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.30f, 0.33f, 0.38f, 1.00f);
}
break;
}
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
main_viewport->PlatformHandle = new int(0);

View file

@ -392,6 +392,17 @@ void platform::set_window_title(const int index, const std::string_view title) {
void platform::mute_output() {}
void platform::unmute_output() {}
PlatformTheme platform::get_theme() {
auto str = [[[NSApplication sharedApplication] effectiveAppearance] name];
if(str == NSAppearanceNameAqua)
return PlatformTheme::Light;
else if(str == NSAppearanceNameDarkAqua)
return PlatformTheme::Dark;
return PlatformTheme::Light;
}
int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) {
NativeWindow* native = new NativeWindow();
native->index = windows.size();