diff --git a/src/app/browser/window/tab/item/page/input/response/control/counter.rs b/src/app/browser/window/tab/item/page/input/response/control/counter.rs index c15a5a4b..2f1cb4a9 100644 --- a/src/app/browser/window/tab/item/page/input/response/control/counter.rs +++ b/src/app/browser/window/tab/item/page/input/response/control/counter.rs @@ -1,4 +1,5 @@ use gtk::{prelude::WidgetExt, Label}; +use plurify::Plurify; pub struct Counter { pub label: Label, @@ -34,6 +35,11 @@ impl Counter { // Toggle visibility on chars left provided self.label.set_visible(!is_empty); + + self.label.set_tooltip_text(Some(&format!( + "{value} {} left", + (value as usize).plurify(&["byte", "bytes", "bytes"]) + ))); } None => self.label.set_visible(false), } diff --git a/src/app/browser/window/tab/item/page/input/titan.rs b/src/app/browser/window/tab/item/page/input/titan.rs index d540c1e9..87d857be 100644 --- a/src/app/browser/window/tab/item/page/input/titan.rs +++ b/src/app/browser/window/tab/item/page/input/titan.rs @@ -57,7 +57,8 @@ impl Titan for gtk::Box { form.buffer().connect_changed({ let control = control.clone(); - move |this| control.update(Some(this.char_count())) + let form = form.clone(); + move |this| control.update(this.char_count(), form.text().len()) }); // Return activated `Self` diff --git a/src/app/browser/window/tab/item/page/input/titan/control.rs b/src/app/browser/window/tab/item/page/input/titan/control.rs index 12597e56..98f88276 100644 --- a/src/app/browser/window/tab/item/page/input/titan/control.rs +++ b/src/app/browser/window/tab/item/page/input/titan/control.rs @@ -44,12 +44,9 @@ impl Control { } // Actions - pub fn update(&self, char_count: Option) { + pub fn update(&self, chars_count: i32, bytes_total: usize) { // Update children components - self.counter.update(char_count); - self.send.set_sensitive(match char_count { - Some(total) => total > 0, - None => false, - }); + self.counter.update(chars_count, bytes_total); + self.send.set_sensitive(bytes_total > 0); } } diff --git a/src/app/browser/window/tab/item/page/input/titan/control/counter.rs b/src/app/browser/window/tab/item/page/input/titan/control/counter.rs index f2ff2898..88ae80fc 100644 --- a/src/app/browser/window/tab/item/page/input/titan/control/counter.rs +++ b/src/app/browser/window/tab/item/page/input/titan/control/counter.rs @@ -1,8 +1,9 @@ use gtk::{prelude::WidgetExt, Label}; +use plurify::Plurify; pub trait Counter { fn counter() -> Self; - fn update(&self, char_count: Option); + fn update(&self, char_count: i32, bytes_total: usize); } impl Counter for Label { @@ -14,13 +15,17 @@ impl Counter for Label { // Actions - fn update(&self, char_count: Option) { - match char_count { - Some(value) => { - self.set_label(&value.to_string()); - self.set_visible(value > 0); - } - None => self.set_visible(false), - } + fn update(&self, chars_count: i32, bytes_total: usize) { + self.set_visible(if bytes_total > 0 { + self.set_label(&bytes_total.to_string()); + self.set_tooltip_markup(Some(&format!( + "{bytes_total} {} / {chars_count} {}", + (bytes_total).plurify(&["byte", "bytes", "bytes"]), + (chars_count as usize).plurify(&["char", "chars", "chars"]), + ))); + true + } else { + false + }) } }