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

Method UICodeEditor

src/eepp/ui/uicodeeditor.cpp:131–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131UICodeEditor::UICodeEditor( const std::string& elementTag, const bool& autoRegisterBaseCommands,
132 const bool& autoRegisterBaseKeybindings ) :
133 UIWidget( elementTag ),
134 mFont( FontManager::instance()->getByName( "monospace" ) ),
135 mDoc( std::make_shared<TextDocument>() ),
136 mDocView( mDoc, mFontStyleConfig, { .tabStops = mTabStops } ),
137 mBlinkTime( Seconds( 0.5f ) ),
138 mFoldsRefreshTime( Seconds( 2.f ) ),
139 mTabWidth( 4 ),
140 mMouseWheelScroll( 50 ),
141 mFontSize( mFontStyleConfig.getFontCharacterSize() ),
142 mLineNumberPaddingLeft( PixelDensity::dpToPx( 6 ) ),
143 mLineNumberPaddingRight( PixelDensity::dpToPx( 6 ) ),
144 mFoldRegionWidth( PixelDensity::dpToPx( 12 ) ),
145 mPreviewColor( Color::Transparent ),
146 mKeyBindings( getInput() ),
147 mFindLongestLineWidthUpdateFrequency( Seconds( 1 ) ) {
148 mWidthPolicy = SizePolicy::Fixed;
149 mHeightPolicy = SizePolicy::Fixed;
150 mFlags |= UI_TAB_STOP | UI_OWNS_CHILDREN_POSITION | UI_SCROLLABLE;
151 setTextSelection( true );
152 setColorScheme( SyntaxColorScheme::getDefault() );
153 refreshTag();
154 mDocView.setOnVisibleLineCountChange( [this] {
155 onAutoSize();
156 sendCommonEvent( Event::OnVisibleLinesCountChange );
157 } );
158 mDocView.setOnFoldUnfoldCb(
159 [this]( auto, auto ) { sendCommonEvent( Event::OnFoldUnfoldRange ); } );
160 mVScrollBar = UIScrollBar::NewVertical();
161 mVScrollBar->setParent( this );
162 mVScrollBar->on( Event::OnSizeChange, [this]( const Event* ) { updateScrollBar(); } );
163 mVScrollBar->on( Event::OnValueChange, [this]( const Event* ) {
164 setScrollY( mVScrollBar->getValue() * getMaxScroll().y, false );
165 } );
166
167 mHScrollBar = UIScrollBar::NewHorizontal();
168 mHScrollBar->setParent( this );
169 mHScrollBar->on( Event::OnSizeChange, [this]( const Event* ) { updateScrollBar(); } );
170 mHScrollBar->on( Event::OnValueChange, [this]( const Event* ) {
171 setScrollX( mHScrollBar->getValue() * getMaxScroll().x, false );
172 } );
173
174 if ( NULL == mFont && elementTag == "codeeditor" )
175 Log::error(
176 "A monospace font must be loaded to be able to use the code editor.\nTry loading "
177 "a font with the name \"monospace\"" );
178
179 mFontStyleConfig.Font = mFont;
180
181 setFontSize( getUISceneNode()->getUIThemeManager()->getDefaultFontSize() );
182
183 setClipType( ClipType::ContentBox );
184 mDoc->registerClient( this );
185 subscribeScheduledUpdate();
186
187 if ( autoRegisterBaseCommands )
188 registerCommands();

Callers

nothing calls this directly

Calls 10

SecondsFunction · 0.85
errorFunction · 0.85
setOnFoldUnfoldCbMethod · 0.80
setParentMethod · 0.80
getUIThemeManagerMethod · 0.80
getByNameMethod · 0.45
onMethod · 0.45
getValueMethod · 0.45
registerClientMethod · 0.45

Tested by

no test coverage detected