started decoupling widgets and ui

This commit is contained in:
Thomas Eppers 2021-10-20 15:05:56 +02:00
parent 05a9669fec
commit a7f509b165
4 changed files with 32 additions and 42 deletions

View File

@ -90,10 +90,10 @@ impl Ui {
)
.split(rect.size());
let (list, state) = ui.services.render(&ui.state);
let (list, state) = ui.services.render(ui.state == State::SelectService);
rect.render_stateful_widget(list, chunks[0], state);
rect.render_widget(ui.repo.render(&ui.state), chunks[1]);
let (list, state) = ui.tags.render(&ui.state);
rect.render_widget(ui.repo.render(ui.state == State::EditRepo), chunks[1]);
let (list, state) = ui.tags.render(ui.state == State::SelectTag);
rect.render_stateful_widget(list, chunks[2], state);
rect.render_widget(ui.info.render(), chunks[3]);
})
@ -145,22 +145,24 @@ impl Ui {
}
_ => (),
},
Ok(Key::Char(key)) => {
if ui.state == State::EditRepo {
Ok(Key::Char(key)) => match ui.state {
State::SelectService => (),
State::EditRepo => {
ui.info.set_info("Editing Repository");
ui.repo.handle_input(Key::Char(key));
}
ui.repo.handle_input(&ui.state, Key::Char(key));
ui.tags.handle_input(&ui.state, Key::Char(key));
}
Ok(Key::Backspace) => {
if ui.state == State::EditRepo {
State::SelectTag => (),
},
Ok(Key::Backspace) => match ui.state {
State::SelectService => (),
State::EditRepo => {
ui.info.set_info("Editing Repository");
ui.repo.handle_input(Key::Backspace);
}
ui.repo.handle_input(&ui.state, Key::Backspace);
ui.tags.handle_input(&ui.state, Key::Backspace);
}
Ok(Key::Up) => {
if ui.state == State::SelectService && ui.services.find_previous_match() {
State::SelectTag => (),
},
Ok(Key::Up) => match ui.state {
State::SelectService if ui.services.find_previous_match() => {
match ui.services.extract_repo() {
Err(e) => ui.info.set_info(&format!("{}", e)),
Ok(s) => {
@ -176,9 +178,10 @@ impl Ui {
}
}
}
ui.tags.handle_input(&ui.state, Key::Up);
ui.repo.handle_input(&ui.state, Key::Up);
}
State::SelectService => (),
State::EditRepo => (),
State::SelectTag => ui.tags.handle_input(Key::Up),
},
Ok(Key::Down) => match ui.state {
State::SelectService if ui.services.find_next_match() => {
match ui.services.extract_repo() {
@ -196,15 +199,10 @@ impl Ui {
}
}
}
_ => {
ui.tags.handle_input(&ui.state, Key::Down);
ui.repo.handle_input(&ui.state, Key::Down);
}
State::SelectService => (),
State::EditRepo => (),
State::SelectTag => ui.tags.handle_input(Key::Down),
},
Ok(key) => {
ui.repo.handle_input(&ui.state, Key::Down);
ui.tags.handle_input(&ui.state, key);
}
_ => (),
}

View File

@ -29,13 +29,13 @@ impl RepoEntry {
self.old_text = entry;
}
pub fn render(&self, state: &crate::ui::State) -> Paragraph {
pub fn render(&self, colored: bool) -> Paragraph {
let title = match self.changed {
true => "Repository*",
false => "Repository",
};
let border_style = if state == &crate::ui::State::EditRepo {
let border_style = if colored {
Style::default().fg(Color::Green)
} else {
Style::default().fg(Color::Gray)
@ -52,11 +52,7 @@ impl RepoEntry {
.alignment(Alignment::Left)
}
pub fn handle_input(&mut self, state: &State, key: termion::event::Key) {
if state != &State::EditRepo {
return;
}
pub fn handle_input(&mut self, key: termion::event::Key) {
match key {
// Key::Char('\n') => self.confirm(), //handled in Ui
Key::Char(c) => {

View File

@ -72,8 +72,8 @@ impl ServiceSwitcher {
}
}
pub fn render(&mut self, state: &State) -> (List, &mut ListState) {
let border_style = if state == &State::SelectService {
pub fn render(&mut self, colored: bool) -> (List, &mut ListState) {
let border_style = if colored {
Style::default().fg(Color::Green)
} else {
Style::default().fg(Color::Gray)

View File

@ -109,8 +109,8 @@ impl TagList {
}
}
pub fn render(&mut self, state: &State) -> (List, &mut ListState) {
let border_style = if state == &State::SelectTag {
pub fn render(&mut self, colored: bool) -> (List, &mut ListState) {
let border_style = if colored {
Style::default().fg(Color::Green)
} else {
Style::default().fg(Color::Gray)
@ -144,11 +144,7 @@ impl TagList {
(items, &mut self.state)
}
pub fn handle_input(&mut self, state: &State, key: termion::event::Key) {
if state != &State::SelectTag {
return;
}
pub fn handle_input(&mut self, key: termion::event::Key) {
match key {
Key::Down => self.next(),
Key::Up => self.previous(),