cursor finally working properly and removed from render_text
This commit is contained in:
@@ -3,7 +3,7 @@ use std::ops::Range;
|
||||
use crate::{
|
||||
layout::{
|
||||
Active, TextAttrs, TextBuffer, TextData, TextOffset, TextureHandle, Textures, UiRegion,
|
||||
Vec2, VisualCursor, WidgetId, Widgets,
|
||||
Vec2, WidgetId, Widgets,
|
||||
},
|
||||
render::{Primitive, PrimitiveHandle, Primitives},
|
||||
util::{HashSet, Id},
|
||||
@@ -231,46 +231,53 @@ impl<'a> PainterCtx<'a> {
|
||||
}
|
||||
|
||||
impl<'a, 'c> Painter<'a, 'c> {
|
||||
fn write_at<P: Primitive>(&mut self, data: P, region: UiRegion) {
|
||||
self.primitives
|
||||
.push(self.ctx.primitives.write(self.id.duplicate(), data, region));
|
||||
fn primitive_at<P: Primitive>(&mut self, primitive: P, region: UiRegion) {
|
||||
self.primitives.push(
|
||||
self.ctx
|
||||
.primitives
|
||||
.write(self.id.duplicate(), primitive, region),
|
||||
);
|
||||
}
|
||||
|
||||
/// Writes a primitive to be rendered
|
||||
pub fn write<P: Primitive>(&mut self, data: P) {
|
||||
self.write_at(data, self.region)
|
||||
pub fn primitive<P: Primitive>(&mut self, primitive: P) {
|
||||
self.primitive_at(primitive, self.region)
|
||||
}
|
||||
|
||||
pub fn primitive_within<P: Primitive>(&mut self, primitive: P, region: UiRegion) {
|
||||
self.primitive_at(primitive, region.within(&self.region));
|
||||
}
|
||||
|
||||
/// Draws a widget within this widget's region.
|
||||
pub fn draw<W>(&mut self, id: &WidgetId<W>) {
|
||||
self.draw_at(id, self.region);
|
||||
pub fn widget<W>(&mut self, id: &WidgetId<W>) {
|
||||
self.widget_at(id, self.region);
|
||||
}
|
||||
|
||||
/// Draws a widget somewhere within this one.
|
||||
/// Useful for drawing child widgets in select areas.
|
||||
pub fn draw_within<W>(&mut self, id: &WidgetId<W>, region: UiRegion) {
|
||||
self.draw_at(id, region.within(&self.region));
|
||||
pub fn widget_within<W>(&mut self, id: &WidgetId<W>, region: UiRegion) {
|
||||
self.widget_at(id, region.within(&self.region));
|
||||
}
|
||||
|
||||
fn draw_at<W>(&mut self, id: &WidgetId<W>, region: UiRegion) {
|
||||
fn widget_at<W>(&mut self, id: &WidgetId<W>, region: UiRegion) {
|
||||
self.children.push(id.id.duplicate());
|
||||
self.ctx
|
||||
.draw_inner(&id.id, region, Some(self.id.duplicate()), None);
|
||||
}
|
||||
|
||||
pub fn draw_texture_within(&mut self, handle: &TextureHandle, region: UiRegion) {
|
||||
pub fn texture_within(&mut self, handle: &TextureHandle, region: UiRegion) {
|
||||
self.textures.push(handle.clone());
|
||||
self.write_at(handle.primitive(), region.within(&self.region));
|
||||
self.primitive_at(handle.primitive(), region.within(&self.region));
|
||||
}
|
||||
|
||||
pub fn draw_texture(&mut self, handle: &TextureHandle) {
|
||||
pub fn texture(&mut self, handle: &TextureHandle) {
|
||||
self.textures.push(handle.clone());
|
||||
self.write(handle.primitive());
|
||||
self.primitive(handle.primitive());
|
||||
}
|
||||
|
||||
pub fn draw_texture_at(&mut self, handle: &TextureHandle, region: UiRegion) {
|
||||
pub fn texture_at(&mut self, handle: &TextureHandle, region: UiRegion) {
|
||||
self.textures.push(handle.clone());
|
||||
self.write_at(handle.primitive(), region);
|
||||
self.primitive_at(handle.primitive(), region);
|
||||
}
|
||||
|
||||
/// returns (handle, offset from top left)
|
||||
@@ -278,9 +285,8 @@ impl<'a, 'c> Painter<'a, 'c> {
|
||||
&mut self,
|
||||
buffer: &mut TextBuffer,
|
||||
attrs: &TextAttrs,
|
||||
cursor: &VisualCursor,
|
||||
) -> (TextureHandle, TextOffset) {
|
||||
self.ctx.text.draw(buffer, attrs, cursor, self.ctx.textures)
|
||||
self.ctx.text.draw(buffer, attrs, self.ctx.textures)
|
||||
}
|
||||
|
||||
pub fn region(&self) -> UiRegion {
|
||||
@@ -327,9 +333,8 @@ impl SizeCtx<'_> {
|
||||
&mut self,
|
||||
buffer: &mut TextBuffer,
|
||||
attrs: &TextAttrs,
|
||||
cursor: &VisualCursor,
|
||||
) -> (TextureHandle, TextOffset) {
|
||||
self.text.draw(buffer, attrs, cursor, self.textures)
|
||||
self.text.draw(buffer, attrs, self.textures)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user