From 920c53c8b4977f314438dffffdb8f2b2d220987c Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Tue, 14 Sep 2021 01:13:17 +0900 Subject: [PATCH] add a left_chunk_percentage field --- src/app.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 77e1905..171f51c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -34,6 +34,7 @@ pub struct App { databases: DatabasesComponent, connections: ConnectionsComponent, pool: Option>, + left_chunk_percentage: u16, pub config: Config, pub error: ErrorComponent, } @@ -54,6 +55,7 @@ impl App { error: ErrorComponent::new(config.key_config), focus: Focus::ConnectionList, pool: None, + left_chunk_percentage: 15, } } @@ -73,7 +75,10 @@ impl App { let main_chunks = Layout::default() .direction(Direction::Horizontal) - .constraints([Constraint::Percentage(15), Constraint::Percentage(85)]) + .constraints([ + Constraint::Percentage(self.left_chunk_percentage), + Constraint::Percentage((100_u16).saturating_sub(self.left_chunk_percentage)), + ]) .split(f.size()); self.databases @@ -327,6 +332,23 @@ impl App { if key == self.config.key_config.enter && self.databases.tree_focused() { self.update_table().await?; return Ok(EventState::Consumed); + } else if key + == self + .config + .key_config + .extend_or_shorten_widget_width_to_left + { + self.left_chunk_percentage = + self.left_chunk_percentage.saturating_sub(5).max(15); + return Ok(EventState::Consumed); + } else if key + == self + .config + .key_config + .extend_or_shorten_widget_width_to_right + { + self.left_chunk_percentage = (self.left_chunk_percentage + 5).min(70); + return Ok(EventState::Consumed); } return Ok(state); @@ -428,6 +450,25 @@ impl App { }; } }; + + if key + == self + .config + .key_config + .extend_or_shorten_widget_width_to_left + { + self.left_chunk_percentage = + self.left_chunk_percentage.saturating_sub(5).max(15); + return Ok(EventState::Consumed); + } else if key + == self + .config + .key_config + .extend_or_shorten_widget_width_to_right + { + self.left_chunk_percentage = (self.left_chunk_percentage + 5).min(70); + return Ok(EventState::Consumed); + } } } Ok(EventState::NotConsumed)