remove extra folding

This commit is contained in:
yggverse 2025-01-22 08:04:51 +02:00
parent dea9669d3c
commit ba965814eb
5 changed files with 45 additions and 101 deletions

View file

@ -25,7 +25,7 @@ impl Control {
let send = Rc::new(Send::build(action_send));
// Init widget
let widget = Rc::new(Widget::build(&counter.widget.label, &send.widget.button));
let widget = Rc::new(Widget::build(&counter.label, &send.button));
// Return activated struct
Self {

View file

@ -1,11 +1,7 @@
mod widget;
use widget::Widget;
use std::rc::Rc;
use gtk::{prelude::WidgetExt, Label};
pub struct Counter {
pub widget: Rc<Widget>,
pub label: Label,
}
impl Default for Counter {
@ -18,12 +14,28 @@ impl Counter {
// Construct
pub fn new() -> Self {
Self {
widget: Rc::new(Widget::new()),
label: Label::builder().build(),
}
}
// Actions
pub fn update(&self, is_empty: bool, bytes_left: Option<isize>) {
self.widget.update(is_empty, bytes_left);
match bytes_left {
Some(value) => {
// Update color on chars left reached
self.label.set_css_classes(&[if value.is_positive() {
"success"
} else {
"error"
}]); // @TODO add warning step?
// Update text
self.label.set_label(&value.to_string());
// Toggle visibility on chars left provided
self.label.set_visible(!is_empty);
}
None => self.label.set_visible(false),
}
}
}

View file

@ -1,41 +0,0 @@
use gtk::{prelude::WidgetExt, Label};
pub struct Widget {
pub label: Label,
}
impl Default for Widget {
fn default() -> Self {
Self::new()
}
}
impl Widget {
// Construct
pub fn new() -> Self {
Self {
label: Label::builder().build(),
}
}
// Actions
pub fn update(&self, is_empty: bool, bytes_left: Option<isize>) {
match bytes_left {
Some(value) => {
// Update color on chars left reached
self.label.set_css_classes(&[if value.is_positive() {
"success"
} else {
"error"
}]); // @TODO add warning step?
// Update text
self.label.set_label(&value.to_string());
// Toggle visibility on chars left provided
self.label.set_visible(!is_empty);
}
None => self.label.set_visible(false),
}
}
}

View file

@ -1,11 +1,11 @@
mod widget;
use widget::Widget;
use gtk::gio::SimpleAction;
use std::rc::Rc;
use gtk::{
gio::SimpleAction,
prelude::{ActionExt, ButtonExt, WidgetExt},
Button,
};
pub struct Send {
pub widget: Rc<Widget>,
pub button: Button,
}
impl Send {
@ -13,15 +13,28 @@ impl Send {
/// Build new `Self`
pub fn build(action_send: SimpleAction) -> Self {
// Init widget
let widget = Rc::new(Widget::build(action_send));
// Init main widget
let button = Button::builder()
.css_classes(["accent"]) // | `suggested-action`
.label("Send")
.sensitive(false)
.build();
// Result
Self { widget }
// Init events
button.connect_clicked({
move |this| {
this.set_sensitive(false);
this.set_label("Sending..");
action_send.activate(None);
}
});
// Return activated `Self`
Self { button }
}
// Actions
pub fn update(&self, is_sensitive: bool) {
self.widget.update(is_sensitive);
self.button.set_sensitive(is_sensitive);
}
}

View file

@ -1,40 +0,0 @@
use gtk::{
gio::SimpleAction,
prelude::{ActionExt, ButtonExt, WidgetExt},
Button,
};
pub struct Widget {
pub button: Button,
}
impl Widget {
// Constructors
/// Build new `Self`
pub fn build(action_send: SimpleAction) -> Self {
// Init main widget
let button = Button::builder()
.css_classes(["accent"]) // | `suggested-action`
.label("Send")
.sensitive(false)
.build();
// Init events
button.connect_clicked({
move |this| {
this.set_sensitive(false);
this.set_label("Sending..");
action_send.activate(None);
}
});
// Return activated `Self`
Self { button }
}
// Actions
pub fn update(&self, is_sensitive: bool) {
self.button.set_sensitive(is_sensitive);
}
}