mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 18:14:00 +01:00
Draw the panel tabs and frames in TextureCraft's colours again
craft-ui's dock has drawn every panel's tab strip and body in the suite's default grey since the move to craft-libs: the app gave craft-ui no theme. Hand it one built from the app's tokens (the strip on the window chrome, the shown tab and body on the panel card, the tab names in the app's text colours), kept while the tokens stay the same.
This commit is contained in:
1 parent
896cd220c8
commit
13deee13b4
5 files changed
+94
No files matched your search
@@ -121,6 +121,9 @@ impl TextureCraftApp {
|
||||
Brightness::Dark | Brightness::MediumDark => craft_theme::Mode::Dark,
|
||||
};
|
||||
let mut root = RootEnv::new().mode(mode).scale(Scale::new(scale));
|
||||
if let Some(theme) = crate::library_theme::library_theme(ctx, &crate::theme::Tokens::get(ctx)) {
|
||||
root = root.library_theme(theme);
|
||||
}
|
||||
// Hide UI on another key leaves Tab to focus traversal and the shortcuts
|
||||
root.tab_toggles_chrome = crate::keymap::shortcut_of(&self.ui.keymap, "ui.hideUi") == Some("Tab");
|
||||
let app_modal = crate::docking::input_blocked(self, ctx).then_some(ViewportId::ROOT);
|
||||
|
||||
@@ -80,6 +80,7 @@ mod levels_display;
|
||||
mod levels_editor;
|
||||
mod levels_handle;
|
||||
mod levels_properties;
|
||||
mod library_theme;
|
||||
mod line_snap;
|
||||
mod list_action;
|
||||
pub mod log_panel;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//! TextureCraft's colours handed to craft-ui, so the dock's frames, tab strips and splitters draw in our theme instead of the suite's default grey
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft_theme::{ColorToken, ModePins, Pins, Rgba, SUITE_DEFAULT, ThemeDef, ThemeId, builtins};
|
||||
use egui::{Color32, Context, Id};
|
||||
|
||||
use crate::theme::Tokens;
|
||||
|
||||
/// The id of TextureCraft's theme, apart from every built-in one
|
||||
const THEME_ID: &str = "texturecraft.app";
|
||||
|
||||
/// The theme craft-ui resolves its tokens from (`RootEnv::library_theme`), kept while the tokens stay the same so it resolves once per theme change
|
||||
pub(crate) fn library_theme(ctx: &Context, tokens: &Tokens) -> Option<Arc<ThemeDef>> {
|
||||
let pins = app_pins(tokens);
|
||||
let memory_id = Id::unique(THEME_ID);
|
||||
let kept: Option<Arc<ThemeDef>> = ctx.data(|data| data.get_temp(memory_id));
|
||||
if let Some(def) = kept.filter(|def| def.pins.dark == pins) {
|
||||
return Some(def);
|
||||
}
|
||||
let def = Arc::new(app_def(pins)?);
|
||||
ctx.data_mut(|data| data.insert_temp(memory_id, Arc::clone(&def)));
|
||||
Some(def)
|
||||
}
|
||||
|
||||
/// The suite default with TextureCraft's colours pinned in both modes (the root's mode picks one); `None` if the suite default is missing
|
||||
fn app_def(pins: Pins) -> Option<ThemeDef> {
|
||||
let mut def = builtins().iter().find(|theme| theme.id.as_str() == SUITE_DEFAULT)?.clone();
|
||||
def.id = ThemeId::parse(THEME_ID).ok()?;
|
||||
def.pins = ModePins { light: pins.clone(), dark: pins };
|
||||
Some(def)
|
||||
}
|
||||
|
||||
fn app_pins(tokens: &Tokens) -> Pins {
|
||||
[
|
||||
(ColorToken::SurfaceBackground, rgba(tokens.chrome)),
|
||||
(ColorToken::SurfacePanel, rgba(tokens.panel)),
|
||||
(ColorToken::LineBorder, rgba(tokens.separator)),
|
||||
(ColorToken::AccentSolid, rgba(tokens.accent)),
|
||||
// The shown tab's name is brighter than the others, as on the panel headers
|
||||
(ColorToken::TextNormal, rgba(tokens.text_strong)),
|
||||
(ColorToken::TextMuted, rgba(tokens.text_dim)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn rgba(color: Color32) -> Rgba {
|
||||
let [r, g, b, a] = color.to_srgba_unmultiplied();
|
||||
Rgba([r, g, b, a])
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//! craft-ui's parts (the dock's frames and tab strips) draw in TextureCraft's colours, not the suite's default grey
|
||||
|
||||
use craft_ui::style::StyleCx;
|
||||
use egui::Color32;
|
||||
use egui_kittest::Harness;
|
||||
use texturecraft_ui_egui::TextureCraftApp;
|
||||
use texturecraft_ui_egui::theme::{Brightness, Tokens};
|
||||
|
||||
use crate::{BAKE_RESOLUTION, SETTLE_FRAMES, TEXTURE_RESOLUTION};
|
||||
|
||||
/// A window wide enough for the dock's groups, strips and splitters
|
||||
const WINDOW_SIZE: egui::Vec2 = egui::vec2(1200.0, 800.0);
|
||||
|
||||
fn srgba(color: craft_theme::Rgba) -> Color32 {
|
||||
let [r, g, b, a] = color.0;
|
||||
Color32::from_rgba_unmultiplied(r, g, b, a)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_dock_strips_and_panel_bodies_take_the_app_theme_colours() {
|
||||
let session = texturecraft_engine::sample_session(TEXTURE_RESOLUTION, BAKE_RESOLUTION).unwrap();
|
||||
let mut harness = Harness::builder()
|
||||
.with_size(WINDOW_SIZE)
|
||||
.with_context_setup(texturecraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|context| TextureCraftApp::new(context, session));
|
||||
for brightness in [Brightness::Dark, Brightness::MediumDark, Brightness::MediumLight, Brightness::Light] {
|
||||
harness.state_mut().ui.prefs.brightness = brightness;
|
||||
harness.run_steps(SETTLE_FRAMES);
|
||||
let tokens = Tokens::get(&harness.ctx);
|
||||
let (strip, body, frame) = StyleCx::with_root(&harness.ctx, |cx| {
|
||||
let color = &cx.tokens.color;
|
||||
(color.surface.background, color.surface.panel, color.line.border)
|
||||
});
|
||||
assert_eq!(srgba(strip), tokens.chrome, "{brightness:?}: the tab strips lie on the window chrome");
|
||||
assert_eq!(srgba(body), tokens.panel, "{brightness:?}: the shown tab and the panel body are the panel card");
|
||||
assert_eq!(srgba(frame), tokens.separator, "{brightness:?}: the group frames are the cards' hairline");
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ mod layer_rename;
|
||||
mod layer_toolbar;
|
||||
mod layers_panel;
|
||||
mod levels_editor;
|
||||
mod library_theme;
|
||||
mod log_panel_680;
|
||||
mod mask_export;
|
||||
mod mask_fill_rows;
|
||||
|
||||
Reference in new issue
Block a user