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 | 3 | use common::model::{Message, Poll, Rank, User}; |
| 4 | 4 | use gpui_kit::{ |
| 5 | 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 | 11 | pub fn voter_count(poll: &Poll) -> usize { |
| 12 | 12 | poll.options |
| @@ -92,20 +92,14 @@ pub fn poll_card( | ||
| 92 | 92 | None => div().id(id), |
| 93 | 93 | } |
| 94 | 94 | .relative() |
| 95 | - .h(px(30.)) | |
| 95 | + .h(px(32.)) | |
| 96 | 96 | .px(px(10.)) |
| 97 | 97 | .flex() |
| 98 | 98 | .items_center() |
| 99 | - .justify_between() | |
| 100 | 99 | .gap(px(8.)) |
| 101 | 100 | .rounded(px(6.)) |
| 102 | 101 | .overflow_hidden() |
| 103 | - .border_1() | |
| 104 | - .border_color(if picked { | |
| 105 | - palette.accent | |
| 106 | - } else { | |
| 107 | - palette.border | |
| 108 | - }) | |
| 102 | + .bg(palette.field) | |
| 109 | 103 | .child( |
| 110 | 104 | div() |
| 111 | 105 | .absolute() |
| @@ -113,28 +107,43 @@ pub fn poll_card( | ||
| 113 | 107 | .top_0() |
| 114 | 108 | .h_full() |
| 115 | 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 | 112 | .child( |
| 119 | 113 | div() |
| 114 | + .flex_shrink_0() | |
| 115 | + .size(px(14.)) | |
| 120 | 116 | .flex() |
| 121 | 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 | 136 | .min_w_0() |
| 124 | - .children(picked.then(|| { | |
| 125 | - div() | |
| 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())), | |
| 137 | + .truncate() | |
| 138 | + .child(option.text.clone()), | |
| 131 | 139 | ) |
| 132 | 140 | .child( |
| 133 | 141 | div() |
| 134 | 142 | .flex_shrink_0() |
| 135 | 143 | .text_size(text(12.)) |
| 136 | - .text_color(palette.muted) | |
| 137 | - .child(format!("{count} · {share}%")), | |
| 144 | + .font_weight(FontWeight::SEMIBOLD) | |
| 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 | 154 | .text_size(text(12.)) |
| 146 | 155 | .text_color(palette.muted) |
| 147 | 156 | .child(match voters { |
| 148 | - 1 => "1 voter".to_string(), | |
| 149 | - _ => format!("{voters} voters"), | |
| 157 | + 1 => "1 vote".to_string(), | |
| 158 | + _ => format!("{voters} votes"), | |
| 150 | 159 | }) |
| 151 | - .child( | |
| 152 | - div() | |
| 153 | - .flex() | |
| 154 | - .items_center() | |
| 155 | - .gap(px(8.)) | |
| 156 | - .children(poll.closed.then_some("Closed")) | |
| 157 | - .children(close_id.map(|close_id| { | |
| 158 | - let close_entity = entity.clone(); | |
| 159 | - clickable( | |
| 160 | - format!("poll_close_{close_id}"), | |
| 161 | - palette, | |
| 162 | - move |window, cx| { | |
| 163 | - let close_id = close_id.clone(); | |
| 164 | - close_entity | |
| 165 | - .update(cx, |yumush, cx| yumush.close_poll(close_id, window, cx)); | |
| 166 | - }, | |
| 167 | - ) | |
| 168 | - .px(px(6.)) | |
| 169 | - .py(px(2.)) | |
| 170 | - .rounded(px(6.)) | |
| 171 | - .border_1() | |
| 172 | - .border_color(palette.border) | |
| 173 | - .child("Close") | |
| 174 | - })), | |
| 175 | - ); | |
| 160 | + .children(poll.closed.then_some("Closed")) | |
| 161 | + .children(close_id.map(|close_id| { | |
| 162 | + let close_entity = entity.clone(); | |
| 163 | + clickable( | |
| 164 | + format!("poll_close_{close_id}"), | |
| 165 | + palette, | |
| 166 | + move |window, cx| { | |
| 167 | + let close_id = close_id.clone(); | |
| 168 | + close_entity.update(cx, |yumush, cx| yumush.close_poll(close_id, window, cx)); | |
| 169 | + }, | |
| 170 | + ) | |
| 171 | + .tip("End poll") | |
| 172 | + .size(px(22.)) | |
| 173 | + .flex() | |
| 174 | + .items_center() | |
| 175 | + .justify_center() | |
| 176 | + .rounded(px(6.)) | |
| 177 | + .child(Icon::new(IconName::CircleStop).w(px(13.)).h(px(13.))) | |
| 178 | + })); | |
| 176 | 179 | |
| 177 | 180 | div() |
| 178 | 181 | .flex() |
| 179 | 182 | .flex_col() |
| 180 | 183 | .gap(px(6.)) |
| 181 | - .p(px(10.)) | |
| 182 | - .max_w(px(420.)) | |
| 183 | - .rounded(px(8.)) | |
| 184 | - .border_1() | |
| 185 | - .border_color(palette.border) | |
| 184 | + .p(px(12.)) | |
| 185 | + .w(px(320.)) | |
| 186 | + .max_w_full() | |
| 187 | + .rounded(px(10.)) | |
| 186 | 188 | .bg(palette.panel) |
| 187 | 189 | .child( |
| 188 | 190 | div() |
| 189 | - .font_weight(FontWeight::SEMIBOLD) | |
| 190 | - .child(poll.question.clone()), | |
| 191 | + .flex() | |
| 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 | 208 | .children(rows) |
| 193 | 209 | .child(footer) |