Cleaner poll card
Browse files at this commitb2c96e7d80a4cfe4c98b801a081fdcad4021748aParent: ff2ed3d- ui
- cleaner poll card
1 changed file +71 -55
- crates/client/src/gui/poll.rs +71 -55
crates/client/src/gui/poll.rsmodified+71 -55
| @@ -3,10 +3,10 @@ use std::collections::HashSet; | |||
| 3 | use common::model::{Message, Poll, Rank, User}; | 3 | use common::model::{Message, Poll, Rank, User}; |
| 4 | use gpui_kit::{ | 4 | use gpui_kit::{ |
| 5 | Context, Div, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement, Styled, | 5 | Context, Div, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement, Styled, |
| 6 | - Window, assets::IconName, component::Icon, div, px, relative, | 6 | + Window, assets::IconName, component::Icon, div, prelude::FluentBuilder as _, px, relative, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | -use super::{Palette, Yumush, chat::Chat, clickable, notify_error, text}; | 9 | +use super::{Palette, Tooltip as _, Yumush, chat::Chat, clickable, notify_error, text}; |
| 10 | 10 | ||
| 11 | pub fn voter_count(poll: &Poll) -> usize { | 11 | pub fn voter_count(poll: &Poll) -> usize { |
| 12 | poll.options | 12 | poll.options |
| @@ -92,20 +92,14 @@ pub fn poll_card( | |||
| 92 | None => div().id(id), | 92 | None => div().id(id), |
| 93 | } | 93 | } |
| 94 | .relative() | 94 | .relative() |
| 95 | - .h(px(30.)) | 95 | + .h(px(32.)) |
| 96 | .px(px(10.)) | 96 | .px(px(10.)) |
| 97 | .flex() | 97 | .flex() |
| 98 | .items_center() | 98 | .items_center() |
| 99 | - .justify_between() | ||
| 100 | .gap(px(8.)) | 99 | .gap(px(8.)) |
| 101 | .rounded(px(6.)) | 100 | .rounded(px(6.)) |
| 102 | .overflow_hidden() | 101 | .overflow_hidden() |
| 103 | - .border_1() | 102 | + .bg(palette.field) |
| 104 | - .border_color(if picked { | ||
| 105 | - palette.accent | ||
| 106 | - } else { | ||
| 107 | - palette.border | ||
| 108 | - }) | ||
| 109 | .child( | 103 | .child( |
| 110 | div() | 104 | div() |
| 111 | .absolute() | 105 | .absolute() |
| @@ -113,28 +107,43 @@ pub fn poll_card( | |||
| 113 | .top_0() | 107 | .top_0() |
| 114 | .h_full() | 108 | .h_full() |
| 115 | .w(relative(share as f32 / 100.)) | 109 | .w(relative(share as f32 / 100.)) |
| 116 | - .bg(palette.accent.opacity(0.18)), | 110 | + .bg(palette.accent.opacity(if picked { 0.35 } else { 0.15 })), |
| 117 | ) | 111 | ) |
| 118 | .child( | 112 | .child( |
| 119 | div() | 113 | div() |
| 114 | + .flex_shrink_0() | ||
| 115 | + .size(px(14.)) | ||
| 120 | .flex() | 116 | .flex() |
| 121 | .items_center() | 117 | .items_center() |
| 122 | - .gap(px(6.)) | 118 | + .justify_center() |
| 119 | + .rounded_full() | ||
| 120 | + .border_1() | ||
| 121 | + .border_color(if picked { | ||
| 122 | + palette.accent | ||
| 123 | + } else { | ||
| 124 | + palette.muted | ||
| 125 | + }) | ||
| 126 | + .when(picked, |marker| { | ||
| 127 | + marker | ||
| 128 | + .bg(palette.accent) | ||
| 129 | + .text_color(palette.on_accent) | ||
| 130 | + .child(Icon::new(IconName::Check).w(px(10.)).h(px(10.))) | ||
| 131 | + }), | ||
| 132 | + ) | ||
| 133 | + .child( | ||
| 134 | + div() | ||
| 135 | + .flex_1() | ||
| 123 | .min_w_0() | 136 | .min_w_0() |
| 124 | - .children(picked.then(|| { | 137 | + .truncate() |
| 125 | - div() | 138 | + .child(option.text.clone()), |
| 126 | - .flex_shrink_0() | ||
| 127 | - .text_color(palette.accent) | ||
| 128 | - .child(Icon::new(IconName::Check).w(px(12.)).h(px(12.))) | ||
| 129 | - })) | ||
| 130 | - .child(div().min_w_0().truncate().child(option.text.clone())), | ||
| 131 | ) | 139 | ) |
| 132 | .child( | 140 | .child( |
| 133 | div() | 141 | div() |
| 134 | .flex_shrink_0() | 142 | .flex_shrink_0() |
| 135 | .text_size(text(12.)) | 143 | .text_size(text(12.)) |
| 136 | - .text_color(palette.muted) | 144 | + .font_weight(FontWeight::SEMIBOLD) |
| 137 | - .child(format!("{count} · {share}%")), | 145 | + .text_color(if picked { palette.text } else { palette.muted }) |
| 146 | + .child(format!("{share}%")), | ||
| 138 | ) | 147 | ) |
| 139 | }); | 148 | }); |
| 140 | 149 | ||
| @@ -145,49 +154,56 @@ pub fn poll_card( | |||
| 145 | .text_size(text(12.)) | 154 | .text_size(text(12.)) |
| 146 | .text_color(palette.muted) | 155 | .text_color(palette.muted) |
| 147 | .child(match voters { | 156 | .child(match voters { |
| 148 | - 1 => "1 voter".to_string(), | 157 | + 1 => "1 vote".to_string(), |
| 149 | - _ => format!("{voters} voters"), | 158 | + _ => format!("{voters} votes"), |
| 150 | }) | 159 | }) |
| 151 | - .child( | 160 | + .children(poll.closed.then_some("Closed")) |
| 152 | - div() | 161 | + .children(close_id.map(|close_id| { |
| 153 | - .flex() | 162 | + let close_entity = entity.clone(); |
| 154 | - .items_center() | 163 | + clickable( |
| 155 | - .gap(px(8.)) | 164 | + format!("poll_close_{close_id}"), |
| 156 | - .children(poll.closed.then_some("Closed")) | 165 | + palette, |
| 157 | - .children(close_id.map(|close_id| { | 166 | + move |window, cx| { |
| 158 | - let close_entity = entity.clone(); | 167 | + let close_id = close_id.clone(); |
| 159 | - clickable( | 168 | + close_entity.update(cx, |yumush, cx| yumush.close_poll(close_id, window, cx)); |
| 160 | - format!("poll_close_{close_id}"), | 169 | + }, |
| 161 | - palette, | 170 | + ) |
| 162 | - move |window, cx| { | 171 | + .tip("End poll") |
| 163 | - let close_id = close_id.clone(); | 172 | + .size(px(22.)) |
| 164 | - close_entity | 173 | + .flex() |
| 165 | - .update(cx, |yumush, cx| yumush.close_poll(close_id, window, cx)); | 174 | + .items_center() |
| 166 | - }, | 175 | + .justify_center() |
| 167 | - ) | 176 | + .rounded(px(6.)) |
| 168 | - .px(px(6.)) | 177 | + .child(Icon::new(IconName::CircleStop).w(px(13.)).h(px(13.))) |
| 169 | - .py(px(2.)) | 178 | + })); |
| 170 | - .rounded(px(6.)) | ||
| 171 | - .border_1() | ||
| 172 | - .border_color(palette.border) | ||
| 173 | - .child("Close") | ||
| 174 | - })), | ||
| 175 | - ); | ||
| 176 | 179 | ||
| 177 | div() | 180 | div() |
| 178 | .flex() | 181 | .flex() |
| 179 | .flex_col() | 182 | .flex_col() |
| 180 | .gap(px(6.)) | 183 | .gap(px(6.)) |
| 181 | - .p(px(10.)) | 184 | + .p(px(12.)) |
| 182 | - .max_w(px(420.)) | 185 | + .w(px(320.)) |
| 183 | - .rounded(px(8.)) | 186 | + .max_w_full() |
| 184 | - .border_1() | 187 | + .rounded(px(10.)) |
| 185 | - .border_color(palette.border) | ||
| 186 | .bg(palette.panel) | 188 | .bg(palette.panel) |
| 187 | .child( | 189 | .child( |
| 188 | div() | 190 | div() |
| 189 | - .font_weight(FontWeight::SEMIBOLD) | 191 | + .flex() |
| 190 | - .child(poll.question.clone()), | 192 | + .items_center() |
| 193 | + .gap(px(8.)) | ||
| 194 | + .mb(px(2.)) | ||
| 195 | + .child( | ||
| 196 | + div() | ||
| 197 | + .flex_shrink_0() | ||
| 198 | + .text_color(palette.accent) | ||
| 199 | + .child(Icon::new(IconName::ChartBar).w(px(14.)).h(px(14.))), | ||
| 200 | + ) | ||
| 201 | + .child( | ||
| 202 | + div() | ||
| 203 | + .min_w_0() | ||
| 204 | + .font_weight(FontWeight::SEMIBOLD) | ||
| 205 | + .child(poll.question.clone()), | ||
| 206 | + ), | ||
| 191 | ) | 207 | ) |
| 192 | .children(rows) | 208 | .children(rows) |
| 193 | .child(footer) | 209 | .child(footer) |