Newer
Older
use bevy::prelude::*;
use kayak_font::Alignment;
use crate::{
prelude::KayakWidgetContext,
styles::{KCursorIcon, KStyle, RenderCommand, StyleProp, Units},
#[derive(Component, Debug, PartialEq, Clone)]
/// The name of the font to use
///
/// The given font must already be loaded into the [`KayakContext`](kayak_core::KayakContext)
/// The height of a line of text (currently in pixels)
/// If true, displays the default text cursor when hovered.
///
/// Custom styles to pass in.
pub user_styles: KStyle,
/// Basic word wrapping.
/// Defautls to true
pub word_wrap: bool,
impl Default for TextProps {
fn default() -> Self {
user_styles: Default::default(),
/// A widget that renders text
///
#[derive(Bundle)]
pub struct TextWidgetBundle {
pub text: TextProps,
pub styles: KStyle,
pub widget_name: WidgetName,
}
impl Default for TextWidgetBundle {
fn default() -> Self {
Self {
text: Default::default(),
width: Units::Stretch(1.0).into(),
height: Units::Stretch(1.0).into(),
..Default::default()
},
In((_widget_context, entity)): In<(KayakWidgetContext, Entity)>,
mut query: Query<(&mut KStyle, &TextProps)>,
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
if let Ok((mut styles, text)) = query.get_mut(entity) {
*styles = KStyle::default()
.with_style(&text.user_styles)
.with_style(KStyle {
render_command: StyleProp::Value(RenderCommand::Text {
content: text.content.clone(),
alignment: text.alignment,
word_wrap: text.word_wrap,
}),
font: if let Some(ref font) = text.font {
StyleProp::Value(font.clone())
} else {
StyleProp::default()
},
cursor: if text.show_cursor {
StyleProp::Value(KCursorIcon(CursorIcon::Text))
} else {
StyleProp::default()
},
font_size: if text.size >= 0.0 {
StyleProp::Value(text.size)
} else {
StyleProp::default()
},
line_height: if let Some(line_height) = text.line_height {
StyleProp::Value(line_height)
} else {
StyleProp::default()
},
// bottom: Units::Stretch(1.0).into(),
// top: Units::Stretch(1.0).into(),
// left: Units::Stretch(0.0).into(),
// right: Units::Stretch(0.0).into(),
..Default::default()
});
// style.cursor = StyleProp::Value(KCursorIcon(CursorIcon::Hand));