Skip to content

Commit 1365620

Browse files
authored
feat(borders): Add FULL and EMPTY border sets (#1182)
`border::FULL` uses a full block symbol, while `border::EMPTY` uses an empty space. This is useful for when you need to allocate space for the border and apply the border style to a block without actually drawing a border. This makes it possible to style the entire title area or a block rather than just the title content. ```rust use ratatui::{symbols::border, widgets::Block}; let block = Block::bordered().title("Title").border_set(border::FULL); let block = Block::bordered().title("Title").border_set(border::EMPTY); ```
1 parent cd64367 commit 1365620

File tree

2 files changed

+505
-237
lines changed

2 files changed

+505
-237
lines changed

src/symbols.rs

+1-237
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use strum::{Display, EnumString};
22

3+
pub mod border;
34
pub mod line;
45

56
pub mod block {
@@ -116,243 +117,6 @@ pub mod bar {
116117
};
117118
}
118119

119-
pub mod border {
120-
use super::line;
121-
122-
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
123-
pub struct Set {
124-
pub top_left: &'static str,
125-
pub top_right: &'static str,
126-
pub bottom_left: &'static str,
127-
pub bottom_right: &'static str,
128-
pub vertical_left: &'static str,
129-
pub vertical_right: &'static str,
130-
pub horizontal_top: &'static str,
131-
pub horizontal_bottom: &'static str,
132-
}
133-
134-
impl Default for Set {
135-
fn default() -> Self {
136-
PLAIN
137-
}
138-
}
139-
140-
/// Border Set with a single line width
141-
///
142-
/// ```text
143-
/// ┌─────┐
144-
/// │xxxxx│
145-
/// │xxxxx│
146-
/// └─────┘
147-
pub const PLAIN: Set = Set {
148-
top_left: line::NORMAL.top_left,
149-
top_right: line::NORMAL.top_right,
150-
bottom_left: line::NORMAL.bottom_left,
151-
bottom_right: line::NORMAL.bottom_right,
152-
vertical_left: line::NORMAL.vertical,
153-
vertical_right: line::NORMAL.vertical,
154-
horizontal_top: line::NORMAL.horizontal,
155-
horizontal_bottom: line::NORMAL.horizontal,
156-
};
157-
158-
/// Border Set with a single line width and rounded corners
159-
///
160-
/// ```text
161-
/// ╭─────╮
162-
/// │xxxxx│
163-
/// │xxxxx│
164-
/// ╰─────╯
165-
pub const ROUNDED: Set = Set {
166-
top_left: line::ROUNDED.top_left,
167-
top_right: line::ROUNDED.top_right,
168-
bottom_left: line::ROUNDED.bottom_left,
169-
bottom_right: line::ROUNDED.bottom_right,
170-
vertical_left: line::ROUNDED.vertical,
171-
vertical_right: line::ROUNDED.vertical,
172-
horizontal_top: line::ROUNDED.horizontal,
173-
horizontal_bottom: line::ROUNDED.horizontal,
174-
};
175-
176-
/// Border Set with a double line width
177-
///
178-
/// ```text
179-
/// ╔═════╗
180-
/// ║xxxxx║
181-
/// ║xxxxx║
182-
/// ╚═════╝
183-
pub const DOUBLE: Set = Set {
184-
top_left: line::DOUBLE.top_left,
185-
top_right: line::DOUBLE.top_right,
186-
bottom_left: line::DOUBLE.bottom_left,
187-
bottom_right: line::DOUBLE.bottom_right,
188-
vertical_left: line::DOUBLE.vertical,
189-
vertical_right: line::DOUBLE.vertical,
190-
horizontal_top: line::DOUBLE.horizontal,
191-
horizontal_bottom: line::DOUBLE.horizontal,
192-
};
193-
194-
/// Border Set with a thick line width
195-
///
196-
/// ```text
197-
/// ┏━━━━━┓
198-
/// ┃xxxxx┃
199-
/// ┃xxxxx┃
200-
/// ┗━━━━━┛
201-
pub const THICK: Set = Set {
202-
top_left: line::THICK.top_left,
203-
top_right: line::THICK.top_right,
204-
bottom_left: line::THICK.bottom_left,
205-
bottom_right: line::THICK.bottom_right,
206-
vertical_left: line::THICK.vertical,
207-
vertical_right: line::THICK.vertical,
208-
horizontal_top: line::THICK.horizontal,
209-
horizontal_bottom: line::THICK.horizontal,
210-
};
211-
212-
pub const QUADRANT_TOP_LEFT: &str = "▘";
213-
pub const QUADRANT_TOP_RIGHT: &str = "▝";
214-
pub const QUADRANT_BOTTOM_LEFT: &str = "▖";
215-
pub const QUADRANT_BOTTOM_RIGHT: &str = "▗";
216-
pub const QUADRANT_TOP_HALF: &str = "▀";
217-
pub const QUADRANT_BOTTOM_HALF: &str = "▄";
218-
pub const QUADRANT_LEFT_HALF: &str = "▌";
219-
pub const QUADRANT_RIGHT_HALF: &str = "▐";
220-
pub const QUADRANT_TOP_LEFT_BOTTOM_LEFT_BOTTOM_RIGHT: &str = "▙";
221-
pub const QUADRANT_TOP_LEFT_TOP_RIGHT_BOTTOM_LEFT: &str = "▛";
222-
pub const QUADRANT_TOP_LEFT_TOP_RIGHT_BOTTOM_RIGHT: &str = "▜";
223-
pub const QUADRANT_TOP_RIGHT_BOTTOM_LEFT_BOTTOM_RIGHT: &str = "▟";
224-
pub const QUADRANT_TOP_LEFT_BOTTOM_RIGHT: &str = "▚";
225-
pub const QUADRANT_TOP_RIGHT_BOTTOM_LEFT: &str = "▞";
226-
pub const QUADRANT_BLOCK: &str = "█";
227-
228-
/// Quadrant used for setting a border outside a block by one half cell "pixel".
229-
///
230-
/// ```text
231-
/// ▛▀▀▀▀▀▜
232-
/// ▌xxxxx▐
233-
/// ▌xxxxx▐
234-
/// ▙▄▄▄▄▄▟
235-
/// ```
236-
pub const QUADRANT_OUTSIDE: Set = Set {
237-
top_left: QUADRANT_TOP_LEFT_TOP_RIGHT_BOTTOM_LEFT,
238-
top_right: QUADRANT_TOP_LEFT_TOP_RIGHT_BOTTOM_RIGHT,
239-
bottom_left: QUADRANT_TOP_LEFT_BOTTOM_LEFT_BOTTOM_RIGHT,
240-
bottom_right: QUADRANT_TOP_RIGHT_BOTTOM_LEFT_BOTTOM_RIGHT,
241-
vertical_left: QUADRANT_LEFT_HALF,
242-
vertical_right: QUADRANT_RIGHT_HALF,
243-
horizontal_top: QUADRANT_TOP_HALF,
244-
horizontal_bottom: QUADRANT_BOTTOM_HALF,
245-
};
246-
247-
/// Quadrant used for setting a border inside a block by one half cell "pixel".
248-
///
249-
/// ```text
250-
/// ▗▄▄▄▄▄▖
251-
/// ▐xxxxx▌
252-
/// ▐xxxxx▌
253-
/// ▝▀▀▀▀▀▘
254-
/// ```
255-
pub const QUADRANT_INSIDE: Set = Set {
256-
top_right: QUADRANT_BOTTOM_LEFT,
257-
top_left: QUADRANT_BOTTOM_RIGHT,
258-
bottom_right: QUADRANT_TOP_LEFT,
259-
bottom_left: QUADRANT_TOP_RIGHT,
260-
vertical_left: QUADRANT_RIGHT_HALF,
261-
vertical_right: QUADRANT_LEFT_HALF,
262-
horizontal_top: QUADRANT_BOTTOM_HALF,
263-
horizontal_bottom: QUADRANT_TOP_HALF,
264-
};
265-
266-
pub const ONE_EIGHTH_TOP_EIGHT: &str = "▔";
267-
pub const ONE_EIGHTH_BOTTOM_EIGHT: &str = "▁";
268-
pub const ONE_EIGHTH_LEFT_EIGHT: &str = "▏";
269-
pub const ONE_EIGHTH_RIGHT_EIGHT: &str = "▕";
270-
271-
/// Wide border set based on McGugan box technique
272-
///
273-
/// ```text
274-
/// ▁▁▁▁▁▁▁
275-
/// ▏xxxxx▕
276-
/// ▏xxxxx▕
277-
/// ▔▔▔▔▔▔▔
278-
/// ```
279-
#[allow(clippy::doc_markdown)]
280-
pub const ONE_EIGHTH_WIDE: Set = Set {
281-
top_right: ONE_EIGHTH_BOTTOM_EIGHT,
282-
top_left: ONE_EIGHTH_BOTTOM_EIGHT,
283-
bottom_right: ONE_EIGHTH_TOP_EIGHT,
284-
bottom_left: ONE_EIGHTH_TOP_EIGHT,
285-
vertical_left: ONE_EIGHTH_LEFT_EIGHT,
286-
vertical_right: ONE_EIGHTH_RIGHT_EIGHT,
287-
horizontal_top: ONE_EIGHTH_BOTTOM_EIGHT,
288-
horizontal_bottom: ONE_EIGHTH_TOP_EIGHT,
289-
};
290-
291-
/// Tall border set based on McGugan box technique
292-
///
293-
/// ```text
294-
/// ▕▔▔▏
295-
/// ▕xx▏
296-
/// ▕xx▏
297-
/// ▕▁▁▏
298-
/// ```
299-
#[allow(clippy::doc_markdown)]
300-
pub const ONE_EIGHTH_TALL: Set = Set {
301-
top_right: ONE_EIGHTH_LEFT_EIGHT,
302-
top_left: ONE_EIGHTH_RIGHT_EIGHT,
303-
bottom_right: ONE_EIGHTH_LEFT_EIGHT,
304-
bottom_left: ONE_EIGHTH_RIGHT_EIGHT,
305-
vertical_left: ONE_EIGHTH_RIGHT_EIGHT,
306-
vertical_right: ONE_EIGHTH_LEFT_EIGHT,
307-
horizontal_top: ONE_EIGHTH_TOP_EIGHT,
308-
horizontal_bottom: ONE_EIGHTH_BOTTOM_EIGHT,
309-
};
310-
311-
/// Wide proportional (visually equal width and height) border with using set of quadrants.
312-
///
313-
/// The border is created by using half blocks for top and bottom, and full
314-
/// blocks for right and left sides to make horizontal and vertical borders seem equal.
315-
///
316-
/// ```text
317-
/// ▄▄▄▄
318-
/// █xx█
319-
/// █xx█
320-
/// ▀▀▀▀
321-
/// ```
322-
pub const PROPORTIONAL_WIDE: Set = Set {
323-
top_right: QUADRANT_BOTTOM_HALF,
324-
top_left: QUADRANT_BOTTOM_HALF,
325-
bottom_right: QUADRANT_TOP_HALF,
326-
bottom_left: QUADRANT_TOP_HALF,
327-
vertical_left: QUADRANT_BLOCK,
328-
vertical_right: QUADRANT_BLOCK,
329-
horizontal_top: QUADRANT_BOTTOM_HALF,
330-
horizontal_bottom: QUADRANT_TOP_HALF,
331-
};
332-
333-
/// Tall proportional (visually equal width and height) border with using set of quadrants.
334-
///
335-
/// The border is created by using full blocks for all sides, except for the top and bottom,
336-
/// which use half blocks to make horizontal and vertical borders seem equal.
337-
///
338-
/// ```text
339-
/// ▕█▀▀█
340-
/// ▕█xx█
341-
/// ▕█xx█
342-
/// ▕█▄▄█
343-
/// ```
344-
pub const PROPORTIONAL_TALL: Set = Set {
345-
top_right: QUADRANT_BLOCK,
346-
top_left: QUADRANT_BLOCK,
347-
bottom_right: QUADRANT_BLOCK,
348-
bottom_left: QUADRANT_BLOCK,
349-
vertical_left: QUADRANT_BLOCK,
350-
vertical_right: QUADRANT_BLOCK,
351-
horizontal_top: QUADRANT_TOP_HALF,
352-
horizontal_bottom: QUADRANT_BOTTOM_HALF,
353-
};
354-
}
355-
356120
pub const DOT: &str = "•";
357121

358122
pub mod braille {

0 commit comments

Comments
 (0)