subspace-dashboard 0.2.0

Subspace Framework board kit: the Dashboard trait, shared widgets and design tokens. Internal crate; apps depend on `subspace-framework`.
Documentation
//! Scrolling detail content and the optional fixed footer below it.

use gpui_kit::component::v_flex;
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::{
    AnyElement, Div, InteractiveElement as _, IntoElement, ParentElement as _, ScrollHandle,
    StatefulInteractiveElement as _, Styled as _, div, px,
};

const TOP_PADDING_PX: f32 = 16.;
const SIDE_PADDING_PX: f32 = 20.;
/// Keeps the last line clear of the panel edge.
const BOTTOM_PADDING_PX: f32 = 48.;
const FOOTER_GAP_PX: f32 = 8.;

/// Scrolling panel content with an optional fixed footer, such as a chat composer.
pub struct PanelBody {
    pub content: AnyElement,
    pub footer: Option<AnyElement>,
    pub scroll: Option<ScrollHandle>,
    /// The content supplies its own bounded viewport; the frame must not scroll.
    pub content_owns_scroll: bool,
}

impl<E: IntoElement> From<E> for PanelBody {
    fn from(content: E) -> Self {
        Self {
            content: content.into_any_element(),
            footer: None,
            scroll: None,
            content_owns_scroll: false,
        }
    }
}

pub(super) fn render(body: PanelBody) -> Div {
    let bottom_padding = if body.footer.is_some() {
        FOOTER_GAP_PX
    } else {
        BOTTOM_PADDING_PX
    };
    let scroll = div()
        .id("detail-body")
        .flex_1()
        .min_h_0()
        .map(|pane| {
            if body.content_owns_scroll {
                pane.flex().flex_col().overflow_hidden()
            } else {
                pane.overflow_y_scroll()
                    .when_some(body.scroll, |pane, scroll| pane.track_scroll(&scroll))
            }
        })
        .pt(px(TOP_PADDING_PX))
        .px(px(SIDE_PADDING_PX))
        .pb(px(bottom_padding))
        .child(body.content);
    v_flex()
        .flex_1()
        .min_h_0()
        .overflow_hidden()
        .child(scroll)
        .children(
            body.footer
                .map(|footer| div().flex_shrink_0().child(footer)),
        )
}