rename z offset to layer offset
This commit is contained in:
@@ -39,11 +39,11 @@ impl Widget for TextEdit {
|
|||||||
let region = self.view.draw(painter);
|
let region = self.view.draw(painter);
|
||||||
painter.layer = base;
|
painter.layer = base;
|
||||||
|
|
||||||
match &self.selection {
|
let size = vec2(1, self.attrs.line_height);
|
||||||
|
match self.selection {
|
||||||
TextSelection::None => (),
|
TextSelection::None => (),
|
||||||
TextSelection::Pos(cursor) => {
|
TextSelection::Pos(cursor) => {
|
||||||
if let Some(offset) = cursor_pos(cursor, &self.buf) {
|
if let Some(offset) = cursor_pos(cursor, &self.buf) {
|
||||||
let size = vec2(1, self.attrs.line_height);
|
|
||||||
painter.primitive_within(
|
painter.primitive_within(
|
||||||
RectPrimitive::color(Color::WHITE),
|
RectPrimitive::color(Color::WHITE),
|
||||||
size.align(Align::TOP_LEFT).offset(offset).within(®ion),
|
size.align(Align::TOP_LEFT).offset(offset).within(®ion),
|
||||||
@@ -51,19 +51,17 @@ impl Widget for TextEdit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextSelection::Span { start, end } => {
|
TextSelection::Span { start, end } => {
|
||||||
let (start, end) = sort_cursors(*start, *end);
|
let (start, end) = sort_cursors(start, end);
|
||||||
let line_height = self.attrs.line_height;
|
for (top_left, width) in iter_layout_lines(start, end, &self.buf) {
|
||||||
for (top_left, width) in iter_layout_lines(&self.buf, &start, &end) {
|
|
||||||
painter.primitive_within(
|
painter.primitive_within(
|
||||||
RectPrimitive::color(Color::SKY),
|
RectPrimitive::color(Color::SKY),
|
||||||
vec2(width, line_height)
|
size.with_x(width)
|
||||||
.align(Align::TOP_LEFT)
|
.align(Align::TOP_LEFT)
|
||||||
.offset(top_left)
|
.offset(top_left)
|
||||||
.within(®ion),
|
.within(®ion),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(end_offset) = cursor_pos(&end, &self.buf) {
|
if let Some(end_offset) = cursor_pos(end, &self.buf) {
|
||||||
let size = vec2(1, self.attrs.line_height);
|
|
||||||
painter.primitive_within(
|
painter.primitive_within(
|
||||||
RectPrimitive::color(Color::WHITE),
|
RectPrimitive::color(Color::WHITE),
|
||||||
size.align(Align::TOP_LEFT)
|
size.align(Align::TOP_LEFT)
|
||||||
@@ -86,11 +84,11 @@ impl Widget for TextEdit {
|
|||||||
|
|
||||||
/// provides top left + width
|
/// provides top left + width
|
||||||
fn iter_layout_lines(
|
fn iter_layout_lines(
|
||||||
|
start: Cursor,
|
||||||
|
end: Cursor,
|
||||||
buf: &TextBuffer,
|
buf: &TextBuffer,
|
||||||
start: &Cursor,
|
|
||||||
end: &Cursor,
|
|
||||||
) -> impl Iterator<Item = (Vec2, f32)> {
|
) -> impl Iterator<Item = (Vec2, f32)> {
|
||||||
gen {
|
gen move {
|
||||||
let mut iter = buf.layout_runs();
|
let mut iter = buf.layout_runs();
|
||||||
for line in iter.by_ref() {
|
for line in iter.by_ref() {
|
||||||
if line.line_i == start.line
|
if line.line_i == start.line
|
||||||
@@ -145,7 +143,7 @@ fn index_x(run: &LayoutRun, index: usize) -> Option<f32> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// returns top of line segment where cursor should visually select
|
/// returns top of line segment where cursor should visually select
|
||||||
fn cursor_pos(cursor: &Cursor, buf: &TextBuffer) -> Option<Vec2> {
|
fn cursor_pos(cursor: Cursor, buf: &TextBuffer) -> Option<Vec2> {
|
||||||
let mut prev = None;
|
let mut prev = None;
|
||||||
for run in buf
|
for run in buf
|
||||||
.layout_runs()
|
.layout_runs()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub trait CoreWidget<W, Tag> {
|
|||||||
fn scroll(self) -> impl WidgetIdFn<Scroll>;
|
fn scroll(self) -> impl WidgetIdFn<Scroll>;
|
||||||
fn masked(self) -> impl WidgetFn<Masked>;
|
fn masked(self) -> impl WidgetFn<Masked>;
|
||||||
fn background<T>(self, w: impl WidgetLike<T>) -> impl WidgetFn<Stack>;
|
fn background<T>(self, w: impl WidgetLike<T>) -> impl WidgetFn<Stack>;
|
||||||
fn z_offset(self, offset: usize) -> impl WidgetFn<Stack>;
|
fn layer_offset(self, offset: usize) -> impl WidgetFn<Stack>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||||
@@ -121,7 +121,7 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn z_offset(self, offset: usize) -> impl WidgetFn<Stack> {
|
fn layer_offset(self, offset: usize) -> impl WidgetFn<Stack> {
|
||||||
move |ui| Stack {
|
move |ui| Stack {
|
||||||
children: vec![self.add(ui).any()],
|
children: vec![self.add(ui).any()],
|
||||||
size: StackSize::Child(0),
|
size: StackSize::Child(0),
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ impl Vec2 {
|
|||||||
pub const fn tuple(&self) -> (f32, f32) {
|
pub const fn tuple(&self) -> (f32, f32) {
|
||||||
(self.x, self.y)
|
(self.x, self.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn with_x(mut self, x: f32) -> Self {
|
||||||
|
self.x = x;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn with_y(mut self, y: f32) -> Self {
|
||||||
|
self.y = y;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: const UiNum + Copy> const From<T> for Vec2 {
|
impl<T: const UiNum + Copy> const From<T> for Vec2 {
|
||||||
|
|||||||
Reference in New Issue
Block a user