1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
use super::internal;
use crate::prelude::*;
/// Modifiers for changing the text properties of a view.
pub trait TextModifiers: internal::Modifiable {
/// Sets the text content of the view.
fn text<T: ToStringLocalized>(mut self, value: impl Res<T>) -> Self {
let entity = self.entity();
let current = self.current();
self.context().with_current(current, |cx| {
value.set_or_bind(cx, entity, move |cx, val| {
let cx: &mut EventContext<'_> = &mut EventContext::new_with_current(cx, entity);
let text_data = val.get(cx).to_string_local(cx);
// cx.text_context.set_text(entity, &text_data);
cx.style.text.insert(entity, text_data);
cx.style.needs_text_update(entity);
cx.needs_relayout();
cx.needs_redraw();
});
});
self
}
modifier!(
/// Sets the font that should be used by the view.
///
/// The font name refers to the name assigned when the font is added to context.
font_family,
Vec<FamilyOwned>,
SystemFlags::REFLOW
);
modifier!(
/// Sets the font weight that should be used by the view.
font_weight,
FontWeight,
SystemFlags::REFLOW
);
modifier!(
/// Sets the font style that should be used by the view.
font_slant,
FontSlant,
SystemFlags::REFLOW
);
modifier!(
/// Sets the font stretch that should be used by the view if the font supports it.
font_width,
FontWidth,
SystemFlags::REFLOW
);
modifier!(
/// Sets the font variation settings that should be used by the view.
font_variation_settings,
Vec<FontVariation>,
SystemFlags::REFLOW
);
/// Sets the text color of the view.
fn color<U: Clone + Into<Color>>(mut self, value: impl Res<U>) -> Self {
let entity = self.entity();
let current = self.current();
self.context().with_current(current, move |cx| {
value.set_or_bind(cx, entity, move |cx, v| {
cx.style.font_color.insert(entity, v.get(cx).into());
cx.style.needs_text_update(entity);
cx.needs_redraw(entity);
});
});
self
}
/// Sets the font size of the view.
fn font_size<U: Into<FontSize>>(mut self, value: impl Res<U>) -> Self {
let entity = self.entity();
let current = self.current();
self.context().with_current(current, move |cx| {
value.set_or_bind(cx, entity, move |cx, v| {
cx.style.font_size.insert(cx.current, v.get(cx).into());
cx.style.needs_text_update(entity);
});
});
self
}
modifier!(
/// Sets the ext caret color of the view.
caret_color,
Color,
SystemFlags::REDRAW
);
modifier!(
/// Sets the color used to highlight selected text within the view.
selection_color,
Color,
SystemFlags::REDRAW
);
modifier!(
/// Sets whether the text of the view should be allowed to wrap.
text_wrap,
bool,
SystemFlags::REFLOW
);
modifier!(
/// Sets the horizontal alignment of text within the view.
text_align,
TextAlign,
SystemFlags::REFLOW
);
modifier!(
/// Sets the text overflow.
text_overflow,
TextOverflow,
SystemFlags::REFLOW
);
modifier!(
/// Sets the max number of .
line_clamp,
LineClamp,
SystemFlags::REFLOW
);
modifier!(
/// Sets the max number of .
text_decoration_line,
TextDecorationLine,
SystemFlags::REFLOW
);
}
impl<'a, V> TextModifiers for Handle<'a, V> {}