diff --git a/crates/ui-widgets/src/popover/anchored.rs b/crates/ui-widgets/src/popover/anchored.rs index cde6373fd..250d2c09b 100644 --- a/crates/ui-widgets/src/popover/anchored.rs +++ b/crates/ui-widgets/src/popover/anchored.rs @@ -2,7 +2,8 @@ use crate::contract::overlay::{Anchor, Dismiss, OverlayFit}; use crate::contract::{ - Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, Overlay, POPUP_PAD, Props as _, Role, SaveKey, Trigger, + Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, Overlay, POPUP_PAD, Pad, Props as _, Role, SaveKey, + Trigger, }; use crate::runtime::env::Label; use crate::runtime::focus::{FocusPolicy, Initial}; @@ -90,7 +91,9 @@ impl<'a> Popover<'a> { /// is the one surface. #[must_use] pub fn content_surface(self) -> Self { - todo!("cv.F41") + self.props.surface = None; + self.props.pad = Pad::None; + self } /// Changes the layer the popover shows in, for the settings without a setter of their own: the size a diff --git a/crates/ui-widgets/src/popover/anchored/stories.rs b/crates/ui-widgets/src/popover/anchored/stories.rs index 8375968d4..28ee0266c 100644 --- a/crates/ui-widgets/src/popover/anchored/stories.rs +++ b/crates/ui-widgets/src/popover/anchored/stories.rs @@ -1,10 +1,13 @@ //! Stories of `Popover`. use super::Popover; +use crate::bars::{Bar, BarItem, BarItems, BarKind}; use crate::buttons::Button; use crate::contract::{Bind, Show as _, ShowContainer as _}; use crate::layout_components::Stack; +use crate::runtime::commands::EditCommands; use crate::runtime::focus::Initial; +use crate::style::SurfaceKind; use crate::testing::{Drive, StoryData, StoryOutput, story}; use egui::Ui; @@ -20,6 +23,23 @@ fn body(ui: &mut Ui) -> bool { .unwrap_or(false) } +/// What the bar story popover holds: a floating bar, the popover's one surface; whether an item was clicked. +fn floating_bar(ui: &mut Ui) -> bool { + Bar::new("Tools", BarKind::Tool) + .surface(SurfaceKind::Floating) + .show(ui, |ui, _| { + let items = BarItems::new(vec![ + BarItem::new(EditCommands::Undo), + BarItem::new(EditCommands::Redo), + BarItem::new(EditCommands::Cut).section(1), + ]) + .show(ui); + crate::contract::clicked(&items) + }) + .inner + .unwrap_or(false) +} + /// Shows `story` in a row as wide as the room: the opener sits at the start edge and the popup hangs from it, so the /// popup's place mirrors with the direction. fn in_row(ui: &mut Ui, mut story: impl FnMut(&mut Ui) -> StoryOutput) -> StoryOutput { @@ -30,7 +50,7 @@ fn in_row(ui: &mut Ui, mut story: impl FnMut(&mut Ui) -> StoryOutput) -> StoryOu } } -fn popover_with(ui: &mut Ui, data: &mut StoryData, build: impl Fn(Popover<'_>) -> Popover<'_>) -> StoryOutput { +fn popover_with(ui: &mut Ui, data: &mut StoryData, build: impl Fn(Popover<'_>) -> Popover<'_>, body: fn(&mut Ui) -> bool) -> StoryOutput { in_row(ui, |ui| { let opener = Button::new("Grid").show(ui); let mut clicked = false; @@ -47,10 +67,15 @@ fn popover_with(ui: &mut Ui, data: &mut StoryData, build: impl Fn(Popover<'_>) - fn popover(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let resizable = *data.value("resizable", false); let enter = *data.value("enter", false); - popover_with(ui, data, |popover| popover.resizable(resizable).close_on_enter(enter)) + popover_with(ui, data, |popover| popover.resizable(resizable).close_on_enter(enter), body) } #[story(Popover<'static>, covers = [], drive = Drive::Never)] fn popover_resizable_closing_on_enter(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - popover_with(ui, data, |popover| popover.resizable(true).close_on_enter(true).initial_focus(Initial::First)) + popover_with(ui, data, |popover| popover.resizable(true).close_on_enter(true).initial_focus(Initial::First), body) +} + +#[story(Popover<'static>, covers = [], drive = Drive::Never)] +fn popover_bar_on_the_canvas(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + popover_with(ui, data, |popover| popover.content_surface(), floating_bar) }