- enhancement: Folding button scales with editor font.

This commit is contained in:
Roy Qu 2024-03-14 20:06:45 +08:00
parent a3e6d111f8
commit 46b273a88d
5 changed files with 24 additions and 15 deletions

View File

@ -55,6 +55,7 @@ Red Panda C++ Version 2.27
- enhancement: Make output in the debug console cleaner.
- enhancement: Execute the last debug command in the debug console if ENTER pressed.
- change: When debugging, don't auto set focus to the editor.
- enhancement: Folding button scales with editor font.
Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors.

View File

@ -5275,7 +5275,7 @@ void Editor::applySettings()
// Set gutter properties
gutter().setLeftOffset(pointToPixel(pSettings->editor().fontSize()) + pSettings->editor().gutterLeftOffset());
gutter().setRightOffset(pSettings->editor().gutterRightOffset());
gutter().setRightOffset(pointToPixel(pSettings->editor().fontSize()) + pSettings->editor().gutterRightOffset());
gutter().setBorderStyle(QSynedit::GutterBorderStyle::None);
gutter().setUseFontStyle(pSettings->editor().gutterUseCustomFont());
if (pSettings->editor().gutterUseCustomFont()) {

View File

@ -1365,7 +1365,7 @@ void Settings::Editor::doSave()
saveValue("gutter_visible", mGutterVisible);
saveValue("gutter_auto_size", mGutterAutoSize);
saveValue("gutter_left_offset",mGutterLeftOffset);
saveValue("gutter_right_offset",mGutterRightOffset);
saveValue("gutter_right_offset2",mGutterRightOffset);
saveValue("gutter_digits_count", mGutterDigitsCount);
saveValue("gutter_show_line_numbers",mGutterShowLineNumbers);
saveValue("gutter_add_leading_zero",mGutterAddLeadingZero);
@ -1514,7 +1514,11 @@ void Settings::Editor::doLoad()
mGutterVisible = boolValue("gutter_visible",true);
mGutterAutoSize = boolValue("gutter_auto_size",true);
mGutterLeftOffset = intValue("gutter_left_offset",6);
mGutterRightOffset = intValue("gutter_right_offset",24);
mGutterRightOffset = intValue("gutter_right_offset",-1);
if (mGutterRightOffset>0)
mGutterRightOffset = std::max(0, mGutterRightOffset-20);
else
mGutterRightOffset = intValue("gutter_right_offset2",4);
mGutterDigitsCount = intValue("gutter_digits_count",1);
mGutterShowLineNumbers = boolValue("gutter_show_line_numbers",true);
mGutterAddLeadingZero = boolValue("gutter_add_leading_zero",false);

View File

@ -160,6 +160,7 @@ void QSynEditPainter::paintGutter(const QRect& clip)
// Draw the folding lines and squares
if (mEdit->useCodeFolding()) {
int lineWidth = std::max(0.0,std::ceil(mEdit->font().pixelSize() / 15));
for (int row = mLastRow; row>= mFirstRow; row--) {
int line = mEdit->rowToLine(row);
if ((line > mEdit->mDocument->count()) && (mEdit->mDocument->count() != 0))
@ -171,7 +172,7 @@ void QSynEditPainter::paintGutter(const QRect& clip)
rcFold.setRight(rcFold.left() + mEdit->mGutter.rightOffset() - 4);
rcFold.setBottom(rcFold.top() + mEdit->mTextHeight);
mPainter->setPen(mEdit->mCodeFolding.folderBarLinesColor);
mPainter->setPen(QPen(mEdit->mCodeFolding.folderBarLinesColor,lineWidth));
// Need to paint a line?
if (mEdit->foldAroundLine(line)) {
@ -200,24 +201,28 @@ void QSynEditPainter::paintGutter(const QRect& clip)
// make a square rect
inflateRect(rcFold,-2, 0);
rcFold.setTop(
rcFold.top() + ((mEdit->mTextHeight - rcFold.width()) / 2));
rcFold.setBottom(rcFold.top() + rcFold.width());
int size = std::min(mEdit->font().pixelSize() * 4 / 5, mEdit->mGutter.rightOffset()) - lineWidth;
float centerX = rcFold.left() + rcFold.width() / 2.0;
float centerY = rcFold.top() + rcFold.height() / 2.0;
float halfSize = size / 2.0;
rcFold.setLeft(centerX - halfSize);
rcFold.setRight(centerX + halfSize);
rcFold.setTop(centerY - halfSize);
rcFold.setBottom(centerY + halfSize);
// Paint the square the user can click on
mPainter->setBrush(mEdit->mGutter.color());
mPainter->setPen(mEdit->mCodeFolding.folderBarLinesColor);
//mPainter->setPen(mEdit->mCodeFolding.folderBarLinesColor);
mPainter->drawRect(rcFold);
// Paint minus sign
mPainter->drawLine(
rcFold.left() + 2, rcFold.top() + (rcFold.height() / 2 ),
rcFold.right() - 2, rcFold.top() + (rcFold.height() / 2 ));
rcFold.left() + lineWidth * 2 , centerY,
rcFold.right() - lineWidth * 2 , centerY );
// Paint vertical line of plus sign
if (foldRange->collapsed) {
x = rcFold.left() + (rcFold.width() / 2);
mPainter->drawLine(x, rcFold.top() + 2,
x, rcFold.bottom() - 2);
mPainter->drawLine(centerX, rcFold.top() + lineWidth * 2,
centerX, rcFold.bottom() - lineWidth * 2 );
}
}
}

View File

@ -3220,8 +3220,7 @@ void QSynEdit::recalcCharExtent()
mTextHeight = 0;
mCharWidth = 0;
QFontMetrics fm(font());
QFontMetrics fm2(font());
mTextHeight = std::max(fm.lineSpacing(),fm2.lineSpacing());
mTextHeight = fm.lineSpacing();
mCharWidth = fm.horizontalAdvance("M");
if (hasStyles[0]) { // has bold font