MCPcopy Create free account
hub / github.com/TankOs/SFGUI / HandleKeyEvent

Method HandleKeyEvent

src/SFGUI/Entry.cpp:176–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176void Entry::HandleKeyEvent( sf::Keyboard::Key /*key*/, sf::Keyboard::Scancode scancode, bool press ) {
177 if( !press || !HasFocus() ) {
178 return;
179 }
180
181 switch( scancode ) {
182 case sf::Keyboard::Scan::Backspace: { // backspace
183 if( ( m_string.getSize() > 0 ) && ( m_cursor_position > 0 ) ) {
184 m_string.erase( static_cast<std::size_t>( m_cursor_position - 1 ) );
185
186 // Store old number of visible characters.
187 auto old_num_visible_chars = m_visible_string.getSize();
188
189 MoveCursor( -1 );
190 RecalculateVisibleString();
191
192 // If new amount of chars is less and we have some chars in front, go
193 // back.
194 if( m_visible_offset > 0 && old_num_visible_chars > m_visible_string.getSize() ) {
195 --m_visible_offset;
196 RecalculateVisibleString();
197 }
198
199 m_elapsed_time = 0.f;
200 m_cursor_status = true;
201
202 GetSignals().Emit( OnTextChanged );
203 }
204 } break;
205 case sf::Keyboard::Scan::Delete: {
206 if( ( m_string.getSize() > 0 ) && ( m_cursor_position < static_cast<int>( m_string.getSize() ) ) ) {
207 m_string.erase( static_cast<std::size_t>( m_cursor_position ) );
208
209 // Store old number of visible characters.
210 auto old_num_visible_chars = m_visible_string.getSize();
211
212 RecalculateVisibleString();
213
214 // If new amount of chars is less and we have some chars in front, go
215 // back.
216 if( m_visible_offset > 0 && old_num_visible_chars > m_visible_string.getSize() ) {
217 --m_visible_offset;
218 RecalculateVisibleString();
219 }
220
221 m_elapsed_time = 0.f;
222 m_cursor_status = true;
223
224 GetSignals().Emit( OnTextChanged );
225 }
226 } break;
227 case sf::Keyboard::Scan::Home: {
228 if( m_string.getSize() > 0 ) {
229 m_visible_offset = 0;
230 SetCursorPosition( 0 );
231 }
232 } break;
233 case sf::Keyboard::Scan::End: {

Callers

nothing calls this directly

Calls 1

EmitMethod · 0.80

Tested by

no test coverage detected