mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement tooltip for input counters
This commit is contained in:
parent
afc33c1a03
commit
d1c05b6469
4 changed files with 25 additions and 16 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use gtk::{prelude::WidgetExt, Label};
|
use gtk::{prelude::WidgetExt, Label};
|
||||||
|
use plurify::Plurify;
|
||||||
|
|
||||||
pub struct Counter {
|
pub struct Counter {
|
||||||
pub label: Label,
|
pub label: Label,
|
||||||
|
|
@ -34,6 +35,11 @@ impl Counter {
|
||||||
|
|
||||||
// Toggle visibility on chars left provided
|
// Toggle visibility on chars left provided
|
||||||
self.label.set_visible(!is_empty);
|
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),
|
None => self.label.set_visible(false),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ impl Titan for gtk::Box {
|
||||||
|
|
||||||
form.buffer().connect_changed({
|
form.buffer().connect_changed({
|
||||||
let control = control.clone();
|
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`
|
// Return activated `Self`
|
||||||
|
|
|
||||||
|
|
@ -44,12 +44,9 @@ impl Control {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, char_count: Option<i32>) {
|
pub fn update(&self, chars_count: i32, bytes_total: usize) {
|
||||||
// Update children components
|
// Update children components
|
||||||
self.counter.update(char_count);
|
self.counter.update(chars_count, bytes_total);
|
||||||
self.send.set_sensitive(match char_count {
|
self.send.set_sensitive(bytes_total > 0);
|
||||||
Some(total) => total > 0,
|
|
||||||
None => false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use gtk::{prelude::WidgetExt, Label};
|
use gtk::{prelude::WidgetExt, Label};
|
||||||
|
use plurify::Plurify;
|
||||||
|
|
||||||
pub trait Counter {
|
pub trait Counter {
|
||||||
fn counter() -> Self;
|
fn counter() -> Self;
|
||||||
fn update(&self, char_count: Option<i32>);
|
fn update(&self, char_count: i32, bytes_total: usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Counter for Label {
|
impl Counter for Label {
|
||||||
|
|
@ -14,13 +15,17 @@ impl Counter for Label {
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
fn update(&self, char_count: Option<i32>) {
|
fn update(&self, chars_count: i32, bytes_total: usize) {
|
||||||
match char_count {
|
self.set_visible(if bytes_total > 0 {
|
||||||
Some(value) => {
|
self.set_label(&bytes_total.to_string());
|
||||||
self.set_label(&value.to_string());
|
self.set_tooltip_markup(Some(&format!(
|
||||||
self.set_visible(value > 0);
|
"{bytes_total} {} <sup>/ {chars_count} {}</sup>",
|
||||||
}
|
(bytes_total).plurify(&["byte", "bytes", "bytes"]),
|
||||||
None => self.set_visible(false),
|
(chars_count as usize).plurify(&["char", "chars", "chars"]),
|
||||||
}
|
)));
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue