iris: add positioned text overflow
This commit is contained in:
1 parent
1f15125992
commit
a475ae772f
14 files changed
+735
-31
No files matched your search
@@ -0,0 +1,160 @@
|
||||
use iris::prelude::*;
|
||||
|
||||
const SAMPLE: &str = "The quick brown fox jumps over the lazy dog";
|
||||
|
||||
fn overflow_row<Rsc: UiRsc + 'static>(
|
||||
rsc: &mut Rsc,
|
||||
label: &str,
|
||||
overflow: TextOverflow,
|
||||
position: Len,
|
||||
fill: PaintId,
|
||||
) -> WeakWidget<Sized> {
|
||||
(
|
||||
wtext(label).size(14).color(PaintId::GRAY).width(dp(76)),
|
||||
wtext(SAMPLE)
|
||||
.size(20)
|
||||
.overflow(overflow)
|
||||
.overflow_position(position)
|
||||
.width(dp(260))
|
||||
.background(rect(fill)),
|
||||
)
|
||||
.span(Dir::RIGHT)
|
||||
.gap(dp(8))
|
||||
.width(dp(344))
|
||||
.add(rsc)
|
||||
}
|
||||
|
||||
pub(crate) fn build<Rsc: HasEvents + 'static>(rsc: &mut Rsc, ui_state: &mut impl HasRoot<Rsc>)
|
||||
where
|
||||
Rsc::State: FocusHost,
|
||||
{
|
||||
let panel = rsc
|
||||
.ui_mut()
|
||||
.paints
|
||||
.add(Srgba8::new(34, 36, 42, 255).to_linear());
|
||||
let field = rsc
|
||||
.ui_mut()
|
||||
.paints
|
||||
.add(Srgba8::new(53, 57, 66, 255).to_linear());
|
||||
|
||||
let styled = "Bold, italic, underlined, and colored spans";
|
||||
let styled = wtext(styled)
|
||||
.size(20)
|
||||
.spans(vec![
|
||||
SpanStyle::new(0..4).bold(),
|
||||
SpanStyle::new(6..12).italic(),
|
||||
SpanStyle::new(14..24).underline(),
|
||||
SpanStyle::new(30..37).color(PaintId::SKY),
|
||||
])
|
||||
.width(rest(1));
|
||||
|
||||
let aligned = (
|
||||
wtext("Left aligned").text_align(Align::CENTER_LEFT),
|
||||
wtext("Centered").text_align(Align::CENTER),
|
||||
wtext("Right aligned").text_align(Align::CENTER_RIGHT),
|
||||
)
|
||||
.span(Dir::DOWN)
|
||||
.gap(dp(4))
|
||||
.width(rest(1))
|
||||
.background(rect(field.clone()));
|
||||
|
||||
let wrapped = wtext(
|
||||
"Wrapping shapes the same source into as many lines as its container needs. Resize the window to see it reflow.",
|
||||
)
|
||||
.overflow(TextOverflow::Wrap)
|
||||
.size(18)
|
||||
.width(dp(340))
|
||||
.background(rect(field.clone()));
|
||||
|
||||
let editable = wtext(SAMPLE)
|
||||
.overflow(TextOverflow::Ellipsis)
|
||||
.editable(EditMode::SingleLine)
|
||||
.size(20)
|
||||
.attr::<Selectable>(())
|
||||
.width(dp(344))
|
||||
.background(rect(field.clone()));
|
||||
|
||||
let intro = (
|
||||
wtext("Iris text")
|
||||
.size(30)
|
||||
.spans(vec![SpanStyle::new(0..9).bold()]),
|
||||
wtext("Drag across display text to select it. The overflow markers select hidden source text, but are never copied.")
|
||||
.overflow(TextOverflow::Wrap)
|
||||
.color(PaintId::GRAY)
|
||||
.width(rest(1)),
|
||||
)
|
||||
.span(Dir::DOWN)
|
||||
.gap(dp(6))
|
||||
.add(rsc);
|
||||
let styles = (
|
||||
wtext("Styles and alignment").size(16).color(PaintId::SKY),
|
||||
styled,
|
||||
aligned,
|
||||
)
|
||||
.span(Dir::DOWN)
|
||||
.gap(dp(6))
|
||||
.add(rsc);
|
||||
let wrapping = (wtext("Wrapping").size(16).color(PaintId::SKY), wrapped)
|
||||
.span(Dir::DOWN)
|
||||
.gap(dp(6))
|
||||
.add(rsc);
|
||||
let overflow = (
|
||||
wtext("Overflow treatment and position")
|
||||
.size(16)
|
||||
.color(PaintId::SKY),
|
||||
overflow_row(rsc, "hidden", TextOverflow::Hidden, rel(0), field.clone()),
|
||||
overflow_row(
|
||||
rsc,
|
||||
"ellipsis 0",
|
||||
TextOverflow::Ellipsis,
|
||||
rel(0),
|
||||
field.clone(),
|
||||
),
|
||||
overflow_row(
|
||||
rsc,
|
||||
"ellipsis .5",
|
||||
TextOverflow::Ellipsis,
|
||||
rel(0.5),
|
||||
field.clone(),
|
||||
),
|
||||
overflow_row(
|
||||
rsc,
|
||||
"ellipsis 1",
|
||||
TextOverflow::Ellipsis,
|
||||
rel(1),
|
||||
field.clone(),
|
||||
),
|
||||
)
|
||||
.span(Dir::DOWN)
|
||||
.gap(dp(6))
|
||||
.add(rsc);
|
||||
let editing = (
|
||||
wtext("Editable ellipsis (move the caret through the text)")
|
||||
.size(16)
|
||||
.color(PaintId::SKY),
|
||||
editable,
|
||||
)
|
||||
.span(Dir::DOWN)
|
||||
.gap(dp(6))
|
||||
.add(rsc);
|
||||
|
||||
let content = (intro, styles, wrapping, overflow, editing)
|
||||
.span(Dir::DOWN)
|
||||
.gap(dp(14))
|
||||
.controller(SelectionController::new().separator("\n"))
|
||||
.add(rsc);
|
||||
|
||||
content
|
||||
.on(CursorSense::drag_senses(), move |ctx, rsc: &mut Rsc| {
|
||||
let input = &ctx.data;
|
||||
rsc.with_nearest_controller::<SelectionController, _>(content, |id, selection, rsc| {
|
||||
selection.drag(id, rsc, input)
|
||||
});
|
||||
})
|
||||
.add(rsc);
|
||||
content
|
||||
.pad(dp(24))
|
||||
.width(rest(1))
|
||||
.background(rect(panel))
|
||||
.set_root(rsc, ui_state);
|
||||
}
|
||||
Reference in new issue
Block a user