use teksilo_core::build_context::BuildContext;
use teksilo_core::styles::{DateEditStyle, DateEditStyleConfig, SharedDateEditStyle};
use teksilo_core::widget_id::WidgetId;
pub const CALENDAR_BUTTON_WIDTH: f32 = 24.0;
pub const CALENDAR_ICON_SIZE: f32 = 14.0;
pub const SEGMENT_GAP: f32 = 1.0;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DateEditRecipe {
pub calendar_button_width: f32,
pub calendar_icon_size: f32,
pub segment_gap: f32,
}
impl Default for DateEditRecipe {
fn default() -> Self {
Self {
calendar_button_width: CALENDAR_BUTTON_WIDTH,
calendar_icon_size: CALENDAR_ICON_SIZE,
segment_gap: SEGMENT_GAP,
}
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct RecipeDateEditStyle {
pub recipe: DateEditRecipe,
}
impl RecipeDateEditStyle {
pub fn new(recipe: DateEditRecipe) -> Self {
Self { recipe }
}
}
impl DateEditStyle for RecipeDateEditStyle {
fn make_body(&self, cfg: &DateEditStyleConfig, _ctx: &mut BuildContext) -> WidgetId {
cfg.body
}
}
pub fn resolve_date_edit_style(
override_: &Option<SharedDateEditStyle>,
ctx: &BuildContext,
) -> SharedDateEditStyle {
if let Some(s) = override_.clone() {
return s;
}
ctx.theme_signal()
.get()
.style_slots
.date_edit
.clone()
.unwrap_or_else(|| std::rc::Rc::new(RecipeDateEditStyle::default()) as SharedDateEditStyle)
}