From a14a7d7eb61850b4a3b41edc84e63e43775dd425 Mon Sep 17 00:00:00 2001 From: Fabian Gruber Date: Sun, 11 Aug 2024 19:41:48 +0200 Subject: [PATCH] feat: added rounded-corners option to draw rounded borders --- book/src/editor.md | 1 + helix-term/src/ui/completion.rs | 9 +++++++-- helix-term/src/ui/info.rs | 6 ++++-- helix-term/src/ui/picker.rs | 14 ++++++++------ helix-term/src/ui/popup.rs | 5 +++-- helix-term/src/ui/prompt.rs | 6 ++++-- helix-tui/src/widgets/block.rs | 8 ++++++++ helix-view/src/editor.rs | 3 +++ 8 files changed, 38 insertions(+), 14 deletions(-) diff --git a/book/src/editor.md b/book/src/editor.md index 82d5f8461..56ef13c29 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -49,6 +49,7 @@ | `default-line-ending` | The line ending to use for new documents. Can be `native`, `lf`, `crlf`, `ff`, `cr` or `nel`. `native` uses the platform's native line ending (`crlf` on Windows, otherwise `lf`). | `native` | | `insert-final-newline` | Whether to automatically insert a trailing line-ending on write if missing | `true` | | `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` | +| `rounded-corners` | Set to `true` to draw rounded border corners | `false` | | `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid` | `jump-label-alphabet` | The characters that are used to generate two character jump labels. Characters at the start of the alphabet are used first. | `"abcdefghijklmnopqrstuvwxyz"` | `end-of-line-diagnostics` | Minimum severity of diagnostics to render at the end of the line. Set to `disable` to disable entirely. Refer to the setting about `inline-diagnostics` for more details | "disable" diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 14397bb5c..6b457083c 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -9,7 +9,7 @@ use helix_view::{ theme::{Modifier, Style}, ViewId, }; -use tui::{buffer::Buffer as Surface, text::Span}; +use tui::{buffer::Buffer as Surface, text::Span, widgets::BorderType}; use std::{borrow::Cow, sync::Arc}; @@ -531,7 +531,12 @@ impl Component for Completion { if cx.editor.popup_border() { use tui::widgets::{Block, Widget}; - Widget::render(Block::bordered(), doc_area, surface); + let border_type = BorderType::new(cx.editor.config().rounded_corners); + Widget::render( + Block::bordered().border_type(border_type), + doc_area, + surface, + ); } markdown_doc.render(doc_area, surface, cx); diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs index 217cee6b3..54840589e 100644 --- a/helix-term/src/ui/info.rs +++ b/helix-term/src/ui/info.rs @@ -3,7 +3,7 @@ use helix_view::graphics::{Margin, Rect}; use helix_view::info::Info; use tui::buffer::Buffer as Surface; use tui::text::Text; -use tui::widgets::{Block, Paragraph, Widget}; +use tui::widgets::{Block, BorderType, Paragraph, Widget}; impl Component for Info { fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { @@ -23,9 +23,11 @@ impl Component for Info { )); surface.clear_with(area, popup_style); + let border_type = BorderType::new(cx.editor.config().rounded_corners); let block = Block::bordered() .title(self.title.as_str()) - .border_style(popup_style); + .border_style(popup_style) + .border_type(border_type); let margin = Margin::horizontal(1); let inner = block.inner(area).inner(margin); diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 82fe96891..146649aa7 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -655,12 +655,13 @@ impl Picker { let background = cx.editor.theme.get("ui.background"); surface.clear_with(area, background); - const BLOCK: Block<'_> = Block::bordered(); + let border_type = BorderType::new(cx.editor.config().rounded_corners); + let block: Block<'_> = Block::bordered().border_type(border_type); // calculate the inner area inside the box - let inner = BLOCK.inner(area); + let inner = block.inner(area); - BLOCK.render(area, surface); + block.render(area, surface); // -- Render the input bar: @@ -840,14 +841,15 @@ impl Picker { let text = cx.editor.theme.get("ui.text"); surface.clear_with(area, background); - const BLOCK: Block<'_> = Block::bordered(); + let border_type = BorderType::new(cx.editor.config().rounded_corners); + let block: Block<'_> = Block::bordered().border_type(border_type); // calculate the inner area inside the box - let inner = BLOCK.inner(area); + let inner = block.inner(area); // 1 column gap on either side let margin = Margin::horizontal(1); let inner = inner.inner(margin); - BLOCK.render(area, surface); + block.render(area, surface); if let Some((preview, range)) = self.get_preview(cx.editor) { let doc = match preview.document() { diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 2cefaf61b..bb7543a46 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -5,7 +5,7 @@ use crate::{ }; use tui::{ buffer::Buffer as Surface, - widgets::{Block, Widget}, + widgets::{Block, BorderType, Widget}, }; use helix_core::Position; @@ -323,8 +323,9 @@ impl Component for Popup { let mut inner = area; if render_borders { + let border_type = BorderType::new(cx.editor.config().rounded_corners); inner = area.inner(Margin::all(1)); - Widget::render(Block::bordered(), area, surface); + Widget::render(Block::bordered().border_type(border_type), area, surface); } let border = usize::from(render_borders); diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 6ba2fcb9e..31de9a7b2 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -8,7 +8,7 @@ use helix_view::keyboard::KeyCode; use std::sync::Arc; use std::{borrow::Cow, ops::RangeFrom}; use tui::buffer::Buffer as Surface; -use tui::widgets::{Block, Widget}; +use tui::widgets::{Block, BorderType, Widget}; use helix_core::{ unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position, @@ -485,9 +485,11 @@ impl Prompt { let background = theme.get("ui.help"); surface.clear_with(area, background); + let border_type = BorderType::new(cx.editor.config().rounded_corners); let block = Block::bordered() // .title(self.title.as_str()) - .border_style(background); + .border_style(background) + .border_type(border_type); let inner = block.inner(area).inner(Margin::horizontal(1)); diff --git a/helix-tui/src/widgets/block.rs b/helix-tui/src/widgets/block.rs index 8b8141ea9..ac53648d4 100644 --- a/helix-tui/src/widgets/block.rs +++ b/helix-tui/src/widgets/block.rs @@ -17,6 +17,14 @@ pub enum BorderType { } impl BorderType { + pub fn new(rounded: bool) -> Self { + if rounded { + Self::Rounded + } else { + Self::default() + } + } + pub fn line_symbols(border_type: Self) -> line::Set { match border_type { Self::Plain => line::NORMAL, diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 1708b3b4e..7dae3d956 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -333,6 +333,8 @@ pub struct Config { pub smart_tab: Option, /// Draw border around popups. pub popup_border: PopupBorderConfig, + /// Draw rounded border corners + pub rounded_corners: bool, /// Which indent heuristic to use when a new line is inserted #[serde(default)] pub indent_heuristic: IndentationHeuristic, @@ -975,6 +977,7 @@ impl Default for Config { insert_final_newline: true, smart_tab: Some(SmartTabConfig::default()), popup_border: PopupBorderConfig::None, + rounded_corners: false, indent_heuristic: IndentationHeuristic::default(), jump_label_alphabet: ('a'..='z').collect(), inline_diagnostics: InlineDiagnosticsConfig::default(),