Implement the reviewed UI icon system and durable review workflow (#853)
Thanks @Nathan-Dane.
This commit is contained in:
1 parent
c599238653
commit
64966bab88
374 files changed
+8187
-2221
No files matched your search
@@ -3,7 +3,6 @@
|
||||
//! uses comes from [`Tokens`].
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
#[path = "../../../assets/styles/ui/palettes.rs"]
|
||||
mod palettes;
|
||||
@@ -11,10 +10,11 @@ mod palettes;
|
||||
use egui::{Color32, Stroke};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
static DARK: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
thread_local! {
|
||||
/// The colour vision mode, per thread, where the dark theme is one global (`DARK`). Each app
|
||||
/// Theme state belongs to the UI thread drawing the frame. Concurrent app/test renderers
|
||||
/// must not change one another's palette while a frame or icon texture is being built.
|
||||
static DARK: Cell<bool> = const { Cell::new(true) };
|
||||
/// The colour vision mode, per thread. Each app
|
||||
/// sets it from its own preferences at the start of every frame (`SolveApp::logic`), on the
|
||||
/// thread that draws it. Tests run many apps side by side on their own threads in one process:
|
||||
/// with one global, a test in a mode changed the colours under another one
|
||||
@@ -26,7 +26,12 @@ thread_local! {
|
||||
|
||||
/// Is the dark theme on?
|
||||
pub fn is_dark() -> bool {
|
||||
DARK.load(Ordering::Relaxed)
|
||||
DARK.get()
|
||||
}
|
||||
|
||||
/// The common conversion boundary for compiled icon palette data.
|
||||
pub(crate) const fn icon_color(rgb: [u8; 3]) -> Color32 {
|
||||
Color32::from_rgb(rgb[0], rgb[1], rgb[2])
|
||||
}
|
||||
|
||||
/// Colour vision modes (#778): a second set of values for the colours that carry a meaning, for
|
||||
@@ -333,7 +338,7 @@ pub fn material_color(name: &str) -> Option<Color32> {
|
||||
|
||||
/// Switch themes (the visuals follow on the next [`apply`]).
|
||||
pub fn set_dark(dark: bool) {
|
||||
DARK.store(dark, Ordering::Relaxed);
|
||||
DARK.set(dark);
|
||||
}
|
||||
|
||||
fn visuals(dark: bool) -> egui::Visuals {
|
||||
@@ -373,6 +378,24 @@ pub fn apply(ctx: &egui::Context) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn concurrent_ui_renderers_keep_their_own_theme_and_vision() {
|
||||
let barrier = std::sync::Barrier::new(2);
|
||||
std::thread::scope(|scope| {
|
||||
for (dark, vision) in [(false, super::ColorVision::Off), (true, super::ColorVision::Protan)] {
|
||||
let barrier = &barrier;
|
||||
scope.spawn(move || {
|
||||
super::set_dark(dark);
|
||||
super::set_vision(vision);
|
||||
barrier.wait();
|
||||
assert_eq!(super::is_dark(), dark);
|
||||
assert_eq!(super::vision(), vision);
|
||||
assert_eq!(super::Tokens::get().sketch_accent, super::Tokens::themed(dark, vision).sketch_accent);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Title and section bands stand out from a dialog, the title more than its sections.
|
||||
#[test]
|
||||
fn heading_bands_are_darker_than_the_dialog_in_order() {
|
||||
|
||||
Reference in new issue
Block a user