| 101 | } |
| 102 | |
| 103 | pub fn render(&mut self, frame: &mut Frame, area: Rect, theme: &Theme) { |
| 104 | if !self.visible || self.items.is_empty() { |
| 105 | self.last_area = None; |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | let popup_width = area.width.saturating_sub(4).min(70); |
| 110 | let popup_height = (self.items.len() as u16 + 4).min(area.height.saturating_sub(2)); |
| 111 | if popup_height < 5 || popup_width < 20 { |
| 112 | self.last_area = None; |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | let popup_x = area.x + (area.width.saturating_sub(popup_width)) / 2; |
| 117 | let popup_y = area.y + (area.height.saturating_sub(popup_height)) / 2; |
| 118 | |
| 119 | let popup_area = Rect { |
| 120 | x: popup_x, |
| 121 | y: popup_y, |
| 122 | width: popup_width, |
| 123 | height: popup_height, |
| 124 | }; |
| 125 | self.last_area = Some(popup_area); |
| 126 | |
| 127 | let list_items: Vec<ListItem> = self |
| 128 | .items |
| 129 | .iter() |
| 130 | .map(|t| { |
| 131 | let is_current = self |
| 132 | .current_theme_id |
| 133 | .as_ref() |
| 134 | .map_or(false, |id| id == &t.id); |
| 135 | |
| 136 | let marker = if is_current { "● " } else { " " }; |
| 137 | let marker_style = if is_current { |
| 138 | theme.style(StyleKind::Success) |
| 139 | } else { |
| 140 | theme.style(StyleKind::Muted) |
| 141 | }; |
| 142 | |
| 143 | let name_style = theme.style(StyleKind::Primary).add_modifier(Modifier::BOLD); |
| 144 | let line = Line::from(vec![ |
| 145 | Span::styled(marker, marker_style), |
| 146 | Span::styled(&t.id, name_style), |
| 147 | ]); |
| 148 | ListItem::new(line) |
| 149 | }) |
| 150 | .collect(); |
| 151 | |
| 152 | let block = Block::default() |
| 153 | .borders(Borders::ALL) |
| 154 | .border_style(theme.style(StyleKind::Primary)) |
| 155 | .style(Style::default().bg(theme.background)) |
| 156 | .title(" Select Theme (↑↓ Navigate, Enter Select, Esc Cancel) "); |
| 157 | |
| 158 | let list = List::new(list_items) |
| 159 | .block(block) |
| 160 | .style(Style::default().bg(theme.background)) |