mod counter;
mod send;
mod widget;
use counter::Counter;
use send::Send;
use widget::Widget;
use gtk::{gio::SimpleAction, Box};
use std::sync::Arc;
pub struct Control {
counter: Arc<Counter>,
send: Arc<Send>,
widget: Arc<Widget>,
}
impl Control {
pub fn new_arc(action_send: SimpleAction) -> Arc<Self> {
let counter = Counter::new_arc();
let send = Send::new_arc(action_send);
let widget = Widget::new_arc(counter.gobject(), send.gobject());
Arc::new(Self {
counter,
send,
widget,
})
}
pub fn update(&self, chars_left: Option<i32>) {
self.counter.update(chars_left);
self.send.update(match chars_left {
Some(left) => left > 0,
None => false,
});
}
pub fn gobject(&self) -> &Box {
&self.widget.gobject()
}
}