Newer
Older
/// Props used by the [`Text`] widget
#[derive(WidgetProps, 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.
///
/// This _will_ override `cursor` values set by styles.
pub show_cursor: bool,
#[prop_field(OnLayout)]
pub on_layout: Option<OnLayout>,
pub focusable: Option<bool>,
}
impl Default for TextProps {
fn default() -> Self {
/// A widget that renders plain text
///
/// # Props
///
/// __Type:__ [`TextProps`]
///
/// | Common Prop | Accepted |
/// | :---------: | :------: |
/// | `children` | ❌ |
/// | `styles` | ✅ |
/// | `on_event` | ✅ |
/// | `on_layout` | ✅ |
let mut styles = Style {
render_command: StyleProp::Value(RenderCommand::Text {
content: props.content.clone(),
}),
..Default::default()
};
if let Some(ref font) = props.font {
styles.font = StyleProp::Value(font.clone());
}
if props.show_cursor {
styles.cursor = StyleProp::Value(CursorIcon::Text);
}
if props.size >= 0.0 {
styles.font_size = StyleProp::Value(props.size);
if let Some(line_height) = props.line_height {
styles.line_height = StyleProp::Value(line_height);
}
props.styles = Some(styles.with_style(&props.styles));