Add retained paints and shared text selection
This commit is contained in:
1 parent
1e6d3b1edd
commit
a33fbca966
42 files changed
+2424
-470
No files matched your search
+22
-3
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
Axis, Color, Len, MoveOffset, RegionAlign, RenderedText, Size, StrongWidget, TextAttrs,
|
||||
Axis, Len, MoveOffset, PaintId, RegionAlign, RenderedText, Size, StrongWidget, TextAttrs,
|
||||
TextBuffer, TextData, TextureHandle, UiRegion, UiRenderState, UiRsc, UiScalar, UiVec2,
|
||||
WidgetId,
|
||||
render::{
|
||||
@@ -20,6 +20,7 @@ pub struct Painter<'a> {
|
||||
pub(super) child_move_slot: Option<MoveIdx>,
|
||||
pub(super) own_mask: MaskIdx,
|
||||
pub(super) textures: Vec<TextureHandle>,
|
||||
pub(super) paints: Vec<PaintId>,
|
||||
pub(super) primitives: Vec<PrimitiveHandle>,
|
||||
pub(super) recycle: std::iter::Peekable<std::vec::IntoIter<PrimitiveHandle>>,
|
||||
pub(super) children: Vec<WidgetId>,
|
||||
@@ -118,6 +119,20 @@ impl<'a> Painter<'a> {
|
||||
self.primitive_at(primitive, self.region)
|
||||
}
|
||||
|
||||
/// Resolves a public paint handle to the compact index stored by a GPU
|
||||
/// primitive and retains the handle for exactly as long as that draw.
|
||||
pub fn paint(&mut self, paint: &PaintId) -> u32 {
|
||||
if !self.paints.contains(paint) {
|
||||
self.paints.push(paint.clone());
|
||||
}
|
||||
paint.slot()
|
||||
}
|
||||
|
||||
pub fn paint_value(&mut self, paint: &mut crate::PaintValue) -> u32 {
|
||||
let paint = paint.resolve(&mut self.rsc.ui_mut().paints).clone();
|
||||
self.paint(&paint)
|
||||
}
|
||||
|
||||
pub fn primitive_within<P: Primitive>(&mut self, primitive: P, region: UiRegion) {
|
||||
self.primitive_at(primitive, region.within(&self.region));
|
||||
}
|
||||
@@ -128,7 +143,8 @@ impl<'a> Painter<'a> {
|
||||
/// so keeps pointing at whichever slot it was drawn under. See
|
||||
/// `ActiveData::own_mask` for what pushing a fresh one cost.
|
||||
pub fn set_mask(&mut self, region: UiRegion) {
|
||||
let shape = self.write_primitive(RectPrimitive::color(Color::NONE), region, Drawn::No);
|
||||
let paint = self.paint(&PaintId::NONE);
|
||||
let shape = self.write_primitive(RectPrimitive::color(paint), region, Drawn::No);
|
||||
self.set_mask_to(shape);
|
||||
}
|
||||
|
||||
@@ -433,6 +449,9 @@ impl<'a> Painter<'a> {
|
||||
0
|
||||
}
|
||||
};
|
||||
for paint in text.paints.iter() {
|
||||
self.paint(paint);
|
||||
}
|
||||
for glyph in text.glyphs.iter() {
|
||||
let mut region = origin;
|
||||
region.x.end = region.x.start;
|
||||
@@ -445,7 +464,7 @@ impl<'a> Painter<'a> {
|
||||
glyph.entry.uv_min,
|
||||
glyph.entry.uv_max,
|
||||
glyph.entry.layer,
|
||||
glyph.color,
|
||||
glyph.paint,
|
||||
flags_for(glyph.entry.is_color),
|
||||
),
|
||||
region,
|
||||
|
||||
Reference in new issue
Block a user