Pump versions.

Add keybindings to the ecode markdown viewer.
Optimization in BlockLayouter.
Hack to display code in <pre><code> HTML elements.
This commit is contained in:
Martín Lucas Golini
2026-04-26 01:12:42 -03:00
parent d8596bbdcd
commit d93b03f624
10 changed files with 88 additions and 15 deletions

View File

@@ -247,6 +247,7 @@ enum class PropertyId : Uint32 {
Bottom = String::hash( "bottom" ),
Left = String::hash( "left" ),
ZIndex = String::hash( "z-index" ),
DataLanguage = String::hash( "data-language" ), // Minor hack
};
enum class PropertyType : Uint32 {

View File

@@ -56,6 +56,7 @@ class EE_API UIHTMLWidget : public UILayout {
Rectf mOffsets{ 0, 0, 0, 0 };
int mZIndex{ 0 };
UILayouter* mLayouter{ nullptr };
UnorderedMap<std::string, StyleSheetProperty> mDataProperties;
};
}} // namespace EE::UI

View File

@@ -4,10 +4,10 @@
#include <eepp/config.hpp>
#include <string>
#define EEPP_MAJOR_VERSION 2
#define EEPP_MINOR_VERSION 9
#define EEPP_PATCH_LEVEL 2
#define EEPP_CODENAME "Sādhanā"
#define EEPP_MAJOR_VERSION 3
#define EEPP_MINOR_VERSION 0
#define EEPP_PATCH_LEVEL 0
#define EEPP_CODENAME "Khaya"
/** The compiled version of the library */
#define EEPP_VERSION( x ) \

View File

@@ -54,6 +54,8 @@ void BlockLayouter::updateLayout() {
mResizedCount = 0;
mPacking = true;
mContainer->beginAttributesTransaction();
setMatchParentIfNeededVerticalGrowth();
const StyleSheetProperty* prop = nullptr;
@@ -94,6 +96,8 @@ void BlockLayouter::updateLayout() {
mContainer->getLayoutHeightPolicy() == SizePolicy::WrapContent )
mContainer->setInternalPixelsHeight( totH );
mContainer->endAttributesTransaction();
if ( mResizedCount > 0 )
positionRichTextChildren( rt );

View File

@@ -456,6 +456,8 @@ void StyleSheetSpecification::registerDefaultProperties() {
registerProperty( "display-options", "" ).setType( PropertyType::String );
registerProperty( "menu-width-mode", "" ).setType( PropertyType::String );
registerProperty( "data-language", "" ).setType( PropertyType::String );
// Shorthands
registerShorthand( "margin", { "margin-top", "margin-right", "margin-bottom", "margin-left" },
"box" );

View File

@@ -3055,6 +3055,10 @@ bool UICodeEditor::applyProperty( const StyleSheetProperty& attribute ) {
case PropertyId::Text:
mDoc->textInput( attribute.asString() );
break;
case PropertyId::DataLanguage:
setSyntaxDefinition(
SyntaxDefinitionManager::instance()->findFromString( attribute.asString() ) );
break;
default:
return UIWidget::applyProperty( attribute );
}
@@ -5697,13 +5701,46 @@ void UICodeEditor::loadFromXmlNode( const pugi::xml_node& node ) {
UIWidget::loadFromXmlNode( node );
if ( !node.text().empty() ) {
std::string_view str{ node.text().as_string() };
if ( '\n' == str.back() )
str = str.substr( 0, str.size() - 1 );
mDoc->textInput( str );
std::string text;
bool hasElementChildren = false;
for ( pugi::xml_node child : node.children() ) {
if ( child.type() == pugi::node_element ) {
hasElementChildren = true;
break;
}
}
auto collectText = []( const pugi::xml_node& n, std::string& out, auto& self ) -> void {
for ( pugi::xml_node c : n.children() ) {
if ( c.type() == pugi::node_pcdata || c.type() == pugi::node_cdata ) {
out += c.value();
} else if ( c.type() == pugi::node_element ) {
self( c, out, self );
}
}
};
if ( hasElementChildren ) {
for ( pugi::xml_node child : node.children() ) {
if ( child.type() == pugi::node_element ) {
if ( !text.empty() )
text += "\n";
collectText( child, text, collectText );
}
}
} else {
for ( pugi::xml_node child : node.children() ) {
if ( child.type() == pugi::node_pcdata || child.type() == pugi::node_cdata ) {
text += child.value();
}
}
if ( !text.empty() && text.back() == '\n' )
text.pop_back();
}
if ( !text.empty() )
mDoc->textInput( text );
endAttributesTransaction();
}

View File

@@ -50,7 +50,9 @@ UIHTMLBody* UIHTMLBody::New( const std::string& tag ) {
return eeNew( UIHTMLBody, ( tag ) );
}
UIHTMLBody::UIHTMLBody( const std::string& tag ) : UIRichText( tag ) {}
UIHTMLBody::UIHTMLBody( const std::string& tag ) : UIRichText( tag ) {
enableReportSizeChangeToChildren();
}
Uint32 UIHTMLBody::getType() const {
return UI_TYPE_HTML_BODY;
@@ -228,6 +230,13 @@ bool UIRichText::applyProperty( const StyleSheetProperty& attribute ) {
setTextAlign( TEXT_ALIGN_RIGHT );
break;
}
case PropertyId::DataLanguage: {
if ( mTag == "pre" && mChild && mChild->isType( UI_TYPE_CODEEDITOR ) ) {
mChild->asType<UICodeEditor>()->applyProperty( attribute );
} else
mDataProperties["data-language"] = attribute;
break;
}
default:
return UILayout::applyProperty( attribute );
}
@@ -479,6 +488,11 @@ void UIRichText::loadFromXmlNode( const pugi::xml_node& node ) {
editor->setShowLineNumber( false );
editor->setShowFoldingRegion( false );
editor->setLocked( true );
auto langIt = mDataProperties.find( "data-language" );
if ( langIt != mDataProperties.end() ) {
editor->applyProperty( langIt->second );
}
}
} else {
// Let parent logic load standard child widget

View File

@@ -3236,7 +3236,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) {
auto splitter = getSplitter();
auto editor = static_cast<UICodeEditor*>( client );
auto doc = editor->getDocumentRef();
auto scrollView = UIScrollView::New();
auto scrollView = UIScrollViewCommandExecuter::New();
auto mdView = UIMarkdownView::New();
mdView->setParent( scrollView );
@@ -3274,11 +3274,14 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) {
mdView->loadFromString( doc->toUtf8String() );
auto title =
i18n( "markdown_live_preview_ellipsis", "Markdown Live Preview:" ) + " " +
i18n( "markdown_live_preview_colon", "Markdown Live Preview:" ) + " " +
doc->getFilename();
auto [tab, _] =
getSplitter()->createWidgetInTabWidget( tabWidget, scrollView, title );
tab->setIcon( findIcon( "filetype-md" ) );
tab->setTooltipText( title );
registerUnlockedCommands( *scrollView );
if ( removeUnusedEditor )
splitter->removeUnusedTab( tabWidget );

View File

@@ -7,13 +7,13 @@
using namespace EE;
#define ECODE_MAJOR_VERSION 0
#define ECODE_MINOR_VERSION 7
#define ECODE_PATCH_LEVEL 5
#define ECODE_MINOR_VERSION 8
#define ECODE_PATCH_LEVEL 0
/* ECODE_COMMIT_NUMBER 9999 is used for official releases, nightly builds (pre-releases) will
* contain the number of commits after the last official release
*/
#define ECODE_COMMIT_NUMBER 9999
#define ECODE_CODENAME "Vastiva"
#define ECODE_CODENAME "Kappa"
/** The compiled version of the library */
#define ECODE_VERSION( x ) \

View File

@@ -97,6 +97,17 @@ class UIVLinearLayoutCommandExecuter : public UILinearLayout, public WidgetComma
}
};
class UIScrollViewCommandExecuter : public UIScrollView, public WidgetCommandExecuter {
public:
static UIScrollViewCommandExecuter* New() { return eeNew( UIScrollViewCommandExecuter, () ); }
UIScrollViewCommandExecuter() : UIScrollView(), WidgetCommandExecuter( getInput() ) {}
virtual Uint32 onKeyDown( const KeyEvent& event ) {
return WidgetCommandExecuter::onKeyDown( event ) || UIScrollView::onKeyDown( event );
}
};
} // namespace ecode
#endif // ECODE_WIDGETCOMMANDEXECUTER_HPP