MCPcopy Create free account
hub / github.com/bajrangCoder/setu / render

Method render

src/components/protocol_selector.rs:44–110  ·  view source on GitHub ↗
(self, _window: &mut Window, cx: &mut App)

Source from the content-addressed store, hash-verified

42 Self {
43 selected,
44 on_change: None,
45 }
46 }
47
48 pub fn on_change(
49 mut self,
50 callback: impl Fn(ProtocolType, &mut Window, &mut App) + 'static,
51 ) -> Self {
52 self.on_change = Some(Rc::new(callback));
53 self
54 }
55}
56
57impl RenderOnce for ProtocolSelector {
58 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
59 let theme = cx.theme();
60 let protocols = [
61 ProtocolType::Rest,
62 ProtocolType::WebSocket,
63 ProtocolType::GraphQL,
64 ProtocolType::Sse,
65 ];
66 let on_change = self.on_change;
67 let selected = self.selected;
68
69 div()
70 .flex()
71 .items_center()
72 .gap(px(2.0))
73 .p(px(2.0))
74 .bg(theme.muted)
75 .rounded(px(6.0))
76 .children(protocols.into_iter().map(move |protocol| {
77 let is_selected = protocol == selected;
78 let is_available = protocol.is_available();
79 let on_change = on_change.clone();
80 let hover_key = format!("protocol-selector-{}", protocol.label());
81 let rest_color = if is_selected {
82 theme.foreground
83 } else {
84 theme.muted_foreground
85 };
86 let hover_color = if is_available && !is_selected {
87 theme.secondary_foreground
88 } else {
89 rest_color
90 };
91
92 div()
93 .id(protocol.label())
94 .relative()
95 .flex()
96 .items_center()
97 .gap(px(4.0))
98 .px(px(8.0))
99 .py(px(4.0))
100 .rounded(px(4.0))
101 .cursor(if is_available {

Callers

nothing calls this directly

Calls 3

is_availableMethod · 0.80
childMethod · 0.80
labelMethod · 0.45

Tested by

no test coverage detected