gitkraft_gui/features/theme/
view.rs1use iced::widget::pick_list;
7use iced::{Element, Length};
8
9use crate::message::Message;
10
11#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct ThemeChoice {
14 pub index: usize,
15 pub name: &'static str,
16}
17
18impl std::fmt::Display for ThemeChoice {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 f.write_str(self.name)
21 }
22}
23
24pub fn all_themes() -> Vec<ThemeChoice> {
27 gitkraft_core::THEME_NAMES
28 .iter()
29 .enumerate()
30 .map(|(i, name)| ThemeChoice { index: i, name })
31 .collect()
32}
33
34pub fn theme_selector(current_theme_index: usize) -> Element<'static, Message> {
40 let choices = all_themes();
41 let selected = choices.get(current_theme_index).cloned();
42
43 pick_list(choices, selected, |choice| {
44 Message::ThemeChanged(choice.index)
45 })
46 .placeholder("Select theme")
47 .text_size(13.0)
48 .width(Length::Fixed(180.0))
49 .into()
50}