1use bevy::prelude::*;
3use wde_renderer::prelude::{Texture, WdeColor};
4
5use crate::style::UiStyle;
6
7#[derive(Component, Clone, Default, Debug)]
11#[require(ComputedUiNode)]
12pub struct UiNode(pub UiStyle);
13
14#[derive(Component, Clone, Copy, Default, Debug, PartialEq)]
16pub struct ComputedUiNode {
17 pub position: Vec2,
19 pub size: Vec2,
20 pub border: Vec4,
22 pub padding: Vec4,
24 pub order: u32
26}
27impl ComputedUiNode {
28 pub fn rect(&self) -> Rect {
29 Rect::from_corners(self.position, self.position + self.size)
30 }
31}
32
33#[derive(Component, Clone, Copy, Debug)]
36pub struct UiBackground(pub WdeColor);
37
38#[derive(Component, Clone, Copy, Debug)]
40pub struct UiBorderColor(pub WdeColor);
41
42#[derive(Component, Clone, Copy, Default, Debug)]
44pub struct UiCornerRadius(pub f32);
45
46#[derive(Component, Clone, Debug)]
49pub struct UiImage {
50 pub texture: Handle<Texture>,
51 pub tint: WdeColor
53}
54impl UiImage {
55 pub fn new(texture: Handle<Texture>) -> Self {
56 Self {
57 texture,
58 tint: WdeColor::WHITE
59 }
60 }
61 pub fn with_tint(self, tint: WdeColor) -> Self {
62 Self { tint, ..self }
63 }
64}