mirror of
https://github.com/holub/mame
synced 2025-05-10 08:12:13 +03:00
word_wrapping::TRUNCATE was completely broken; this fixes it
This commit is contained in:
parent
8362576906
commit
c3b7a9e470
@ -78,7 +78,7 @@ CORE IMPLEMENTATION
|
|||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
|
|
||||||
text_layout::text_layout(render_font &font, float xscale, float yscale, float width, text_layout::text_justify justify, text_layout::word_wrapping wrap)
|
text_layout::text_layout(render_font &font, float xscale, float yscale, float width, text_layout::text_justify justify, text_layout::word_wrapping wrap)
|
||||||
: m_font(font), m_xscale(xscale), m_yscale(yscale), m_width(width), m_justify(justify), m_wrap(wrap), m_current_line(nullptr), m_last_break(0), m_text_position(0)
|
: m_font(font), m_xscale(xscale), m_yscale(yscale), m_width(width), m_justify(justify), m_wrap(wrap), m_current_line(nullptr), m_last_break(0), m_text_position(0), m_truncating(false)
|
||||||
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ text_layout::text_layout(render_font &font, float xscale, float yscale, float wi
|
|||||||
|
|
||||||
text_layout::text_layout(text_layout &&that)
|
text_layout::text_layout(text_layout &&that)
|
||||||
: m_font(that.m_font), m_xscale(that.m_xscale), m_yscale(that.m_yscale), m_width(that.m_width), m_justify(that.m_justify), m_wrap(that.m_wrap), m_lines(std::move(that.m_lines)),
|
: m_font(that.m_font), m_xscale(that.m_xscale), m_yscale(that.m_yscale), m_width(that.m_width), m_justify(that.m_justify), m_wrap(that.m_wrap), m_lines(std::move(that.m_lines)),
|
||||||
m_current_line(that.m_current_line), m_last_break(that.m_last_break), m_text_position(that.m_text_position)
|
m_current_line(that.m_current_line), m_last_break(that.m_last_break), m_text_position(that.m_text_position), m_truncating(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ void text_layout::add_text(const char *text, const char_style &style)
|
|||||||
update_maximum_line_width();
|
update_maximum_line_width();
|
||||||
m_current_line = nullptr;
|
m_current_line = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else if (!m_truncating)
|
||||||
{
|
{
|
||||||
// if we hit a space, remember the location and width *without* the space
|
// if we hit a space, remember the location and width *without* the space
|
||||||
if (is_space_character(ch))
|
if (is_space_character(ch))
|
||||||
@ -250,6 +250,7 @@ void text_layout::start_new_line(text_layout::text_justify justify, float height
|
|||||||
update_maximum_line_width();
|
update_maximum_line_width();
|
||||||
m_current_line = new_line.get();
|
m_current_line = new_line.get();
|
||||||
m_last_break = 0;
|
m_last_break = 0;
|
||||||
|
m_truncating = false;
|
||||||
|
|
||||||
// append it
|
// append it
|
||||||
m_lines.push_back(std::move(new_line));
|
m_lines.push_back(std::move(new_line));
|
||||||
@ -272,6 +273,8 @@ float text_layout::get_char_width(unicode_char ch, float size)
|
|||||||
|
|
||||||
void text_layout::truncate_wrap()
|
void text_layout::truncate_wrap()
|
||||||
{
|
{
|
||||||
|
const unicode_char elipsis = 0x2026;
|
||||||
|
|
||||||
// for now, lets assume that we're only truncating the last character
|
// for now, lets assume that we're only truncating the last character
|
||||||
size_t truncate_position = m_current_line->character_count() - 1;
|
size_t truncate_position = m_current_line->character_count() - 1;
|
||||||
const auto& truncate_char = m_current_line->character(truncate_position);
|
const auto& truncate_char = m_current_line->character(truncate_position);
|
||||||
@ -285,7 +288,7 @@ void text_layout::truncate_wrap()
|
|||||||
source.span = 0;
|
source.span = 0;
|
||||||
|
|
||||||
// figure out how wide an elipsis is
|
// figure out how wide an elipsis is
|
||||||
float elipsis_width = 3 * get_char_width('.', style.size);
|
float elipsis_width = get_char_width(elipsis, style.size);
|
||||||
|
|
||||||
// where should we really truncate from?
|
// where should we really truncate from?
|
||||||
while (truncate_position > 0 && m_current_line->character(truncate_position).xoffset + elipsis_width < width())
|
while (truncate_position > 0 && m_current_line->character(truncate_position).xoffset + elipsis_width < width())
|
||||||
@ -295,10 +298,10 @@ void text_layout::truncate_wrap()
|
|||||||
m_current_line->truncate(truncate_position);
|
m_current_line->truncate(truncate_position);
|
||||||
|
|
||||||
// and append the elipsis
|
// and append the elipsis
|
||||||
m_current_line->add_character('.', style, source);
|
m_current_line->add_character(elipsis, style, source);
|
||||||
|
|
||||||
// finally start a new line
|
// take note that we are truncating; supress new characters
|
||||||
start_new_line(m_current_line->justify(), style.size);
|
m_truncating = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,6 +145,7 @@ private:
|
|||||||
line *m_current_line;
|
line *m_current_line;
|
||||||
size_t m_last_break;
|
size_t m_last_break;
|
||||||
size_t m_text_position;
|
size_t m_text_position;
|
||||||
|
bool m_truncating;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
void add_text(const char *text, const char_style &style);
|
void add_text(const char *text, const char_style &style);
|
||||||
|
Loading…
Reference in New Issue
Block a user