More pixel density errors fixed.

This commit is contained in:
Martín Lucas Golini
2026-09-30 10:24:06 -03:00
parent cd16932ba9
commit fcded81a7f
17 changed files with 68 additions and 47 deletions
+31 -12
View File
@@ -389,8 +389,9 @@ class UIDiffEditorPlugin : public UICodeEditorPlugin {
void onRegister( UICodeEditor* editor ) override {
Float glyphWidth = editor->getGlyphWidth();
Float totalChars = mView->getViewMode() == UIDiffView::ViewMode::Unified ? 10 : 5;
mGutterWidth = PixelDensity::dpToPx( glyphWidth * totalChars );
Float totalChars =
editor == mView->getEditor() ? mLineNumberDigits * 2 + 1 : mLineNumberDigits;
mGutterWidth = glyphWidth * totalChars;
mPluginTopSpace = PixelDensity::dpToPxI( 20 );
editor->registerGutterSpace( this, mGutterWidth, 0 );
@@ -425,6 +426,13 @@ class UIDiffEditorPlugin : public UICodeEditorPlugin {
onRegister( editor );
}
void setLineNumberDigits( UICodeEditor* editor, int digits ) {
if ( mLineNumberDigits == digits )
return;
mLineNumberDigits = digits;
registerUpdate( editor );
}
void drawTop( UICodeEditor* editor, const Vector2f& screenStart, const Sizef& size,
const Float& /*fontSize*/ ) override {
Float width = editor->getTopAreaWidth();
@@ -602,34 +610,37 @@ class UIDiffEditorPlugin : public UICodeEditorPlugin {
const auto& lines = mView->getDiffLines();
const auto& line = lines[viewLines[index]];
static constexpr auto bufSize = 16;
static constexpr auto bufSize = 64;
String::StringBaseType buf[bufSize] = {};
if ( mView->getViewMode() == UIDiffView::ViewMode::Unified ) {
switch ( line.type ) {
case UIDiffView::DiffLineType::Added:
String::formatBuffer( buf, bufSize, "%5s %5lld", "",
(long long)line.newLineNum );
String::formatBuffer( buf, bufSize, "%*s %*lld", mLineNumberDigits, "",
mLineNumberDigits, (long long)line.newLineNum );
break;
case UIDiffView::DiffLineType::Removed:
String::formatBuffer( buf, bufSize, "%5lld %5s", (long long)line.oldLineNum,
"" );
String::formatBuffer( buf, bufSize, "%*lld %*s", mLineNumberDigits,
(long long)line.oldLineNum, mLineNumberDigits, "" );
break;
case UIDiffView::DiffLineType::Header:
String::formatBuffer( buf, bufSize, "%5lld %5lld", (long long)line.oldLineNum,
String::formatBuffer( buf, bufSize, "%*lld %*lld", mLineNumberDigits,
(long long)line.oldLineNum, mLineNumberDigits,
(long long)line.newLineNum );
break;
case UIDiffView::DiffLineType::Common:
String::formatBuffer( buf, bufSize, "%5lld %5s", (long long)line.oldLineNum,
"" );
String::formatBuffer( buf, bufSize, "%*lld %*s", mLineNumberDigits,
(long long)line.oldLineNum, mLineNumberDigits, "" );
break;
}
} else {
if ( editor == mView->getLeftEditor() ) {
if ( line.oldLineNum > 0 )
String::formatBuffer( buf, bufSize, "%5lld", (long long)line.oldLineNum );
String::formatBuffer( buf, bufSize, "%*lld", mLineNumberDigits,
(long long)line.oldLineNum );
} else {
if ( line.newLineNum > 0 )
String::formatBuffer( buf, bufSize, "%5lld", (long long)line.newLineNum );
String::formatBuffer( buf, bufSize, "%*lld", mLineNumberDigits,
(long long)line.newLineNum );
}
}
@@ -653,6 +664,7 @@ class UIDiffEditorPlugin : public UICodeEditorPlugin {
protected:
UIDiffView* mView;
int mLineNumberDigits{ 5 };
Float mGutterWidth{ 0 };
Float mPluginTopSpace{ 0 };
Float mHeaderIconWidth{ 0 };
@@ -1052,8 +1064,10 @@ void UIDiffView::updateEditorsText() {
String leftText;
String rightText;
mViewLines.clear();
Int64 largestLineNum = 99999;
for ( size_t i = 0; i < mLines.size(); ++i ) {
largestLineNum = std::max( { largestLineNum, mLines[i].oldLineNum, mLines[i].newLineNum } );
if ( mCollapsed )
continue;
bool showLine = mShowCompleteView;
@@ -1102,6 +1116,11 @@ void UIDiffView::updateEditorsText() {
mLeftEditor->getDocument().setSyntaxDefinition( mSyntaxDef );
mRightEditor->getDocument().setSyntaxDefinition( mSyntaxDef );
}
const int lineNumberDigits = Math::countDigits( largestLineNum );
mPlugin->setLineNumberDigits( mEditor, lineNumberDigits );
mLeftPlugin->setLineNumberDigits( mLeftEditor, lineNumberDigits );
mRightPlugin->setLineNumberDigits( mRightEditor, lineNumberDigits );
}
bool UIDiffView::loadImageDiffFromPaths( const std::string& oldFilePath,
+2 -2
View File
@@ -265,8 +265,8 @@ UIFontPickerDialog::UIFontPickerDialog( Uint32 flags ) : UIWindow(), mFlags( fla
setTitle( i18n( "font_picker_select_font", "Select Font" ) );
const Sizef sceneSize( getUISceneNode()->getSize() );
const Sizef maxSize( eemax( 320.f, sceneSize.getWidth() - PixelDensity::dpToPx( 32 ) ),
eemax( 320.f, sceneSize.getHeight() - PixelDensity::dpToPx( 32 ) ) );
const Sizef maxSize( eemax( 320.f, sceneSize.getWidth() - 32.f ),
eemax( 320.f, sceneSize.getHeight() - 32.f ) );
setMinWindowSize(
Sizef( eemin( 720.f, maxSize.getWidth() ), eemin( 440.f, maxSize.getHeight() ) ) );
setSizeWithDecoration(
+1 -1
View File
@@ -78,7 +78,7 @@ UIImageViewer::UIImageViewer() : UIWidget( "imageviewer" ) {
mLoader->setVisible( false );
mLoader->setEnabled( false );
mLoader->setSize( { 64, 64 } );
mLoader->setOutlineThickness( PixelDensity::dpToPx( 6 ) );
mLoader->setOutlineThickness( 6 );
mTextView = UITextView::New();
mTextView->setParent( this );
mTextView->setEnabled( false );
+1 -1
View File
@@ -227,7 +227,7 @@ UIPushButton* UIMergeView::addToolbarAction( const std::string& command, const S
if ( auto* toolbarIcon = getUISceneNode()->findIcon( icon ) )
button->setIcon( toolbarIcon->createDrawable( PixelDensity::dpToPxI( 12 ) ) );
button->setClass( "mergeview_toolbar_button" );
button->setLayoutMarginRight( PixelDensity::dpToPx( 4 ) );
button->setLayoutMarginRight( 4 );
const auto keybind = getKeyBindings().getCommandKeybindString( command );
button->setTooltipText( keybind.empty() ? text : text + " (" + keybind + ")" );
button->onClick( [this, command]( const Event* ) { execute( command ); } );
+7 -5
View File
@@ -929,15 +929,17 @@ void UICodeEditor::setMouseWheelScroll( const Float& mouseWheelScroll ) {
}
void UICodeEditor::setLineNumberPaddingLeft( const Float& dpLeft ) {
if ( dpLeft != mLineNumberPaddingLeft ) {
mLineNumberPaddingLeft = dpLeft;
Float pxLeft = PixelDensity::dpToPx( dpLeft );
if ( pxLeft != mLineNumberPaddingLeft ) {
mLineNumberPaddingLeft = pxLeft;
invalidateDraw();
}
}
void UICodeEditor::setLineNumberPaddingRight( const Float& dpRight ) {
if ( dpRight != mLineNumberPaddingRight ) {
mLineNumberPaddingRight = dpRight;
Float pxRight = PixelDensity::dpToPx( dpRight );
if ( pxRight != mLineNumberPaddingRight ) {
mLineNumberPaddingRight = pxRight;
invalidateDraw();
}
}
@@ -3272,7 +3274,7 @@ std::string UICodeEditor::getPropertyString( const PropertyDefinition* propertyD
case PropertyId::FontWeight:
return Text::fontWeightToString( mFontStyleConfig.Weight );
case PropertyId::TextStrokeWidth:
return String::fromFloat( PixelDensity::dpToPx( getOutlineThickness() ), "px" );
return String::fromFloat( getOutlineThickness(), "px" );
case PropertyId::TextStrokeColor:
return getOutlineColor().toHexString();
case PropertyId::TextSelection:
+1 -1
View File
@@ -281,7 +281,7 @@ std::string UIConsole::getPropertyString( const PropertyDefinition* propertyDef,
case PropertyId::FontWeight:
return Text::fontWeightToString( getFontStyleConfig().Weight );
case PropertyId::TextStrokeWidth:
return String::fromFloat( PixelDensity::dpToPx( getFontOutlineThickness() ), "px" );
return String::fromFloat( getFontOutlineThickness(), "px" );
case PropertyId::TextStrokeColor:
return getFontOutlineColor().toHexString();
default:
+3 -3
View File
@@ -64,7 +64,7 @@ UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint3
mTextEdit = UITextEdit::New();
mTextEdit->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed )
->setLayoutMargin( Rectf( 0, 4, 0, 4 ) )
->setSize( PixelDensity::dpToPx( Vector2f{ 400, 100 } ) )
->setSize( Vector2f{ 400, 100 } )
->setParent( vlay );
mTextEdit->getDocument().setCommand( "complete-edit",
[this] { sendCommonEvent( Event::OnConfirm ); } );
@@ -74,14 +74,14 @@ UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint3
mDropDownList = UIDropDownList::New();
mDropDownList->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::WrapContent )
->setLayoutMargin( Rectf( 0, 4, 0, 4 ) )
->setSize( PixelDensity::dpToPx( Vector2f{ 200, 18 } ) )
->setSize( Vector2f{ 200, 18 } )
->setParent( vlay );
mDropDownList->setPopUpToRoot( true );
} else if ( mMsgBoxType == COMBOBOX ) {
mComboBox = UIComboBox::New();
mComboBox->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::WrapContent )
->setLayoutMargin( Rectf( 0, 4, 0, 4 ) )
->setSize( PixelDensity::dpToPx( Vector2f{ 200, 18 } ) )
->setSize( Vector2f{ 200, 18 } )
->setParent( vlay );
mComboBox->getDropDownList()->setPopUpToRoot( true );
mComboBox->getDropDownList()->getDocument().setCommand(
+1 -1
View File
@@ -681,7 +681,7 @@ std::string UIRichText::getPropertyString( const PropertyDefinition* propertyDef
return String::fromFloat( getFontShadowOffset().x ) + " " +
String::fromFloat( getFontShadowOffset().y );
case PropertyId::TextStrokeWidth:
return String::fromFloat( PixelDensity::dpToPx( getOutlineThickness() ), "px" );
return String::fromFloat( getOutlineThickness(), "px" );
case PropertyId::TextStrokeColor:
return getOutlineColor().toHexString();
case PropertyId::SelectionColor:
+1 -1
View File
@@ -301,7 +301,7 @@ std::string UITextEdit::getPropertyString( const PropertyDefinition* propertyDef
case PropertyId::HintFontStyle:
return Text::styleFlagToString( getHintFontStyle() );
case PropertyId::HintStrokeWidth:
return String::fromFloat( PixelDensity::dpToPx( getHintOutlineThickness() ), "px" );
return String::fromFloat( getHintOutlineThickness(), "px" );
case PropertyId::HintStrokeColor:
return getHintOutlineColor().toHexString();
case PropertyId::HintDisplay:
+1 -1
View File
@@ -602,7 +602,7 @@ std::string UITextInput::getPropertyString( const PropertyDefinition* propertyDe
case PropertyId::HintFontStyle:
return Text::styleFlagToString( getHintFontStyle() );
case PropertyId::HintStrokeWidth:
return String::fromFloat( PixelDensity::dpToPx( getHintOutlineThickness() ), "px" );
return String::fromFloat( getHintOutlineThickness(), "px" );
case PropertyId::HintStrokeColor:
return getHintOutlineColor().toHexString();
case PropertyId::HintDisplay:
+1 -1
View File
@@ -226,7 +226,7 @@ std::string UITextSpan::getPropertyString( const PropertyDefinition* propertyDef
return String::fromFloat( getFontShadowOffset().x ) + " " +
String::fromFloat( getFontShadowOffset().y );
case PropertyId::TextStrokeWidth:
return String::fromFloat( PixelDensity::dpToPx( getOutlineThickness() ), "px" );
return String::fromFloat( getOutlineThickness(), "px" );
case PropertyId::TextStrokeColor:
return getOutlineColor().toHexString();
case PropertyId::TextDecoration:
+1 -1
View File
@@ -917,7 +917,7 @@ std::string UITextView::getPropertyString( const PropertyDefinition* propertyDef
case PropertyId::FontWeight:
return Text::fontWeightToString( mFontStyleConfig.Weight );
case PropertyId::TextStrokeWidth:
return String::fromFloat( PixelDensity::dpToPx( getOutlineThickness() ), "px" );
return String::fromFloat( getOutlineThickness(), "px" );
case PropertyId::TextStrokeColor:
return getOutlineColor().toHexString();
case PropertyId::Wordwrap:
+1 -1
View File
@@ -513,7 +513,7 @@ std::string UITooltip::getPropertyString( const PropertyDefinition* propertyDef,
case PropertyId::FontWeight:
return Text::fontWeightToString( mStyleConfig.Weight );
case PropertyId::TextStrokeWidth:
return String::fromFloat( PixelDensity::dpToPx( getOutlineThickness() ), "px" );
return String::fromFloat( getOutlineThickness(), "px" );
case PropertyId::TextStrokeColor:
return getOutlineColor().toHexString();
case PropertyId::Wordwrap:
+10 -10
View File
@@ -255,7 +255,7 @@ UIWidget* UIWidget::updateLayoutMarginAuto() {
}
UIWidget* UIWidget::setLayoutPixelsMargin( const Rectf& margin ) {
if ( mLayoutMargin != margin ) {
if ( mLayoutMarginPx != margin ) {
mLayoutMarginPx = margin;
mLayoutMargin = PixelDensity::pxToDp( mLayoutMarginPx ).ceil();
onMarginChange();
@@ -267,7 +267,7 @@ UIWidget* UIWidget::setLayoutPixelsMargin( const Rectf& margin ) {
}
UIWidget* UIWidget::setLayoutPixelsMarginLeft( const Float& marginLeft ) {
if ( mLayoutMargin.Left != marginLeft ) {
if ( mLayoutMarginPx.Left != marginLeft ) {
mLayoutMarginPx.Left = marginLeft;
mLayoutMargin.Left = eeceil( PixelDensity::pxToDp( mLayoutMarginPx.Left ) );
onMarginChange();
@@ -279,7 +279,7 @@ UIWidget* UIWidget::setLayoutPixelsMarginLeft( const Float& marginLeft ) {
}
UIWidget* UIWidget::setLayoutPixelsMarginRight( const Float& marginRight ) {
if ( mLayoutMargin.Right != marginRight ) {
if ( mLayoutMarginPx.Right != marginRight ) {
mLayoutMarginPx.Right = marginRight;
mLayoutMargin.Right = eeceil( PixelDensity::pxToDp( mLayoutMarginPx.Right ) );
onMarginChange();
@@ -291,7 +291,7 @@ UIWidget* UIWidget::setLayoutPixelsMarginRight( const Float& marginRight ) {
}
UIWidget* UIWidget::setLayoutPixelsMarginTop( const Float& marginTop ) {
if ( mLayoutMargin.Top != marginTop ) {
if ( mLayoutMarginPx.Top != marginTop ) {
mLayoutMarginPx.Top = marginTop;
mLayoutMargin.Top = eeceil( PixelDensity::pxToDp( mLayoutMarginPx.Top ) );
onMarginChange();
@@ -303,7 +303,7 @@ UIWidget* UIWidget::setLayoutPixelsMarginTop( const Float& marginTop ) {
}
UIWidget* UIWidget::setLayoutPixelsMarginBottom( const Float& marginBottom ) {
if ( mLayoutMargin.Bottom != marginBottom ) {
if ( mLayoutMarginPx.Bottom != marginBottom ) {
mLayoutMarginPx.Bottom = marginBottom;
mLayoutMargin.Bottom = eeceil( PixelDensity::pxToDp( mLayoutMarginPx.Bottom ) );
onMarginChange();
@@ -1009,7 +1009,7 @@ UIWidget* UIWidget::setPaddingBottom( const Float& paddingBottom ) {
}
UIWidget* UIWidget::setPaddingPixels( const Rectf& padding ) {
if ( padding != mPadding ) {
if ( padding != mPaddingPx ) {
mPaddingPx = padding;
mPadding = PixelDensity::pxToDp( mPaddingPx ).ceil();
onAutoSize();
@@ -1021,7 +1021,7 @@ UIWidget* UIWidget::setPaddingPixels( const Rectf& padding ) {
}
UIWidget* UIWidget::setPaddingPixelsLeft( const Float& paddingLeft ) {
if ( paddingLeft != mPadding.Left ) {
if ( paddingLeft != mPaddingPx.Left ) {
mPaddingPx.Left = paddingLeft;
mPadding.Left = eeceil( PixelDensity::pxToDp( mPaddingPx.Left ) );
onAutoSize();
@@ -1033,7 +1033,7 @@ UIWidget* UIWidget::setPaddingPixelsLeft( const Float& paddingLeft ) {
}
UIWidget* UIWidget::setPaddingPixelsRight( const Float& paddingRight ) {
if ( paddingRight != mPadding.Right ) {
if ( paddingRight != mPaddingPx.Right ) {
mPaddingPx.Right = paddingRight;
mPadding.Right = eeceil( PixelDensity::pxToDp( mPaddingPx.Right ) );
onAutoSize();
@@ -1045,7 +1045,7 @@ UIWidget* UIWidget::setPaddingPixelsRight( const Float& paddingRight ) {
}
UIWidget* UIWidget::setPaddingPixelsTop( const Float& paddingTop ) {
if ( paddingTop != mPadding.Top ) {
if ( paddingTop != mPaddingPx.Top ) {
mPaddingPx.Top = paddingTop;
mPadding.Top = eeceil( PixelDensity::pxToDp( mPaddingPx.Top ) );
onAutoSize();
@@ -1057,7 +1057,7 @@ UIWidget* UIWidget::setPaddingPixelsTop( const Float& paddingTop ) {
}
UIWidget* UIWidget::setPaddingPixelsBottom( const Float& paddingBottom ) {
if ( paddingBottom != mPadding.Bottom ) {
if ( paddingBottom != mPaddingPx.Bottom ) {
mPaddingPx.Bottom = paddingBottom;
mPadding.Bottom = eeceil( PixelDensity::pxToDp( mPaddingPx.Bottom ) );
onAutoSize();
+3 -3
View File
@@ -122,7 +122,7 @@ void UIWidgetTable::setTheme( UITheme* Theme ) {
void UIWidgetTable::autoPadding() {
if ( mFlags & UI_AUTO_PADDING ) {
mContainerPadding = PixelDensity::dpToPx( makePadding() );
mContainerPadding = makePadding();
}
}
@@ -134,7 +134,7 @@ void UIWidgetTable::onSizeChange() {
}
void UIWidgetTable::containerResize() {
Rectf padding = mContainerPadding + mPaddingPx;
Rectf padding = mContainerPadding + mPadding;
mContainer->setPosition( padding.Left, padding.Top );
@@ -627,7 +627,7 @@ UIWidgetTable* UIWidgetTable::setSmoothScroll( bool smoothScroll ) {
}
Rectf UIWidgetTable::getContainerPadding() const {
return PixelDensity::pxToDp( mContainerPadding + mPaddingPx );
return mContainerPadding + mPadding;
}
void UIWidgetTable::onPaddingChange() {
+1 -1
View File
@@ -2602,7 +2602,7 @@ void App::createDocManyLangsAlert( UICodeEditor* editor ) {
UIPushButton* btn = UIPushButton::New();
btn->setParent( flow );
btn->setText( lang->getLanguageName() );
btn->setLayoutMarginRight( PixelDensity::dpToPx( 8 ) );
btn->setLayoutMarginRight( 8 );
btn->onClick( [this, editor, lang, docAlert, ext]( auto ) {
editor->setSyntaxDefinition( *lang );
editor->disableReportSizeChangeToChildren();
@@ -2097,7 +2097,7 @@ void LLMChatUI::doAgentRequest() {
auto* thinking = editor->findByClass<UIImage>( "thinking" );
auto thinkingID = String::hash( String::format( "thinking-%p", thinking ) );
thinking->setVisible( true );
thinking->setPosition( { PixelDensity::dpToPx( 8 ), PixelDensity::dpToPx( 3 ) } );
thinking->setPosition( { 8, 3 } );
thinking->setInterval( [thinking] { thinking->rotate( 360 / 32 ); }, Seconds( 0.125 ),
thinkingID );
@@ -2127,7 +2127,7 @@ void LLMChatUI::doAgentRequest() {
auto* thinking = editor->findByClass<UIImage>( "thinking" );
auto thinkingID = String::hash( String::format( "thinking-%p", thinking ) );
thinking->setVisible( true );
thinking->setPosition( { PixelDensity::dpToPx( 8 ), PixelDensity::dpToPx( 3 ) } );
thinking->setPosition( { 8, 3 } );
thinking->setInterval( [thinking] { thinking->rotate( 360 / 32 ); }, Seconds( 0.125 ),
thinkingID );