mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
remove extra folding
This commit is contained in:
parent
dea9669d3c
commit
ba965814eb
5 changed files with 45 additions and 101 deletions
|
|
@ -25,7 +25,7 @@ impl Control {
|
||||||
let send = Rc::new(Send::build(action_send));
|
let send = Rc::new(Send::build(action_send));
|
||||||
|
|
||||||
// Init widget
|
// 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
|
// Return activated struct
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
mod widget;
|
use gtk::{prelude::WidgetExt, Label};
|
||||||
|
|
||||||
use widget::Widget;
|
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub struct Counter {
|
pub struct Counter {
|
||||||
pub widget: Rc<Widget>,
|
pub label: Label,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Counter {
|
impl Default for Counter {
|
||||||
|
|
@ -18,12 +14,28 @@ impl Counter {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
widget: Rc::new(Widget::new()),
|
label: Label::builder().build(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, is_empty: bool, bytes_left: Option<isize>) {
|
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),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
mod widget;
|
use gtk::{
|
||||||
use widget::Widget;
|
gio::SimpleAction,
|
||||||
|
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||||
use gtk::gio::SimpleAction;
|
Button,
|
||||||
use std::rc::Rc;
|
};
|
||||||
|
|
||||||
pub struct Send {
|
pub struct Send {
|
||||||
pub widget: Rc<Widget>,
|
pub button: Button,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Send {
|
impl Send {
|
||||||
|
|
@ -13,15 +13,28 @@ impl Send {
|
||||||
|
|
||||||
/// Build new `Self`
|
/// Build new `Self`
|
||||||
pub fn build(action_send: SimpleAction) -> Self {
|
pub fn build(action_send: SimpleAction) -> Self {
|
||||||
// Init widget
|
// Init main widget
|
||||||
let widget = Rc::new(Widget::build(action_send));
|
let button = Button::builder()
|
||||||
|
.css_classes(["accent"]) // | `suggested-action`
|
||||||
|
.label("Send")
|
||||||
|
.sensitive(false)
|
||||||
|
.build();
|
||||||
|
|
||||||
// Result
|
// Init events
|
||||||
Self { widget }
|
button.connect_clicked({
|
||||||
|
move |this| {
|
||||||
|
this.set_sensitive(false);
|
||||||
|
this.set_label("Sending..");
|
||||||
|
action_send.activate(None);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Return activated `Self`
|
||||||
|
Self { button }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, is_sensitive: bool) {
|
pub fn update(&self, is_sensitive: bool) {
|
||||||
self.widget.update(is_sensitive);
|
self.button.set_sensitive(is_sensitive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue