fix(editor): lua theme on light mode

This commit is contained in:
maelstrom 2025-05-20 19:05:49 +02:00
parent b9f68ee160
commit a74b409459
2 changed files with 20 additions and 3 deletions

View file

@ -23,6 +23,7 @@
bool worldSpaceTransforms = false;
inline bool isDarkMode() {
// https://stackoverflow.com/a/78854851/16255372
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
const auto scheme = QGuiApplication::styleHints()->colorScheme();
return scheme == Qt::ColorScheme::Dark;
@ -62,7 +63,6 @@ MainWindow::MainWindow(QWidget *parent)
ui->setupUi(this);
setMouseTracking(true);
// https://stackoverflow.com/a/78854851/16255372
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() + QStringList { "./assets/icons" });
if (isDarkMode())
QIcon::setFallbackThemeName("editor-dark");

View file

@ -17,9 +17,24 @@
#include "mainwindow.h"
#include "objects/script.h"
#include "datatypes/meta.h"
#include <QPalette>
#include <QStyleHints>
QsciAPIs* makeApis(QsciLexer*);
inline bool isDarkMode() {
// https://stackoverflow.com/a/78854851/16255372
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
const auto scheme = QGuiApplication::styleHints()->colorScheme();
return scheme == Qt::ColorScheme::Dark;
#else
const QPalette defaultPalette;
const auto text = defaultPalette.color(QPalette::WindowText);
const auto window = defaultPalette.color(QPalette::Window);
return text.lightness() > window.lightness();
#endif // QT_VERSION
}
std::map<int, const QColor> DARK_MODE_COLOR_SCHEME = {{
{QsciLexerLua::Comment, QColor("#808080")},
{QsciLexerLua::LineComment, QColor("#808080")},
@ -156,8 +171,10 @@ ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
// Set color scheme
// https://stackoverflow.com/a/26318796/16255372
for (auto& [style, color] : DARK_MODE_COLOR_SCHEME) {
lexer->setColor(color, style);
if (isDarkMode()) {
for (auto& [style, color] : DARK_MODE_COLOR_SCHEME) {
lexer->setColor(color, style);
}
}
// lexer->setAutoIndentStyle(QsciScintilla::AiOpening | QsciScintilla::AiMaintain | QsciScintilla::AiClosing);