use super::grid;
use super::pack;
use super::widget;
use super::wish;
#[derive(Clone, Debug, PartialEq)]
pub struct TkRadioButton {
pub id: String,
var: String,
}
pub fn make_radio_button(
parent: &impl widget::TkWidget,
group: &str,
value: &str,
) -> TkRadioButton {
let id = wish::next_wid(parent.id());
let var = format!("::rb_group_{}", group);
let msg = format!("ttk::radiobutton {} -value {} -variable {}", id, value, var);
wish::tell_wish(&msg);
TkRadioButton { id, var }
}
impl widget::TkWidget for TkRadioButton {
fn id(&self) -> &str {
&self.id
}
}
impl grid::TkGridLayout for TkRadioButton {}
impl pack::TkPackLayout for TkRadioButton {}
impl widget::TkLabelOptions for TkRadioButton {}
impl TkRadioButton {
pub fn command(&self, command: impl Fn(bool) + Send + 'static) {
wish::add_callback1_bool(&self.id, wish::mk_callback1_bool(command));
let msg = format!(
"{} configure -command {{ puts cb1-{}-${} ; flush stdout }}",
self.id, self.id, self.var
);
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());
}
pub fn value_get(&self) -> String {
let msg = format!("puts ${} ; flush stdout", self.var);
wish::ask_wish(&msg)
}
pub fn value(&self, value: &str) {
let msg = format!("set {} {}", self.var, value);
wish::tell_wish(&msg);
}
}