Newer
Older
use bevy::prelude::*;
use kayak_font::Alignment;
use crate::{
context::{Mounted, WidgetName},
prelude::WidgetContext,
styles::{KStyle, RenderCommand, StyleProp},
widget::Widget,
/// 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.
///
impl Default for TextProps {
fn default() -> Self {
#[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(),
styles: Default::default(),
widget_name: TextProps::default().get_name(),
}
}
pub fn text_update(
In((_, entity)): In<(WidgetContext, Entity)>,
mut query: Query<(&mut KStyle, &TextProps), Or<(Changed<TextProps>, With<Mounted>)>>,
) -> bool {
if let Ok((mut style, text)) = query.get_mut(entity) {
style.render_command = StyleProp::Value(RenderCommand::Text {
content: text.content.clone(),
alignment: text.alignment,
});
if let Some(ref font) = text.font {
style.font = StyleProp::Value(font.clone());
}
// if text.show_cursor {
// style.cursor = StyleProp::Value(CursorIcon::Text);
// }
if text.size >= 0.0 {
style.font_size = StyleProp::Value(text.size);
}
if let Some(line_height) = text.line_height {
style.line_height = StyleProp::Value(line_height);
}
// style.cursor = CursorIcon::Hand.into();
return true;