diff --git a/include/eepp/ui/css/elementdefinition.hpp b/include/eepp/ui/css/elementdefinition.hpp index 4c2ded06c..32c274ee1 100644 --- a/include/eepp/ui/css/elementdefinition.hpp +++ b/include/eepp/ui/css/elementdefinition.hpp @@ -28,6 +28,8 @@ class EE_API ElementDefinition : NonCopyable { const StyleSheetStyleVector& getStyles() const; + void refresh(); + protected: StyleSheetStyleVector mStyles; StyleSheetProperties mProperties; diff --git a/include/eepp/ui/css/stylesheet.hpp b/include/eepp/ui/css/stylesheet.hpp index 2cab50fa6..2a96a4dd7 100644 --- a/include/eepp/ui/css/stylesheet.hpp +++ b/include/eepp/ui/css/stylesheet.hpp @@ -55,6 +55,11 @@ class EE_API StyleSheet { bool markerExists( const Uint32& marker ) const; + std::vector> + findStyleFromSelectorName( const std::string& selector ); + + bool refreshCacheFromStyles( const std::vector>& styles ); + protected: Uint32 mMarker{ 0 }; std::vector> mNodes; diff --git a/include/eepp/ui/css/stylesheetproperty.hpp b/include/eepp/ui/css/stylesheetproperty.hpp index a84635c1f..77535c3d6 100644 --- a/include/eepp/ui/css/stylesheetproperty.hpp +++ b/include/eepp/ui/css/stylesheetproperty.hpp @@ -64,7 +64,7 @@ class EE_API StyleSheetProperty { void setName( const std::string& name ); - void setValue( const std::string& value ); + void setValue( const std::string& value, bool updateHash = false ); const bool& isVolatile() const; diff --git a/include/eepp/ui/css/stylesheetstyle.hpp b/include/eepp/ui/css/stylesheetstyle.hpp index fba13e314..2ba0f5c37 100644 --- a/include/eepp/ui/css/stylesheetstyle.hpp +++ b/include/eepp/ui/css/stylesheetstyle.hpp @@ -59,6 +59,8 @@ class EE_API StyleSheetStyle { void setMarker( const Uint32& marker ); + bool updatePropertyValue( const std::string& name, const std::string& value ); + protected: Uint32 mMarker{ 0 }; StyleSheetSelector mSelector; diff --git a/include/eepp/ui/uitreeview.hpp b/include/eepp/ui/uitreeview.hpp index 9a10b3649..0ec12ba70 100644 --- a/include/eepp/ui/uitreeview.hpp +++ b/include/eepp/ui/uitreeview.hpp @@ -142,6 +142,8 @@ class EE_API UITreeView : public UIAbstractTableView { bool tryOpenModelIndex( const ModelIndex& index, bool forceUpdate = true ); + void updateContentSize(); + protected: enum class IterationDecision { Continue, @@ -191,8 +193,6 @@ class EE_API UITreeView : public UIAbstractTableView { virtual void onSortColumn( const size_t& colIndex ); - void updateContentSize(); - void setAllExpanded( const ModelIndex& index = {}, bool expanded = true ); virtual UIWidget* setupCell( UITableCell* widget, UIWidget* rowWidget, diff --git a/src/eepp/ui/css/elementdefinition.cpp b/src/eepp/ui/css/elementdefinition.cpp index 07d68f7ea..eda4a15b7 100644 --- a/src/eepp/ui/css/elementdefinition.cpp +++ b/src/eepp/ui/css/elementdefinition.cpp @@ -4,32 +4,7 @@ namespace EE { namespace UI { namespace CSS { ElementDefinition::ElementDefinition( const StyleSheetStyleVector& styleSheetStyles ) : mStyles( styleSheetStyles ), mStructurallyVolatile( false ) { - for ( auto& styleSheetStyle : styleSheetStyles ) { - const StyleSheetProperties& properties = styleSheetStyle->getProperties(); - - if ( styleSheetStyle->getSelector().isStructurallyVolatile() ) - mStructurallyVolatile = true; - - for ( auto iterator = properties.begin(); iterator != properties.end(); ++iterator ) { - const StyleSheetProperty& property = iterator->second; - const auto& it = mProperties.find( property.getId() ); - - if ( it == mProperties.end() || - property.getSpecificity() >= it->second.getSpecificity() ) { - mProperties[property.getId()] = property; - } - - if ( String::startsWith( property.getName(), "transition" ) ) - mTransitionProperties.push_back( &property ); - else if ( String::startsWith( property.getName(), "animation" ) ) - mAnimationProperties.push_back( &property ); - } - - findVariables( styleSheetStyle ); - } - - for ( auto& property : mProperties ) - mPropertyIds.insert( property.first ); + refresh(); } StyleSheetProperty* ElementDefinition::getProperty( const Uint32& id ) { @@ -65,6 +40,40 @@ const StyleSheetStyleVector& ElementDefinition::getStyles() const { return mStyles; } +void ElementDefinition::refresh() { + mProperties.clear(); + mTransitionProperties.clear(); + mAnimationProperties.clear(); + mPropertyIds.clear(); + mStructurallyVolatile = false; + for ( auto& styleSheetStyle : mStyles ) { + const StyleSheetProperties& properties = styleSheetStyle->getProperties(); + + if ( styleSheetStyle->getSelector().isStructurallyVolatile() ) + mStructurallyVolatile = true; + + for ( auto iterator = properties.begin(); iterator != properties.end(); ++iterator ) { + const StyleSheetProperty& property = iterator->second; + const auto& it = mProperties.find( property.getId() ); + + if ( it == mProperties.end() || + property.getSpecificity() >= it->second.getSpecificity() ) { + mProperties[property.getId()] = property; + } + + if ( String::startsWith( property.getName(), "transition" ) ) + mTransitionProperties.push_back( &property ); + else if ( String::startsWith( property.getName(), "animation" ) ) + mAnimationProperties.push_back( &property ); + } + + findVariables( styleSheetStyle ); + } + + for ( auto& property : mProperties ) + mPropertyIds.insert( property.first ); +} + void ElementDefinition::findVariables( const StyleSheetStyle* style ) { for ( const auto& vars : style->getVariables() ) { const StyleSheetVariable& variable = vars.second; diff --git a/src/eepp/ui/css/stylesheet.cpp b/src/eepp/ui/css/stylesheet.cpp index e5e517ec5..953904512 100644 --- a/src/eepp/ui/css/stylesheet.cpp +++ b/src/eepp/ui/css/stylesheet.cpp @@ -106,6 +106,32 @@ bool StyleSheet::markerExists( const Uint32& marker ) const { return false; } +std::vector> +StyleSheet::findStyleFromSelectorName( const std::string& selector ) { + std::vector> found; + for ( const auto& node : mNodes ) { + if ( selector == node->getSelector().getName() ) + found.push_back( node ); + } + return found; +} + +bool StyleSheet::refreshCacheFromStyles( + const std::vector>& styles ) { + bool refreshed = false; + for ( const auto& style : styles ) { + for ( auto& node : mNodeCache ) { + for ( auto& nodeStyle : node.second->getStyles() ) { + if ( nodeStyle == style.get() ) { + node.second->refresh(); + refreshed = true; + } + } + } + } + return refreshed; +} + bool StyleSheet::addStyleToNodeIndex( StyleSheetStyle* style ) { const std::string& id = style->getSelector().getSelectorId(); const std::string& tag = style->getSelector().getSelectorTagName(); diff --git a/src/eepp/ui/css/stylesheetproperty.cpp b/src/eepp/ui/css/stylesheetproperty.cpp index b442ec248..ea19b8e2b 100644 --- a/src/eepp/ui/css/stylesheetproperty.cpp +++ b/src/eepp/ui/css/stylesheetproperty.cpp @@ -154,9 +154,10 @@ void StyleSheetProperty::setName( const std::string& name ) { mNameHash = String::hash( mName ); } -void StyleSheetProperty::setValue( const std::string& value ) { +void StyleSheetProperty::setValue( const std::string& value, bool updateHash ) { mValue = value; - // mValueHash = String::hash( value ); + if ( updateHash ) + mValueHash = String::hash( value ); mIsVarValue = String::startsWith( mValue, "var(" ); createIndexed(); } diff --git a/src/eepp/ui/css/stylesheetstyle.cpp b/src/eepp/ui/css/stylesheetstyle.cpp index cf4db6a5a..ce48ff9e9 100644 --- a/src/eepp/ui/css/stylesheetstyle.cpp +++ b/src/eepp/ui/css/stylesheetstyle.cpp @@ -59,6 +59,17 @@ StyleSheetProperties& StyleSheetStyle::getPropertiesRef() { return mProperties; } +bool StyleSheetStyle::updatePropertyValue( const std::string& name, const std::string& value ) { + bool updated = false; + for ( auto& prop : mProperties ) { + if ( prop.second.getName() == name ) { + prop.second.setValue( value, true ); + updated = true; + } + } + return updated; +} + const StyleSheetVariables& StyleSheetStyle::getVariables() const { return mVariables; } diff --git a/src/eepp/ui/tools/uicodeeditorsplitter.cpp b/src/eepp/ui/tools/uicodeeditorsplitter.cpp index fc8c01da9..e0e63bc28 100644 --- a/src/eepp/ui/tools/uicodeeditorsplitter.cpp +++ b/src/eepp/ui/tools/uicodeeditorsplitter.cpp @@ -203,12 +203,8 @@ UICodeEditor* UICodeEditorSplitter::createCodeEditor() { /* editor commands */ doc.setCommand( "switch-to-previous-colorscheme", [&] { auto it = mColorSchemes.find( mCurrentColorScheme ); - auto prev = std::prev( it, 1 ); - if ( prev != mColorSchemes.end() ) { - setColorScheme( prev->first ); - } else { - setColorScheme( mColorSchemes.rbegin()->first ); - } + setColorScheme( it == mColorSchemes.begin() ? mColorSchemes.rbegin()->first + : ( --it )->first ); } ); doc.setCommand( "switch-to-next-colorscheme", [&] { diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index fe6e95247..165b56b46 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -291,7 +291,6 @@ std::vector UISceneNode::loadNode( pugi::xml_node node, Node* parent, uiwidget->onWidgetCreated(); } else if ( String::toLower( std::string( widget.name() ) ) == "style" ) { - // combineStyleSheet( widget.text().as_string(), false ); CSS::StyleSheetParser parser; if ( parser.loadFromString( widget.text().as_string() ) ) { diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 57d68495c..975b23efb 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -78,13 +78,14 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, windowState.position.y = iniState.getValueI( "window", "y", -1 ); editor.showLineNumbers = ini.getValueB( "editor", "show_line_numbers", true ); editor.showWhiteSpaces = ini.getValueB( "editor", "show_white_spaces", true ); - editor.showLineEndings = ini.getValueB( "editor", "show_line_endings", true ); + editor.showLineEndings = ini.getValueB( "editor", "show_line_endings", false ); editor.highlightMatchingBracket = ini.getValueB( "editor", "highlight_matching_brackets", true ); editor.highlightCurrentLine = ini.getValueB( "editor", "highlight_current_line", true ); editor.verticalScrollbar = ini.getValueB( "editor", "vertical_scrollbar", true ); editor.horizontalScrollbar = ini.getValueB( "editor", "horizontal_scrollbar", true ); ui.fontSize = ini.getValue( "ui", "font_size", "11dp" ); + ui.panelFontSize = ini.getValue( "ui", "panel_font_size", "11dp" ); ui.showSidePanel = ini.getValueB( "ui", "show_side_panel", true ); ui.panelPosition = panelPositionFromString( ini.getValue( "ui", "panel_position", "left" ) ); ui.serifFont = ini.getValue( "ui", "serif_font", "fonts/NotoSans-Regular.ttf" ); @@ -195,6 +196,7 @@ void AppConfig::save( const std::vector& recentFiles, ini.setValueB( "editor", "horizontal_scrollbar", editor.horizontalScrollbar ); ini.setValue( "editor", "font_size", editor.fontSize.toString() ); ini.setValue( "ui", "font_size", ui.fontSize.toString() ); + ini.setValue( "ui", "panel_font_size", ui.panelFontSize.toString() ); ini.setValueB( "ui", "show_side_panel", ui.showSidePanel ); ini.setValue( "ui", "panel_position", panelPositionToString( ui.panelPosition ) ); ini.setValue( "ui", "serif_font", ui.serifFont ); diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index 34251f260..d2bab11d9 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -24,6 +24,7 @@ enum class PanelPosition { Left, Right }; struct UIConfig { StyleSheetLength fontSize{ 11, StyleSheetLength::Dp }; + StyleSheetLength panelFontSize{ 11, StyleSheetLength::Dp }; bool showSidePanel{ true }; PanelPosition panelPosition{ PanelPosition::Left }; std::string serifFont; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index c0ecd35e4..f49dd104b 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -897,6 +897,37 @@ void App::setUIFontSize() { setFocusEditorOnClose( msgBox ); } +void App::setUIPanelFontSize() { + UIMessageBox* msgBox = UIMessageBox::New( + UIMessageBox::INPUT, i18n( "set_side_panel_font_size", "Set side panel font size:" ) ); + msgBox->setTitle( mWindowTitle ); + msgBox->getTextInput()->setText( mConfig.ui.panelFontSize.toString() ); + msgBox->setCloseShortcut( { KEY_ESCAPE, 0 } ); + msgBox->showWhenReady(); + msgBox->addEventListener( Event::OnConfirm, [&, msgBox]( const Event* ) { + mConfig.ui.panelFontSize = StyleSheetLength( msgBox->getTextInput()->getText() ); + + // Update the CSS + auto selsFound = mUISceneNode->getStyleSheet().findStyleFromSelectorName( + "#project_view > treeview::row > treeview::cell > treeview::cell::text" ); + if ( !selsFound.empty() ) { + for ( auto sel : selsFound ) + sel->updatePropertyValue( "font-size", mConfig.ui.panelFontSize.toString() ); + mUISceneNode->getStyleSheet().refreshCacheFromStyles( selsFound ); + } + + UITreeView* treeView = mUISceneNode->find( "project_view" ); + if ( !treeView ) { + msgBox->closeWindow(); + return; + } + treeView->reloadStyle( true, true, true, true ); + treeView->updateContentSize(); + msgBox->closeWindow(); + } ); + setFocusEditorOnClose( msgBox ); +} + void App::setFocusEditorOnClose( UIMessageBox* msgBox ) { msgBox->addEventListener( Event::OnClose, [&]( const Event* ) { if ( mSplitter && mSplitter->getCurWidget() ) @@ -1362,6 +1393,7 @@ std::vector App::getUnlockedCommands() { "editor-font-size", "terminal-font-size", "ui-font-size", + "ui-panel-font-size", "serif-font", "monospace-font", "terminal-font", @@ -2125,8 +2157,8 @@ FontTrueType* App::loadFont( const std::string& name, std::string fontPath, } void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDensity, - const std::string& colorScheme, bool terminal, bool frameBuffer, - bool benchmarkMode ) { + const std::string& colorScheme, bool terminal, bool frameBuffer, bool benchmarkMode, + const std::string& css ) { DisplayManager* displayManager = Engine::instance()->getDisplayManager(); Display* currentDisplay = displayManager->getDisplayIndex( 0 ); mDisplayDPI = currentDisplay->getDPI(); @@ -2280,6 +2312,20 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mUISceneNode->getRoot()->addClass( "appbackground" ); + if ( !css.empty() && FileSystem::fileExists( css ) ) { + CSS::StyleSheetParser parser; + if ( parser.loadFromFile( css ) ) + mUISceneNode->combineStyleSheet( parser.getStyleSheet(), false ); + } + + std::string panelUI( String::format( R"css( + #project_view > treeview::row > treeview::cell > treeview::cell::text { + font-size: %s; + } + )css", + mConfig.ui.panelFontSize.toString().c_str() ) ); + mUISceneNode->combineStyleSheet( panelUI, false ); + const std::string baseUI = R"html(