Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ pub const CHAR_HOR_UP_L: char = '┴';
pub const CHAR_HOR_DOWN_L: char = '┬';
pub const CHAR_VER_RIGHT_L: char = '├';
pub const CHAR_VER_LEFT_L: char = '┤';
pub const CHAR_CROSS: char = '┼';

pub const CHAR_ARROW_DOWN: char = '🭯';
pub const CHAR_ARROW_UP: char = '🭭';
pub const CHAR_ARROW_RIGHT: char = '►';
pub const CHAR_ARROW_LEFT: char = '◄';

pub fn is_arrowhead(c: char) -> bool {
c.eq(&CHAR_ARROW_LEFT)
|| c.eq(&CHAR_ARROW_RIGHT)
|| c.eq(&CHAR_ARROW_UP)
|| c.eq(&CHAR_ARROW_DOWN)
}
pub const CHAR_ARROW_UP: char = '🭯';
pub const CHAR_ARROW_DOWN: char = '🭭';
pub const CHAR_ARROW_RIGHT: char = '▶';
pub const CHAR_ARROW_LEFT: char = '◀';

pub const CHAR_SPACE: char = ' ';
pub const CHAR_NEWLINE: char = '\n';
Expand Down
31 changes: 20 additions & 11 deletions src/data/grid_cell.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::consts::{CHAR_NEWLINE, CHAR_SPACE};
use crate::consts::CHAR_SPACE;
use crate::data::overlap;
use crate::shapes::line::LineDirection;

#[derive(Clone, Copy)]
pub struct GridCell {
pub highlight_index: usize,
pub content: char,
pub preview: Option<char>,
pub highlighted: bool,
pub line_direction: Option<LineDirection>,
}

impl GridCell {
Expand All @@ -15,22 +18,22 @@ impl GridCell {
content,
preview: None,
highlighted: false,
line_direction: None,
}
}

pub fn empty() -> Self {
GridCell::new(CHAR_SPACE)
pub fn set_line_direction(&mut self, direction: LineDirection) {
self.line_direction = Some(direction);
}

pub fn newline() -> Self {
GridCell::new(CHAR_NEWLINE)
pub fn empty() -> Self {
GridCell::new(CHAR_SPACE)
}

pub fn read(&self) -> char {
if let Some(content) = self.preview {
return content;
}
self.content
pub fn read(&self) -> (char, char) {
let content = self.content;
let preview = self.preview.unwrap_or(' ');
(content, preview)
}

pub fn read_content(&self) -> char {
Expand All @@ -53,13 +56,19 @@ impl GridCell {

pub fn commit(&mut self) {
if let Some(preview) = self.preview {
self.content = preview;
// TODO: Implement line overlap processing here
// Each cell should carry an information about the starting point and the drawing
// direction, so the overlap algorithm could use
self.content =
overlap::calculate_cell_content(self.line_direction, self.content, preview);
self.preview = None;
self.line_direction = None;
}
}

pub fn discard(&mut self) {
self.preview = None;
self.line_direction = None;
}

pub fn highlight(&mut self, highlight_index: usize) {
Expand Down
2 changes: 1 addition & 1 deletion src/data/grid_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl GridList {
}
}
last_i = Some(cell.highlight_index);
line.push(cell.read());
line.push(cell.read().0);
}
if !line.is_empty() {
result.push(line);
Expand Down
2 changes: 2 additions & 0 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub mod grid_list;
pub mod selection;
pub mod shape_list;

mod overlap;

#[derive(Clone, PartialEq, Data)]
pub struct ApplicationState {
pub mode: DrawingTools,
Expand Down
Loading