Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow reverse selection of options #103

Merged
merged 1 commit into from
Feb 26, 2021
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
4 changes: 4 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ pub fn handle_keys_configure_chart(keycode: KeyCode, mut app: &mut app::App) {
let config = app.stocks[app.current_tab].chart_config_mut();
config.tab();
}
KeyCode::BackTab => {
let config = app.stocks[app.current_tab].chart_config_mut();
config.back_tab();
}
KeyCode::Enter => {
let time_frame = app.stocks[app.current_tab].time_frame;
let config = app.stocks[app.current_tab].chart_config_mut();
Expand Down
17 changes: 14 additions & 3 deletions src/widget/chart_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,31 @@ impl ChartConfigurationState {
input_field.pop();
}

pub fn tab(&mut self) {
fn get_tab_artifacts(&mut self) -> Option<(&mut usize, usize)> {
let tab_field = match self.selection {
Some(Selection::KagiReversalType) => &mut self.input.kagi_reversal_type,
Some(Selection::KagiPriceType) => &mut self.input.kagi_price_type,
_ => return,
_ => return None,
};

let mod_value = match self.selection {
Some(Selection::KagiReversalType) => 2,
Some(Selection::KagiPriceType) => 2,
_ => 1,
};
Some((tab_field, mod_value))
}

pub fn tab(&mut self) {
if let Some((tab_field, mod_value)) = self.get_tab_artifacts() {
*tab_field = (*tab_field + 1) % mod_value;
}
}

*tab_field = (*tab_field + 1) % mod_value;
pub fn back_tab(&mut self) {
if let Some((tab_field, mod_value)) = self.get_tab_artifacts() {
*tab_field = (*tab_field + mod_value - 1) % mod_value;
}
}

pub fn enter(&mut self, time_frame: TimeFrame) {
Expand Down