mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Fix SVG align rendering defaults to match HTML.
Fix accidental reflow on UIRichText.
This commit is contained in:
@@ -168,8 +168,13 @@ class EE_API RichText : public Drawable {
|
||||
/** @return The current selection as a string. */
|
||||
String getSelectionString() const;
|
||||
|
||||
/** Tries to update the layout if has been invalidated. This is automatically called before
|
||||
* draw. */
|
||||
void updateLayout();
|
||||
|
||||
/** Invalidates the current layout */
|
||||
void invalidateLayout();
|
||||
|
||||
protected:
|
||||
std::vector<Block> mBlocks;
|
||||
std::vector<RenderParagraph> mLines;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <eepp/ui/uicodeeditor.hpp>
|
||||
#include <eepp/ui/uilinearlayout.hpp>
|
||||
#include <eepp/ui/uiselectbutton.hpp>
|
||||
#include <eepp/ui/widgetcommandexecuter.hpp>
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace Tools {
|
||||
|
||||
class UIDiffEditorPlugin;
|
||||
|
||||
class EE_API UIDiffView : public UIWidget {
|
||||
class EE_API UIDiffView : public UIWidget, public WidgetCommandExecuter {
|
||||
public:
|
||||
enum class ViewMode { Unified, SideBySide };
|
||||
enum class SubLineDiffAlgorithm { LCS, SES };
|
||||
|
||||
@@ -150,7 +150,7 @@ class EE_API UIRichText : public UILayout {
|
||||
Int64 selCurEnd() const { return mSelCurEnd; }
|
||||
|
||||
enum class IntrinsicMode { None, Min, Max };
|
||||
void rebuildRichText( IntrinsicMode mode = IntrinsicMode::None );
|
||||
void rebuildRichText( RichText& richText, IntrinsicMode mode = IntrinsicMode::None );
|
||||
void positionChildren();
|
||||
void updateDefaultSpansStyle();
|
||||
};
|
||||
|
||||
@@ -272,19 +272,19 @@ void RichText::addSpan( const String& text, const FontStyleConfig& style ) {
|
||||
span->setString( text );
|
||||
span->setStyleConfig( style );
|
||||
mBlocks.push_back( span ); // Implicitly constructs the variant's Text alternative
|
||||
mNeedsLayoutUpdate = true;
|
||||
invalidateLayout();
|
||||
}
|
||||
|
||||
void RichText::addDrawable( std::shared_ptr<Drawable> drawable ) {
|
||||
if ( !drawable )
|
||||
return;
|
||||
mBlocks.push_back( drawable );
|
||||
mNeedsLayoutUpdate = true;
|
||||
invalidateLayout();
|
||||
}
|
||||
|
||||
void RichText::addCustomSize( const Sizef& size ) {
|
||||
mBlocks.push_back( size );
|
||||
mNeedsLayoutUpdate = true;
|
||||
invalidateLayout();
|
||||
}
|
||||
|
||||
void RichText::addSpan( const String& text, Font* font, Uint32 characterSize, Color color,
|
||||
@@ -307,30 +307,30 @@ void RichText::clear() {
|
||||
mBlocks.clear();
|
||||
mLines.clear();
|
||||
mSelection = { 0, 0 };
|
||||
mNeedsLayoutUpdate = true;
|
||||
invalidateLayout();
|
||||
}
|
||||
|
||||
void RichText::setFontStyleConfig( const FontStyleConfig& styleConfig ) {
|
||||
mDefaultStyle = styleConfig;
|
||||
mNeedsLayoutUpdate = true;
|
||||
invalidateLayout();
|
||||
}
|
||||
|
||||
void RichText::setAlign( Uint32 align ) {
|
||||
if ( mAlign != align ) {
|
||||
mAlign = align;
|
||||
mNeedsLayoutUpdate = true;
|
||||
invalidateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
void RichText::setMaxWidth( Float width ) {
|
||||
if ( mMaxWidth != width ) {
|
||||
mMaxWidth = width;
|
||||
mNeedsLayoutUpdate = true;
|
||||
invalidateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
void RichText::invalidate() {
|
||||
mNeedsLayoutUpdate = true;
|
||||
invalidateLayout();
|
||||
for ( auto& block : mBlocks ) {
|
||||
if ( auto pText = std::get_if<std::shared_ptr<Text>>( &block ) ) {
|
||||
if ( *pText )
|
||||
@@ -574,4 +574,8 @@ Sizef RichText::getSize() {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
void RichText::invalidateLayout() {
|
||||
mNeedsLayoutUpdate = true;
|
||||
}
|
||||
|
||||
}} // namespace EE::Graphics
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <eepp/ui/uiscrollbar.hpp>
|
||||
#include <eepp/ui/uiscrollview.hpp>
|
||||
#include <eepp/ui/uithememanager.hpp>
|
||||
#include <eepp/window/window.hpp>
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
|
||||
@@ -294,7 +295,9 @@ std::vector<std::string> UIDiffView::splitDiff( const std::string& multiFileDiff
|
||||
return diffs;
|
||||
}
|
||||
|
||||
UIDiffView::UIDiffView() : UIWidget( "diffview" ) {
|
||||
UIDiffView::UIDiffView() :
|
||||
UIWidget( "diffview" ),
|
||||
WidgetCommandExecuter( KeyBindings{ getUISceneNode()->getWindow()->getInput() } ) {
|
||||
setFlags( UI_AUTO_SIZE );
|
||||
createEditor( mEditor, mPlugin );
|
||||
createEditor( mLeftEditor, mLeftPlugin );
|
||||
|
||||
@@ -164,7 +164,8 @@ void UIHTMLTable::computeIntrinsicWidths() const {
|
||||
|
||||
if ( colspan == 1 && colIndex < maxCols ) {
|
||||
if ( cellSpecified > 0.f ) {
|
||||
mColSpecifiedWidths[colIndex] = std::max( mColSpecifiedWidths[colIndex], cellSpecified );
|
||||
mColSpecifiedWidths[colIndex] =
|
||||
std::max( mColSpecifiedWidths[colIndex], cellSpecified );
|
||||
}
|
||||
}
|
||||
colIndex += colspan;
|
||||
|
||||
@@ -186,16 +186,14 @@ void UIImage::calcDestSize() {
|
||||
void UIImage::draw() {
|
||||
UINode::draw();
|
||||
|
||||
if ( mVisible ) {
|
||||
if ( NULL != mDrawable && 0.f != mAlpha ) {
|
||||
calcDestSize();
|
||||
if ( mVisible && NULL != mDrawable && 0.f != mAlpha ) {
|
||||
calcDestSize();
|
||||
|
||||
mDrawable->setColor( mColor );
|
||||
mDrawable->draw( Vector2f( std::trunc( mScreenPos.x ) + std::trunc( mAlignOffset.x ),
|
||||
std::trunc( mScreenPos.y ) + std::trunc( mAlignOffset.y ) ),
|
||||
mDestSize );
|
||||
mDrawable->clearColor();
|
||||
}
|
||||
mDrawable->setColor( mColor );
|
||||
mDrawable->draw( Vector2f( std::trunc( mScreenPos.x ) + std::trunc( mAlignOffset.x ),
|
||||
std::trunc( mScreenPos.y ) + std::trunc( mAlignOffset.y ) ),
|
||||
mDestSize );
|
||||
mDrawable->clearColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <eepp/graphics/fontmanager.hpp>
|
||||
#include <eepp/graphics/text.hpp>
|
||||
#include <eepp/ui/css/propertydefinition.hpp>
|
||||
#include <eepp/ui/tools/htmlformatter.hpp>
|
||||
#include <eepp/ui/uicodeeditor.hpp>
|
||||
#include <eepp/ui/uirichtext.hpp>
|
||||
#include <eepp/ui/uiscenenode.hpp>
|
||||
@@ -10,7 +11,6 @@
|
||||
#include <eepp/ui/uiwidgetcreator.hpp>
|
||||
|
||||
#define PUGIXML_HEADER_ONLY
|
||||
#include <eepp/ui/tools/htmlformatter.hpp>
|
||||
#include <pugixml/pugixml.hpp>
|
||||
|
||||
namespace EE { namespace UI {
|
||||
@@ -388,12 +388,7 @@ void UIRichText::loadFromXmlNode( const pugi::xml_node& node ) {
|
||||
|
||||
for ( pugi::xml_node child = node.first_child(); child; child = child.next_sibling() ) {
|
||||
if ( child.type() == pugi::node_element ) {
|
||||
if ( String::iequals( child.name(), "span" ) ||
|
||||
String::iequals( child.name(), "textspan" ) ) {
|
||||
UITextSpan* span = UITextSpan::New();
|
||||
span->setParent( this );
|
||||
span->loadFromXmlNode( child );
|
||||
} else if ( mTag == "pre" && String::iequals( child.name(), "code" ) ) {
|
||||
if ( mTag == "pre" && String::iequals( child.name(), "code" ) ) {
|
||||
// Use a UICodeEditor for <pre><code>
|
||||
UICodeEditor* editor = UICodeEditor::New();
|
||||
if ( editor ) {
|
||||
@@ -477,24 +472,24 @@ void UIRichText::onAlphaChange() {
|
||||
UILayout::onAlphaChange();
|
||||
}
|
||||
|
||||
void UIRichText::rebuildRichText( IntrinsicMode mode ) {
|
||||
mRichText.clear();
|
||||
void UIRichText::rebuildRichText( RichText& richText, IntrinsicMode mode ) {
|
||||
richText.clear();
|
||||
|
||||
// Calculate maximum layout width for the RichText block
|
||||
Float maxWidth = mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right;
|
||||
if ( maxWidth < 0 )
|
||||
maxWidth = 0;
|
||||
if ( mWidthPolicy == SizePolicy::WrapContent || mode != IntrinsicMode::None ) {
|
||||
mRichText.setMaxWidth( 0.f ); // Let it grow unbounded to query text bounds later
|
||||
richText.setMaxWidth( 0.f ); // Let it grow unbounded to query text bounds later
|
||||
} else {
|
||||
mRichText.setMaxWidth( maxWidth );
|
||||
richText.setMaxWidth( maxWidth );
|
||||
}
|
||||
|
||||
auto processWidget = [&]( UIWidget* widget, auto& processWidgetRef ) -> void {
|
||||
if ( widget->isType( UI_TYPE_TEXTSPAN ) ) {
|
||||
UITextSpan* span = widget->asType<UITextSpan>();
|
||||
if ( !span->getText().empty() ) {
|
||||
mRichText.addSpan( span->getText(), span->getFontStyleConfig() );
|
||||
richText.addSpan( span->getText(), span->getFontStyleConfig() );
|
||||
}
|
||||
Node* spanChild = span->getFirstChild();
|
||||
while ( spanChild != NULL ) {
|
||||
@@ -504,8 +499,8 @@ void UIRichText::rebuildRichText( IntrinsicMode mode ) {
|
||||
spanChild = spanChild->getNextNode();
|
||||
}
|
||||
} else if ( widget->isType( UI_TYPE_BR ) ) {
|
||||
mRichText.addSpan( "\n",
|
||||
widget->asType<UILineBreak>()->getRichText().getFontStyleConfig() );
|
||||
richText.addSpan( "\n",
|
||||
widget->asType<UILineBreak>()->getRichText().getFontStyleConfig() );
|
||||
} else {
|
||||
Rectf margin = widget->getLayoutPixelsMargin();
|
||||
|
||||
@@ -532,8 +527,8 @@ void UIRichText::rebuildRichText( IntrinsicMode mode ) {
|
||||
size = widget->getPixelsSize();
|
||||
}
|
||||
|
||||
mRichText.addCustomSize( Sizef( size.getWidth() + margin.Left + margin.Right,
|
||||
size.getHeight() + margin.Top + margin.Bottom ) );
|
||||
richText.addCustomSize( Sizef( size.getWidth() + margin.Left + margin.Right,
|
||||
size.getHeight() + margin.Top + margin.Bottom ) );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -705,7 +700,7 @@ void UIRichText::updateLayout() {
|
||||
setInternalPixelsSize( { lengthFromValue( *prop ), mSize.getHeight() } );
|
||||
}
|
||||
|
||||
rebuildRichText();
|
||||
rebuildRichText( mRichText );
|
||||
|
||||
mRichText.updateLayout();
|
||||
|
||||
@@ -735,14 +730,11 @@ Float UIRichText::getMinIntrinsicWidth() const {
|
||||
}
|
||||
|
||||
if ( mIntrinsicWidthsDirty ) {
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( IntrinsicMode::Min );
|
||||
mMinIntrinsicWidth = const_cast<RichText&>( mRichText ).getMinIntrinsicWidth() +
|
||||
mPaddingPx.Left + mPaddingPx.Right;
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( IntrinsicMode::Max );
|
||||
mMaxIntrinsicWidth = const_cast<RichText&>( mRichText ).getMaxIntrinsicWidth() +
|
||||
mPaddingPx.Left + mPaddingPx.Right;
|
||||
// We need to rebuild the rich text with the original state, otherwise layout will be broken
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( IntrinsicMode::None );
|
||||
RichText richText( mRichText );
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( richText, IntrinsicMode::Min );
|
||||
mMinIntrinsicWidth = richText.getMinIntrinsicWidth() + mPaddingPx.Left + mPaddingPx.Right;
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( richText, IntrinsicMode::Max );
|
||||
mMaxIntrinsicWidth = richText.getMaxIntrinsicWidth() + mPaddingPx.Left + mPaddingPx.Right;
|
||||
mIntrinsicWidthsDirty = false;
|
||||
}
|
||||
return mMinIntrinsicWidth;
|
||||
@@ -754,14 +746,11 @@ Float UIRichText::getMaxIntrinsicWidth() const {
|
||||
}
|
||||
|
||||
if ( mIntrinsicWidthsDirty ) {
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( IntrinsicMode::Min );
|
||||
mMinIntrinsicWidth = const_cast<RichText&>( mRichText ).getMinIntrinsicWidth() +
|
||||
mPaddingPx.Left + mPaddingPx.Right;
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( IntrinsicMode::Max );
|
||||
mMaxIntrinsicWidth = const_cast<RichText&>( mRichText ).getMaxIntrinsicWidth() +
|
||||
mPaddingPx.Left + mPaddingPx.Right;
|
||||
// We need to rebuild the rich text with the original state, otherwise layout will be broken
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( IntrinsicMode::None );
|
||||
RichText richText( mRichText );
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( richText, IntrinsicMode::Min );
|
||||
mMinIntrinsicWidth = richText.getMinIntrinsicWidth() + mPaddingPx.Left + mPaddingPx.Right;
|
||||
const_cast<UIRichText*>( this )->rebuildRichText( richText, IntrinsicMode::Max );
|
||||
mMaxIntrinsicWidth = richText.getMaxIntrinsicWidth() + mPaddingPx.Left + mPaddingPx.Right;
|
||||
mIntrinsicWidthsDirty = false;
|
||||
}
|
||||
return mMaxIntrinsicWidth;
|
||||
|
||||
6
src/thirdparty/nanosvg/nanosvg.h
vendored
6
src/thirdparty/nanosvg/nanosvg.h
vendored
@@ -165,7 +165,7 @@ typedef struct NSVGimage
|
||||
{
|
||||
float width; // Width of the image.
|
||||
float height; // Height of the image.
|
||||
unsigned current_color; // For "currentColor"
|
||||
unsigned current_color; // For "currentColor"
|
||||
NSVGshape* shapes; // Linked list of shapes in the image.
|
||||
} NSVGimage;
|
||||
|
||||
@@ -649,6 +649,10 @@ static NSVGparser* nsvg__createParser(unsigned current_color)
|
||||
|
||||
p->image->current_color = current_color;
|
||||
|
||||
p->alignX = NSVG_ALIGN_MID;
|
||||
p->alignY = NSVG_ALIGN_MID;
|
||||
p->alignType = NSVG_ALIGN_MEET;
|
||||
|
||||
return p;
|
||||
|
||||
error:
|
||||
|
||||
@@ -2675,6 +2675,7 @@ void App::loadDiffFromMemory( const std::string& content, const std::string& ori
|
||||
diffView->setHeadersVisible( true );
|
||||
diffView->loadFromPatch( content, originalFilePath );
|
||||
diffView->setSyntaxColorScheme( *getCurrentColorScheme() );
|
||||
registerUnlockedCommands( *diffView );
|
||||
}
|
||||
|
||||
void App::loadDiffFromPath( const std::string& path ) {
|
||||
@@ -2721,6 +2722,7 @@ void App::loadDiffFromPath( const std::string& path ) {
|
||||
diffView->setHeadersVisible( true );
|
||||
diffView->loadFromPatch( content, path );
|
||||
diffView->setSyntaxColorScheme( *getCurrentColorScheme() );
|
||||
registerUnlockedCommands( *diffView );
|
||||
}
|
||||
|
||||
void App::loadDiffFromPaths( const std::string& oldPath, const std::string& newPath ) {
|
||||
@@ -2740,6 +2742,7 @@ void App::loadDiffFromPaths( const std::string& oldPath, const std::string& newP
|
||||
diffView->setHeadersVisible( true );
|
||||
diffView->loadFromFile( oldPath, newPath );
|
||||
diffView->setSyntaxColorScheme( *getCurrentColorScheme() );
|
||||
registerUnlockedCommands( *diffView );
|
||||
}
|
||||
|
||||
void App::loadDiffFromStrings( const std::string& str, const std::string& otherStr ) {
|
||||
@@ -2752,6 +2755,7 @@ void App::loadDiffFromStrings( const std::string& str, const std::string& otherS
|
||||
diffView->setHeadersVisible( true );
|
||||
diffView->loadFromStrings( str, otherStr );
|
||||
diffView->setSyntaxColorScheme( *getCurrentColorScheme() );
|
||||
registerUnlockedCommands( *diffView );
|
||||
}
|
||||
|
||||
void App::openFileFromPath( const std::string& path ) {
|
||||
|
||||
Reference in New Issue
Block a user