mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-19 00:16:36 +00:00
Design lint: layer the env values, route egui access through the adapter, derive setters, token and relation checks in tests
The gate's design-lint test finds nothing. Env value types (pane edge, column align, row pressed, in-bar), band fill and span live in the layer that uses them; the cursor image and inside label are read back by the higher layer. Hand setters become derived props, tests assert relations, and the remaining sites are listed exceptions with reasons. The shortcut chord chip's sample is built only for screen tests.
This commit is contained in:
@@ -264,7 +264,10 @@ pub struct AppShell<'a, S> {
|
||||
window: WindowKey,
|
||||
bare: bool,
|
||||
embedded: bool,
|
||||
/// An embedded shell as tall as its content, with the most a body that fills takes.
|
||||
/// An embedded shell as wide as the room of the flow it is shown in and as tall as its body's content and its top
|
||||
/// and bottom slots, from the measure its body keeps while its inputs hold; a body that fills takes at most this
|
||||
/// room. Shown with [`show`](Self::show), it takes that room in the flow.
|
||||
#[prop(name = "content_height", quantity = "room the host's flow offers, in points")]
|
||||
content_room: Option<f32>,
|
||||
/// The screen mode. Without a binding the shell keeps it, starting at `Standard`.
|
||||
#[prop]
|
||||
@@ -320,13 +323,6 @@ impl<'a, S> AppShell<'a, S> {
|
||||
AppShell { embedded: true, ..Self::new(window) }
|
||||
}
|
||||
|
||||
/// An embedded shell as wide as the room of the flow it is shown in and as tall as its body's content and its top
|
||||
/// and bottom slots, from the measure its body keeps while its inputs hold; a body that fills takes at most `room`.
|
||||
/// Shown with [`show`](Self::show), it takes that room in the flow.
|
||||
pub fn content_height(self, room: f32) -> Self {
|
||||
AppShell { embedded: true, content_room: Some(room), ..self }
|
||||
}
|
||||
|
||||
/// The title bar slot, the first top slot, keyed `"title"`: visible, and revealing in body-only mode. The title bar
|
||||
/// types fill it.
|
||||
pub fn title_bar(self, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
|
||||
@@ -419,6 +415,7 @@ impl<'a, S> AppShell<'a, S> {
|
||||
slots,
|
||||
mut body,
|
||||
} = self;
|
||||
let embedded = embedded || content_room.is_some();
|
||||
let env = Env::of(ui);
|
||||
let outer = env.get::<ShellEntry>().0;
|
||||
let words = env.words::<ShellWords>();
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
//! [`crate::runtime::keys::with_window_intents`], last in the app's UI.
|
||||
|
||||
use crate::fonts::{Stack, UiFonts};
|
||||
#[cfg(feature = "app")]
|
||||
use crate::runtime::egui::memory;
|
||||
use crate::runtime::frame::{FrameInput, FrameOutput, set_input, take_output};
|
||||
use crate::runtime::windows;
|
||||
use crate::runtime::{InstallError, InstallSpec};
|
||||
@@ -62,15 +64,19 @@ pub fn before_ui(ctx: &Context, frame: &eframe::Frame) {
|
||||
fit_once(ctx);
|
||||
}
|
||||
|
||||
/// Whether the fit has run for this context.
|
||||
#[cfg(feature = "app")]
|
||||
#[derive(Default)]
|
||||
struct Fitted(bool);
|
||||
|
||||
/// Runs [`fit_first`] from the first passes until its monitor is known, then never again for this context.
|
||||
#[cfg(feature = "app")]
|
||||
fn fit_once(ctx: &Context) {
|
||||
let key = egui::Id::unique("craft_ui_shell::embed::fitted");
|
||||
if ctx.data(|data| data.get_temp::<bool>(key)).unwrap_or(false) {
|
||||
if memory::with::<Fitted, _>(ctx, |fitted| fitted.0) {
|
||||
return;
|
||||
}
|
||||
if fit_first(ctx) {
|
||||
ctx.data_mut(|data| data.insert_temp(key, true));
|
||||
memory::with::<Fitted, _>(ctx, |fitted| fitted.0 = true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,10 @@ impl Outcome for ViewportWindowOutput {
|
||||
#[derive(Pattern, Props)]
|
||||
pub struct ViewportWindow {
|
||||
title: Label,
|
||||
/// What lies over the app's other windows while this one is open and blocks them; `None` blocks nothing.
|
||||
/// Makes the app's other windows ignore input while this one is open, with `backdrop` over them where the window is
|
||||
/// a layer (`Backdrop::Scrim` dims them, `Backdrop::None` leaves them as they are). Without it the window blocks
|
||||
/// nothing.
|
||||
#[prop(name = "app_modal")]
|
||||
modal: Option<Backdrop>,
|
||||
/// Changes the layer the window has where windows are unavailable, whose limits and place its OS window takes.
|
||||
overlay: Option<Box<dyn FnOnce(Overlay) -> Overlay>>,
|
||||
@@ -59,13 +62,6 @@ impl ViewportWindow {
|
||||
ViewportWindow { title: title.into(), modal: None, overlay: None, remember: None }
|
||||
}
|
||||
|
||||
/// Makes the app's other windows ignore input while this one is open, with `backdrop` over them where the window is
|
||||
/// a layer (`Backdrop::Scrim` dims them, `Backdrop::None` leaves them as they are).
|
||||
pub fn app_modal(mut self, backdrop: Backdrop) -> Self {
|
||||
self.modal = Some(backdrop);
|
||||
self
|
||||
}
|
||||
|
||||
/// Changes the layer the window falls back to, which starts as the resizable dialog layer: the smallest and
|
||||
/// largest size (`Overlay::size_limits`), the place (`Overlay::placed`) and the resizability. Calls compose in
|
||||
/// order.
|
||||
|
||||
Reference in New Issue
Block a user