mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-28 17:30:12 +01:00
# Conflicts: # crates/dialogs/src/lib.rs # crates/dialogs/src/ui/mod.rs # crates/draw/src/ui/gradient/mod.rs # crates/draw/src/ui/gradient/swatch.rs # crates/menu/src/shortcuts/view.rs # crates/menu/tests/it/main.rs # crates/menu/tests/it/shortcuts/mod.rs # crates/pages/tests/it/main.rs # crates/print/src/lib.rs # crates/review/tests/it/main.rs # crates/story-render/src/main.rs # crates/table/tests/it/main.rs # crates/text/tests/it/main.rs # crates/ui-canvas/src/canvas/navigate/mod.rs # crates/ui-canvas/tests/it/canvas/mod.rs # crates/ui-contract/tests/it/access/mod.rs # crates/ui-contract/tests/it/fonts/mod.rs # crates/ui-contract/tests/it/runtime/mod.rs # crates/ui-gallery/src/foundations/mod.rs # crates/ui-patterns/src/patterns/preferences/mod.rs # crates/ui-patterns/tests/it/docking/mod.rs # crates/ui-patterns/tests/it/form_dialogs/mod.rs # crates/ui-patterns/tests/it/panels/palette.rs # crates/ui-patterns/tests/it/preferences/mod.rs # crates/ui-shell/src/shell/mod.rs # crates/ui-shell/tests/it/shell/mod.rs # crates/ui-widgets/src/tabs/strip.rs # crates/ui-widgets/tests/it/bars/mod.rs # crates/ui-widgets/tests/it/contract/mod.rs # crates/ui-widgets/tests/it/layout/mod.rs # crates/ui-widgets/tests/it/main.rs # crates/ui-widgets/tests/it/menu/mod.rs # crates/ui-widgets/tests/it/pickers/mod.rs # crates/ui-widgets/tests/it/text/mod.rs
57 lines
2.2 KiB
Rust
57 lines
2.2 KiB
Rust
//! `ScreenModeButton`: the status bar's screen mode button, a flyout of the shell's screen modes.
|
|
|
|
use super::screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeSet};
|
|
use super::words::ShellWords;
|
|
use crate::contract::{NoValue, Outcome, Props as _, Show as _};
|
|
use crate::rails::{FlyoutButton, RailTool};
|
|
use crate::runtime::env::Env;
|
|
use egui::{Response, Ui};
|
|
|
|
#[cfg(feature = "suite")]
|
|
pub(crate) mod stories;
|
|
|
|
/// A flyout button over the screen modes of the shell's set, with `mode` marked: a click, Enter or Space cycles; a
|
|
/// hold, a drag away or a right click lists the modes without cycling. The face is the Cycle command's icon and tooltip; disabled
|
|
/// while Cycle is disabled.
|
|
#[must_use = "show the button with `show`"]
|
|
#[derive(crate::contract::Pattern)]
|
|
pub struct ScreenModeButton {
|
|
mode: ScreenMode,
|
|
}
|
|
|
|
/// What a [`ScreenModeButton`] reports.
|
|
#[derive(Debug)]
|
|
#[non_exhaustive]
|
|
pub struct ScreenModeButtonOutput {
|
|
/// The button's response.
|
|
pub response: Response,
|
|
}
|
|
|
|
impl Outcome for ScreenModeButtonOutput {
|
|
type Value = NoValue;
|
|
|
|
fn response(&self) -> &Response {
|
|
&self.response
|
|
}
|
|
}
|
|
|
|
impl ScreenModeButton {
|
|
/// A button showing `mode` as the current one.
|
|
pub fn new(mode: ScreenMode) -> Self {
|
|
ScreenModeButton { mode }
|
|
}
|
|
|
|
/// Shows the button in `ui`. The rows are the radio commands of the modes of the shell's [`ScreenModeSet`], which
|
|
/// the shell publishes to its regions (`Panels` outside a shell), so their marks and states come from the shell; the
|
|
/// shell applies whichever command runs.
|
|
pub fn show(self, ui: &mut Ui) -> ScreenModeButtonOutput {
|
|
let env = Env::of(ui);
|
|
let modes = env.get::<ScreenModeSet>().modes();
|
|
let tools: Vec<RailTool<ScreenMode>> = modes.iter().map(|mode| RailTool::new(*mode, ScreenModeCommands::of(*mode))).collect();
|
|
// The shell's own word names the button when the Cycle command does not resolve.
|
|
let name = env.words::<ShellWords>().screen_mode.clone();
|
|
let out = FlyoutButton::new(&tools, &self.mode).label(name).hold_selects(false).click(ScreenModeCommands::Cycle).show(ui);
|
|
ScreenModeButtonOutput { response: out.response }
|
|
}
|
|
}
|