Add support for string escapes like \n in label texts (fixes #84)

This commit is contained in:
elkowar 2021-01-02 18:17:23 +01:00
parent 8aa0e8c74d
commit c079eb855d
3 changed files with 11 additions and 1 deletions

7
Cargo.lock generated
View file

@ -364,6 +364,7 @@ dependencies = [
"smart-default", "smart-default",
"stoppable_thread", "stoppable_thread",
"structopt", "structopt",
"unescape",
] ]
[[package]] [[package]]
@ -2000,6 +2001,12 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "unescape"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccb97dac3243214f8d8507998906ca3e2e0b900bf9bf4870477f125b82e68f6e"
[[package]] [[package]]
name = "unicode-segmentation" name = "unicode-segmentation"
version = "1.6.0" version = "1.6.0"

View file

@ -44,6 +44,7 @@ smart-default = "0.6"
filedescriptor = "0.7" filedescriptor = "0.7"
simple-signal = "1.1" simple-signal = "1.1"
dashmap = "3.11" dashmap = "3.11"
unescape = "0.1"
[dev-dependencies] [dev-dependencies]
pretty_assertions = "0.6.1" pretty_assertions = "0.6.1"

View file

@ -342,7 +342,9 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
// @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(text: as_string, limit_width: as_i32 = i32::MAX) {
gtk_widget.set_text(&text.chars().take(limit_width as usize).collect::<String>()); let text = text.chars().take(limit_width as usize).collect::<String>();
let text = unescape::unescape(&text).context(format!("Failed to unescape label text {}", &text))?;
gtk_widget.set_text(&text);
}, },
// @prop markup - Pango markup to display // @prop markup - Pango markup to display
prop(markup: as_string) { prop(markup: as_string) {