mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 01:44:25 +00:00
EditorMock: a screen-mode binding and the Full screen story
The old gallery showed the mock app in the Canvas shell in Standard, Full screen, Revealed and Right to left. Full screen is an EditorMock story over the shell's screen_mode binding; right to left is the gallery's own direction switch.
This commit is contained in:
@@ -21,7 +21,7 @@ use craft_ui::patterns::form_dialogs::{
|
||||
use craft_ui::rails::ToolRail;
|
||||
use craft_ui::runtime::commands::{CommandRef, Commands as _, EditCommands};
|
||||
use craft_ui::runtime::env::{Label, WindowKey};
|
||||
use craft_ui::shell::{AppShell, AppShellOutput, CaptionFamily, Captions, Frame, ShellDialogsCx as _, Title, TitleBar};
|
||||
use craft_ui::shell::{AppShell, AppShellOutput, CaptionFamily, Captions, Frame, ScreenMode, ShellDialogsCx as _, Title, TitleBar};
|
||||
use craft_window::Layout;
|
||||
use egui::Ui;
|
||||
|
||||
@@ -41,24 +41,33 @@ const BLUR_MEMORY: SaveKey = SaveKey::new("craft_ui_gallery.gaussianBlur");
|
||||
/// - Menus: every row is an app command with its chord; the body takes them.
|
||||
/// - Dialogs: Layer, Delete, Layer and Filter, Gaussian Blur open on the window's dialog host; Image, Image Size
|
||||
/// shows its dialog over the document's size.
|
||||
/// - Screen modes: the shell's own commands (F) and the reveal keys act inside the window's region.
|
||||
/// - Screen modes: the shell's own commands (F) and the reveal keys act inside the window's region; the
|
||||
/// [`screen_mode`](Self::screen_mode) binding holds the mode.
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct EditorMock<'a> {
|
||||
label: Label,
|
||||
state: &'a mut MockState,
|
||||
screen_mode: Bind<'a, ScreenMode>,
|
||||
}
|
||||
|
||||
impl<'a> EditorMock<'a> {
|
||||
/// A mock editor named `label` over `state`.
|
||||
pub fn new(label: impl Into<Label>, state: &'a mut MockState) -> Self {
|
||||
EditorMock { label: label.into(), state }
|
||||
EditorMock { label: label.into(), state, screen_mode: Bind::kept() }
|
||||
}
|
||||
|
||||
/// The window's screen mode; without a binding the window keeps it, starting at `Standard`.
|
||||
pub fn screen_mode(mut self, mode: Bind<'a, ScreenMode>) -> Self {
|
||||
self.screen_mode = mode;
|
||||
self
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
let EditorMock { label, state } = self;
|
||||
let EditorMock { label, state, screen_mode } = self;
|
||||
let window = WindowKey::new(format!("mock-{:x}-{}", ui.scope_id().value(), label.as_str()));
|
||||
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))
|
||||
|
||||
@@ -5,7 +5,9 @@ use super::panels::show_layers;
|
||||
use super::tools::MoveTool;
|
||||
use super::{EditorMock, MockState};
|
||||
use craft_behavior::geometry::Directions;
|
||||
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 egui::Ui;
|
||||
@@ -40,6 +42,16 @@ fn editor_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
EditorMock::new("Editor", state).show(ui).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 state = data.value("mock", MockState::default());
|
||||
let shown = EditorMock::new("Editor", state).screen_mode(Bind::bound(&mut mode)).show(ui);
|
||||
*data.value("mode", ScreenMode::FullScreen) = mode;
|
||||
shown.into()
|
||||
}
|
||||
|
||||
#[story(MoveTool<'static>, covers = [], drive = Drive::Never)]
|
||||
fn move_tool(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let directions = *data.choice("directions", Directions::Four, &[("Layers", Directions::Four), ("Pixels", Directions::Eight)]);
|
||||
|
||||
Reference in New Issue
Block a user