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
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2026 FernTech
//! Tier-3 style protocol for `Toggle`. See `docs/styling-system.md`.
use std::rc::Rc;
use serde::{Deserialize, Serialize};
use crate::build_context::BuildContext;
use crate::signal::Signal;
use crate::widget_id::WidgetId;
/// Toggle visual archetype. Most styles compose Switch; the others
/// give designers explicit alternates without forking the widget.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default, Serialize, Deserialize)]
pub enum ToggleVariant {
/// Capsule track + circular knob that slides on (the IntUI default
/// and most other 2026-era look-and-feels).
#[default]
Switch,
/// Pill-shaped track without a sliding knob — a colored / muted
/// fill toggles instead.
Pill,
/// Square track with a square knob (brutalist / 8-bit aesthetic).
Square,
/// Inset toggle — the entire control is a flat surface that
/// recesses on activation.
Inset,
}
#[derive(Clone, Debug)]
pub struct ToggleStyleConfig {
/// Whether the toggle is currently on. The style usually animates
/// the knob position from this signal directly via
/// [`Signal::animate_to`](crate::signal::Signal).
pub is_on: Signal<bool>,
pub is_hovered: Signal<bool>,
/// Pointer-pressed (down). IntUI ignores it; design languages with
/// press feedback (e.g. the Material 3 switch thumb-grow) read it.
pub is_pressed: Signal<bool>,
pub is_focused: Signal<bool>,
/// Input-modality "focus-visible": `true` after keyboard input. The focus
/// ring shows only when this and `is_focused` are both true, so a pointer
/// click focuses without a ring while keyboard navigation reveals one.
pub is_focus_visible: Signal<bool>,
pub is_disabled: Signal<bool>,
pub variant: ToggleVariant,
}
pub trait ToggleStyle: 'static {
fn make_body(&self, cfg: &ToggleStyleConfig, ctx: &mut BuildContext) -> WidgetId;
}
pub type SharedToggleStyle = Rc<dyn ToggleStyle>;