checkbox.rs
use iced::widget::{button, text, Button};
use inflorescence_model::to_record;
use crate::Theme;
pub const WIDTH: u32 = 31;
const TO_RECORD_LABEL_INCLUDE: &str = "■";
const TO_RECORD_LABEL_EXCLUDE: &str = "□";
const TO_RECORD_LABEL_PARTIAL: &str = "▤";
/// A checkbox with three possible states
pub fn three_way<'a, M>(state: to_record::PickSet) -> Button<'a, M, Theme>
where
M: 'a,
{
let label = match state {
to_record::PickSet::Include => TO_RECORD_LABEL_INCLUDE,
to_record::PickSet::Exclude => TO_RECORD_LABEL_EXCLUDE,
to_record::PickSet::Partial => TO_RECORD_LABEL_PARTIAL,
};
checkbox_btn(label)
}
/// A checkbox with two possible states
pub fn two_way<'a, M>(state: to_record::Pick) -> Button<'a, M, Theme>
where
M: 'a,
{
let label = match state {
to_record::Pick::Include => TO_RECORD_LABEL_INCLUDE,
to_record::Pick::Exclude => TO_RECORD_LABEL_EXCLUDE,
};
checkbox_btn(label)
}
fn checkbox_btn<'a, M>(label: &'a str) -> Button<'a, M, Theme>
where
M: 'a,
{
button(
text(label)
.size(21)
.shaping(text::Shaping::Advanced)
.center()
.wrapping(text::Wrapping::None),
)
.width(WIDTH)
.height(31)
.padding(0)
}