Skip to main content

teksilo_widgets/styles/
recipe_list_container_style.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! Default `ListContainerStyle` impl.
5//!
6//! IntUI's list/tree container chrome is just the drag-insertion
7//! indicator. The recipe ships a `RectWidget`-leaf factory for
8//! custom recipes that want a composed indicator, and a
9//! `ListInsertionRecipe` (`BorderRole::Accent`, 2 dp thickness) for
10//! the inline paint path the widgets use today.
11
12use teksilo_core::build_context::BuildContext;
13use teksilo_core::styles::{
14    ListContainerStyle, ListInsertionConfig, ListInsertionRecipe, SharedListContainerStyle,
15};
16use teksilo_core::widget_id::WidgetId;
17use teksilo_tokens::{BorderRole, InputTokens};
18
19use crate::primitives::RectWidget;
20
21/// Default `ListContainerStyle` shipped with Teksilo.
22#[derive(Debug, Default, Clone, Copy)]
23pub struct RecipeListContainerStyle;
24
25impl RecipeListContainerStyle {
26    /// This style resolved against a density's [`InputTokens`], as
27    /// `RecipeListContainerStyle::for_tokens(&ctx.theme().input)` at the widget's own
28    /// build site.
29    ///
30    /// The style is a unit struct carrying one decoration — the 2 dp
31    /// insertion bar — so the projection is the identity at every density.
32    pub fn for_tokens(_tokens: &InputTokens) -> Self {
33        Self
34    }
35}
36
37impl ListContainerStyle for RecipeListContainerStyle {
38    fn make_insertion_indicator(
39        &self,
40        cfg: &ListInsertionConfig,
41        ctx: &mut BuildContext,
42    ) -> WidgetId {
43        // Reference shape: a `width × 2` accent-coloured rect.
44        // Custom container styles may install a different leaf.
45        let _ = cfg.axis_offset; // positioned by the container's place_children
46        let _ = cfg.width;
47        ctx.add(RectWidget::new().background(BorderRole::Accent))
48    }
49
50    fn insertion(&self) -> ListInsertionRecipe {
51        ListInsertionRecipe::default()
52    }
53}
54
55pub fn resolve_list_container_style(
56    override_: &Option<SharedListContainerStyle>,
57    ctx: &BuildContext,
58) -> SharedListContainerStyle {
59    if let Some(s) = override_.clone() {
60        return s;
61    }
62    ctx.theme_signal()
63        .get()
64        .style_slots
65        .list_container
66        .clone()
67        .unwrap_or_else(|| std::rc::Rc::new(RecipeListContainerStyle) as SharedListContainerStyle)
68}