| 136 | } |
| 137 | |
| 138 | void Text::update( bool force ) const |
| 139 | { |
| 140 | if ( !force && !dirty ) |
| 141 | return; // Nothing to do. |
| 142 | dirty = false; |
| 143 | |
| 144 | FontAndSize curFont = defaultFont; |
| 145 | |
| 146 | // Compute `elem.computedSize` and `line.computedSize[WithPadding].y`. |
| 147 | for ( const Line& line : lines ) |
| 148 | { |
| 149 | line.computedSize.y = 0; |
| 150 | |
| 151 | for ( const Elem& elem : line.elems ) |
| 152 | { |
| 153 | std::visit( overloaded{ |
| 154 | [&]( const std::string& str ) |
| 155 | { |
| 156 | if ( curFont.first ) |
| 157 | ImGui::PushFont( curFont.first, curFont.second ); |
| 158 | MR_FINALLY{ |
| 159 | if ( curFont.first ) |
| 160 | ImGui::PopFont(); |
| 161 | }; |
| 162 | |
| 163 | elem.computedSize = round( ImGui::CalcTextSize( str.c_str() ) ); |
| 164 | }, |
| 165 | [&]( TextIcon ) |
| 166 | { |
| 167 | // Just this for now. |
| 168 | elem.computedSize.x = elem.computedSize.y = std::round( ImGui::GetTextLineHeight() ); |
| 169 | }, |
| 170 | [&]( const TextColor& ) |
| 171 | { |
| 172 | elem.computedSize = ImVec2(); |
| 173 | }, |
| 174 | [&]( const TextFont& font ) |
| 175 | { |
| 176 | elem.computedSize = ImVec2(); |
| 177 | curFont = { font.font, font.size }; |
| 178 | }, |
| 179 | }, elem.var ); |
| 180 | |
| 181 | if ( elem.computedSize.y > line.computedSize.y ) |
| 182 | line.computedSize.y = elem.computedSize.y; |
| 183 | } |
| 184 | |
| 185 | line.computedSizeWithPadding.y = std::max( line.computedSize.y, line.size.y ); |
| 186 | } |
| 187 | |
| 188 | float columnWidths[32]{}; |
| 189 | |
| 190 | // Compute `elem.computedSizeWithPadding` (here Y requires knowing line heights, and X could've been computed earlier). |
| 191 | // Also compute initial `computedSizeWithPadding` for elements, before the column alignment. |
| 192 | for ( const Line& line : lines ) |
| 193 | { |
| 194 | for ( const Elem& elem : line.elems ) |
| 195 | { |