diff --git a/src/context.rs b/src/context.rs index 4cac17487e7d4c9e2b924d9c588b43f0d2909f98..0d88087bbce52f6968339a7a58e91b8713d7acde 100644 --- a/src/context.rs +++ b/src/context.rs @@ -343,7 +343,7 @@ fn recurse_node_tree_to_build_primitives( let mut render_primitive = node.primitive.clone(); let mut new_z_index = main_z_index; - let _layout = if let Some(layout) = layout_cache.rect.get_mut(¤t_node) { + let layout = if let Some(layout) = layout_cache.rect.get_mut(¤t_node) { log::trace!( "z_index is {} and node.z is {} for: {}-{}", new_z_index, @@ -388,9 +388,10 @@ fn recurse_node_tree_to_build_primitives( } RenderPrimitive::Empty => { log::trace!( - "Empty node: {}-{}", + "Empty node: {}-{} is equal to: {:?}", widget_names.get(current_node.0).unwrap().0, current_node.0.index(), + layout ); } _ => {} diff --git a/src/widgets/text.rs b/src/widgets/text.rs index a7f8ce2dfbd2ced1c328ccd55565dedc81aeb980..574c7c0324fbcd770360f758257be9548683e9ca 100644 --- a/src/widgets/text.rs +++ b/src/widgets/text.rs @@ -1,16 +1,13 @@ use bevy::prelude::*; use kayak_font::Alignment; -use kayak_ui_macros::rsx; use crate::{ context::WidgetName, prelude::KayakWidgetContext, - styles::{KCursorIcon, KStyle, RenderCommand, StyleProp}, + styles::{KCursorIcon, KStyle, RenderCommand, StyleProp, Units}, widget::Widget, }; -use super::ElementBundle; - #[derive(Component, Debug, PartialEq, Clone)] pub struct TextProps { /// The string to display @@ -69,6 +66,8 @@ impl Default for TextWidgetBundle { Self { text: Default::default(), styles: KStyle { + width: Units::Stretch(1.0).into(), + height: Units::Stretch(1.0).into(), ..Default::default() }, widget_name: TextProps::default().get_name(), @@ -77,52 +76,46 @@ impl Default for TextWidgetBundle { } pub fn text_render( - In((widget_context, entity)): In<(KayakWidgetContext, Entity)>, - mut commands: Commands, - mut query: Query<&TextProps>, + In((_widget_context, entity)): In<(KayakWidgetContext, Entity)>, + mut query: Query<(&mut KStyle, &TextProps)>, ) -> bool { - if let Ok(text) = query.get_mut(entity) { - let mut style = KStyle::default(); - - style = style.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() - }); + 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)); - - let parent_id = Some(entity); - rsx! { - <ElementBundle styles={style} /> - } } true