Compare commits
1 Commits
4981bd739a
...
bc829397c8
| Author | SHA1 | Date | |
|---|---|---|---|
| bc829397c8 |
@@ -126,26 +126,35 @@ impl<'a> TextEditCtx<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn replace(&mut self, len: usize, text: &str) {
|
||||||
|
for _ in 0..len {
|
||||||
|
self.delete();
|
||||||
|
}
|
||||||
|
self.insert_inner(text, false);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, text: &str) {
|
pub fn insert(&mut self, text: &str) {
|
||||||
let mut lines = text.split('\n');
|
let mut lines = text.split('\n');
|
||||||
let Some(first) = lines.next() else {
|
let Some(first) = lines.next() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
self.insert_inner(first);
|
self.insert_inner(first, true);
|
||||||
for line in lines {
|
for line in lines {
|
||||||
self.newline();
|
self.newline();
|
||||||
self.insert_inner(line);
|
self.insert_inner(line, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_inner(&mut self, text: &str) {
|
fn insert_inner(&mut self, text: &str, mov: bool) {
|
||||||
if let Some(cursor) = &mut self.text.cursor {
|
if let Some(cursor) = &mut self.text.cursor {
|
||||||
let line = &mut self.text.view.buf.lines[cursor.line];
|
let line = &mut self.text.view.buf.lines[cursor.line];
|
||||||
let mut line_text = line.text().to_string();
|
let mut line_text = line.text().to_string();
|
||||||
line_text.insert_str(cursor.index, text);
|
line_text.insert_str(cursor.index, text);
|
||||||
line.set_text(line_text, line.ending(), line.attrs_list().clone());
|
line.set_text(line_text, line.ending(), line.attrs_list().clone());
|
||||||
for _ in 0..text.len() {
|
if mov {
|
||||||
self.motion(Motion::Right);
|
for _ in 0..text.chars().count() {
|
||||||
|
self.motion(Motion::Right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,8 +272,8 @@ impl UiRegion {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_screen(&self, size: Vec2) -> ScreenRegion {
|
pub fn to_screen(&self, size: Vec2) -> PixelRegion {
|
||||||
ScreenRegion {
|
PixelRegion {
|
||||||
top_left: self.top_left.rel * size + self.top_left.abs,
|
top_left: self.top_left.rel * size + self.top_left.abs,
|
||||||
bot_right: self.bot_right.rel * size + self.bot_right.abs,
|
bot_right: self.bot_right.rel * size + self.bot_right.abs,
|
||||||
}
|
}
|
||||||
@@ -329,17 +329,22 @@ impl Display for UiRegion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ScreenRegion {
|
pub struct PixelRegion {
|
||||||
pub top_left: Vec2,
|
pub top_left: Vec2,
|
||||||
pub bot_right: Vec2,
|
pub bot_right: Vec2,
|
||||||
}
|
}
|
||||||
impl ScreenRegion {
|
|
||||||
|
impl PixelRegion {
|
||||||
pub fn contains(&self, pos: Vec2) -> bool {
|
pub fn contains(&self, pos: Vec2) -> bool {
|
||||||
pos.x >= self.top_left.x
|
pos.x >= self.top_left.x
|
||||||
&& pos.x <= self.bot_right.x
|
&& pos.x <= self.bot_right.x
|
||||||
&& pos.y >= self.top_left.y
|
&& pos.y >= self.top_left.y
|
||||||
&& pos.y <= self.bot_right.y
|
&& pos.y <= self.bot_right.y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn size(&self) -> Vec2 {
|
||||||
|
self.bot_right - self.top_left
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UIRegionAxisView<'a> {
|
pub struct UIRegionAxisView<'a> {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use image::DynamicImage;
|
|||||||
use crate::{
|
use crate::{
|
||||||
core::{TextEdit, TextEditCtx},
|
core::{TextEdit, TextEditCtx},
|
||||||
layout::{
|
layout::{
|
||||||
IdLike, PainterCtx, PainterData, StaticWidgetId, TextureHandle, Vec2, Widget, WidgetId,
|
IdLike, PainterCtx, PainterData, PixelRegion, StaticWidgetId, TextureHandle, Vec2, Widget,
|
||||||
WidgetLike,
|
WidgetId, WidgetLike,
|
||||||
},
|
},
|
||||||
util::Id,
|
util::Id,
|
||||||
};
|
};
|
||||||
@@ -179,6 +179,11 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn window_region<W>(&self, id: &impl IdLike<W>) -> Option<PixelRegion> {
|
||||||
|
let region = self.data.active.get(&id.id())?.region;
|
||||||
|
Some(region.to_screen(self.data.output_size))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn debug(&self, label: &str) {
|
pub fn debug(&self, label: &str) {
|
||||||
for (id, inst) in &self.data.active {
|
for (id, inst) in &self.data.active {
|
||||||
let l = &self.data.widgets.data(id).unwrap().label;
|
let l = &self.data.widgets.data(id).unwrap().label;
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ impl Vec2 {
|
|||||||
y: self.y.ceil(),
|
y: self.y.ceil(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn tuple(&self) -> (f32, f32) {
|
||||||
|
(self.x, self.y)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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