swoop_ui/button/
text_button.rs1use bevy_color::prelude::*;
2use bevy_ecs::prelude::*;
3use bevy_math::prelude::*;
4use bevy_ui::prelude::*;
5
6use crate::background::BackgroundStyle;
7use crate::border::{BorderStyle, BorderView};
8use crate::prelude::{BackgroundView, PositionView, StackView};
9use crate::shadow::{BoxShadowView, TextShadowView};
10use crate::text::{TextStyle, TextView};
11use crate::{View, ViewToBundle};
12
13#[derive(Debug, Clone)]
37pub struct TextButton {
38 name: Name,
40
41 node: Node,
43
44 botton: Button,
46
47 border: BorderStyle,
49
50 background: BackgroundStyle,
52
53 box_shadow: BoxShadow,
55
56 text: TextStyle,
58
59 text_shadow: TextShadow,
61}
62
63impl Default for TextButton {
64 fn default() -> Self {
65 Self {
66 name: Name::new("TextButton"),
67 node: Node {
68 display: Display::Flex,
69 flex_direction: FlexDirection::Row,
70 justify_content: JustifyContent::Center,
71 align_items: AlignItems::Center,
72 column_gap: Val::Px(0.0),
73 ..Default::default()
74 },
75 botton: Button,
76 border: BorderStyle::button(),
77 background: BackgroundStyle::button(),
78 box_shadow: BoxShadow::default(),
79 text: TextStyle::button(),
80 text_shadow: TextShadow {
81 offset: Vec2::ZERO,
82 color: Srgba::NONE.into(),
83 },
84 }
85 }
86}
87
88impl View for TextButton {
89 fn name_node(&mut self) -> &mut Name {
90 &mut self.name
91 }
92
93 fn node_node(&mut self) -> &mut Node {
94 &mut self.node
95 }
96}
97
98impl ViewToBundle for TextButton {
99 fn pack(self) -> impl Bundle {
100 (
101 self.name,
102 self.node,
103 self.botton,
104 self.border,
105 self.background,
106 self.box_shadow,
107 children![self.text, self.text_shadow],
108 )
109 }
110}
111
112impl StackView for TextButton {}
113
114impl BackgroundView for TextButton {
115 fn background_node(&mut self) -> &mut BackgroundStyle {
116 &mut self.background
117 }
118}
119
120impl BorderView for TextButton {
121 fn border_node(&mut self) -> &mut BorderStyle {
122 &mut self.border
123 }
124}
125
126impl BoxShadowView for TextButton {
127 fn box_shadow_node(&mut self) -> &mut BoxShadow {
128 &mut self.box_shadow
129 }
130}
131
132impl TextView for TextButton {
133 fn text_node(&mut self) -> &mut crate::text::TextStyle {
134 &mut self.text
135 }
136}
137
138impl TextShadowView for TextButton {
139 fn text_shadow_node(&mut self) -> &mut TextShadow {
140 &mut self.text_shadow
141 }
142}
143
144impl PositionView for TextButton {}