Fix frame cursor functions ignoring stack
This commit is contained in:
parent
53b2728c82
commit
c1907bb8ee
2 changed files with 11 additions and 3 deletions
|
|
@ -184,7 +184,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignores the stack.
|
/// Ignores the stack.
|
||||||
pub(crate) fn at(&self, x: u16, y: u16) -> &Cell {
|
pub fn at(&self, x: u16, y: u16) -> &Cell {
|
||||||
assert!(x < self.size.width);
|
assert!(x < self.size.width);
|
||||||
assert!(y < self.size.height);
|
assert!(y < self.size.height);
|
||||||
let i = self.index(x, y);
|
let i = self.index(x, y);
|
||||||
|
|
@ -208,6 +208,14 @@ impl Buffer {
|
||||||
self.stack.pop();
|
self.stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn local_to_global(&self, pos: Pos) -> Pos {
|
||||||
|
pos + self.stack.last().map(|(p, _)| *p).unwrap_or(Pos::ZERO)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn global_to_local(&self, pos: Pos) -> Pos {
|
||||||
|
pos - self.stack.last().map(|(p, _)| *p).unwrap_or(Pos::ZERO)
|
||||||
|
}
|
||||||
|
|
||||||
fn drawable_area(&self) -> (Pos, Size) {
|
fn drawable_area(&self) -> (Pos, Size) {
|
||||||
self.stack.last().copied().unwrap_or((Pos::ZERO, self.size))
|
self.stack.last().copied().unwrap_or((Pos::ZERO, self.size))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,11 @@ impl Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor(&self) -> Option<Pos> {
|
pub fn cursor(&self) -> Option<Pos> {
|
||||||
self.cursor
|
self.cursor.map(|p| self.buffer.global_to_local(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_cursor(&mut self, pos: Option<Pos>) {
|
pub fn set_cursor(&mut self, pos: Option<Pos>) {
|
||||||
self.cursor = pos;
|
self.cursor = pos.map(|p| self.buffer.local_to_global(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_cursor(&mut self, pos: Pos) {
|
pub fn show_cursor(&mut self, pos: Pos) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue