Settling: a region runs again when its environment changes (theme, density, scale, language, window active)

The env key folds in the generation of the scope's built-in words, and a settling child's place holds the env key it ran under.
This commit is contained in:
aiongg
2026-11-17 23:52:35 +00:00
parent 427c816db0
commit 725df6bf03
6 changed files with 33 additions and 9 deletions
+10 -2
View File
@@ -63,7 +63,8 @@ impl Lazy {
/// - the pointer is over it or was in its last run, a press started on it, or it holds focus or held it;
/// - an animation in it is not at its end, something in it asked for a repaint, or a wake time it asked for came;
/// - a bound value it read was written;
/// - its place, room, clip or scale differs from its last run;
/// - its place, room, clip or scale differs from its last run, or its environment does: the theme, density, language
/// or the window's active state;
/// - its [`content`](Self::content) version differs from its last run;
/// - the app asked for a repaint outside every settling child (`frame::request_repaint`), or a given value was
/// edited: the framework cannot see which children show that app data, so every child runs then;
@@ -126,7 +127,14 @@ impl Lazy {
}
}
let layout = *ui.layout();
let place = Place { room: available, clip: ui.clip_rect(), layer: ui.layer_id(), layout, pixels_per_point: ctx.pixels_per_point() };
let place = Place {
room: available,
clip: ui.clip_rect(),
layer: ui.layer_id(),
layout,
pixels_per_point: ctx.pixels_per_point(),
env: Env::of(ui).key,
};
if self.settles
&& let Some(size) = lazy::settled(&ctx, owner, id, sizing, real.then_some(place), self.content)
{
+1
View File
@@ -51,6 +51,7 @@ impl<'a, K: Hash + PartialEq> Pages<'a, K> {
layer: ui.layer_id(),
layout,
pixels_per_point: ctx.pixels_per_point(),
env: crate::runtime::env::Env::of(ui).key,
};
let kept = lazy::measured(&ctx, id, place).map(|(size, reads)| {
// The page reads them again, as far as an edit later in the pass sees it.
+7 -3
View File
@@ -444,7 +444,10 @@ impl Env {
let shell = Arc::new(windows::shell_of(ctx, pass::current_viewport(ctx)));
let active = shell.window.active;
let keyboard = Arc::new(crate::runtime::keys::layout_of(ctx));
let key = EnvKey::new(tokens.key(), root.direction, scale, os, active, root.values.style_hash()).with_line(line_ratio);
let words = host_words(ctx, host.as_ref());
let key = EnvKey::new(tokens.key(), root.direction, scale, os, active, root.values.style_hash())
.with_line(line_ratio)
.with_words(words.generation());
Env {
scoped: Arc::new(Scoped {
inherited: Arc::new(Inherited {
@@ -458,7 +461,7 @@ impl Env {
motion,
scale,
commands: CommandChain::default(),
words: host_words(ctx, host.as_ref()),
words,
format: host_format(ctx, host.as_ref()),
dates: host_dates(ctx, host.as_ref()),
today: root.today,
@@ -561,7 +564,8 @@ impl Env {
let mut scoped = (*self.scoped).clone();
f(&mut scoped);
scoped.key = EnvKey::new(scoped.tokens.key(), scoped.direction, scoped.scale, scoped.os, scoped.active, scoped.values.style_hash())
.with_line(scoped.line_ratio);
.with_line(scoped.line_ratio)
.with_words(scoped.words.generation());
Env { scoped: Arc::new(scoped) }
}
+7 -2
View File
@@ -19,6 +19,7 @@ use crate::runtime::focus::{self, Transcript};
use crate::runtime::frame::{self, PerViewport};
use crate::runtime::reads::BindKey;
use crate::runtime::replay::{self, Record};
use crate::style::EnvKey;
use egui::{Context, Id, IdMap, IdSet, Layout, Rect, Vec2};
use std::collections::HashSet;
use std::sync::Arc;
@@ -121,7 +122,7 @@ struct Entry {
touched: u64,
}
/// Where a settling child ran: it is settled only while it runs at the same place.
/// Where a settling child ran: it is settled only while it runs at the same place, in the same environment.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct Place {
/// The region its parent offered it.
@@ -130,6 +131,9 @@ pub(crate) struct Place {
pub(crate) layer: Layer,
pub(crate) layout: Layout,
pub(crate) pixels_per_point: f32,
/// The scope's environment (`Env::key`): its tokens (theme, density), scale, direction, language and whether the
/// window is active.
pub(crate) env: EnvKey,
}
/// The last measuring run of a measure-only child: content a pass measures and never shows, as a page `Pages` holds
@@ -287,7 +291,8 @@ pub(crate) fn replay(ctx: &Context, id: Id) {
/// - none of its stops holds focus or is the target of a focus request, now or in its last run;
/// - no intent of this pass is routed to a component in it (an AccessKit request on one of its nodes);
/// - no value it read (a bound value, an inspection record, a command's state) changed this frame (`note_edit`);
/// - its content version is the one of its last run;
/// - its content version is the one of its last run, and its environment (theme, density, scale, language, window
/// active) the one it ran in;
/// - no frame unsettled every child (`unsettle`): an app's repaint request outside every settling child or an edit of a
/// given value, this frame or the one before;
/// - for a child with no content version: no input other than pointer motion this frame or the one before;
+7 -1
View File
@@ -24,7 +24,7 @@ pub enum Ink {
}
/// The key of everything a style depends on besides its own key: tokens, direction, scale, the OS, the window's
/// active state and the style-affecting app values.
/// active state, the style-affecting app values and the language of the built-in words.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub struct EnvKey(u64);
@@ -46,6 +46,12 @@ impl EnvKey {
self.folded(u64::from(line_ratio.to_bits()))
}
/// This key with the generation of the scope's built-in words folded in (`Words::generation`): text, and with it
/// sizes, follow the language.
pub(crate) fn with_words(self, generation: u64) -> Self {
self.folded(generation)
}
/// This key with one more input folded in: a face's styles depend on the host's ink as well.
pub(crate) fn folded(self, input: u64) -> Self {
let mut hasher = std::collections::hash_map::DefaultHasher::new();
+1 -1
View File
@@ -97,7 +97,7 @@ pub fn with_cx<R>(ctx: &Context, tokens: &UiTokens, variant: Variant, size: Cont
Scale::default(),
Os::Linux,
true,
env_key(tokens).with_line(line_ratio),
env_key(tokens).with_line(line_ratio).with_words(0),
line_ratio,
);
f(&cx)