diff --git a/src/pages/phone.rs b/src/pages/phone.rs index 6feeb43..82665a5 100644 --- a/src/pages/phone.rs +++ b/src/pages/phone.rs @@ -26,6 +26,7 @@ pub struct Phone { config: Config, focused_pane_index: usize, panes: Vec>, + fullscreen_pane_index: Option, } pub trait RequestBuilder { @@ -54,6 +55,7 @@ impl Phone { config: Config::default(), panes: vec![Box::new(parameter_editor), Box::new(body_editor), Box::new(response_viewer)], focused_pane_index: 0, + fullscreen_pane_index: None, }) } @@ -119,6 +121,7 @@ impl Page for Phone { KeyCode::Left | KeyCode::Char('h') | KeyCode::Char('H') => EventResponse::Stop(Action::FocusPrev), KeyCode::Down | KeyCode::Char('j') | KeyCode::Char('J') => EventResponse::Stop(Action::Down), KeyCode::Up | KeyCode::Char('k') | KeyCode::Char('K') => EventResponse::Stop(Action::Up), + KeyCode::Char('f') | KeyCode::Char('F') => EventResponse::Stop(Action::ToggleFullScreen), KeyCode::Char(c) if ('1'..='9').contains(&c) => { EventResponse::Stop(Action::Tab(c.to_digit(10).unwrap_or(0) - 1)) }, @@ -163,6 +166,9 @@ impl Page for Phone { pane.focus()?; } }, + Action::ToggleFullScreen => { + self.fullscreen_pane_index = self.fullscreen_pane_index.map_or(Some(self.focused_pane_index), |_| None); + }, Action::Update => { for pane in self.panes.iter_mut() { pane.update(action.clone(), state)?; @@ -187,8 +193,9 @@ impl Page for Phone { } fn draw(&mut self, frame: &mut Frame<'_>, area: Rect, state: &State) -> Result<()> { - let outer_layout = Layout::vertical(vec![Constraint::Max(3), Constraint::Fill(1), Constraint::Fill(1)]).split(area); - let input_layout = Layout::horizontal(vec![Constraint::Fill(1), Constraint::Fill(1)]).split(outer_layout[1]); + let outer_layout = + Layout::vertical(vec![Constraint::Max(3), self.panes[1].height_constraint(), self.panes[2].height_constraint()]) + .split(area); frame.render_widget( Paragraph::new(Line::from(vec![ Span::styled( @@ -204,9 +211,16 @@ impl Page for Phone { outer_layout[0], ); - self.panes[0].draw(frame, input_layout[0], state)?; - self.panes[1].draw(frame, input_layout[1], state)?; - self.panes[2].draw(frame, outer_layout[2], state)?; + if let Some(fullscreen_pane_index) = self.fullscreen_pane_index { + let area = outer_layout[1].union(outer_layout[2]); + self.panes[fullscreen_pane_index].draw(frame, area, state)?; + } else { + let input_layout = Layout::horizontal(vec![Constraint::Fill(1), Constraint::Fill(1)]).split(outer_layout[1]); + + self.panes[0].draw(frame, input_layout[0], state)?; + self.panes[1].draw(frame, input_layout[1], state)?; + self.panes[2].draw(frame, outer_layout[2], state)?; + } Ok(()) } } diff --git a/src/panes/body_editor.rs b/src/panes/body_editor.rs index 3a5f45a..c10b057 100644 --- a/src/panes/body_editor.rs +++ b/src/panes/body_editor.rs @@ -91,7 +91,13 @@ impl Pane for BodyEditor<'_> { } fn height_constraint(&self) -> Constraint { - Constraint::Fill(1) + if self.content_types.is_empty() { + return Constraint::Fill(1); + } + match self.focused { + true => Constraint::Fill(3), + false => Constraint::Fill(1), + } } fn handle_key_events(&mut self, key: KeyEvent, state: &mut State) -> Result>> { diff --git a/src/panes/response_viewer.rs b/src/panes/response_viewer.rs index 5c508bf..a944118 100644 --- a/src/panes/response_viewer.rs +++ b/src/panes/response_viewer.rs @@ -83,7 +83,10 @@ impl Pane for ResponseViewer { } fn height_constraint(&self) -> Constraint { - Constraint::Fill(1) + match self.focused { + true => Constraint::Fill(3), + false => Constraint::Fill(1), + } } fn handle_key_events(&mut self, _key: KeyEvent, state: &mut State) -> Result>> {