MCPcopy Create free account
hub / github.com/SpartanJ/eepp / getLineWidth

Method getLineWidth

src/eepp/ui/uicodeeditor.cpp:2085–2135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2083}
2084
2085Float UICodeEditor::getLineWidth( const Int64& docLine ) {
2086 if ( docLine >= (Int64)mDoc->linesCount() || !mDocView.isLineVisible( docLine ) )
2087 return 0;
2088
2089 bool isMonospaceLine = this->isMonospaceLine( docLine );
2090
2091 if ( mDocView.isWrappedLine( docLine ) ) {
2092 auto vline = mDocView.getVisibleLineInfo( docLine );
2093 const auto& line = mDoc->line( docLine ).getText();
2094 Float width = 0;
2095
2096 if ( !isMonospaceLine ) {
2097 auto found = mLinesWidthCache.find( docLine );
2098 if ( found != mLinesWidthCache.end() &&
2099 mDoc->getLineHash( docLine ) == found->second.first )
2100 return found->second.second;
2101 }
2102
2103 for ( size_t i = 0; i < vline.visualLines.size(); i++ ) {
2104 auto pos = vline.visualLines[i].column();
2105 auto len =
2106 i + 1 < vline.visualLines.size() ? vline.visualLines[i + 1].column() : line.size();
2107 auto vlineStr = line.view().substr( pos, len - pos );
2108 auto curWidth =
2109 getTextWidth( vlineStr, isMonospaceLine, {},
2110 mDoc->line( docLine ).getTextHints() | getWidgetTextDrawHints() );
2111 width = eemax( width, curWidth );
2112 }
2113
2114 if ( !isMonospaceLine ) {
2115 mLinesWidthCache[docLine] = { line.getHash(), width };
2116 }
2117
2118 return width;
2119 }
2120
2121 if ( !isMonospaceLine ) {
2122 auto& line = mDoc->line( docLine );
2123 auto found = mLinesWidthCache.find( docLine );
2124 if ( found != mLinesWidthCache.end() && line.getHash() == found->second.first )
2125 return found->second.second;
2126 Float width = getTextWidth( line.getText(), {}, mTabStops ? 0 : std::optional<Float>{},
2127 line.getTextHints() | getWidgetTextDrawHints() );
2128 mLinesWidthCache[docLine] = { line.getHash(), width };
2129 return width;
2130 }
2131
2132 return getTextWidth( mDoc->line( docLine ).getText(), isMonospaceLine,
2133 mTabStops ? 0 : std::optional<Float>{},
2134 mDoc->line( docLine ).getTextHints() | getWidgetTextDrawHints() );
2135}
2136
2137void UICodeEditor::updateScrollBar() {
2138 Int64 notVisibleLineCount = (Int64)getTotalVisibleLines() - (Int64)getViewPortLineCount().y;

Callers 5

drawAfterLineTextMethod · 0.45
drawMethod · 0.45
getBorderWidthMethod · 0.45
UTESTFunction · 0.45
UTESTFunction · 0.45

Calls 15

isMonospaceLineMethod · 0.95
getTextWidthFunction · 0.85
getWidgetTextDrawHintsFunction · 0.85
eemaxFunction · 0.85
linesCountMethod · 0.80
isLineVisibleMethod · 0.80
isWrappedLineMethod · 0.80
getVisibleLineInfoMethod · 0.80
getLineHashMethod · 0.80
columnMethod · 0.80
substrMethod · 0.80
viewMethod · 0.80

Tested by 2

UTESTFunction · 0.36
UTESTFunction · 0.36