fix panic caused by strings that where cut outside of char boundary
This commit is contained in:
@@ -56,19 +56,25 @@ impl View for SplitButton {
|
|||||||
ColorStyle::highlight()
|
ColorStyle::highlight()
|
||||||
};
|
};
|
||||||
|
|
||||||
// shorten titles that are too long and append ".." to indicate this
|
// draw left string
|
||||||
let mut left_shortened = self.left.clone();
|
|
||||||
left_shortened.truncate(printer.size.x - self.right.width() - 1);
|
|
||||||
if left_shortened.width() < self.left.width() {
|
|
||||||
let offset = left_shortened.width() - 2;
|
|
||||||
left_shortened.replace_range(offset.., "..");
|
|
||||||
}
|
|
||||||
|
|
||||||
printer.with_color(style, |printer| {
|
printer.with_color(style, |printer| {
|
||||||
printer.print((0, 0), &left_shortened);
|
printer.print((0, 0), &self.left);
|
||||||
});
|
});
|
||||||
|
|
||||||
// track duration goes to the end of the line
|
// draw ".." to indicate a cut off string
|
||||||
|
let max_length = printer
|
||||||
|
.size
|
||||||
|
.x
|
||||||
|
.checked_sub(self.right.width() + 1)
|
||||||
|
.unwrap_or(0);
|
||||||
|
if max_length < self.left.width() {
|
||||||
|
let offset = max_length.checked_sub(1).unwrap_or(0);
|
||||||
|
printer.with_color(style, |printer| {
|
||||||
|
printer.print((offset, 0), "..");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw right string
|
||||||
let offset = HAlign::Right.get_offset(self.right.width(), printer.size.x);
|
let offset = HAlign::Right.get_offset(self.right.width(), printer.size.x);
|
||||||
|
|
||||||
printer.with_color(style, |printer| {
|
printer.with_color(style, |printer| {
|
||||||
|
|||||||
Reference in New Issue
Block a user