mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
EditorMock: show_at, and its stories fill a stage as tall as the room offered
A card sizes a filling story from its content, and the window's canvas has none. EditorMock::show_at shows the window at a rect through AppShell::show_at; both stories pass a stage of testing::room_height. The gallery's dock preview keeps show.
This commit is contained in:
@@ -25,7 +25,7 @@ use craft_ui::runtime::commands::{self, CommandRef, Commands as _, EditCommands}
|
||||
use craft_ui::runtime::env::{Env, Label, WindowKey};
|
||||
use craft_ui::shell::{AppShell, AppShellOutput, CaptionFamily, Captions, Frame, ScreenMode, ShellDialogsCx as _, Title, TitleBar};
|
||||
use craft_window::Layout;
|
||||
use egui::Ui;
|
||||
use egui::{Rect, Ui};
|
||||
|
||||
/// The parameters of Gaussian Blur.
|
||||
const BLUR: &str = r#"{"radius":0.1..1000=1}"#;
|
||||
@@ -66,17 +66,30 @@ impl<'a> EditorMock<'a> {
|
||||
|
||||
/// Shows the window in the room offered. Each instance keeps its screen mode, Tab toggle and dialogs apart.
|
||||
pub fn show(self, ui: &mut Ui) -> AppShellOutput {
|
||||
self.show_in(ui, None)
|
||||
}
|
||||
|
||||
/// Shows the window at `rect`, taking that rect's room in the flow of `ui`: for a host that sizes it (a story
|
||||
/// card, which sizes a filling story from its content, and the window's canvas has none).
|
||||
pub fn show_at(self, ui: &mut Ui, rect: Rect) -> AppShellOutput {
|
||||
self.show_in(ui, Some(rect))
|
||||
}
|
||||
|
||||
fn show_in(self, ui: &mut Ui, at: Option<Rect>) -> AppShellOutput {
|
||||
let EditorMock { label, state, screen_mode } = self;
|
||||
let window = WindowKey::new(format!("mock-{:x}-{}", ui.scope_id().value(), label.as_str()));
|
||||
AppShell::embedded(window)
|
||||
let shell = AppShell::embedded(window)
|
||||
.screen_mode(screen_mode)
|
||||
.title_bar_if(true, |ui, _, state: &mut MockState| title_bar(ui, state))
|
||||
.options_bar(true, |ui, _, state: &mut MockState| options_bar(ui, state))
|
||||
.tools(true, |ui, _, state: &mut MockState| tool_rail(ui, state))
|
||||
.status(true, |ui, _, state: &mut MockState| status_bar(ui, state))
|
||||
.body_label(label)
|
||||
.body(|ui, cx, state: &mut MockState| body(ui, cx, state))
|
||||
.show(ui, state)
|
||||
.body(|ui, cx, state: &mut MockState| body(ui, cx, state));
|
||||
match at {
|
||||
Some(rect) => shell.show_at(ui, rect, state),
|
||||
None => shell.show(ui, state),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use craft_ui::contract::Bind;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::shell::ScreenMode;
|
||||
use craft_ui::testing::canvas_story::StoryDocument;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, ToolStory, story, tool_story};
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, ToolStory, room_height, stage_fitting, story, tool_story};
|
||||
use egui::Ui;
|
||||
|
||||
craft_ui::words! {
|
||||
@@ -39,15 +39,19 @@ const ZOOM: f64 = 50.0;
|
||||
#[story(EditorMock<'static>, covers = [])]
|
||||
fn editor_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let state = data.value("mock", MockState::default());
|
||||
EditorMock::new("Editor", state).show(ui).into()
|
||||
let height = room_height(ui);
|
||||
let room = stage_fitting(ui, |_| height);
|
||||
EditorMock::new("Editor", state).show_at(ui, room).into()
|
||||
}
|
||||
|
||||
/// The window in full screen: the body only. F cycles the screen modes, Tab and the edges reveal the bars.
|
||||
#[story(EditorMock<'static>, covers = [], drive = Drive::Never)]
|
||||
fn editor_window_full_screen(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut mode = *data.value("mode", ScreenMode::FullScreen);
|
||||
let height = room_height(ui);
|
||||
let room = stage_fitting(ui, |_| height);
|
||||
let state = data.value("mock", MockState::default());
|
||||
let shown = EditorMock::new("Editor", state).screen_mode(Bind::bound(&mut mode)).show(ui);
|
||||
let shown = EditorMock::new("Editor", state).screen_mode(Bind::bound(&mut mode)).show_at(ui, room);
|
||||
*data.value("mode", ScreenMode::FullScreen) = mode;
|
||||
shown.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user