A simple CPU rendered GUI IDE experience.
move vo
bendn 7 months ago
parent ae84ab5 · commit e750557
-rw-r--r--src/main.rs13
-rw-r--r--src/text.rs4
2 files changed, 8 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 8425ea5..2b46f39 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,7 +21,7 @@ fn main() {
#[implicit_fn::implicit_fn]
pub(crate) fn entry(event_loop: EventLoop<()>) {
let ppem = 20.0;
- let ls = 20.0; let mut vo = 0;
+ let ls = 20.0;
let mut text = TextArea::default();
std::env::args().nth(1).map(|x| {
@@ -76,7 +76,7 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
{
let (c, r) = dsb::fit(&FONT,ppem,ls, (size.width as _,size.height as _));
let now = Instant::now();
- let cells =text.cells((c, r),[204, 202, 194], [36, 41, 54], vo);
+ let cells =text.cells((c, r),[204, 202, 194], [36, 41, 54]);
println!("cell=");
dbg!(now.elapsed());
let now = Instant::now();
@@ -96,11 +96,11 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
let cell = Image::<_, 4>::build(3, (fh).ceil() as u32).fill([0xFF, 0xCC, 0x66, 255]);
unsafe {
let (x, y) = text.cursor();
- if (vo..vo+r-1).contains(&y) {
+ if (text.vo..text.vo+r-1).contains(&y) {
res.as_mut().overlay_at(
&cell,
(x as f32 * fw).floor() as u32,
- ((y-vo) as f32 * (fh + ls * fac)).floor()
+ ((y-text.vo) as f32 * (fh + ls * fac)).floor()
as u32,
// 4 + ((x - 1) as f32 * sz) as u32,
// (x as f32 * (ppem * 1.25)) as u32 - 20,
@@ -137,13 +137,12 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
if rows < 0.0 {
let rows = rows.ceil().abs() as usize;
let (_, r) = dsb::fit(&FONT,ppem,ls, (window.inner_size() .width as _,window.inner_size().height as _));
- vo = (vo + rows).min(text.l() - r);
+ text.vo = (text.vo + rows).min(text.l() - r);
} else {
let rows = rows.floor() as usize;
- vo = vo.saturating_sub(rows);
+ text.vo = text.vo.saturating_sub(rows);
}
window.request_redraw();
- dbg!(vo);
}
Event::WindowEvent{
event:WindowEvent::KeyboardInput { device_id, event, is_synthetic }, window_id
diff --git a/src/text.rs b/src/text.rs
index af0c07b..a1455fb 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -31,6 +31,7 @@ pub struct TextArea {
cursor: usize,
highlighter: Highlighter,
column: usize,
+ pub vo: usize,
}
impl TextArea {
@@ -143,7 +144,6 @@ impl TextArea {
(c, r): (usize, usize),
color: [u8; 3],
bg: [u8; 3],
- vo: usize,
) -> Vec<Cell> {
let mut x = HighlightConfiguration::new(
tree_sitter_rust::LANGUAGE.into(),
@@ -238,7 +238,7 @@ impl TextArea {
}
}
}
- let cells = cells[vo * c..vo * c + r * c].to_vec();
+ let cells = cells[self.vo * c..self.vo * c + r * c].to_vec();
assert_eq!(cells.len(), c * r);
cells