freya-devtools-app 0.4.0-rc.16

Devtools App for Freya app
use freya::prelude::*;
use torin::gaps::Gaps;

fn gap_label(tooltip_text: &'static str, value: f32) -> impl IntoElement {
    TooltipContainer::new(Tooltip::new(tooltip_text)).child(
        label()
            .text_align(TextAlign::Center)
            .width(Size::px(25.))
            .height(Size::px(25.))
            .text(format!("{value}")),
    )
}

pub fn computed_layout(inner_area: String, padding: Gaps, margin: Gaps) -> impl IntoElement {
    rect().width(Size::fill()).max_width(Size::px(300.)).child(
        rect()
            .width(Size::fill())
            .height(Size::px(220.))
            .main_align(Alignment::center())
            .cross_align(Alignment::center())
            .background((40, 40, 40))
            .content(Content::Flex)
            .corner_radius(CornerRadius::new_all(5.))
            .child(gap_label("Top margin", margin.top()))
            .child(
                rect()
                    .direction(Direction::Horizontal)
                    .height(Size::flex(1.))
                    .width(Size::fill())
                    .cross_align(Alignment::center())
                    .content(Content::Flex)
                    .child(gap_label("Left margin", margin.left()))
                    .child(
                        rect()
                            .width(Size::flex(1.))
                            .height(Size::fill())
                            .content(Content::Flex)
                            .cross_align(Alignment::Center)
                            .background((71, 180, 240))
                            .corner_radius(CornerRadius::new_all(5.))
                            .child(gap_label("Top padding", padding.top()))
                            .child(
                                rect()
                                    .direction(Direction::Horizontal)
                                    .height(Size::flex(1.))
                                    .content(Content::Flex)
                                    .cross_align(Alignment::center())
                                    .child(gap_label("Left padding", padding.left()))
                                    .child(
                                        rect()
                                            .width(Size::flex(1.))
                                            .height(Size::fill())
                                            .main_align(Alignment::center())
                                            .cross_align(Alignment::center())
                                            .background((40, 40, 40))
                                            .corner_radius(CornerRadius::new_all(5.))
                                            .child(
                                                TooltipContainer::new(Tooltip::new("Inner area"))
                                                    .child(label().text(inner_area)),
                                            ),
                                    )
                                    .child(gap_label("Right padding", padding.right())),
                            )
                            .child(gap_label("Bottom padding", padding.bottom())),
                    )
                    .child(gap_label("Right margin", margin.right())),
            )
            .child(gap_label("Bottom margin", margin.bottom())),
    )
}