| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
#![forbid(unsafe_code)] |
| 243 |
|
| 244 |
use egui::{ |
| 245 |
Color32, ComboBox, CornerRadius, DragValue, Margin, Painter, Rect, Response, RichText, Shape, |
| 246 |
Slider, Stroke, TextEdit, Ui, |
| 247 |
}; |
| 248 |
use makeover_layout::{ |
| 249 |
Bevel, Choice, Depth, Edge, Field, FieldKind, Fill, State, ThemeVariant, Tone, |
| 250 |
}; |
| 251 |
use std::ops::RangeInclusive; |
| 252 |
|
| 253 |
|
| 254 |
pub mod table; |
| 255 |
pub mod widget; |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 264 |
pub struct Palette { |
| 265 |
|
| 266 |
pub page: Color32, |
| 267 |
|
| 268 |
pub raised: Color32, |
| 269 |
|
| 270 |
pub overlay: Color32, |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
pub well: Color32, |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
pub sunken: Color32, |
| 289 |
|
| 290 |
pub bevel_light: Color32, |
| 291 |
|
| 292 |
pub bevel_dark: Color32, |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
pub elevation: Color32, |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
pub content: Color32, |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
pub content_secondary: Color32, |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
pub content_muted: Color32, |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
pub action: Color32, |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
pub danger: Color32, |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
pub success: Color32, |
| 363 |
|
| 364 |
pub warning: Color32, |
| 365 |
|
| 366 |
pub info: Color32, |
| 367 |
} |
| 368 |
|
| 369 |
impl Palette { |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
#[must_use] |
| 383 |
pub const fn fill(&self, fill: Fill) -> Option<Color32> { |
| 384 |
match fill { |
| 385 |
Fill::Page => Some(self.page), |
| 386 |
Fill::Raised => Some(self.raised), |
| 387 |
Fill::Overlay => Some(self.overlay), |
| 388 |
Fill::Well => Some(self.well), |
| 389 |
Fill::Sunken => Some(self.sunken), |
| 390 |
_ => None, |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
#[must_use] |
| 406 |
pub const fn tone(&self, tone: Tone) -> Color32 { |
| 407 |
match tone { |
| 408 |
Tone::Neutral => self.content, |
| 409 |
Tone::Info => self.info, |
| 410 |
Tone::Success => self.success, |
| 411 |
Tone::Warning => self.warning, |
| 412 |
Tone::Danger => self.danger, |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
#[must_use] |
| 436 |
pub const fn cast(&self) -> egui::Shadow { |
| 437 |
egui::Shadow { |
| 438 |
offset: [0, 2], |
| 439 |
blur: 24, |
| 440 |
spread: 0, |
| 441 |
color: self.elevation, |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
#[must_use] |
| 447 |
pub const fn edge(&self, edge: Edge) -> Color32 { |
| 448 |
match edge { |
| 449 |
Edge::Light => self.bevel_light, |
| 450 |
Edge::Dark => self.bevel_dark, |
| 451 |
} |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
#[derive(Debug, Clone, Copy, PartialEq)] |
| 461 |
pub struct FrameStyle { |
| 462 |
|
| 463 |
pub radius: CornerRadius, |
| 464 |
|
| 465 |
pub margin: Margin, |
| 466 |
|
| 467 |
pub stroke: f32, |
| 468 |
} |
| 469 |
|
| 470 |
impl Default for FrameStyle { |
| 471 |
|
| 472 |
fn default() -> Self { |
| 473 |
Self { |
| 474 |
radius: CornerRadius::ZERO, |
| 475 |
margin: Margin::ZERO, |
| 476 |
stroke: 1.0, |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
pub fn paint_bevel(painter: &Painter, rect: Rect, bevel: Bevel, palette: &Palette, stroke: f32) { |
| 500 |
let (top_left, bottom_right) = bevel.edges(); |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
let r = rect.shrink(stroke / 2.0); |
| 506 |
|
| 507 |
painter.add(Shape::line( |
| 508 |
vec![r.left_bottom(), r.left_top(), r.right_top()], |
| 509 |
Stroke::new(stroke, palette.edge(top_left)), |
| 510 |
)); |
| 511 |
painter.add(Shape::line( |
| 512 |
vec![r.right_top(), r.right_bottom(), r.left_bottom()], |
| 513 |
Stroke::new(stroke, palette.edge(bottom_right)), |
| 514 |
)); |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
pub fn frame<R>( |
| 524 |
ui: &mut Ui, |
| 525 |
depth: Depth, |
| 526 |
palette: &Palette, |
| 527 |
style: FrameStyle, |
| 528 |
add_contents: impl FnOnce(&mut Ui) -> R, |
| 529 |
) -> R { |
| 530 |
let mut f = egui::Frame::new() |
| 531 |
.corner_radius(style.radius) |
| 532 |
.inner_margin(style.margin); |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
if let Some(fill) = depth.fill().and_then(|f| palette.fill(f)) { |
| 539 |
f = f.fill(fill); |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
if depth.fill() == Some(Fill::Overlay) { |
| 548 |
f = f.shadow(palette.cast()); |
| 549 |
} |
| 550 |
let framed = f.show(ui, add_contents); |
| 551 |
if let Some(bevel) = depth.bevel() { |
| 552 |
paint_bevel( |
| 553 |
ui.painter(), |
| 554 |
framed.response.rect, |
| 555 |
bevel, |
| 556 |
palette, |
| 557 |
style.stroke, |
| 558 |
); |
| 559 |
} |
| 560 |
framed.inner |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
#[derive(Debug, Clone, Copy, PartialEq)] |
| 568 |
pub struct FieldStyle { |
| 569 |
|
| 570 |
pub frame: FrameStyle, |
| 571 |
|
| 572 |
|
| 573 |
pub gap: f32, |
| 574 |
|
| 575 |
pub group_gap: f32, |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
pub required_marker: &'static str, |
| 584 |
} |
| 585 |
|
| 586 |
impl Default for FieldStyle { |
| 587 |
|
| 588 |
fn default() -> Self { |
| 589 |
Self { |
| 590 |
frame: FrameStyle::default(), |
| 591 |
gap: 0.0, |
| 592 |
group_gap: 0.0, |
| 593 |
required_marker: "*", |
| 594 |
} |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
#[derive(Debug, Default)] |
| 609 |
pub enum Filling<'a> { |
| 610 |
|
| 611 |
#[default] |
| 612 |
Absent, |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
Text(&'a mut String), |
| 618 |
|
| 619 |
On(&'a mut bool), |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
Between { |
| 632 |
|
| 633 |
lower: &'a mut String, |
| 634 |
|
| 635 |
upper: &'a mut String, |
| 636 |
}, |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
fn label_text(field: &Field<'_>, style: &FieldStyle) -> String { |
| 641 |
if field.required { |
| 642 |
format!("{} {}", field.label, style.required_marker) |
| 643 |
} else { |
| 644 |
field.label.to_owned() |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 656 |
enum Control { |
| 657 |
|
| 658 |
Typed, |
| 659 |
|
| 660 |
|
| 661 |
Chosen, |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
Listed, |
| 669 |
|
| 670 |
Toggled, |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
Slid, |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
Themed, |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
Spanned, |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
fn combo_row(opt: &Choice<'_>) -> String { |
| 746 |
let mut text = opt.label.to_owned(); |
| 747 |
for extra in [opt.detail, opt.unavailable].into_iter().flatten() { |
| 748 |
text.push_str(" "); |
| 749 |
text.push_str(extra); |
| 750 |
} |
| 751 |
text |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
const OPTION_DETAIL_INDENT: f32 = 22.0; |
| 762 |
|
| 763 |
const fn control_shape(kind: FieldKind) -> Control { |
| 764 |
match kind { |
| 765 |
FieldKind::Select => Control::Chosen, |
| 766 |
FieldKind::Radio => Control::Listed, |
| 767 |
FieldKind::Checkbox => Control::Toggled, |
| 768 |
FieldKind::Range => Control::Slid, |
| 769 |
FieldKind::Interval => Control::Spanned, |
| 770 |
FieldKind::Theme => Control::Themed, |
| 771 |
_ => Control::Typed, |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
fn shape_of(field: &Field<'_>) -> Control { |
| 788 |
match control_shape(field.kind) { |
| 789 |
Control::Slid if !field.bounded() => Control::Typed, |
| 790 |
shape => shape, |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
fn unit_of<'a>(field: &Field<'a>) -> Option<&'a str> { |
| 802 |
field.unit.filter(|_| field.kind.measurable()) |
| 803 |
} |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
fn extent(field: &Field<'_>) -> Option<RangeInclusive<f64>> { |
| 812 |
let min = field.min?.parse::<f64>().ok()?; |
| 813 |
let max = field.max?.parse::<f64>().ok()?; |
| 814 |
Some(min..=max) |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
fn decimals(step: Option<&str>) -> Option<usize> { |
| 825 |
let step = step?; |
| 826 |
Some(match step.split_once('.') { |
| 827 |
Some((_, fraction)) => fraction.trim_end_matches('0').len(), |
| 828 |
None => 0, |
| 829 |
}) |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
fn shown_label<'a>(options: &'a [Choice<'a>], value: &'a str) -> &'a str { |
| 843 |
options |
| 844 |
.iter() |
| 845 |
.find(|opt| opt.value == value) |
| 846 |
.map_or(value, |opt| opt.label) |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
fn chosen_text<'a>(field: &'a Field<'a>, value: &'a str, palette: &Palette) -> (&'a str, Color32) { |
| 873 |
match field.placeholder { |
| 874 |
Some(ghost) if value.is_empty() => (ghost, palette.content_muted), |
| 875 |
_ => (shown_label(field.options, value), palette.content), |
| 876 |
} |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
fn option_color(value: &str, option: &str, palette: &Palette) -> Color32 { |
| 888 |
if value == option { |
| 889 |
palette.content |
| 890 |
} else { |
| 891 |
palette.content_secondary |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 901 |
enum Bound { |
| 902 |
|
| 903 |
Low, |
| 904 |
|
| 905 |
High, |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
struct Axis<'a> { |
| 914 |
|
| 915 |
|
| 916 |
extent: Option<RangeInclusive<f64>>, |
| 917 |
|
| 918 |
step: Option<&'a str>, |
| 919 |
|
| 920 |
unit: Option<&'a str>, |
| 921 |
} |
| 922 |
|
| 923 |
impl Axis<'_> { |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
fn edge(&self, which: Bound) -> f64 { |
| 931 |
self.extent.as_ref().map_or(0.0, |extent| match which { |
| 932 |
Bound::Low => *extent.start(), |
| 933 |
Bound::High => *extent.end(), |
| 934 |
}) |
| 935 |
} |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
fn end(&self, ui: &mut Ui, value: &mut String, which: Bound) -> Response { |
| 955 |
let mut number = value.parse::<f64>().unwrap_or(self.edge(which)); |
| 956 |
let mut drag = DragValue::new(&mut number); |
| 957 |
if let Some(extent) = self.extent.clone() { |
| 958 |
drag = drag.range(extent); |
| 959 |
} |
| 960 |
if let Some(places) = decimals(self.step) { |
| 961 |
drag = drag.max_decimals(places); |
| 962 |
} |
| 963 |
if let Some(step) = self.step.and_then(|s| s.parse::<f64>().ok()) { |
| 964 |
drag = drag.speed(step); |
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
if let Some(unit) = self.unit { |
| 969 |
drag = drag.suffix(format!(" {unit}")); |
| 970 |
} |
| 971 |
let response = ui.add(drag); |
| 972 |
if response.changed() { |
| 973 |
*value = match decimals(self.step) { |
| 974 |
Some(places) => format!("{number:.places$}"), |
| 975 |
None => number.to_string(), |
| 976 |
}; |
| 977 |
} |
| 978 |
response |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
|
| 983 |
fn control( |
| 984 |
ui: &mut Ui, |
| 985 |
field: &Field<'_>, |
| 986 |
filling: Filling<'_>, |
| 987 |
palette: &Palette, |
| 988 |
style: &FieldStyle, |
| 989 |
named_by: Option<egui::Id>, |
| 990 |
) -> Response { |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
let mut discard = String::new(); |
| 996 |
|
| 997 |
|
| 998 |
let mut spare = String::new(); |
| 999 |
let mut off = false; |
| 1000 |
|
| 1001 |
match shape_of(field) { |
| 1002 |
Control::Slid => { |
| 1003 |
let value = match filling { |
| 1004 |
Filling::Text(text) => text, |
| 1005 |
_ => &mut discard, |
| 1006 |
}; |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
let Some(extent) = extent(field) else { |
| 1011 |
return ui.label(RichText::new(value.as_str()).color(palette.content)); |
| 1012 |
}; |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
let mut number = value.parse::<f64>().unwrap_or(*extent.start()); |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
let step = field.curve.step(); |
| 1023 |
let mut slider = Slider::new(&mut number, extent.clone()).text(""); |
| 1024 |
if let Some(places) = decimals(step) { |
| 1025 |
slider = slider.max_decimals(places); |
| 1026 |
} |
| 1027 |
if let Some(step) = step.and_then(|s| s.parse::<f64>().ok()) { |
| 1028 |
slider = slider.step_by(step); |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
if field.curve.is_ratio(*extent.start(), *extent.end()) { |
| 1036 |
slider = slider.logarithmic(true); |
| 1037 |
} |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
if let Some(unit) = unit_of(field) { |
| 1043 |
slider = slider.suffix(format!(" {unit}")); |
| 1044 |
} |
| 1045 |
let response = ui.add(slider); |
| 1046 |
if response.changed() { |
| 1047 |
*value = match decimals(step) { |
| 1048 |
Some(places) => format!("{number:.places$}"), |
| 1049 |
None => number.to_string(), |
| 1050 |
}; |
| 1051 |
} |
| 1052 |
response |
| 1053 |
} |
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
Control::Spanned => { |
| 1063 |
let (lower, upper) = match filling { |
| 1064 |
Filling::Between { lower, upper } => (lower, upper), |
| 1065 |
_ => (&mut discard, &mut spare), |
| 1066 |
}; |
| 1067 |
let axis = Axis { |
| 1068 |
extent: extent(field), |
| 1069 |
step: field.step, |
| 1070 |
unit: unit_of(field), |
| 1071 |
}; |
| 1072 |
ui.horizontal(|ui| { |
| 1073 |
let low = axis.end(ui, lower, Bound::Low); |
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
ui.label(RichText::new("to").color(palette.content_secondary)); |
| 1078 |
let high = axis.end(ui, upper, Bound::High); |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
if let Some(id) = named_by { |
| 1085 |
low.clone().labelled_by(id); |
| 1086 |
high.clone().labelled_by(id); |
| 1087 |
} |
| 1088 |
low | high |
| 1089 |
}) |
| 1090 |
.inner |
| 1091 |
} |
| 1092 |
Control::Typed => { |
| 1093 |
let text = match filling { |
| 1094 |
Filling::Text(text) => text, |
| 1095 |
_ => &mut discard, |
| 1096 |
}; |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
let mut edit = if field.kind.multiline() { |
| 1107 |
TextEdit::multiline(text) |
| 1108 |
} else { |
| 1109 |
TextEdit::singleline(text) |
| 1110 |
} |
| 1111 |
.frame(egui::Frame::NONE) |
| 1112 |
.margin(Margin::ZERO) |
| 1113 |
.text_color(palette.content) |
| 1114 |
.password(field.kind.confidential()); |
| 1115 |
if let Some(ghost) = field.placeholder { |
| 1116 |
edit = edit.hint_text(RichText::new(ghost).color(palette.content_muted)); |
| 1117 |
} |
| 1118 |
let response = frame(ui, Depth::Well, palette, style.frame, |ui| ui.add(edit)); |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
match unit_of(field) { |
| 1123 |
Some(unit) => { |
| 1124 |
ui.label(RichText::new(unit).color(palette.content_muted)); |
| 1125 |
response |
| 1126 |
} |
| 1127 |
None => response, |
| 1128 |
} |
| 1129 |
} |
| 1130 |
Control::Toggled => { |
| 1131 |
let on = match filling { |
| 1132 |
Filling::On(on) => on, |
| 1133 |
_ => &mut off, |
| 1134 |
}; |
| 1135 |
ui.checkbox(on, RichText::new(field.label).color(palette.content)) |
| 1136 |
} |
| 1137 |
Control::Listed => { |
| 1138 |
let value = match filling { |
| 1139 |
Filling::Text(text) => text, |
| 1140 |
_ => &mut discard, |
| 1141 |
}; |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
let group = ui.vertical(|ui| { |
| 1147 |
let mut answered: Option<Response> = None; |
| 1148 |
for opt in field.options { |
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
let picked = if let Some(reason) = opt.unavailable { |
| 1155 |
ui.horizontal(|ui| { |
| 1156 |
let picked = ui |
| 1157 |
.add_enabled_ui(false, |ui| { |
| 1158 |
ui.radio_value( |
| 1159 |
value, |
| 1160 |
opt.value.to_owned(), |
| 1161 |
RichText::new(opt.label).color(palette.content_muted), |
| 1162 |
) |
| 1163 |
}) |
| 1164 |
.inner; |
| 1165 |
ui.label(RichText::new(reason).color(palette.content_muted)); |
| 1166 |
picked |
| 1167 |
}) |
| 1168 |
.inner |
| 1169 |
} else { |
| 1170 |
ui.radio_value( |
| 1171 |
value, |
| 1172 |
opt.value.to_owned(), |
| 1173 |
RichText::new(opt.label).color(option_color(value, opt.value, palette)), |
| 1174 |
) |
| 1175 |
}; |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
if let Some(detail) = opt.detail { |
| 1189 |
ui.horizontal(|ui| { |
| 1190 |
ui.add_space(OPTION_DETAIL_INDENT); |
| 1191 |
ui.label(RichText::new(detail).color(palette.content_muted)); |
| 1192 |
}); |
| 1193 |
} |
| 1194 |
answered = Some(match answered { |
| 1195 |
Some(prev) => prev.union(picked), |
| 1196 |
None => picked, |
| 1197 |
}); |
| 1198 |
} |
| 1199 |
answered |
| 1200 |
}); |
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
group.inner.unwrap_or(group.response) |
| 1206 |
} |
| 1207 |
Control::Chosen => { |
| 1208 |
let value = match filling { |
| 1209 |
Filling::Text(text) => text, |
| 1210 |
_ => &mut discard, |
| 1211 |
}; |
| 1212 |
let (shown, tone) = chosen_text(field, value, palette); |
| 1213 |
ComboBox::from_id_salt(field.name) |
| 1214 |
.selected_text(RichText::new(shown).color(tone)) |
| 1215 |
.show_ui(ui, |ui| { |
| 1216 |
for opt in field.options { |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
let text = combo_row(opt); |
| 1226 |
if opt.unavailable.is_some() { |
| 1227 |
ui.add_enabled_ui(false, |ui| { |
| 1228 |
ui.selectable_value( |
| 1229 |
value, |
| 1230 |
opt.value.to_owned(), |
| 1231 |
RichText::new(text).color(palette.content_muted), |
| 1232 |
); |
| 1233 |
}); |
| 1234 |
continue; |
| 1235 |
} |
| 1236 |
ui.selectable_value( |
| 1237 |
value, |
| 1238 |
opt.value.to_owned(), |
| 1239 |
RichText::new(text).color(option_color(value, opt.value, palette)), |
| 1240 |
); |
| 1241 |
} |
| 1242 |
}) |
| 1243 |
.response |
| 1244 |
} |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
Control::Themed => { |
| 1251 |
let value = match filling { |
| 1252 |
Filling::Text(text) => text, |
| 1253 |
_ => &mut discard, |
| 1254 |
}; |
| 1255 |
let shown = themed_text(field, value); |
| 1256 |
ComboBox::from_id_salt(field.name) |
| 1257 |
.selected_text(RichText::new(shown).color(palette.content)) |
| 1258 |
.show_ui(ui, |ui| { |
| 1259 |
if let Some(follow) = field.follows { |
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
ui.selectable_value( |
| 1264 |
value, |
| 1265 |
follow.value.to_owned(), |
| 1266 |
RichText::new(follow.label).color(option_color( |
| 1267 |
value, |
| 1268 |
follow.value, |
| 1269 |
palette, |
| 1270 |
)), |
| 1271 |
); |
| 1272 |
} |
| 1273 |
let mut open: Option<ThemeVariant> = None; |
| 1274 |
for theme in field.themes { |
| 1275 |
if open != Some(theme.variant) { |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
if open.is_some() { |
| 1282 |
ui.separator(); |
| 1283 |
} |
| 1284 |
ui.label( |
| 1285 |
RichText::new(theme.variant.heading()).color(palette.content_muted), |
| 1286 |
); |
| 1287 |
open = Some(theme.variant); |
| 1288 |
} |
| 1289 |
ui.selectable_value( |
| 1290 |
value, |
| 1291 |
theme.id.to_owned(), |
| 1292 |
RichText::new(format!("{} {}", theme.name, theme.contrast.badge())) |
| 1293 |
.color(option_color(value, theme.id, palette)), |
| 1294 |
); |
| 1295 |
} |
| 1296 |
}) |
| 1297 |
.response |
| 1298 |
} |
| 1299 |
} |
| 1300 |
} |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
fn themed_text<'a>(field: &'a Field<'a>, value: &'a str) -> &'a str { |
| 1313 |
if let Some(follow) = field.follows |
| 1314 |
&& follow.value == value |
| 1315 |
{ |
| 1316 |
return follow.label; |
| 1317 |
} |
| 1318 |
field |
| 1319 |
.themes |
| 1320 |
.iter() |
| 1321 |
.find(|theme| theme.id == value) |
| 1322 |
.map_or(value, |theme| theme.name) |
| 1323 |
} |
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
pub fn field( |
| 1344 |
ui: &mut Ui, |
| 1345 |
field: &Field<'_>, |
| 1346 |
filling: Filling<'_>, |
| 1347 |
state: Option<State>, |
| 1348 |
palette: &Palette, |
| 1349 |
style: &FieldStyle, |
| 1350 |
) -> Option<Response> { |
| 1351 |
if !field.kind.visible() { |
| 1352 |
return None; |
| 1353 |
} |
| 1354 |
let enabled = !state.is_some_and(State::suppresses_interaction); |
| 1355 |
let text = if enabled { |
| 1356 |
palette.content |
| 1357 |
} else { |
| 1358 |
palette.content_muted |
| 1359 |
}; |
| 1360 |
|
| 1361 |
let response = ui |
| 1362 |
.vertical(|ui| { |
| 1363 |
ui.spacing_mut().item_spacing.y = style.gap; |
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
let named_by = (!field.kind.labels_itself()) |
| 1369 |
.then(|| ui.label(RichText::new(label_text(field, style)).color(text))); |
| 1370 |
|
| 1371 |
let response = ui |
| 1372 |
.add_enabled_ui(enabled, |ui| { |
| 1373 |
control( |
| 1374 |
ui, |
| 1375 |
field, |
| 1376 |
filling, |
| 1377 |
palette, |
| 1378 |
style, |
| 1379 |
named_by.as_ref().map(|l| l.id), |
| 1380 |
) |
| 1381 |
}) |
| 1382 |
.inner; |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
let response = match named_by { |
| 1401 |
Some(label) => response.labelled_by(label.id), |
| 1402 |
None => response, |
| 1403 |
}; |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
if let Some(hint) = field.hint { |
| 1412 |
ui.label(RichText::new(hint).color(palette.content_muted)); |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
if let Some((tone, note)) = field.note { |
| 1418 |
ui.label(RichText::new(note).color(palette.tone(tone))); |
| 1419 |
} |
| 1420 |
if let Some(error) = field.error { |
| 1421 |
ui.label(RichText::new(error).color(palette.danger)); |
| 1422 |
} |
| 1423 |
response |
| 1424 |
}) |
| 1425 |
.inner; |
| 1426 |
|
| 1427 |
Some(response) |
| 1428 |
} |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
pub fn group<'a>( |
| 1444 |
ui: &mut Ui, |
| 1445 |
fields: &'a [Field<'a>], |
| 1446 |
show_extended: bool, |
| 1447 |
style: &FieldStyle, |
| 1448 |
mut draw: impl FnMut(&mut Ui, &'a Field<'a>), |
| 1449 |
) { |
| 1450 |
ui.vertical(|ui| { |
| 1451 |
ui.spacing_mut().item_spacing.y = style.group_gap; |
| 1452 |
for f in fields { |
| 1453 |
if f.extended && !show_extended { |
| 1454 |
continue; |
| 1455 |
} |
| 1456 |
draw(ui, f); |
| 1457 |
} |
| 1458 |
}); |
| 1459 |
} |
| 1460 |
|
| 1461 |
#[cfg(test)] |
| 1462 |
mod tests { |
| 1463 |
use super::*; |
| 1464 |
|
| 1465 |
fn palette(well: Color32) -> Palette { |
| 1466 |
Palette { |
| 1467 |
page: Color32::from_rgb(1, 1, 1), |
| 1468 |
raised: Color32::from_rgb(2, 2, 2), |
| 1469 |
overlay: Color32::from_rgb(3, 3, 3), |
| 1470 |
well, |
| 1471 |
sunken: Color32::from_rgb(4, 4, 4), |
| 1472 |
bevel_light: Color32::WHITE, |
| 1473 |
bevel_dark: Color32::BLACK, |
| 1474 |
elevation: Color32::from_black_alpha(46), |
| 1475 |
content: Color32::from_rgb(5, 5, 5), |
| 1476 |
content_secondary: Color32::from_rgb(55, 55, 55), |
| 1477 |
content_muted: Color32::from_rgb(6, 6, 6), |
| 1478 |
action: Color32::from_rgb(7, 7, 7), |
| 1479 |
danger: Color32::from_rgb(8, 8, 8), |
| 1480 |
success: Color32::from_rgb(9, 9, 9), |
| 1481 |
warning: Color32::from_rgb(10, 10, 10), |
| 1482 |
info: Color32::from_rgb(11, 11, 11), |
| 1483 |
} |
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
#[test] |
| 1490 |
fn a_unit_is_drawn_only_where_the_kind_is_a_quantity() { |
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
let ranged = makeover_layout::Field { |
| 1496 |
unit: Some("s"), |
| 1497 |
..makeover_layout::Field::range("attack", "Attack", "0", "5") |
| 1498 |
}; |
| 1499 |
assert_eq!(unit_of(&ranged), Some("s")); |
| 1500 |
|
| 1501 |
let typed = makeover_layout::Field { |
| 1502 |
unit: Some("ms"), |
| 1503 |
..makeover_layout::Field::new(makeover_layout::FieldKind::Number, "fade", "Fade") |
| 1504 |
}; |
| 1505 |
assert_eq!(unit_of(&typed), Some("ms")); |
| 1506 |
|
| 1507 |
let worded = makeover_layout::Field { |
| 1508 |
unit: Some("s"), |
| 1509 |
..makeover_layout::Field::new(makeover_layout::FieldKind::Text, "name", "Name") |
| 1510 |
}; |
| 1511 |
assert_eq!(unit_of(&worded), None); |
| 1512 |
|
| 1513 |
let bare = makeover_layout::Field::range("attack", "Attack", "0", "5"); |
| 1514 |
assert_eq!(unit_of(&bare), None); |
| 1515 |
} |
| 1516 |
|
| 1517 |
#[test] |
| 1518 |
fn the_cast_hands_egui_the_themes_tone() { |
| 1519 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1520 |
let cast = p.cast(); |
| 1521 |
assert_eq!(cast.color, p.elevation); |
| 1522 |
assert!(cast.blur > 0, "a cast shadow is soft"); |
| 1523 |
assert_eq!(cast.offset, [0, 2], "it falls downward and only a little"); |
| 1524 |
} |
| 1525 |
|
| 1526 |
#[test] |
| 1527 |
fn a_well_resolves_to_its_own_token() { |
| 1528 |
|
| 1529 |
|
| 1530 |
let w = Color32::from_rgb(9, 9, 9); |
| 1531 |
let p = palette(w); |
| 1532 |
assert_eq!(p.fill(Fill::Well), Some(w)); |
| 1533 |
assert_ne!(p.fill(Fill::Well), Some(p.page)); |
| 1534 |
} |
| 1535 |
|
| 1536 |
#[test] |
| 1537 |
fn every_intent_is_a_plain_lookup() { |
| 1538 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1539 |
assert_eq!(p.fill(Fill::Page), Some(p.page)); |
| 1540 |
assert_eq!(p.fill(Fill::Raised), Some(p.raised)); |
| 1541 |
assert_eq!(p.fill(Fill::Overlay), Some(p.overlay)); |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
#[test] |
| 1548 |
fn sunken_is_neither_the_well_nor_the_page() { |
| 1549 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1550 |
assert_eq!(p.fill(Fill::Sunken), Some(p.sunken)); |
| 1551 |
assert_ne!(p.fill(Fill::Sunken), p.fill(Fill::Well)); |
| 1552 |
assert_ne!(p.fill(Fill::Sunken), p.fill(Fill::Page)); |
| 1553 |
} |
| 1554 |
|
| 1555 |
#[test] |
| 1556 |
fn a_raised_region_never_resolves_to_the_well_fill() { |
| 1557 |
|
| 1558 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1559 |
let raised = Depth::Raised.fill().and_then(|f| p.fill(f)); |
| 1560 |
let well = Depth::Well.fill().and_then(|f| p.fill(f)); |
| 1561 |
assert_eq!(raised, Some(p.raised)); |
| 1562 |
assert_ne!(raised, well); |
| 1563 |
} |
| 1564 |
|
| 1565 |
#[test] |
| 1566 |
fn an_overlay_is_cast_onto_the_page_and_takes_no_edge() { |
| 1567 |
|
| 1568 |
|
| 1569 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1570 |
assert_eq!( |
| 1571 |
Depth::Overlay.fill().and_then(|f| p.fill(f)), |
| 1572 |
Some(p.overlay) |
| 1573 |
); |
| 1574 |
assert_eq!(Depth::Overlay.bevel(), None); |
| 1575 |
|
| 1576 |
|
| 1577 |
assert_eq!(p.cast().color, p.elevation); |
| 1578 |
} |
| 1579 |
|
| 1580 |
#[test] |
| 1581 |
fn the_lit_edge_swaps_when_a_card_is_pressed() { |
| 1582 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1583 |
let (tl, _) = Depth::Raised.bevel().unwrap().edges(); |
| 1584 |
let (ptl, _) = Depth::Raised.pressed().bevel().unwrap().edges(); |
| 1585 |
assert_eq!(p.edge(tl), p.bevel_light); |
| 1586 |
assert_eq!(p.edge(ptl), p.bevel_dark); |
| 1587 |
} |
| 1588 |
|
| 1589 |
#[test] |
| 1590 |
fn flat_asks_for_neither_fill_nor_edge() { |
| 1591 |
assert!(Depth::Flat.fill().is_none()); |
| 1592 |
assert!(Depth::Flat.bevel().is_none()); |
| 1593 |
} |
| 1594 |
|
| 1595 |
#[test] |
| 1596 |
fn a_select_keeps_a_value_none_of_its_options_carries() { |
| 1597 |
|
| 1598 |
|
| 1599 |
let options = [ |
| 1600 |
Choice::plain("1"), |
| 1601 |
Choice::plain("3"), |
| 1602 |
Choice::plain("7"), |
| 1603 |
Choice::plain("14"), |
| 1604 |
]; |
| 1605 |
assert_eq!(shown_label(&options, "10"), "10"); |
| 1606 |
|
| 1607 |
let spelled = [Choice::new("7", "One week")]; |
| 1608 |
assert_eq!(shown_label(&spelled, "7"), "One week"); |
| 1609 |
} |
| 1610 |
|
| 1611 |
#[test] |
| 1612 |
fn an_unanswered_chooser_reads_its_ghost_text_and_reads_it_muted() { |
| 1613 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1614 |
let options = [Choice::new("sp404", "SP-404")]; |
| 1615 |
let field = Field { |
| 1616 |
placeholder: Some("Select device..."), |
| 1617 |
..Field::select("device", "Conform for device", &options) |
| 1618 |
}; |
| 1619 |
|
| 1620 |
assert_eq!( |
| 1621 |
chosen_text(&field, "", &p), |
| 1622 |
("Select device...", p.content_muted), |
| 1623 |
"ghost text is not an answer, so it takes the tone the typed kinds' ghost text does" |
| 1624 |
); |
| 1625 |
|
| 1626 |
|
| 1627 |
assert_eq!(chosen_text(&field, "sp404", &p), ("SP-404", p.content)); |
| 1628 |
} |
| 1629 |
|
| 1630 |
#[test] |
| 1631 |
fn a_wrong_answer_is_not_an_absent_one() { |
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1636 |
let options = [Choice::plain("1"), Choice::plain("7")]; |
| 1637 |
let field = Field { |
| 1638 |
placeholder: Some("Pick one"), |
| 1639 |
..Field::select("retention", "Keep backups for", &options) |
| 1640 |
}; |
| 1641 |
|
| 1642 |
assert_eq!(chosen_text(&field, "10", &p), ("10", p.content)); |
| 1643 |
} |
| 1644 |
|
| 1645 |
#[test] |
| 1646 |
fn a_chooser_with_no_ghost_text_is_unchanged() { |
| 1647 |
|
| 1648 |
|
| 1649 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1650 |
let options = [Choice::plain("1")]; |
| 1651 |
let field = Field::select("retention", "Keep backups for", &options); |
| 1652 |
assert_eq!(chosen_text(&field, "", &p), ("", p.content)); |
| 1653 |
} |
| 1654 |
|
| 1655 |
#[test] |
| 1656 |
fn a_range_is_slid_and_a_number_is_typed_into() { |
| 1657 |
|
| 1658 |
|
| 1659 |
assert_eq!(control_shape(FieldKind::Range), Control::Slid); |
| 1660 |
assert_eq!(control_shape(FieldKind::Number), Control::Typed); |
| 1661 |
} |
| 1662 |
|
| 1663 |
#[test] |
| 1664 |
fn a_range_missing_an_end_falls_back_to_a_well() { |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
let whole = Field::range("review", "Review above", "0", "1"); |
| 1670 |
assert_eq!(shape_of(&whole), Control::Slid); |
| 1671 |
|
| 1672 |
let half = Field { |
| 1673 |
max: Some("1"), |
| 1674 |
..Field::new(FieldKind::Range, "review", "Review above") |
| 1675 |
}; |
| 1676 |
assert_eq!(shape_of(&half), Control::Typed); |
| 1677 |
assert_eq!(extent(&half), None); |
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
let dated = Field::range("when", "When", "2026-08-01", "2026-08-31"); |
| 1683 |
assert_eq!(extent(&dated), None); |
| 1684 |
} |
| 1685 |
|
| 1686 |
#[test] |
| 1687 |
fn an_interval_is_its_own_shape_and_not_two_numbers() { |
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
assert_eq!(control_shape(FieldKind::Interval), Control::Spanned); |
| 1692 |
assert_eq!(shape_of(&Field::interval("a", "b", "A")), Control::Spanned); |
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
let axis = Field { |
| 1697 |
min: Some("0"), |
| 1698 |
max: Some("300"), |
| 1699 |
..Field::interval("bpm_min", "bpm_max", "BPM") |
| 1700 |
}; |
| 1701 |
assert_eq!(shape_of(&axis), Control::Spanned); |
| 1702 |
} |
| 1703 |
|
| 1704 |
#[test] |
| 1705 |
fn an_empty_end_reads_as_the_bound_it_stands_for() { |
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
let axis = Axis { |
| 1711 |
extent: Some(0.0..=300.0), |
| 1712 |
step: Some("1"), |
| 1713 |
unit: Some("BPM"), |
| 1714 |
}; |
| 1715 |
assert!((axis.edge(Bound::Low) - 0.0).abs() < f64::EPSILON); |
| 1716 |
assert!((axis.edge(Bound::High) - 300.0).abs() < f64::EPSILON); |
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
let open = Axis { |
| 1722 |
extent: None, |
| 1723 |
step: None, |
| 1724 |
unit: None, |
| 1725 |
}; |
| 1726 |
assert!((open.edge(Bound::Low) - 0.0).abs() < f64::EPSILON); |
| 1727 |
assert!((open.edge(Bound::High) - 0.0).abs() < f64::EPSILON); |
| 1728 |
} |
| 1729 |
|
| 1730 |
#[test] |
| 1731 |
fn the_step_decides_how_a_dragged_value_is_written_back() { |
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
assert_eq!(decimals(None), None); |
| 1736 |
assert_eq!(decimals(Some("1")), Some(0)); |
| 1737 |
assert_eq!(decimals(Some("0.01")), Some(2)); |
| 1738 |
|
| 1739 |
assert_eq!(decimals(Some("0.10")), Some(1)); |
| 1740 |
} |
| 1741 |
|
| 1742 |
#[test] |
| 1743 |
fn an_unavailable_option_is_drawn_muted_rather_than_dropped() { |
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1748 |
let options = [ |
| 1749 |
Choice::new("chromatic", "Chromatic"), |
| 1750 |
Choice::new("multi", "Multi-sample").unless("Drop a second sample."), |
| 1751 |
]; |
| 1752 |
assert!(options[0].available()); |
| 1753 |
assert!(!options[1].available()); |
| 1754 |
assert_eq!( |
| 1755 |
option_color("chromatic", options[0].value, &p), |
| 1756 |
p.content, |
| 1757 |
"the chosen option is the emphasised thing" |
| 1758 |
); |
| 1759 |
assert_eq!( |
| 1760 |
option_color("chromatic", options[1].value, &p), |
| 1761 |
p.content_secondary, |
| 1762 |
"and `option_color` never mutes: the unavailable path is what does" |
| 1763 |
); |
| 1764 |
} |
| 1765 |
|
| 1766 |
#[test] |
| 1767 |
fn a_closed_chooser_carries_both_of_an_options_extra_lines_in_its_row() { |
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
let plain = Choice::new("24", "Small Files"); |
| 1772 |
assert_eq!(combo_row(&plain), "Small Files"); |
| 1773 |
|
| 1774 |
let detailed = plain.detailing("$24/mo. Fits audio, plugins, binaries."); |
| 1775 |
assert_eq!( |
| 1776 |
combo_row(&detailed), |
| 1777 |
"Small Files $24/mo. Fits audio, plugins, binaries." |
| 1778 |
); |
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
let both = detailed.unless("Sold out."); |
| 1783 |
assert_eq!( |
| 1784 |
combo_row(&both), |
| 1785 |
"Small Files $24/mo. Fits audio, plugins, binaries. Sold out." |
| 1786 |
); |
| 1787 |
assert_eq!( |
| 1788 |
combo_row(&plain.unless("Sold out.")), |
| 1789 |
"Small Files Sold out.", |
| 1790 |
"the reason still reads the way it did before the detail existed" |
| 1791 |
); |
| 1792 |
} |
| 1793 |
|
| 1794 |
#[test] |
| 1795 |
fn only_a_required_field_is_marked() { |
| 1796 |
let style = FieldStyle::default(); |
| 1797 |
let plain = Field::new(FieldKind::Text, "title", "Title"); |
| 1798 |
assert_eq!(label_text(&plain, &style), "Title"); |
| 1799 |
|
| 1800 |
let required = Field { |
| 1801 |
required: true, |
| 1802 |
..plain |
| 1803 |
}; |
| 1804 |
assert_eq!(label_text(&required, &style), "Title *"); |
| 1805 |
|
| 1806 |
|
| 1807 |
let house = FieldStyle { |
| 1808 |
required_marker: "(required)", |
| 1809 |
..style |
| 1810 |
}; |
| 1811 |
assert_eq!(label_text(&required, &house), "Title (required)"); |
| 1812 |
} |
| 1813 |
|
| 1814 |
#[test] |
| 1815 |
fn a_select_and_a_checkbox_are_pressed_and_everything_else_is_typed_into() { |
| 1816 |
|
| 1817 |
|
| 1818 |
assert_eq!(control_shape(FieldKind::Select), Control::Chosen); |
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
assert_eq!(control_shape(FieldKind::Theme), Control::Themed); |
| 1823 |
assert_eq!(control_shape(FieldKind::Radio), Control::Listed); |
| 1824 |
assert_eq!(control_shape(FieldKind::Checkbox), Control::Toggled); |
| 1825 |
for k in [ |
| 1826 |
FieldKind::Text, |
| 1827 |
FieldKind::Secret, |
| 1828 |
FieldKind::Number, |
| 1829 |
FieldKind::Email, |
| 1830 |
FieldKind::Url, |
| 1831 |
FieldKind::Tel, |
| 1832 |
FieldKind::Textarea, |
| 1833 |
FieldKind::Rich, |
| 1834 |
] { |
| 1835 |
assert_eq!(control_shape(k), Control::Typed, "{k:?} is typed into"); |
| 1836 |
} |
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
assert!(FieldKind::Rich.multiline()); |
| 1841 |
assert!(FieldKind::Textarea.multiline()); |
| 1842 |
assert!(!FieldKind::Text.multiline()); |
| 1843 |
} |
| 1844 |
|
| 1845 |
#[test] |
| 1846 |
fn the_two_option_taking_kinds_are_drawn_differently_on_purpose() { |
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
assert!(FieldKind::Select.offers_options()); |
| 1853 |
assert!(FieldKind::Radio.offers_options()); |
| 1854 |
assert_ne!( |
| 1855 |
control_shape(FieldKind::Select), |
| 1856 |
control_shape(FieldKind::Radio) |
| 1857 |
); |
| 1858 |
} |
| 1859 |
|
| 1860 |
#[test] |
| 1861 |
fn an_unchosen_option_is_secondary_and_never_muted() { |
| 1862 |
let p = palette(Color32::from_rgb(4, 4, 4)); |
| 1863 |
assert_eq!(option_color("wav", "wav", &p), p.content); |
| 1864 |
assert_eq!(option_color("wav", "aiff", &p), p.content_secondary); |
| 1865 |
|
| 1866 |
|
| 1867 |
assert_ne!(option_color("wav", "aiff", &p), p.content_muted); |
| 1868 |
} |
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
fn announced(draw: impl FnMut(&mut egui::Ui)) -> Vec<(egui::accesskit::Role, String)> { |
| 1878 |
let ctx = egui::Context::default(); |
| 1879 |
ctx.enable_accesskit(); |
| 1880 |
let mut draw = draw; |
| 1881 |
let input = || egui::RawInput { |
| 1882 |
screen_rect: Some(egui::Rect::from_min_size( |
| 1883 |
egui::Pos2::ZERO, |
| 1884 |
egui::vec2(800.0, 600.0), |
| 1885 |
)), |
| 1886 |
..Default::default() |
| 1887 |
}; |
| 1888 |
|
| 1889 |
|
| 1890 |
let _ = ctx.run_ui(input(), &mut draw); |
| 1891 |
let out = ctx.run_ui(input(), &mut draw); |
| 1892 |
|
| 1893 |
let update = out |
| 1894 |
.platform_output |
| 1895 |
.accesskit_update |
| 1896 |
.expect("accesskit is on, so a tree was built"); |
| 1897 |
let by_id: std::collections::HashMap<_, _> = update.nodes.iter().cloned().collect(); |
| 1898 |
update |
| 1899 |
.nodes |
| 1900 |
.iter() |
| 1901 |
.map(|(_, node)| { |
| 1902 |
let named = node.label().map(str::to_owned).or_else(|| { |
| 1903 |
node.labelled_by() |
| 1904 |
.iter() |
| 1905 |
.find_map(|id| by_id.get(id)) |
| 1906 |
.and_then(|by| by.label().or_else(|| by.value()).map(str::to_owned)) |
| 1907 |
}); |
| 1908 |
(node.role(), named.unwrap_or_default()) |
| 1909 |
}) |
| 1910 |
.collect() |
| 1911 |
} |
| 1912 |
|
| 1913 |
#[test] |
| 1914 |
fn a_fields_label_names_its_control_rather_than_sitting_beside_it() { |
| 1915 |
let f = Field::new(FieldKind::Text, "name", "Vault name"); |
| 1916 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1917 |
let drawn = announced(|ui| { |
| 1918 |
let mut text = String::new(); |
| 1919 |
field( |
| 1920 |
ui, |
| 1921 |
&f, |
| 1922 |
Filling::Text(&mut text), |
| 1923 |
None, |
| 1924 |
&p, |
| 1925 |
&FieldStyle::default(), |
| 1926 |
); |
| 1927 |
}); |
| 1928 |
|
| 1929 |
let box_ = drawn |
| 1930 |
.iter() |
| 1931 |
.find(|(role, _)| *role == egui::accesskit::Role::TextInput) |
| 1932 |
.expect("a text field draws a text input"); |
| 1933 |
assert_eq!( |
| 1934 |
box_.1, "Vault name", |
| 1935 |
"the box is announced by the question rather than unnamed: {drawn:?}" |
| 1936 |
); |
| 1937 |
} |
| 1938 |
|
| 1939 |
#[test] |
| 1940 |
fn a_prefilled_box_is_still_announced_by_its_question() { |
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
let f = Field::new(FieldKind::Text, "name", "New name"); |
| 1945 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1946 |
let drawn = announced(|ui| { |
| 1947 |
let mut text = String::from("Drums"); |
| 1948 |
field( |
| 1949 |
ui, |
| 1950 |
&f, |
| 1951 |
Filling::Text(&mut text), |
| 1952 |
None, |
| 1953 |
&p, |
| 1954 |
&FieldStyle::default(), |
| 1955 |
); |
| 1956 |
}); |
| 1957 |
|
| 1958 |
let box_ = drawn |
| 1959 |
.iter() |
| 1960 |
.find(|(role, _)| *role == egui::accesskit::Role::TextInput) |
| 1961 |
.expect("a text field draws a text input"); |
| 1962 |
assert_eq!(box_.1, "New name", "{drawn:?}"); |
| 1963 |
} |
| 1964 |
|
| 1965 |
#[test] |
| 1966 |
fn both_ends_of_an_interval_are_named_by_the_one_question() { |
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
let f = Field::new(FieldKind::Interval, "bpm", "BPM Range"); |
| 1971 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 1972 |
let drawn = announced(|ui| { |
| 1973 |
let mut lower = String::from("90"); |
| 1974 |
let mut upper = String::from("300"); |
| 1975 |
field( |
| 1976 |
ui, |
| 1977 |
&f, |
| 1978 |
Filling::Between { |
| 1979 |
lower: &mut lower, |
| 1980 |
upper: &mut upper, |
| 1981 |
}, |
| 1982 |
None, |
| 1983 |
&p, |
| 1984 |
&FieldStyle::default(), |
| 1985 |
); |
| 1986 |
}); |
| 1987 |
|
| 1988 |
|
| 1989 |
let ends: Vec<_> = drawn |
| 1990 |
.iter() |
| 1991 |
.filter(|(role, _)| *role == egui::accesskit::Role::SpinButton) |
| 1992 |
.collect(); |
| 1993 |
assert_eq!(ends.len(), 2, "an interval draws two boxes: {drawn:?}"); |
| 1994 |
for end in ends { |
| 1995 |
assert_eq!(end.1, "BPM Range", "{drawn:?}"); |
| 1996 |
} |
| 1997 |
} |
| 1998 |
|
| 1999 |
#[test] |
| 2000 |
fn a_checkbox_keeps_naming_itself() { |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
let f = Field::new(FieldKind::Checkbox, "loop", "Loop playback"); |
| 2005 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 2006 |
let drawn = announced(|ui| { |
| 2007 |
let mut ticked = false; |
| 2008 |
field( |
| 2009 |
ui, |
| 2010 |
&f, |
| 2011 |
Filling::On(&mut ticked), |
| 2012 |
None, |
| 2013 |
&p, |
| 2014 |
&FieldStyle::default(), |
| 2015 |
); |
| 2016 |
}); |
| 2017 |
|
| 2018 |
assert!( |
| 2019 |
drawn |
| 2020 |
.iter() |
| 2021 |
.any(|(role, name)| *role == egui::accesskit::Role::CheckBox |
| 2022 |
&& name == "Loop playback"), |
| 2023 |
"{drawn:?}" |
| 2024 |
); |
| 2025 |
} |
| 2026 |
|
| 2027 |
#[test] |
| 2028 |
fn a_hidden_field_draws_nothing_and_answers_nothing() { |
| 2029 |
|
| 2030 |
|
| 2031 |
let f = Field::new(FieldKind::Hidden, "id", "Id"); |
| 2032 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 2033 |
egui::__run_test_ui(|ui| { |
| 2034 |
let drawn = field(ui, &f, Filling::Absent, None, &p, &FieldStyle::default()); |
| 2035 |
assert!(drawn.is_none()); |
| 2036 |
}); |
| 2037 |
} |
| 2038 |
|
| 2039 |
#[test] |
| 2040 |
fn a_disabled_field_stops_answering_and_an_unstated_one_does_not() { |
| 2041 |
let f = Field::new(FieldKind::Text, "title", "Title"); |
| 2042 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 2043 |
let style = FieldStyle::default(); |
| 2044 |
egui::__run_test_ui(|ui| { |
| 2045 |
let mut text = String::from("x"); |
| 2046 |
let disabled = field( |
| 2047 |
ui, |
| 2048 |
&f, |
| 2049 |
Filling::Text(&mut text), |
| 2050 |
Some(State::Disabled), |
| 2051 |
&p, |
| 2052 |
&style, |
| 2053 |
) |
| 2054 |
.unwrap(); |
| 2055 |
assert!(!disabled.enabled()); |
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
let mut text = String::from("x"); |
| 2061 |
let plain = field(ui, &f, Filling::Text(&mut text), None, &p, &style).unwrap(); |
| 2062 |
assert!(plain.enabled(), "an unstated field still answers"); |
| 2063 |
}); |
| 2064 |
} |
| 2065 |
|
| 2066 |
#[test] |
| 2067 |
fn a_field_described_one_way_and_filled_another_is_drawn_inert() { |
| 2068 |
|
| 2069 |
|
| 2070 |
let f = Field::new(FieldKind::Checkbox, "done", "Done"); |
| 2071 |
let p = palette(Color32::from_rgb(9, 9, 9)); |
| 2072 |
let mut text = String::from("untouched"); |
| 2073 |
egui::__run_test_ui(|ui| { |
| 2074 |
let drawn = field( |
| 2075 |
ui, |
| 2076 |
&f, |
| 2077 |
Filling::Text(&mut text), |
| 2078 |
None, |
| 2079 |
&p, |
| 2080 |
&FieldStyle::default(), |
| 2081 |
); |
| 2082 |
assert!(drawn.is_some()); |
| 2083 |
}); |
| 2084 |
assert_eq!(text, "untouched"); |
| 2085 |
} |
| 2086 |
|
| 2087 |
#[test] |
| 2088 |
fn the_disclosure_belongs_to_the_form_and_not_to_the_field() { |
| 2089 |
let fields = [ |
| 2090 |
Field::new(FieldKind::Text, "title", "Title"), |
| 2091 |
Field { |
| 2092 |
extended: true, |
| 2093 |
..Field::new(FieldKind::Text, "notes", "Notes") |
| 2094 |
}, |
| 2095 |
]; |
| 2096 |
let style = FieldStyle::default(); |
| 2097 |
|
| 2098 |
let mut closed = Vec::new(); |
| 2099 |
egui::__run_test_ui(|ui| { |
| 2100 |
group(ui, &fields, false, &style, |_, f| closed.push(f.name)); |
| 2101 |
}); |
| 2102 |
assert_eq!(closed, ["title"]); |
| 2103 |
|
| 2104 |
let mut open = Vec::new(); |
| 2105 |
egui::__run_test_ui(|ui| { |
| 2106 |
group(ui, &fields, true, &style, |_, f| open.push(f.name)); |
| 2107 |
}); |
| 2108 |
assert_eq!(open, ["title", "notes"]); |
| 2109 |
} |
| 2110 |
|
| 2111 |
#[test] |
| 2112 |
fn the_default_frame_is_square_and_one_point() { |
| 2113 |
let d = FrameStyle::default(); |
| 2114 |
assert_eq!(d.radius, CornerRadius::ZERO); |
| 2115 |
assert_eq!(d.margin, Margin::ZERO); |
| 2116 |
assert!((d.stroke - 1.0).abs() < f32::EPSILON); |
| 2117 |
} |
| 2118 |
|
| 2119 |
#[test] |
| 2120 |
fn a_theme_picker_reads_its_chosen_theme_by_name() { |
| 2121 |
const THEMES: &[makeover_layout::ThemeChoice<'_>] = &[makeover_layout::ThemeChoice::new( |
| 2122 |
"carbonfox", |
| 2123 |
"Carbonfox", |
| 2124 |
ThemeVariant::Dark, |
| 2125 |
makeover_layout::Contrast::High, |
| 2126 |
)]; |
| 2127 |
let field = Field::theme("theme", "Theme", THEMES) |
| 2128 |
.following(Choice::new("system", "Follow System")); |
| 2129 |
|
| 2130 |
assert_eq!(themed_text(&field, "carbonfox"), "Carbonfox"); |
| 2131 |
assert_eq!(themed_text(&field, "system"), "Follow System"); |
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
assert_eq!(themed_text(&field, "gone"), "gone"); |
| 2136 |
} |
| 2137 |
} |
| 2138 |
|