|
| 1 | +use bevy_ecs::hierarchy::Children; |
| 2 | +use bevy_scene::{bsn, Scene}; |
| 3 | +use bevy_text::FontWeight; |
| 4 | +use bevy_ui::{ |
| 5 | + px, AlignItems, AlignSelf, Display, FlexDirection, JustifyContent, Node, PositionType, UiRect, |
| 6 | + Val, |
| 7 | +}; |
| 8 | + |
| 9 | +use crate::{ |
| 10 | + constants::{fonts, size}, |
| 11 | + font_styles::InheritableFont, |
| 12 | + rounded_corners::RoundedCorners, |
| 13 | + theme::{ThemeBackgroundColor, ThemeBorderColor, ThemeFontColor}, |
| 14 | + tokens, |
| 15 | +}; |
| 16 | + |
| 17 | +/// A standard pane |
| 18 | +pub fn pane() -> impl Scene { |
| 19 | + bsn! { |
| 20 | + Node { |
| 21 | + display: Display::Flex, |
| 22 | + flex_direction: FlexDirection::Column, |
| 23 | + align_items: AlignItems::Stretch, |
| 24 | + } |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +/// Pane header |
| 29 | +pub fn pane_header() -> impl Scene { |
| 30 | + bsn! { |
| 31 | + Node { |
| 32 | + display: Display::Flex, |
| 33 | + flex_direction: FlexDirection::Row, |
| 34 | + align_items: AlignItems::Center, |
| 35 | + justify_content: JustifyContent::SpaceBetween, |
| 36 | + padding: UiRect::axes(Val::Px(6.0), Val::Px(6.0)), |
| 37 | + border: UiRect { |
| 38 | + left: Val::Px(1.0), |
| 39 | + top: Val::Px(1.0), |
| 40 | + right: Val::Px(1.0), |
| 41 | + bottom: Val::Px(0.0), |
| 42 | + }, |
| 43 | + min_height: size::HEADER_HEIGHT, |
| 44 | + column_gap: Val::Px(6.0), |
| 45 | + border_radius: {RoundedCorners::Top.to_border_radius(4.0)}, |
| 46 | + } |
| 47 | + ThemeBackgroundColor(tokens::PANE_HEADER_BG) |
| 48 | + ThemeBorderColor(tokens::PANE_HEADER_BORDER) |
| 49 | + ThemeFontColor(tokens::PANE_HEADER_TEXT) |
| 50 | + InheritableFont { |
| 51 | + font: fonts::REGULAR, |
| 52 | + font_size: size::MEDIUM_FONT, |
| 53 | + weight: FontWeight::NORMAL, |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +/// Vertical divider between groups of widgets in pane headers |
| 59 | +pub fn pane_header_divider() -> impl Scene { |
| 60 | + bsn! { |
| 61 | + Node { |
| 62 | + width: Val::Px(1.0), |
| 63 | + align_self: AlignSelf::Stretch, |
| 64 | + } |
| 65 | + Children [( |
| 66 | + // Because we want to extend the divider into the header padding area, we'll use |
| 67 | + // an absolutely-positioned child. |
| 68 | + Node { |
| 69 | + position_type: PositionType::Absolute, |
| 70 | + left: px(0), |
| 71 | + right: px(0), |
| 72 | + top: {px(-6)}, |
| 73 | + bottom: {px(-6)}, |
| 74 | + } |
| 75 | + ThemeBackgroundColor(tokens::PANE_HEADER_DIVIDER) |
| 76 | + )] |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +/// Pane body |
| 81 | +pub fn pane_body() -> impl Scene { |
| 82 | + bsn! { |
| 83 | + Node { |
| 84 | + display: Display::Flex, |
| 85 | + flex_direction: FlexDirection::Column, |
| 86 | + row_gap: px(4.0), |
| 87 | + padding: UiRect::axes(Val::Px(6.0), Val::Px(6.0)), |
| 88 | + border_radius: {RoundedCorners::Bottom.to_border_radius(4.0)} |
| 89 | + } |
| 90 | + ThemeBackgroundColor(tokens::PANE_BODY_BG) |
| 91 | + } |
| 92 | +} |
0 commit comments