diff options
author | Vas Crabb <vas@vastheman.com> | 2021-10-17 08:22:28 +1100 |
---|---|---|
committer | Vas Crabb <vas@vastheman.com> | 2021-10-17 08:22:28 +1100 |
commit | 0fd4461d3d4b56cdb62de76360056af5c62d2684 (patch) | |
tree | 8422b4dc5daf8df483271f6b39d0f160882ac571 /src/frontend | |
parent | cd57640deb4bd9d423aad2342f0130fe81215749 (diff) |
frontend: Better code for carrying justification across when wrapping.
Diffstat (limited to 'src/frontend')
-rw-r--r-- | src/frontend/mame/ui/text.cpp | 17 | ||||
-rw-r--r-- | src/frontend/mame/ui/text.h | 2 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/frontend/mame/ui/text.cpp b/src/frontend/mame/ui/text.cpp index f91f12517a0..f1e8ab34e21 100644 --- a/src/frontend/mame/ui/text.cpp +++ b/src/frontend/mame/ui/text.cpp @@ -247,6 +247,8 @@ public: float width() const { return m_width; } float height() const { return m_height; } size_t character_count() const { return m_characters.size(); } + size_t center_justify_start() const { return m_center_justify_start; } + size_t right_justify_start() const { return m_right_justify_start; } const positioned_char &character(size_t index) const { return m_characters[index]; } positioned_char &character(size_t index) { return m_characters[index]; } @@ -362,7 +364,7 @@ void text_layout::add_text(std::string_view text, text_justify line_justify, cha break; case word_wrapping::WORD: - word_wrap(line_justify); + word_wrap(); break; case word_wrapping::NEVER: @@ -527,7 +529,7 @@ void text_layout::truncate_wrap() // word_wrap //------------------------------------------------- -void text_layout::word_wrap(text_justify line_justify) +void text_layout::word_wrap() { // keep track of the last line and break line *const last_line = m_current_line; @@ -535,16 +537,25 @@ void text_layout::word_wrap(text_justify line_justify) // start a new line with the same justification start_new_line(last_line->character(last_line->character_count() - 1).style.size); - m_current_line->set_justification(line_justify); // find the beginning of the word to wrap size_t position = last_break; while ((position + 1) < last_line->character_count() && is_space_character(last_line->character(position).character)) position++; + // carry over justification + if (last_line->right_justify_start() <= position) + m_current_line->set_justification(text_justify::RIGHT); + else if (last_line->center_justify_start() <= position) + m_current_line->set_justification(text_justify::CENTER); + // transcribe the characters for (size_t i = position; i < last_line->character_count(); i++) { + if (last_line->right_justify_start() == i) + m_current_line->set_justification(text_justify::RIGHT); + else if (last_line->center_justify_start() == i) + m_current_line->set_justification(text_justify::CENTER); auto &ch = last_line->character(i); m_current_line->add_character(*this, ch.character, ch.style, ch.source); } diff --git a/src/frontend/mame/ui/text.h b/src/frontend/mame/ui/text.h index e0d52b8a211..0e19970c3b0 100644 --- a/src/frontend/mame/ui/text.h +++ b/src/frontend/mame/ui/text.h @@ -111,7 +111,7 @@ private: void start_new_line(float height); float get_char_width(char32_t ch, float size); void truncate_wrap(); - void word_wrap(text_justify line_justify); + void word_wrap(); void invalidate_calculated_actual_width(); }; |