use super::grid;
use super::pack;
use super::widget;
use super::wish;
#[derive(Clone, Debug, PartialEq)]
pub struct TkButton {
pub id: String,
}
pub fn make_button(parent: &impl widget::TkWidget) -> TkButton {
let id = wish::next_wid(parent.id());
let msg = format!("ttk::button {}", id);
wish::tell_wish(&msg);
TkButton { id }
}
impl widget::TkWidget for TkButton {
fn id(&self) -> &str {
&self.id
}
}
impl grid::TkGridLayout for TkButton {}
impl pack::TkPackLayout for TkButton {}
impl widget::TkLabelOptions for TkButton {}
impl TkButton {
pub fn command(&self, command: impl Fn() + Send + 'static) {
wish::add_callback0(&self.id, wish::mk_callback0(command));
let msg = format!(
"{} configure -command {{ puts clicked-{} ; flush stdout }}",
self.id, self.id
);
wish::tell_wish(&msg);
}
pub fn invoke(&self) {
let msg = format!("{} invoke", self.id);
wish::tell_wish(&msg);
}
pub fn state(&self, value: widget::State) {
widget::configure(&self.id, "state", &value.to_string());
}
}