Skip to main content

teksilo_core/styles/
icon_button_style.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! Tier-3 style protocol for `IconButton`. See `docs/styling-system.md`.
5
6use std::rc::Rc;
7
8use serde::{Deserialize, Serialize};
9
10use crate::build_context::BuildContext;
11use crate::signal::Signal;
12use crate::widget_id::WidgetId;
13
14/// Five sizes calibrated to the IntelliJ Int UI scale. Apps usually
15/// pick one per call; the active style maps each to a (square_size,
16/// icon_size) pair from its recipe.
17#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default, Serialize, Deserialize)]
18pub enum IconButtonSize {
19    Compact,
20    #[default]
21    Default,
22    Toolbar,
23    Large,
24    Hero,
25}
26
27#[derive(Clone, Debug)]
28pub struct IconButtonStyleConfig {
29    /// Pre-built icon subtree (color-bound by the host widget so the
30    /// style stays neutral on icon coloring policy — embedded vs
31    /// standalone vs caller override).
32    pub icon: WidgetId,
33    pub is_pressed: Signal<bool>,
34    pub is_hovered: Signal<bool>,
35    pub is_focused: Signal<bool>,
36    pub is_disabled: Signal<bool>,
37    /// Bistate-toggle source. When present, the style paints the
38    /// `Selected` surface tint while `is_on == true`; absent → plain
39    /// flat treatment for every state.
40    pub is_on: Option<Signal<bool>>,
41    pub size: IconButtonSize,
42}
43
44pub trait IconButtonStyle: 'static {
45    fn make_body(&self, cfg: &IconButtonStyleConfig, ctx: &mut BuildContext) -> WidgetId;
46}
47
48pub type SharedIconButtonStyle = Rc<dyn IconButtonStyle>;