R8.1: document content keeps the file's colours in a dark app
Pages, cells, slides and PDF pages paint as the file says in any appearance; only the chrome around them follows dark mode. The kernel keeps Ely's one light scheme, sent once a view, and MuPDF no longer inverts. Reviews now run gpt-6.1-sol at xhigh. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
42 files changed
+204
-209
No files matched your search
@@ -350,7 +350,7 @@ fn brightness(tile: &Tile) -> u32 {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_page_follows_a_dark_theme_and_back() {
|
||||
fn ely_scheme_paints_the_page_white() {
|
||||
let Some(install) = install() else {
|
||||
eprintln!("SKIP: no pinned LOK build");
|
||||
return;
|
||||
@@ -363,23 +363,11 @@ fn the_page_follows_a_dark_theme_and_back() {
|
||||
let doc = worker
|
||||
.load(&crate::file_url(&source))
|
||||
.expect("the document loads");
|
||||
let area = (1440, 1440, 3840, 3840);
|
||||
let seen = poll_until(&mut worker, &doc, &Events::default(), QUIET, |_| false);
|
||||
let light = brightness(&doc.paint_tile(&mut worker, area, (64, 64)).expect("a tile"));
|
||||
let paint = |worker: &mut Worker, scheme: &str, seen: &Events| {
|
||||
worker.run(&doc, "view.theme", &[scheme]).expect("a theme");
|
||||
let repainted = poll_until(worker, &doc, seen, SETTLE, |seen| seen.all);
|
||||
assert!(repainted.all, "{name}: {scheme} repaints the view");
|
||||
let tile = doc.paint_tile(worker, area, (64, 64)).expect("a tile");
|
||||
(brightness(&tile), repainted)
|
||||
};
|
||||
let (dark, seen) = paint(&mut worker, "COLOR_SCHEME_ELY_DARK", &seen);
|
||||
let (back, _) = paint(&mut worker, "COLOR_SCHEME_ELY_LIGHT", &seen);
|
||||
eprintln!("THEME {name} light {light} dark {dark} back {back}");
|
||||
assert!(
|
||||
light > 200 && dark < 100 && back > 200,
|
||||
"{name}: {light} {dark} {back}"
|
||||
);
|
||||
poll_until(&mut worker, &doc, &Events::default(), QUIET, |_| false);
|
||||
worker.run(&doc, "view.theme", &["COLOR_SCHEME_ELY_LIGHT"]).expect("the scheme");
|
||||
let tile = doc.paint_tile(&mut worker, (1440, 1440, 3840, 3840), (64, 64)).expect("a tile");
|
||||
let shade = brightness(&tile);
|
||||
assert!(shade > 200, "{name}: the page is light, {shade}");
|
||||
worker.close_doc(doc).expect("the document closes");
|
||||
}
|
||||
}
|
||||
@@ -182,18 +182,16 @@ pub(super) fn open_book(text: &str) -> (tempfile::TempDir, Worker, Doc) {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_theme_switch_is_no_edit() {
|
||||
fn the_scheme_is_no_edit() {
|
||||
if install().is_none() {
|
||||
eprintln!("SKIP: no pinned LOK build");
|
||||
return;
|
||||
}
|
||||
let (_dir, mut worker, doc) = open_book(FODS);
|
||||
for scheme in ["COLOR_SCHEME_ELY_DARK", "COLOR_SCHEME_ELY_LIGHT"] {
|
||||
worker.run(&doc, "view.theme", &[scheme]).expect("the theme runs");
|
||||
let undo = worker.values(&doc, ".uno:Undo").expect("the undo stack");
|
||||
let undo: serde_json::Value = serde_json::from_str(&undo).expect("undo JSON");
|
||||
assert_eq!(undo["actions"], "", "{scheme} left undo steps");
|
||||
}
|
||||
worker.run(&doc, "view.theme", &["COLOR_SCHEME_ELY_LIGHT"]).expect("the scheme runs");
|
||||
let undo = worker.values(&doc, ".uno:Undo").expect("the undo stack");
|
||||
let undo: serde_json::Value = serde_json::from_str(&undo).expect("undo JSON");
|
||||
assert_eq!(undo["actions"], "", "the scheme left undo steps");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -21,7 +21,7 @@ pub use client::{
|
||||
#[cfg(feature = "view")]
|
||||
pub use view::{
|
||||
CONTEXT, Copy, Cut, Geom, Layout, LokError, LokView, Paste, Reported, ZOOM_STEPS, notch,
|
||||
Zoomed, init, layout, paper, read_off, scheme,
|
||||
SCHEME, Zoomed, init, layout, paper, read_off,
|
||||
};
|
||||
#[cfg(feature = "view")]
|
||||
mod view;
|
||||
|
||||
@@ -32,7 +32,7 @@ mod scroll;
|
||||
mod sheet;
|
||||
pub use input::{CONTEXT, Copy, Cut, Paste, init};
|
||||
pub use off::read_off;
|
||||
pub use render::{paper, scheme};
|
||||
pub use render::{SCHEME, paper};
|
||||
mod turn;
|
||||
pub use turn::notch;
|
||||
|
||||
@@ -123,8 +123,8 @@ pub struct LokView {
|
||||
pointer: gpui::CursorStyle,
|
||||
selection: Vec<Rect>,
|
||||
cell: crate::Cell,
|
||||
/// Whether the kernel was last told to paint dark.
|
||||
dark: Option<bool>,
|
||||
/// Whether the kernel was told Ely's scheme.
|
||||
lit: bool,
|
||||
/// The zoom follows the viewport so a page fits.
|
||||
fit: bool,
|
||||
/// Set when the wheel and Up, Down turn parts.
|
||||
@@ -218,7 +218,7 @@ impl LokView {
|
||||
pointer: gpui::CursorStyle::Arrow,
|
||||
selection: Vec::new(),
|
||||
cell: crate::Cell::default(),
|
||||
dark: None,
|
||||
lit: false,
|
||||
fit: false,
|
||||
turning: None,
|
||||
part: 0,
|
||||
|
||||
@@ -6,9 +6,9 @@ use super::LokView;
|
||||
use crate::Rect;
|
||||
|
||||
impl LokView {
|
||||
/// Whether the kernel paints dark; None before the first frame.
|
||||
pub fn dark(&self) -> Option<bool> {
|
||||
self.dark
|
||||
/// Whether the kernel was told Ely's scheme.
|
||||
pub fn lit(&self) -> bool {
|
||||
self.lit
|
||||
}
|
||||
|
||||
/// The kernel's state for `uno`, as LOK reports it (LOK-05).
|
||||
|
||||
@@ -15,33 +15,21 @@ use gpui::{Pixels, RenderImage, point};
|
||||
use super::{CONTEXT, LokView, TILE_TWIPS, TWIPS_PER_PIXEL, handles, input};
|
||||
use crate::Rect;
|
||||
|
||||
/// Ely's kernel color schemes, from `ely.xcd`.
|
||||
const DARK: &str = "COLOR_SCHEME_ELY_DARK";
|
||||
const LIGHT: &str = "COLOR_SCHEME_ELY_LIGHT";
|
||||
/// Ely's kernel color scheme, from `ely.xcd`.
|
||||
pub const SCHEME: &str = "COLOR_SCHEME_ELY_LIGHT";
|
||||
|
||||
/// The kernel scheme for a light or dark app.
|
||||
pub fn scheme(dark: bool) -> &'static str {
|
||||
if dark { DARK } else { LIGHT }
|
||||
}
|
||||
|
||||
/// A page's colour; the kernel's Ely schemes share it.
|
||||
pub fn paper(cx: &gpui::App) -> gpui::Hsla {
|
||||
let theme = cx.theme();
|
||||
if theme.is_dark() {
|
||||
theme.colors.surface
|
||||
} else {
|
||||
theme.colors.paper
|
||||
}
|
||||
/// A page's colour, the scheme's `DocColor`.
|
||||
pub fn paper() -> gpui::Hsla {
|
||||
gpui::white()
|
||||
}
|
||||
|
||||
impl LokView {
|
||||
/// Paints with the app's light or dark scheme.
|
||||
pub(super) fn follow_theme(&mut self, dark: bool) {
|
||||
if self.dark != Some(dark) {
|
||||
self.dark = Some(dark);
|
||||
let scheme = scheme(dark);
|
||||
log::info!("lok: paints with {scheme}");
|
||||
self.send(input::Input::Theme(scheme));
|
||||
/// Content keeps the file's colours in any app theme.
|
||||
pub(super) fn paint_light(&mut self) {
|
||||
if !self.lit {
|
||||
self.lit = true;
|
||||
log::info!("lok: paints with {SCHEME}");
|
||||
self.send(input::Input::Theme(SCHEME));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,11 +41,11 @@ impl Render for LokView {
|
||||
self.keep_scroll(|view| view.geom.dpi = dpi);
|
||||
self.retire_tiles();
|
||||
}
|
||||
self.follow_theme(cx.theme().is_dark());
|
||||
self.paint_light();
|
||||
let this = cx.entity().clone();
|
||||
let focus = self.focus.clone();
|
||||
let colors = &cx.theme().colors;
|
||||
let paper = super::paper(cx);
|
||||
let paper = super::paper();
|
||||
let (selection_color, caret_color) = (colors.selection, colors.focus);
|
||||
let canvas_color = colors.sunken;
|
||||
let caret_width = cx.theme().caret_width().to_pixels(window.rem_size());
|
||||
|
||||
@@ -24,37 +24,63 @@ fn area() -> Bounds<Pixels> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A user profile whose dark scheme paints the page black.
|
||||
const DARK_PROFILE: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<item oor:path="/org.openoffice.Office.UI/ColorScheme/ColorSchemes"><node oor:name="TEST_DARK" oor:op="replace"><node oor:name="DocColor"><prop oor:name="Color" oor:op="fuse"><value>0</value></prop></node></node></item>
|
||||
</oor:items>
|
||||
"#;
|
||||
|
||||
/// Shows a view in a window.
|
||||
struct Host(Entity<LokView>);
|
||||
|
||||
impl gpui::Render for Host {
|
||||
fn render(&mut self, _: &mut gpui::Window, _: &mut gpui::Context<Self>) -> impl gpui::IntoElement {
|
||||
self.0.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_view_paints_the_app_theme_and_back() {
|
||||
fn a_dark_app_paints_the_page_white() {
|
||||
let Some(install) = crate::client::tests::install() else {
|
||||
eprintln!("SKIP: no pinned LOK build");
|
||||
return;
|
||||
};
|
||||
let cx = TestAppContext::single();
|
||||
let (view, worker) = cx.update(|app| live_view(app, &install));
|
||||
let doc = cx.update(|app| view.read(app).doc.clone());
|
||||
let mut shades = Vec::new();
|
||||
for dark in [true, false] {
|
||||
cx.update(|app| view.update(app, |view, _| view.follow_theme(dark)));
|
||||
assert!(
|
||||
settle(&cx, |app| view.read(app).settled()),
|
||||
"the theme goes out"
|
||||
);
|
||||
let mut cx = TestAppContext::single();
|
||||
cx.update(|app| {
|
||||
ely_gpui_component::init_for_tests(app);
|
||||
ely_gpui_component::theme::Theme::set_mode_now(ely_gpui_component::theme::Mode::Dark, app);
|
||||
});
|
||||
// A dark profile, as an old Ely left.
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let profile = dir.path().join("profile");
|
||||
std::fs::create_dir_all(profile.join("user")).expect("a profile");
|
||||
std::fs::write(profile.join("user/registrymodifications.xcu"), DARK_PROFILE).expect("the scheme writes");
|
||||
let source = dir.path().join("note.fodt");
|
||||
std::fs::write(&source, crate::client::tests::FODT).expect("the fixture writes");
|
||||
let mut started = crate::Worker::spawn(&install, &profile).expect("the worker");
|
||||
let doc = started.load(&crate::file_url(&source)).expect("the document loads");
|
||||
let laid = super::super::layout(&mut started, &doc).expect("the layout reads");
|
||||
let worker = Arc::new(Mutex::new(started));
|
||||
let shade = || {
|
||||
let mut worker = worker.lock().expect("the worker");
|
||||
let tile = doc
|
||||
.paint_tile(&mut worker, (1440, 1440, 3840, 3840), (64, 64))
|
||||
.expect("a tile");
|
||||
let sum: u64 = tile
|
||||
.pixels
|
||||
.chunks_exact(4)
|
||||
.map(|px| u64::from(px[0]) + u64::from(px[1]) + u64::from(px[2]))
|
||||
.sum();
|
||||
shades.push(sum / (64 * 64 * 3));
|
||||
}
|
||||
let tile = doc.paint_tile(&mut worker, (1440, 1440, 3840, 3840), (64, 64)).expect("a tile");
|
||||
let sum: u64 = tile.pixels.chunks_exact(4).map(|px| u64::from(px[0]) + u64::from(px[1]) + u64::from(px[2])).sum();
|
||||
sum / (64 * 64 * 3)
|
||||
};
|
||||
worker.lock().expect("the worker").run(&doc, "view.theme", &["TEST_DARK"]).expect("the dark scheme");
|
||||
let dark = shade();
|
||||
assert!(dark < 100, "the kernel starts dark: {dark}");
|
||||
let view = cx.update(|app| LokView::open(Arc::clone(&worker), doc.clone(), laid, app));
|
||||
let shown = view.clone();
|
||||
cx.add_window(move |_, _| Host(shown));
|
||||
assert!(
|
||||
shades[0] < 100 && shades[1] > 200,
|
||||
"dark then light: {shades:?}"
|
||||
settle(&cx, |app| view.read(app).lit() && view.read(app).settled()),
|
||||
"the scheme goes out"
|
||||
);
|
||||
assert_eq!(paper(), gpui::white(), "the page mask is the scheme's white");
|
||||
let light = shade();
|
||||
assert!(light > 240, "the view paints the page white: {light}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user