| 104 | |
| 105 | |
| 106 | void Entry::RecalculateVisibleString() const { |
| 107 | float text_padding( Context::Get().GetEngine().GetProperty<float>( "Padding", shared_from_this() ) ); |
| 108 | const std::string& font_name( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) ); |
| 109 | unsigned int font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) ); |
| 110 | const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) ); |
| 111 | |
| 112 | if( m_string.isEmpty() ) { |
| 113 | m_visible_string.clear(); |
| 114 | Invalidate(); |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | std::u32string string( m_string.begin(), m_string.end() ); |
| 119 | string.erase( 0, static_cast<std::size_t>( m_visible_offset ) ); |
| 120 | |
| 121 | if( m_text_placeholder != 0 ) { |
| 122 | string.replace( 0, string.size(), string.size(), m_text_placeholder ); |
| 123 | } |
| 124 | |
| 125 | auto length = Context::Get().GetEngine().GetTextStringMetrics( string, font, font_size ).x; |
| 126 | |
| 127 | // While the string is too long for the given space keep chopping off characters |
| 128 | // on the right end of the string until the cursor is reached, then start |
| 129 | // chopping off characters on the left side of the string. |
| 130 | while( !string.empty() && (GetAllocation().size.x - m_text_margin > 0) && (length > GetAllocation().size.x - m_text_margin - (2.f * text_padding)) ) { |
| 131 | if( ( m_cursor_position - m_visible_offset ) < static_cast<int>( string.size() ) ) { |
| 132 | string.erase( string.size() - 1, 1 ); |
| 133 | } |
| 134 | else { |
| 135 | string.erase( 0, 1 ); |
| 136 | m_visible_offset++; |
| 137 | } |
| 138 | |
| 139 | length = Context::Get().GetEngine().GetTextStringMetrics( string, font, font_size ).x; |
| 140 | } |
| 141 | |
| 142 | m_visible_string = string; |
| 143 | Invalidate(); |
| 144 | } |
| 145 | |
| 146 | void Entry::MoveCursor( int delta ) { |
| 147 | if( delta && ( m_cursor_position + delta >= 0 ) && ( m_cursor_position + delta <= static_cast<int>( m_string.getSize() ) ) ) { |
nothing calls this directly
no test coverage detected