ratatui_command_palette/render/
inline.rs1use ratatui::buffer::Buffer;
2use ratatui::layout::{Constraint, Direction, Layout, Rect};
3use ratatui::style::{Color, Style};
4use ratatui::widgets::{Block, Borders, Widget};
5
6use super::PaletteRenderer;
7use super::parts::{render_query, render_rows};
8use crate::view::PaletteView;
9
10#[derive(Clone, Debug)]
17pub struct InlineDropdownRenderer {
18 title: String,
19}
20
21impl Default for InlineDropdownRenderer {
22 fn default() -> Self {
23 Self::new()
24 }
25}
26
27impl InlineDropdownRenderer {
28 pub fn new() -> Self {
30 Self {
31 title: "Commands".into(),
32 }
33 }
34
35 pub fn title(mut self, title: impl Into<String>) -> Self {
47 self.title = title.into();
48 self
49 }
50}
51
52impl PaletteRenderer for InlineDropdownRenderer {
53 fn render(&self, area: Rect, buf: &mut Buffer, view: &PaletteView) {
54 let block = Block::new()
55 .title(self.title.as_str())
56 .borders(Borders::ALL)
57 .border_style(Style::new().fg(Color::DarkGray));
58 let inner = block.inner(area);
59 block.render(area, buf);
60
61 if inner.height == 0 || inner.width == 0 {
62 return;
63 }
64
65 let sections = Layout::default()
66 .direction(Direction::Vertical)
67 .constraints([Constraint::Length(1), Constraint::Min(0)])
68 .split(inner);
69
70 render_query(sections[0], buf, view);
71 render_rows(sections[1], buf, view);
72 }
73}