MCPcopy Create free account
hub / github.com/MethanePowered/MethaneKit / AnimateTextBlock

Method AnimateTextBlock

Apps/05-Typography/TypographyApp.cpp:344–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342}
343
344void TypographyApp::AnimateTextBlock(size_t block_index, int32_t& vertical_text_pos_in_dots)
345{
346 const gui::TextItem& text = *m_texts[block_index];
347 const std::u32string& full_text = g_text_blocks[block_index];
348 const size_t text_block_length = full_text.length();
349 size_t& displayed_text_length = m_displayed_text_lengths[block_index];
350
351 if (displayed_text_length == (m_settings.is_forward_typing_direction ? 0 : text_block_length))
352 {
353 text.SetText(m_settings.is_forward_typing_direction ? std::u32string() : full_text);
354 if (!m_settings.is_forward_typing_direction)
355 vertical_text_pos_in_dots = text.GetRectInDots().GetBottom() + g_margin_size_in_dots;
356 return;
357 }
358
359 if (displayed_text_length == (m_settings.is_forward_typing_direction ? text_block_length : 0))
360 {
361 if (block_index == (m_settings.is_forward_typing_direction ? g_text_blocks_count - 1 : 0))
362 {
363 ResetAnimation();
364 return;
365 }
366
367 vertical_text_pos_in_dots = text.GetRectInDots().GetBottom() + g_margin_size_in_dots;
368 size_t next_block_index = block_index + (m_settings.is_forward_typing_direction ? 1 : -1);
369 size_t& next_displayed_text_length = m_displayed_text_lengths[next_block_index];
370
371 if (m_settings.is_forward_typing_direction && next_displayed_text_length == 0)
372 next_displayed_text_length = 1;
373
374 if (!m_settings.is_forward_typing_direction && next_displayed_text_length == g_text_blocks[next_block_index].length())
375 next_displayed_text_length = g_text_blocks[next_block_index].length() - 1;
376
377 return;
378 }
379
380 if (m_settings.is_forward_typing_direction)
381 displayed_text_length++;
382 else
383 displayed_text_length--;
384
385 const std::u32string displayed_text = full_text.substr(0, displayed_text_length);
386 const gui::UnitRect text_block_rect = GetTextBlockRectInDots(block_index, vertical_text_pos_in_dots, GetFrameSizeInDots());
387
388 m_text_update_duration = UpdateText(text, displayed_text, text_block_rect);
389
390 vertical_text_pos_in_dots = text.GetRectInDots().GetBottom() + g_margin_size_in_dots;
391}
392
393void TypographyApp::ResetAnimation()
394{

Callers

nothing calls this directly

Calls 5

GetTextBlockRectInDotsFunction · 0.85
UpdateTextFunction · 0.85
GetRectInDotsMethod · 0.80
SetTextMethod · 0.45
GetBottomMethod · 0.45

Tested by

no test coverage detected