summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2018-07-23 22:54:00 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:24 +0300
commit1389c4b1d5ce46086e704f30b7e471a6254d5d54 (patch)
tree628414b6ce8948453fb1e67b9572d383d82bce66 /ui
parent0bcea12400dc9c9dd8073e3c802af8cb0e2a97ca (diff)
Add word break copy area function
closes #13
Diffstat (limited to 'ui')
-rw-r--r--ui/src/components/mod.rs25
-rw-r--r--ui/src/components/utilities.rs2
2 files changed, 25 insertions, 2 deletions
diff --git a/ui/src/components/mod.rs b/ui/src/components/mod.rs
index 5b921846..b7bb6b4a 100644
--- a/ui/src/components/mod.rs
+++ b/ui/src/components/mod.rs
@@ -84,11 +84,34 @@ pub trait Component {
}
}
-pub fn copy_area_with_break(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, src: Area) {
+// TODO: word break.
+pub fn copy_area_with_break(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, src: Area) {
+ if !is_valid_area!(dest) || !is_valid_area!(src) {
+ eprintln!("BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}", src, dest);
+ return;
+ }
+ let mut src_x = get_x(upper_left!(src));
+ let mut src_y = get_y(upper_left!(src));
+ 'y_: for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) {
+ 'x_: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) {
+ grid_dest[(x,y)] = grid_src[(src_x, src_y)];
+ if src_x == get_x(bottom_right!(src)) {
+ src_y += 1;
+ src_x = 0;
+ if src_y == get_y(bottom_right!(src)) {
+ //clear_area(grid_dest, ((get_x(upper_left!(dest)), y), bottom_right!(dest)));
+ break 'y_;
+ }
+ break 'x_;
+ }
+ src_x += 1;
+ }
+ }
}
+
/// Copy a source `Area` to a destination.
pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, src: Area) {
if !is_valid_area!(dest) || !is_valid_area!(src) {
diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs
index 264ece73..70a23b50 100644
--- a/ui/src/components/utilities.rs
+++ b/ui/src/components/utilities.rs
@@ -257,7 +257,7 @@ impl Component for Pager {
//let pager_stop: bool = context.settings.pager.pager_stop;
//let rows = y(bottom_right) - y(upper_left);
//let page_length = rows / self.height;
- copy_area(grid, &self.content, area, ((0, self.cursor_pos), (self.width - 1, self.height - 1)));
+ copy_area_with_break(grid, &self.content, area, ((0, self.cursor_pos), (self.width - 1, self.height - 1)));
context.dirty_areas.push_back(area);
}
fn process_event(&mut self, event: &UIEvent, _context: &mut Context) {