Indicate label truncation (#259)

Closes #257
This commit is contained in:
Ben Fiedler 2021-09-11 12:44:25 +02:00 committed by GitHub
parent 634724bf29
commit 089f617393
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -544,8 +544,15 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
resolve_block!(bargs, gtk_widget, { resolve_block!(bargs, gtk_widget, {
// @prop text - the text to display // @prop text - the text to display
// @prop limit-width - maximum count of characters to display // @prop limit-width - maximum count of characters to display
prop(text: as_string, limit_width: as_i32 = i32::MAX) { // @prop show_truncated - show whether the text was truncated
let text = text.chars().take(limit_width as usize).collect::<String>(); prop(text: as_string, limit_width: as_i32 = i32::MAX, show_truncated: as_bool = true) {
let truncated = text.chars().count() > limit_width as usize;
let mut text = text.chars().take(limit_width as usize).collect::<String>();
if show_truncated && truncated {
text.push_str("...");
}
let text = unescape::unescape(&text).context(format!("Failed to unescape label text {}", &text))?; let text = unescape::unescape(&text).context(format!("Failed to unescape label text {}", &text))?;
let text = unindent::unindent(&text); let text = unindent::unindent(&text);
gtk_widget.set_text(&text); gtk_widget.set_text(&text);