use super::grid;
use super::pack;
use super::widget;
use super::wish;
#[derive(Clone, Debug, PartialEq)]
pub struct TkScale {
pub id: String,
}
pub fn make_scale(parent: &impl widget::TkWidget, orientation: widget::Orientation) -> TkScale {
let id = wish::next_wid(parent.id());
let msg = format!("ttk::scale {} -orient {}", id, orientation);
wish::tell_wish(&msg);
TkScale { id }
}
impl widget::TkWidget for TkScale {
fn id(&self) -> &str {
&self.id
}
}
impl grid::TkGridLayout for TkScale {}
impl pack::TkPackLayout for TkScale {}
impl TkScale {
pub fn command(&self, command: impl Fn(f64) + Send + 'static) {
wish::add_callback1_float(&self.id, wish::mk_callback1_float(command));
let msg = format!(
"{} configure -command [list scale_value {}]",
self.id, self.id
);
wish::tell_wish(&msg);
}
pub fn from(&self, value: f64) {
widget::configure(&self.id, "from", &value.to_string());
}
pub fn to(&self, value: f64) {
widget::configure(&self.id, "to", &value.to_string());
}
pub fn value_get(&self) -> f64 {
let msg = format!("puts [{} get] ; flush stdout", self.id);
let result = wish::ask_wish(&msg);
result.parse::<f64>().unwrap_or(0.0)
}
pub fn value(&self, value: f64) {
widget::configure(&self.id, "value", &value.to_string());
}
pub fn length(&self, value: u64) {
widget::configure(&self.id, "length", &value.to_string());
}
pub fn state(&self, value: widget::State) {
widget::configure(&self.id, "state", &value.to_string());
}
}