From 8e8367eea6ff146c7e1097af153398832691e078 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Tue, 21 Jun 2022 22:22:08 +0530 Subject: Refactor Margin for fine grained control (#2727) --- helix-term/src/commands/lsp.rs | 6 ++---- helix-term/src/ui/info.rs | 5 +---- helix-term/src/ui/markdown.rs | 5 +---- helix-term/src/ui/picker.rs | 5 +---- helix-term/src/ui/popup.rs | 9 +++------ helix-term/src/ui/prompt.rs | 5 +---- 6 files changed, 9 insertions(+), 26 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index b6bea8d6..3ee3c54a 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -287,10 +287,8 @@ pub fn code_action(cx: &mut Context) { }); picker.move_down(); // pre-select the first item - let popup = Popup::new("code-action", picker).margin(helix_view::graphics::Margin { - vertical: 1, - horizontal: 1, - }); + let popup = + Popup::new("code-action", picker).margin(helix_view::graphics::Margin::all(1)); compositor.replace_or_push("code-action", popup); }, ) diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs index 272244c1..cc6b7483 100644 --- a/helix-term/src/ui/info.rs +++ b/helix-term/src/ui/info.rs @@ -27,10 +27,7 @@ impl Component for Info { .borders(Borders::ALL) .border_style(popup_style); - let margin = Margin { - vertical: 0, - horizontal: 1, - }; + let margin = Margin::horizontal(1); let inner = block.inner(area).inner(&margin); block.render(area, surface); diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index 037e2f13..e3ce2cd5 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -323,10 +323,7 @@ impl Component for Markdown { .wrap(Wrap { trim: false }) .scroll((cx.scroll.unwrap_or_default() as u16, 0)); - let margin = Margin { - vertical: 1, - horizontal: 1, - }; + let margin = Margin::all(1); par.render(area.inner(&margin), surface); } diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 95ec8405..ebff9827 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -200,10 +200,7 @@ impl Component for FilePicker { // calculate the inner area inside the box let inner = block.inner(preview_area); // 1 column gap on either side - let margin = Margin { - vertical: 0, - horizontal: 1, - }; + let margin = Margin::horizontal(1); let inner = inner.inner(&margin); block.render(preview_area, surface); diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 185ec15d..f5b79526 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -27,10 +27,7 @@ impl Popup { Self { contents, position: None, - margin: Margin { - vertical: 0, - horizontal: 0, - }, + margin: Margin::none(), size: (0, 0), child_size: (0, 0), scroll: 0, @@ -163,8 +160,8 @@ impl Component for Popup { self.child_size = (width, height); self.size = ( - (width + self.margin.horizontal * 2).min(max_width), - (height + self.margin.vertical * 2).min(max_height), + (width + self.margin.width()).min(max_width), + (height + self.margin.height()).min(max_height), ); // re-clamp scroll offset diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 64154bae..7744a161 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -430,10 +430,7 @@ impl Prompt { .borders(Borders::ALL) .border_style(background); - let inner = block.inner(area).inner(&Margin { - vertical: 0, - horizontal: 1, - }); + let inner = block.inner(area).inner(&Margin::horizontal(1)); block.render(area, surface); text.render(inner, surface, cx); -- cgit v1.2.3-70-g09d2