From c275cbceaa7e9b27df0937d974383f99bb685802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 7 Feb 2024 19:50:52 -0300 Subject: [PATCH] Visual improvements for macOS. --- bin/assets/ui/breeze.css | 2 +- include/eepp/ui/css/stylesheet.hpp | 6 ++++- projects/macos/ee.files | 2 ++ src/eepp/ui/css/stylesheet.cpp | 38 ++++++++++++++++++++++++++---- src/tools/ecode/applayout.xml.hpp | 2 +- src/tools/ecode/ecode.cpp | 18 +++++++++++++- src/tools/ecode/macos/macos.hpp | 4 ++++ src/tools/ecode/macos/macos.m | 19 +++++++++++++++ 8 files changed, 83 insertions(+), 8 deletions(-) diff --git a/bin/assets/ui/breeze.css b/bin/assets/ui/breeze.css index 7cb8c2e1d..051c14a84 100644 --- a/bin/assets/ui/breeze.css +++ b/bin/assets/ui/breeze.css @@ -1094,7 +1094,7 @@ TextInput.table_cell_edit { --menu-font-active: #fcfcfc; --menu-font-disabled: #a8a9aa; --win-icon: #232627; - --floating-icon: #cbcdcd; + --floating-icon: #666666; --term-back-color: #eff0f1; --term-font-color: #232627; --disabled-color: #727679; diff --git a/include/eepp/ui/css/stylesheet.hpp b/include/eepp/ui/css/stylesheet.hpp index 9146e01bf..394f75bca 100644 --- a/include/eepp/ui/css/stylesheet.hpp +++ b/include/eepp/ui/css/stylesheet.hpp @@ -28,7 +28,11 @@ class EE_API StyleSheet { const std::vector>& getStyles() const; - std::shared_ptr getStyleFromSelector( const std::string& selector ) const; + std::vector> + getStylesFromSelector( const std::string& selector ) const; + + std::shared_ptr getStyleFromSelector( const std::string& selector, + bool searchBySpecificity = false ) const; bool updateMediaLists( const MediaFeatures& features ); diff --git a/projects/macos/ee.files b/projects/macos/ee.files index b95b669f6..21d088726 100644 --- a/projects/macos/ee.files +++ b/projects/macos/ee.files @@ -362,6 +362,7 @@ ../../include/eepp/ui/tools/uidocfindreplace.hpp ../../include/eepp/ui/tools/uiwidgetinspector.hpp ../../include/eepp/ui/uiabstractview.hpp +../../include/eepp/ui/uiapplication.hpp ../../include/eepp/ui/uibackgrounddrawable.hpp ../../include/eepp/ui/uiborderdrawable.hpp ../../include/eepp/ui/uicheckbox.hpp @@ -965,6 +966,7 @@ ../../src/eepp/ui/tools/uidocfindreplace.cpp ../../src/eepp/ui/tools/uiwidgetinspector.cpp ../../src/eepp/ui/uiabstractview.cpp +../../src/eepp/ui/uiapplication.cpp ../../src/eepp/ui/uibackgrounddrawable.cpp ../../src/eepp/ui/uiborderdrawable.cpp ../../src/eepp/ui/uicheckbox.cpp diff --git a/src/eepp/ui/css/stylesheet.cpp b/src/eepp/ui/css/stylesheet.cpp index 5678916cd..c16b113d5 100644 --- a/src/eepp/ui/css/stylesheet.cpp +++ b/src/eepp/ui/css/stylesheet.cpp @@ -278,11 +278,41 @@ const std::vector>& StyleSheet::getStyles() con return mNodes; } -std::shared_ptr -StyleSheet::getStyleFromSelector( const std::string& selector ) const { +std::vector> +StyleSheet::getStylesFromSelector( const std::string& selector ) const { + std::vector> found; for ( const auto& node : mNodes ) - if ( node->getSelector().getName() == selector ) - return node; + if ( node->isMediaValid() && node->getSelector().getName() == selector ) + found.push_back( node ); + return found; +} + +std::shared_ptr +StyleSheet::getStyleFromSelector( const std::string& selector, bool searchBySpecificity ) const { + if ( !searchBySpecificity ) { + for ( const auto& node : mNodes ) + if ( node->getSelector().getName() == selector ) + return node; + } else { + std::vector> found; + for ( const auto& node : mNodes ) + if ( node->isMediaValid() && node->getSelector().getName() == selector ) + found.push_back( node ); + if ( !found.empty() ) { + std::sort( found.begin(), found.end(), + []( const std::shared_ptr& lhs, + const std::shared_ptr& rhs ) { + if ( ( lhs->getMediaQueryList() == nullptr ) != + ( rhs->getMediaQueryList() == nullptr ) ) { + return ( lhs->getMediaQueryList() == nullptr ) > + ( rhs->getMediaQueryList() == nullptr ); + } + return lhs->getSelector().getSpecificity() < + rhs->getSelector().getSpecificity(); + } ); + return found.back(); + } + } return {}; } diff --git a/src/tools/ecode/applayout.xml.hpp b/src/tools/ecode/applayout.xml.hpp index 580173434..f45d0306e 100644 --- a/src/tools/ecode/applayout.xml.hpp +++ b/src/tools/ecode/applayout.xml.hpp @@ -35,7 +35,7 @@ TextInput.small_input, color: var(--floating-icon); font-family: icon; font-size: 16dp; - margin-top: 6dp; + margin-top: 4dp; margin-right: 22dp; transition: all 0.15s; } diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index fbb651594..75821d1df 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -1865,7 +1865,7 @@ void App::setTheme( const std::string& path ) { theme->getStyleSheet().addStyle( tstyle ); } else { // Add root variables that arent defined in the custom theme - auto root = theme->getStyleSheet().getStyleFromSelector( ":root" ); + auto root = theme->getStyleSheet().getStyleFromSelector( ":root", true ); if ( root ) { for ( const auto& var : tstyle->getVariables() ) { if ( !root->hasVariable( var.second.getName() ) ) @@ -3588,6 +3588,22 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mUISceneNode->combineStyleSheet( parser.getStyleSheet(), false ); } +#if EE_PLATFORM == EE_PLATFORM_MACOS + if ( ( macOS_isDarkModeEnabled() && + mConfig.ui.colorScheme == ColorSchemePreference::Dark ) || + ( !macOS_isDarkModeEnabled() && + mConfig.ui.colorScheme == ColorSchemePreference::Light ) ) { + auto backVar = mUISceneNode->getStyleSheet() + .getStyleFromSelector( ":root", true ) + ->getVariableByName( "--back" ); + if ( !backVar.isEmpty() ) { + auto backColor( Color::fromString( backVar.getValue() ) ); + macOS_changeTitleBarColor( mWindow->getWindowHandler(), backColor.r / 255.f, + backColor.g / 255.f, backColor.b / 255.f ); + } + } +#endif + std::string panelUI( String::format( R"css( #panel treeview > treeview::row > treeview::cell > treeview::cell::text, #panel treeview > treeview::row > table::cell > table::cell::text { diff --git a/src/tools/ecode/macos/macos.hpp b/src/tools/ecode/macos/macos.hpp index 6b0f37c14..50a191100 100644 --- a/src/tools/ecode/macos/macos.hpp +++ b/src/tools/ecode/macos/macos.hpp @@ -11,6 +11,10 @@ void macOS_enableScrollMomentum(); void macOS_removeTitleBarSeparator( void* nsWindow ); +void macOS_changeTitleBarColor( void* window, double red, double green, double blue ); + +int macOS_isDarkModeEnabled(); + #ifdef __cplusplus } #endif diff --git a/src/tools/ecode/macos/macos.m b/src/tools/ecode/macos/macos.m index a56b99490..842d8fada 100644 --- a/src/tools/ecode/macos/macos.m +++ b/src/tools/ecode/macos/macos.m @@ -1,4 +1,6 @@ +#import #include + #include "macos.hpp" /* setAppleMenu disappeared from the headers in 10.4 */ @@ -70,3 +72,20 @@ void macOS_removeTitleBarSeparator( void* window ) { NSWindow* nsWindow = window; [nsWindow setTitlebarSeparatorStyle:NSTitlebarSeparatorStyleNone]; } + +void macOS_changeTitleBarColor( void* window, double red, double green, double blue ) { + NSWindow* nsWindow = window; + nsWindow.titlebarAppearsTransparent = YES; + nsWindow.backgroundColor = [NSColor colorWithRed:red green:green blue:blue alpha:1.]; +} + +int macOS_isDarkModeEnabled() { + if ( @available( macOS 10.14, * ) ) { + NSAppearance* appearance = + [NSAppearance performSelector:@selector( currentDrawingAppearance )]; + if ( [appearance.name isEqualToString:NSAppearanceNameDarkAqua] ) { + return 1; + } + } + return 0; +}