gitkraft_gui/features/remotes/
view.rs1use iced::widget::{button, column, container, row, text, Space};
7use iced::{Alignment, Element, Length};
8
9use crate::icons;
10use crate::message::Message;
11use crate::state::GitKraft;
12use crate::theme;
13use crate::view_utils;
14
15pub fn view(state: &GitKraft) -> Element<'_, Message> {
17 let tab = state.active_tab();
18 let c = state.colors();
19
20 let header_icon = icon!(icons::CLOUD, 14, c.accent);
21
22 let header_text = text("Remotes").size(14).color(c.text_primary);
23
24 let fetch_icon = icon!(icons::CLOUD_ARROW_DOWN, 14, c.accent);
25
26 let fetch_msg = (!tab.remotes.is_empty()).then_some(Message::Fetch);
27 let fetch_btn = crate::view_utils::on_press_maybe(
28 button(fetch_icon).padding([2, 6]).style(theme::icon_button),
29 fetch_msg,
30 );
31
32 let header_row = row![
33 header_icon,
34 Space::with_width(6),
35 header_text,
36 Space::with_width(Length::Fill),
37 fetch_btn,
38 ]
39 .align_y(Alignment::Center)
40 .padding([8, 10]);
41
42 let mut list_col = column![].spacing(2).width(Length::Fill);
43
44 if tab.remotes.is_empty() {
45 list_col = list_col.push(view_utils::empty_list_hint(
46 "No remotes configured",
47 c.muted,
48 ));
49 } else {
50 for remote in &tab.remotes {
51 let name_label = container(
52 text(remote.name.as_str())
53 .size(13)
54 .color(c.text_primary)
55 .wrapping(iced::widget::text::Wrapping::None),
56 )
57 .width(Length::Fill)
58 .height(Length::Fixed(18.0))
59 .clip(true);
60
61 let url_str = remote.url.as_deref().unwrap_or("<no url>");
62
63 let url_label = container(
64 text(url_str)
65 .size(11)
66 .color(c.muted)
67 .wrapping(iced::widget::text::Wrapping::None),
68 )
69 .width(Length::Fill)
70 .height(Length::Fixed(16.0))
71 .clip(true);
72
73 let remote_item = container(
74 column![name_label, url_label]
75 .spacing(2)
76 .width(Length::Fill),
77 )
78 .padding([4, 10])
79 .width(Length::Fill)
80 .height(Length::Fixed(42.0))
81 .clip(true);
82
83 list_col = list_col.push(remote_item);
84 }
85 }
86
87 column![header_row, list_col]
88 .spacing(2)
89 .width(Length::Fill)
90 .into()
91}