From ba965814eb6ccf72a279ea1ba240f5ff26dfaa5d Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 22 Jan 2025 08:04:51 +0200 Subject: [PATCH] remove extra folding --- .../tab/item/page/input/response/control.rs | 2 +- .../page/input/response/control/counter.rs | 28 +++++++++---- .../input/response/control/counter/widget.rs | 41 ------------------- .../item/page/input/response/control/send.rs | 35 +++++++++++----- .../input/response/control/send/widget.rs | 40 ------------------ 5 files changed, 45 insertions(+), 101 deletions(-) delete mode 100644 src/app/browser/window/tab/item/page/input/response/control/counter/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/response/control/send/widget.rs diff --git a/src/app/browser/window/tab/item/page/input/response/control.rs b/src/app/browser/window/tab/item/page/input/response/control.rs index 55249aa6..06377ef1 100644 --- a/src/app/browser/window/tab/item/page/input/response/control.rs +++ b/src/app/browser/window/tab/item/page/input/response/control.rs @@ -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 { 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 703f4df8..c15a5a4b 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,11 +1,7 @@ -mod widget; - -use widget::Widget; - -use std::rc::Rc; +use gtk::{prelude::WidgetExt, Label}; pub struct Counter { - pub widget: Rc, + 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) { - 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), + } } } diff --git a/src/app/browser/window/tab/item/page/input/response/control/counter/widget.rs b/src/app/browser/window/tab/item/page/input/response/control/counter/widget.rs deleted file mode 100644 index 23030056..00000000 --- a/src/app/browser/window/tab/item/page/input/response/control/counter/widget.rs +++ /dev/null @@ -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) { - 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), - } - } -} diff --git a/src/app/browser/window/tab/item/page/input/response/control/send.rs b/src/app/browser/window/tab/item/page/input/response/control/send.rs index 299b298c..2d418d50 100644 --- a/src/app/browser/window/tab/item/page/input/response/control/send.rs +++ b/src/app/browser/window/tab/item/page/input/response/control/send.rs @@ -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, + 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); } } diff --git a/src/app/browser/window/tab/item/page/input/response/control/send/widget.rs b/src/app/browser/window/tab/item/page/input/response/control/send/widget.rs deleted file mode 100644 index 4df393ad..00000000 --- a/src/app/browser/window/tab/item/page/input/response/control/send/widget.rs +++ /dev/null @@ -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); - } -}