-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nathangavin/refactor-MVC
Refactor mvc
- Loading branch information
Showing
10 changed files
with
1,334 additions
and
935 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod defaultController; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod UtilsModel; | ||
pub mod AppStateModel; | ||
pub mod CsvModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
use crate::model::UtilsModel::Position; | ||
use crate::model::UtilsModel::InputMode; | ||
|
||
use super::UtilsModel::RunningMode; | ||
|
||
pub struct AppStateModel { | ||
/// Current value of the input box | ||
input: String, | ||
/// Current input mode | ||
input_mode: InputMode, | ||
running_mode: RunningMode, | ||
corner_pos: Position, | ||
relative_pos: Position | ||
} | ||
|
||
impl Default for AppStateModel { | ||
fn default() -> AppStateModel { | ||
AppStateModel { | ||
input: String::new(), | ||
input_mode: InputMode::Normal, | ||
running_mode: RunningMode::Normal, | ||
corner_pos: Position { row: 0, col: 0 }, | ||
relative_pos: Position { row: 0, col: 0 }, | ||
} | ||
} | ||
} | ||
|
||
impl AppStateModel { | ||
|
||
pub fn from_running_mode(running_mode: &RunningMode) -> AppStateModel { | ||
let mut state = AppStateModel::default(); | ||
|
||
match running_mode { | ||
RunningMode::Normal => {}, | ||
RunningMode::Debug => { | ||
state.running_mode = RunningMode::Debug; | ||
} | ||
}; | ||
state | ||
} | ||
|
||
pub fn get_relative_pos(&self) -> Position { | ||
self.relative_pos | ||
} | ||
|
||
pub fn increment_relative_pos_row(&mut self) { | ||
self.relative_pos.row += 1; | ||
} | ||
|
||
pub fn decrement_relative_pos_row(&mut self) { | ||
if self.relative_pos.row > 0 { | ||
self.relative_pos.row -= 1; | ||
} | ||
} | ||
|
||
pub fn increment_relative_pos_col(&mut self) { | ||
self.relative_pos.col += 1; | ||
} | ||
|
||
pub fn decrement_relative_pos_col(&mut self) { | ||
if self.relative_pos.col > 0 { | ||
self.relative_pos.col -= 1; | ||
} | ||
|
||
} | ||
|
||
pub fn get_corner_pos(&self) -> Position { | ||
self.corner_pos | ||
} | ||
|
||
pub fn add_to_corner_pos_row(&mut self, n: usize) { | ||
self.corner_pos.row += n; | ||
} | ||
|
||
pub fn remove_from_corner_pos_row(&mut self, n: usize) { | ||
if self.corner_pos.row > n { | ||
self.corner_pos.row -= n; | ||
} else { | ||
self.corner_pos.row = 0; | ||
} | ||
} | ||
|
||
pub fn add_to_corner_pos_col(&mut self, n: usize) { | ||
self.corner_pos.col += n; | ||
} | ||
|
||
pub fn remove_from_corner_pos_col(&mut self, n: usize) { | ||
if self.corner_pos.col > n { | ||
self.corner_pos.col -= n; | ||
} else { | ||
self.corner_pos.col = 0; | ||
} | ||
} | ||
|
||
pub fn append_str_current_input(&mut self, string_value : &str) { | ||
self.input.push_str(&string_value); | ||
} | ||
|
||
pub fn append_char_current_input(&mut self, char_value : char) { | ||
self.input.push(char_value); | ||
} | ||
|
||
pub fn pop_current_input(&mut self) -> Option<char> { | ||
self.input.pop() | ||
} | ||
|
||
pub fn drain_input(&mut self) -> String { | ||
self.input.drain(..).collect() | ||
} | ||
|
||
pub fn clear_input(&mut self) { | ||
self.input.clear(); | ||
} | ||
|
||
pub fn get_input(&self) -> &str { | ||
self.input.as_str() | ||
} | ||
|
||
pub fn get_input_mode(&self) -> &InputMode { | ||
&self.input_mode | ||
} | ||
|
||
pub fn set_input_mode(&mut self, input_node: InputMode) { | ||
self.input_mode = input_node; | ||
} | ||
|
||
pub fn get_running_mode(&self) -> &RunningMode { | ||
&self.running_mode | ||
} | ||
} |
Oops, something went wrong.