hint gaming
This commit is contained in:
@@ -21,18 +21,20 @@ pub struct TextView {
|
||||
// cache
|
||||
tex: Option<RenderedText>,
|
||||
width: Option<f32>,
|
||||
pub hint: Option<WidgetId>,
|
||||
}
|
||||
|
||||
impl TextView {
|
||||
pub fn new(buf: TextBuffer, attrs: TextAttrs) -> Self {
|
||||
pub fn new(buf: TextBuffer, attrs: TextAttrs, hint: Option<WidgetId>) -> Self {
|
||||
Self {
|
||||
attrs: attrs.into(),
|
||||
buf: buf.into(),
|
||||
tex: None,
|
||||
width: None,
|
||||
hint,
|
||||
}
|
||||
}
|
||||
pub fn render(&mut self, ctx: &mut SizeCtx) -> RenderedText {
|
||||
fn render(&mut self, ctx: &mut SizeCtx) -> RenderedText {
|
||||
let width = if self.attrs.wrap {
|
||||
Some(ctx.px_size().x)
|
||||
} else {
|
||||
@@ -71,6 +73,12 @@ impl TextView {
|
||||
let mut region = region.offset(tex.top_left_offset);
|
||||
region.x.end = region.x.start + UiScalar::abs(dims.x);
|
||||
region.y.end = region.y.start + UiScalar::abs(dims.y);
|
||||
if let Some(hint) = &self.hint
|
||||
&& let [line] = &self.buf.lines[..]
|
||||
&& line.text().is_empty()
|
||||
{
|
||||
painter.widget(hint);
|
||||
}
|
||||
painter.texture_within(&tex.handle, region);
|
||||
region
|
||||
}
|
||||
@@ -82,7 +90,7 @@ impl Text {
|
||||
let buf = TextBuffer::new_empty(Metrics::new(attrs.font_size, attrs.line_height));
|
||||
Self {
|
||||
content: content.into().into(),
|
||||
view: TextView::new(buf, attrs),
|
||||
view: TextView::new(buf, attrs, None),
|
||||
}
|
||||
}
|
||||
fn update_buf(&mut self, ctx: &mut SizeCtx) {
|
||||
|
||||
Reference in New Issue
Block a user