| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
use egui; |
| 21 |
|
| 22 |
use super::theme; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
pub enum ConfirmOutcome { |
| 28 |
|
| 29 |
None, |
| 30 |
|
| 31 |
Confirmed, |
| 32 |
|
| 33 |
Cancelled, |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
pub enum NameModalOutcome { |
| 38 |
|
| 39 |
None, |
| 40 |
|
| 41 |
Submitted(String), |
| 42 |
|
| 43 |
Cancelled, |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
pub fn modal_scrim(ctx: &egui::Context) { |
| 55 |
let screen = ctx.content_rect(); |
| 56 |
egui::Area::new(egui::Id::new("modal_scrim")) |
| 57 |
.order(egui::Order::Middle) |
| 58 |
.fixed_pos(screen.min) |
| 59 |
.show(ctx, |ui| { |
| 60 |
|
| 61 |
|
| 62 |
let resp = ui.allocate_response(screen.size(), egui::Sense::click_and_drag()); |
| 63 |
ui.painter() |
| 64 |
.rect_filled(screen, 0.0, egui::Color32::from_black_alpha(128)); |
| 65 |
resp |
| 66 |
}); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
pub fn modal_window<R>( |
| 76 |
ctx: &egui::Context, |
| 77 |
title: &str, |
| 78 |
resizable: bool, |
| 79 |
default_width: Option<f32>, |
| 80 |
add_contents: impl FnOnce(&mut egui::Ui) -> R, |
| 81 |
) -> Option<R> { |
| 82 |
modal_window_with_open(ctx, title, None, resizable, default_width, add_contents) |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
pub fn tool_window<R>( |
| 93 |
ctx: &egui::Context, |
| 94 |
title: &str, |
| 95 |
open: &mut bool, |
| 96 |
default_width: f32, |
| 97 |
min_width: f32, |
| 98 |
add_contents: impl FnOnce(&mut egui::Ui) -> R, |
| 99 |
) -> Option<R> { |
| 100 |
egui::Window::new(title) |
| 101 |
.open(open) |
| 102 |
.resizable(true) |
| 103 |
.collapsible(true) |
| 104 |
.default_width(default_width) |
| 105 |
.min_width(min_width) |
| 106 |
.show(ctx, |ui| add_contents(ui)) |
| 107 |
.and_then(|r| r.inner) |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
pub fn modal_window_with_open<R>( |
| 113 |
ctx: &egui::Context, |
| 114 |
title: &str, |
| 115 |
open: Option<&mut bool>, |
| 116 |
resizable: bool, |
| 117 |
default_width: Option<f32>, |
| 118 |
add_contents: impl FnOnce(&mut egui::Ui) -> R, |
| 119 |
) -> Option<R> { |
| 120 |
let mut window = egui::Window::new(title) |
| 121 |
.collapsible(false) |
| 122 |
.resizable(resizable) |
| 123 |
.anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0]); |
| 124 |
if let Some(o) = open { |
| 125 |
window = window.open(o); |
| 126 |
} |
| 127 |
if let Some(w) = default_width { |
| 128 |
window = window.default_width(w); |
| 129 |
} |
| 130 |
window.show(ctx, |ui| add_contents(ui)).map(|r| r.inner.unwrap()) |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
pub fn confirm_action_row( |
| 142 |
ui: &mut egui::Ui, |
| 143 |
confirm_label: &str, |
| 144 |
can_confirm: bool, |
| 145 |
danger: bool, |
| 146 |
) -> ConfirmOutcome { |
| 147 |
let mut outcome = ConfirmOutcome::None; |
| 148 |
ui.horizontal(|ui| { |
| 149 |
if ui.button("Cancel").clicked() { |
| 150 |
outcome = ConfirmOutcome::Cancelled; |
| 151 |
} |
| 152 |
let label = if danger { |
| 153 |
egui::RichText::new(confirm_label).color(theme::accent_red()) |
| 154 |
} else { |
| 155 |
egui::RichText::new(confirm_label) |
| 156 |
}; |
| 157 |
if ui.add_enabled(can_confirm, egui::Button::new(label)).clicked() { |
| 158 |
outcome = ConfirmOutcome::Confirmed; |
| 159 |
} |
| 160 |
}); |
| 161 |
outcome |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
pub struct ConfirmSpec<'a> { |
| 166 |
pub title: &'a str, |
| 167 |
pub prompt: &'a str, |
| 168 |
pub detail: Option<&'a str>, |
| 169 |
pub confirm_label: &'a str, |
| 170 |
pub danger: bool, |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
pub fn confirm_modal(ctx: &egui::Context, spec: &ConfirmSpec) -> ConfirmOutcome { |
| 177 |
let mut outcome = ConfirmOutcome::None; |
| 178 |
modal_window(ctx, spec.title, false, None, |ui| { |
| 179 |
ui.label(spec.prompt); |
| 180 |
if let Some(detail) = spec.detail { |
| 181 |
ui.add_space(theme::space::SM); |
| 182 |
ui.label( |
| 183 |
egui::RichText::new(detail) |
| 184 |
.small() |
| 185 |
.color(theme::text_secondary()), |
| 186 |
); |
| 187 |
} |
| 188 |
ui.add_space(theme::space::LG); |
| 189 |
outcome = confirm_action_row(ui, spec.confirm_label, true, spec.danger); |
| 190 |
}); |
| 191 |
outcome |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
pub fn name_modal( |
| 202 |
ctx: &egui::Context, |
| 203 |
title: &str, |
| 204 |
hint: Option<&str>, |
| 205 |
label: &str, |
| 206 |
input: &mut String, |
| 207 |
submit_label: &str, |
| 208 |
error: Option<&str>, |
| 209 |
) -> NameModalOutcome { |
| 210 |
let mut outcome = NameModalOutcome::None; |
| 211 |
modal_window(ctx, title, false, None, |ui| { |
| 212 |
if let Some(h) = hint { |
| 213 |
ui.label(egui::RichText::new(h).small().color(theme::text_muted())); |
| 214 |
ui.add_space(theme::space::SM); |
| 215 |
} |
| 216 |
ui.label(label); |
| 217 |
let resp = ui.text_edit_singleline(input); |
| 218 |
if input.is_empty() && ui.memory(|m| m.focused().is_none()) { |
| 219 |
resp.request_focus(); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
if let Some(err) = error { |
| 224 |
ui.add_space(theme::space::XS); |
| 225 |
ui.label( |
| 226 |
egui::RichText::new(err) |
| 227 |
.small() |
| 228 |
.color(theme::accent_red()), |
| 229 |
); |
| 230 |
if !resp.has_focus() { |
| 231 |
resp.request_focus(); |
| 232 |
} |
| 233 |
} |
| 234 |
if resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) { |
| 235 |
outcome = NameModalOutcome::Submitted(input.trim().to_string()); |
| 236 |
} |
| 237 |
ui.add_space(theme::space::MD); |
| 238 |
ui.horizontal(|ui| { |
| 239 |
if ui.button("Cancel").clicked() { |
| 240 |
outcome = NameModalOutcome::Cancelled; |
| 241 |
} |
| 242 |
if ui.button(submit_label).clicked() { |
| 243 |
outcome = NameModalOutcome::Submitted(input.trim().to_string()); |
| 244 |
} |
| 245 |
}); |
| 246 |
}); |
| 247 |
outcome |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
pub struct EmptyStateCta<'a> { |
| 254 |
pub label: &'a str, |
| 255 |
pub tooltip: Option<&'a str>, |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
pub fn empty_state( |
| 265 |
ui: &mut egui::Ui, |
| 266 |
heading: &str, |
| 267 |
body: Option<&str>, |
| 268 |
cta: Option<EmptyStateCta>, |
| 269 |
) -> bool { |
| 270 |
let mut clicked = false; |
| 271 |
ui.vertical_centered(|ui| { |
| 272 |
ui.add_space(ui.available_height() * 0.15); |
| 273 |
ui.label( |
| 274 |
egui::RichText::new(heading) |
| 275 |
.size(20.0) |
| 276 |
.color(theme::text_secondary()), |
| 277 |
); |
| 278 |
if let Some(body_text) = body { |
| 279 |
ui.add_space(theme::space::MD); |
| 280 |
ui.label(egui::RichText::new(body_text).color(theme::text_muted())); |
| 281 |
} |
| 282 |
if let Some(cta) = cta { |
| 283 |
ui.add_space(theme::space::LG); |
| 284 |
let btn = secondary_button(ui, cta.label); |
| 285 |
let btn = if let Some(t) = cta.tooltip { btn.on_hover_text(t) } else { btn }; |
| 286 |
if btn.clicked() { |
| 287 |
clicked = true; |
| 288 |
} |
| 289 |
} |
| 290 |
}); |
| 291 |
clicked |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
pub fn format_bytes(bytes: u64) -> String { |
| 298 |
if bytes < 1024 { |
| 299 |
format!("{bytes} B") |
| 300 |
} else if bytes < 1024 * 1024 { |
| 301 |
format!("{:.1} KB", bytes as f64 / 1024.0) |
| 302 |
} else if bytes < 1024 * 1024 * 1024 { |
| 303 |
format!("{:.1} MB", bytes as f64 / (1024.0 * 1024.0)) |
| 304 |
} else { |
| 305 |
format!("{:.2} GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0)) |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
pub fn info_banner(ui: &mut egui::Ui, body: &str) { |
| 312 |
egui::Frame::new() |
| 313 |
.fill(theme::bg_tertiary()) |
| 314 |
.corner_radius(egui::CornerRadius::same(4)) |
| 315 |
.inner_margin(egui::Margin::same(8)) |
| 316 |
.show(ui, |ui| { |
| 317 |
ui.label( |
| 318 |
egui::RichText::new(body) |
| 319 |
.small() |
| 320 |
.color(theme::text_secondary()), |
| 321 |
); |
| 322 |
}); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
pub fn warning_banner(ui: &mut egui::Ui, body: &str) { |
| 330 |
egui::Frame::new() |
| 331 |
.fill(theme::bg_tertiary()) |
| 332 |
.corner_radius(egui::CornerRadius::same(4)) |
| 333 |
.inner_margin(egui::Margin::same(8)) |
| 334 |
.show(ui, |ui| { |
| 335 |
ui.label(egui::RichText::new(body).color(theme::accent_yellow())); |
| 336 |
}); |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
pub fn toolbar_toggle( |
| 347 |
ui: &mut egui::Ui, |
| 348 |
label: &str, |
| 349 |
active: bool, |
| 350 |
tooltip: &str, |
| 351 |
count: Option<usize>, |
| 352 |
) -> bool { |
| 353 |
let text = match count { |
| 354 |
Some(n) if n > 0 => format!("{label} ({n})"), |
| 355 |
_ => label.to_string(), |
| 356 |
}; |
| 357 |
let colour = if active { theme::accent_blue() } else { theme::text_muted() }; |
| 358 |
ui.button(egui::RichText::new(text).color(colour)) |
| 359 |
.on_hover_text(tooltip) |
| 360 |
.clicked() |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
pub fn toggle_pills<T: Clone + PartialEq>( |
| 369 |
ui: &mut egui::Ui, |
| 370 |
current: &T, |
| 371 |
options: &[(T, &str, &str)], |
| 372 |
) -> Option<T> { |
| 373 |
let mut chosen = None; |
| 374 |
ui.horizontal(|ui| { |
| 375 |
for (value, label, tooltip) in options { |
| 376 |
let is_active = value == current; |
| 377 |
if ui |
| 378 |
.selectable_label(is_active, *label) |
| 379 |
.on_hover_text(*tooltip) |
| 380 |
.clicked() |
| 381 |
&& !is_active |
| 382 |
{ |
| 383 |
chosen = Some(value.clone()); |
| 384 |
} |
| 385 |
} |
| 386 |
}); |
| 387 |
chosen |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
pub fn primary_button(ui: &mut egui::Ui, label: &str) -> egui::Response { |
| 402 |
ui.add(egui::Button::new(egui::RichText::new(label).strong())) |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
pub fn secondary_button(ui: &mut egui::Ui, label: &str) -> egui::Response { |
| 408 |
ui.button(label) |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
pub fn danger_button(ui: &mut egui::Ui, label: &str) -> egui::Response { |
| 414 |
ui.add(egui::Button::new(egui::RichText::new(label).color(theme::accent_red()))) |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
pub fn danger_button_enabled(ui: &mut egui::Ui, label: &str, enabled: bool) -> egui::Response { |
| 421 |
ui.add_enabled( |
| 422 |
enabled, |
| 423 |
egui::Button::new(egui::RichText::new(label).color(theme::accent_red())), |
| 424 |
) |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
pub fn danger_small_button(ui: &mut egui::Ui, label: &str) -> egui::Response { |
| 430 |
ui.add(egui::Button::new(egui::RichText::new(label).color(theme::accent_red())).small()) |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
pub fn section_header(ui: &mut egui::Ui, label: &str) { |
| 437 |
ui.label(egui::RichText::new(label).strong().color(theme::text_secondary())); |
| 438 |
ui.separator(); |
| 439 |
ui.add_space(theme::space::SM); |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
pub fn subsection_label(ui: &mut egui::Ui, label: &str) { |
| 444 |
ui.label(egui::RichText::new(label).strong().color(theme::text_secondary())); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
pub fn filter_section<R>( |
| 453 |
ui: &mut egui::Ui, |
| 454 |
label: &str, |
| 455 |
active: bool, |
| 456 |
add_contents: impl FnOnce(&mut egui::Ui) -> R, |
| 457 |
) { |
| 458 |
let header = if active { format!("{label} *") } else { label.to_string() }; |
| 459 |
egui::CollapsingHeader::new(header) |
| 460 |
.default_open(active) |
| 461 |
.show(ui, |ui| { |
| 462 |
add_contents(ui); |
| 463 |
}); |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
fn selectable_truncating( |
| 472 |
ui: &mut egui::Ui, |
| 473 |
active: bool, |
| 474 |
rich: egui::RichText, |
| 475 |
full_text: &str, |
| 476 |
) -> egui::Response { |
| 477 |
let prev = ui.style().wrap_mode; |
| 478 |
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate); |
| 479 |
let resp = ui.selectable_label(active, rich); |
| 480 |
ui.style_mut().wrap_mode = prev; |
| 481 |
resp.on_hover_text(full_text) |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
pub fn selectable_row(ui: &mut egui::Ui, active: bool, label: impl Into<String>) -> egui::Response { |
| 490 |
let text = label.into(); |
| 491 |
let rich = if active { |
| 492 |
egui::RichText::new(text.clone()).strong().color(theme::accent_blue()) |
| 493 |
} else { |
| 494 |
egui::RichText::new(text.clone()).color(theme::text_primary()) |
| 495 |
}; |
| 496 |
selectable_truncating(ui, active, rich, &text) |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
pub fn selectable_row_secondary( |
| 505 |
ui: &mut egui::Ui, |
| 506 |
active: bool, |
| 507 |
label: impl Into<String>, |
| 508 |
) -> egui::Response { |
| 509 |
let text = label.into(); |
| 510 |
let rich = if active { |
| 511 |
egui::RichText::new(text.clone()).strong().color(theme::accent_blue()) |
| 512 |
} else { |
| 513 |
egui::RichText::new(text.clone()).color(theme::text_secondary()) |
| 514 |
}; |
| 515 |
selectable_truncating(ui, active, rich, &text) |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
pub fn selectable_tag(ui: &mut egui::Ui, active: bool, label: impl Into<String>) -> egui::Response { |
| 524 |
let text = label.into(); |
| 525 |
let rich = if active { |
| 526 |
egui::RichText::new(text.clone()).color(theme::accent_blue()) |
| 527 |
} else { |
| 528 |
egui::RichText::new(text.clone()).color(theme::text_secondary()) |
| 529 |
}; |
| 530 |
selectable_truncating(ui, active, rich, &text) |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
pub fn wizard_steps(ui: &mut egui::Ui, steps: &[&str], current: usize) { |
| 539 |
ui.horizontal_wrapped(|ui| { |
| 540 |
ui.spacing_mut().item_spacing.x = theme::space::SM; |
| 541 |
for (i, step) in steps.iter().enumerate() { |
| 542 |
let label = format!("{}. {}", i + 1, step); |
| 543 |
let colored = if i == current { |
| 544 |
egui::RichText::new(label).strong().color(theme::accent_blue()) |
| 545 |
} else if i < current { |
| 546 |
egui::RichText::new(label).color(theme::text_secondary()) |
| 547 |
} else { |
| 548 |
egui::RichText::new(label).color(theme::text_muted()) |
| 549 |
}; |
| 550 |
ui.label(colored); |
| 551 |
if i + 1 < steps.len() { |
| 552 |
ui.label(egui::RichText::new("\u{00B7}").color(theme::text_muted())); |
| 553 |
} |
| 554 |
} |
| 555 |
}); |
| 556 |
ui.add_space(theme::space::MD); |
| 557 |
ui.separator(); |
| 558 |
ui.add_space(theme::space::MD); |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
pub fn step_number(ui: &mut egui::Ui, n: u32) { |
| 565 |
ui.label(accent_strong(format!("{n}."))); |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
pub fn accent_strong(label: impl Into<String>) -> egui::RichText { |
| 573 |
egui::RichText::new(label.into()).strong().color(theme::accent_blue()) |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
pub fn classification_badge(ui: &mut egui::Ui, class: &str) { |
| 580 |
let color = theme::classification_color(class); |
| 581 |
let label = egui::RichText::new(class) |
| 582 |
.small() |
| 583 |
.color(color); |
| 584 |
ui.label(label); |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
pub fn tag_chip(ui: &mut egui::Ui, tag: &str) -> egui::Response { |
| 593 |
|
| 594 |
let (rect, response) = ui.allocate_exact_size( |
| 595 |
egui::vec2(ui.ctx().fonts_mut(|f| f.glyph_width(&egui::TextStyle::Small.resolve(ui.style()), ' ')) * tag.len() as f32 + 16.0, 20.0), |
| 596 |
egui::Sense::click(), |
| 597 |
); |
| 598 |
|
| 599 |
if ui.is_rect_visible(rect) { |
| 600 |
let bg = if response.hovered() { |
| 601 |
theme::bg_hover() |
| 602 |
} else { |
| 603 |
theme::bg_surface() |
| 604 |
}; |
| 605 |
ui.painter().rect_filled(rect, 4.0, bg); |
| 606 |
ui.painter().text( |
| 607 |
rect.center(), |
| 608 |
egui::Align2::CENTER_CENTER, |
| 609 |
tag, |
| 610 |
egui::FontId::proportional(11.0), |
| 611 |
theme::accent_blue(), |
| 612 |
); |
| 613 |
} |
| 614 |
|
| 615 |
response |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
pub fn tag_chip_removable(ui: &mut egui::Ui, tag: &str, hover_only_remove: bool) -> bool { |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
let mut removed = false; |
| 628 |
ui.horizontal(|ui| { |
| 629 |
ui.spacing_mut().item_spacing.x = 2.0; |
| 630 |
let label_resp = ui.label( |
| 631 |
egui::RichText::new(tag) |
| 632 |
.small() |
| 633 |
.color(theme::accent_blue()), |
| 634 |
); |
| 635 |
let row_hovered = label_resp.hovered() |
| 636 |
|| ui.rect_contains_pointer(label_resp.rect.expand2(egui::vec2(20.0, 0.0))); |
| 637 |
let x_color = if hover_only_remove && !row_hovered { |
| 638 |
theme::text_muted() |
| 639 |
} else { |
| 640 |
theme::accent_red() |
| 641 |
}; |
| 642 |
let btn = ui |
| 643 |
.add( |
| 644 |
egui::Button::new(egui::RichText::new("x").small().color(x_color)) |
| 645 |
.small(), |
| 646 |
) |
| 647 |
.on_hover_text("Remove tag"); |
| 648 |
if btn.clicked() { |
| 649 |
removed = true; |
| 650 |
} |
| 651 |
}); |
| 652 |
removed |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
pub fn format_duration(seconds: f64) -> String { |
| 657 |
if seconds < 60.0 { |
| 658 |
format!("{:.1}s", seconds) |
| 659 |
} else { |
| 660 |
let mins = (seconds / 60.0).floor() as u32; |
| 661 |
let secs = seconds % 60.0; |
| 662 |
format!("{}:{:04.1}", mins, secs) |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
pub fn format_bpm(bpm: f64) -> String { |
| 670 |
if (bpm - bpm.round()).abs() < 0.05 { |
| 671 |
format!("{:.0}", bpm) |
| 672 |
} else { |
| 673 |
format!("{:.1}", bpm) |
| 674 |
} |
| 675 |
} |
| 676 |
|