mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 22:01:13 +00:00
GL backend: elide Text also when word-wrapping
In this case, the last line will have elipsis on the last line when no more line can be printed Note that the behavior is different with the Qt backend
This commit is contained in:
parent
8a2b665498
commit
bc8bc616ed
1 changed files with 16 additions and 11 deletions
|
@ -597,6 +597,7 @@ impl ItemRenderer for GLItemRenderer {
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
let wrap = text.wrap() == TextWrap::word_wrap;
|
let wrap = text.wrap() == TextWrap::word_wrap;
|
||||||
|
let elide = text.overflow() == TextOverflow::elide;
|
||||||
let letter_spacing = text.letter_spacing() * self.scale_factor;
|
let letter_spacing = text.letter_spacing() * self.scale_factor;
|
||||||
let text_size =
|
let text_size =
|
||||||
font.text_size(letter_spacing, string, if wrap { Some(max_width) } else { None });
|
font.text_size(letter_spacing, string, if wrap { Some(max_width) } else { None });
|
||||||
|
@ -631,9 +632,9 @@ impl ItemRenderer for GLItemRenderer {
|
||||||
*y += font_metrics.height();
|
*y += font_metrics.height();
|
||||||
};
|
};
|
||||||
|
|
||||||
if wrap {
|
let mut start = 0;
|
||||||
let mut start = 0;
|
'lines: while start < string.len() && y + font_metrics.height() <= max_height {
|
||||||
while start < string.len() && y + font_metrics.height() <= max_height {
|
if wrap && (!elide || y + 2. * font_metrics.height() <= max_height) {
|
||||||
let index = canvas.break_text(max_width, &string[start..], paint).unwrap();
|
let index = canvas.break_text(max_width, &string[start..], paint).unwrap();
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
// FIXME the word is too big to be shown, but we should still break, ideally
|
// FIXME the word is too big to be shown, but we should still break, ideally
|
||||||
|
@ -643,15 +644,14 @@ impl ItemRenderer for GLItemRenderer {
|
||||||
// trim is there to remove the \n
|
// trim is there to remove the \n
|
||||||
draw_line(&mut canvas, string[start..index].trim(), &mut y);
|
draw_line(&mut canvas, string[start..index].trim(), &mut y);
|
||||||
start = index;
|
start = index;
|
||||||
}
|
} else {
|
||||||
} else {
|
let index = string[start..].find('\n').map_or(string.len(), |i| start + i + 1);
|
||||||
let elide = text.overflow() == TextOverflow::elide;
|
let line = &string[start..index].trim();
|
||||||
'lines: for line in string.lines() {
|
start = index;
|
||||||
if y + font_metrics.height() > max_height {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let text_metrics = canvas.measure_text(0., 0., line, paint).unwrap();
|
let text_metrics = canvas.measure_text(0., 0., line, paint).unwrap();
|
||||||
if text_metrics.width() > max_width {
|
let elide_last_line =
|
||||||
|
elide && index < string.len() && y + 2. * font_metrics.height() > max_height;
|
||||||
|
if text_metrics.width() > max_width || elide_last_line {
|
||||||
let w = max_width
|
let w = max_width
|
||||||
- if elide {
|
- if elide {
|
||||||
canvas.measure_text(0., 0., "…", paint).unwrap().width()
|
canvas.measure_text(0., 0., "…", paint).unwrap().width()
|
||||||
|
@ -672,6 +672,11 @@ impl ItemRenderer for GLItemRenderer {
|
||||||
continue 'lines;
|
continue 'lines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if elide_last_line {
|
||||||
|
let elided = format!("{}…", line);
|
||||||
|
draw_line(&mut canvas, &elided, &mut y);
|
||||||
|
continue 'lines;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
draw_line(&mut canvas, line, &mut y);
|
draw_line(&mut canvas, line, &mut y);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue