1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
//! Notebook widget - a container widget which contains multiple panes, but
//! displays one pane at a time.
//!
//! * also see the Tk [manual](https://www.tcl-lang.org/man/tcl8.6/TkCmd/ttk_notebook.htm)
//!
//! # Events
//!
//! Use [bind](widget::TkWidget::bind) to call a function on following event:
//!
//! * `<<NotebookTabChanged>>` - when new tab selected
use super::grid;
use super::pack;
use super::widget;
use super::wish;
/// Refers to a notebook widget
#[derive(Clone, Debug, PartialEq)]
pub struct TkNotebook {
pub id: String,
}
/// Creates an instance of a notebook in given parent.
pub fn make_notebook(parent: &impl widget::TkWidget) -> TkNotebook {
let id = wish::next_wid(parent.id());
let msg = format!("ttk::notebook {}", id);
wish::tell_wish(&msg);
TkNotebook { id }
}
impl widget::TkWidget for TkNotebook {
/// Returns the widget's id reference - used within tk
fn id(&self) -> &str {
&self.id
}
}
impl grid::TkGridLayout for TkNotebook {}
impl pack::TkPackLayout for TkNotebook {}
impl TkNotebook {
/// TODO: use builder pattern to support images+text
pub fn add(&self, widget: &impl widget::TkWidget, title: &str) {
let msg = format!("{} add {} -text {{{}}}", self.id, widget.id(), title);
wish::tell_wish(&msg);
}
/// Height of notebook, in rows
pub fn height(&self, height: u64) {
widget::configure(&self.id, "height", &height.to_string());
}
/// Sets space around the widget. Takes
/// an array of up to four values, specifying:
///
/// * \[all]
/// * [left-right top-bottom]
/// * [left top-bottom right]
/// * [left top right bottom]
pub fn padding(&self, values: &[u64]) {
widget::padding(&self.id, values);
}
/// Width of notebook, in columns
pub fn width(&self, width: u64) {
widget::configure(&self.id, "width", &width.to_string());
}
}