From 07f1febe9fbf4514ee07f1d92eac8ccb584de307 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Fri, 10 May 2024 12:15:33 -0700 Subject: [PATCH] Removed ChosenMenuItem Also updated the changelog --- CHANGELOG.md | 5 +++++ src/widgets/menu.rs | 23 +++++------------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 459e108..0a55b40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Button::on_click` now takes a `Option` structure. When this value is provided, information about the mouse click that caused the event is provided. +- `OverlayBuilder` has hade many of its functions moved into a new trait, + `Overlayable`. This is to ensure common API surfaces across all overlayable + widgets including the new `Menu` widget. ### Fixed @@ -246,6 +249,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `ModifiersState` types. This trait adds helpers for dealing with platform-specific meanings for keyboard modifiers. - `OverlayLayer::dismiss_all()` dismisses all overlays immediately. +- `Menu` is a new widget type that can be shown in an `OverlayLayer` to create + contextual menus or other popup menus. [plotters]: https://github.com/plotters-rs/plotters diff --git a/src/widgets/menu.rs b/src/widgets/menu.rs index 4114498..0a2340c 100644 --- a/src/widgets/menu.rs +++ b/src/widgets/menu.rs @@ -12,7 +12,7 @@ use kludgine::DrawableExt; use parking_lot::Mutex; use self::sealed::{SharedMenuState, SubmenuFactory}; -use super::button::{ButtonClick, ButtonColors, ButtonKind, VisualState}; +use super::button::{ButtonColors, ButtonKind, VisualState}; use super::container::{self, ContainerShadow}; use super::disclose::IndicatorSize; use super::layers::{OverlayBuilder, OverlayHandle, OverlayLayer, Overlayable}; @@ -74,7 +74,7 @@ where #[must_use] pub fn on_selected(self, selected: F) -> Menu where - F: FnMut(ChosenMenuItem) + Send + 'static, + F: FnMut(T) + Send + 'static, { Menu { items: self.items, @@ -234,16 +234,6 @@ impl OpenMenuHandle { } } -/// The selected item of a shown [`Menu`]. -#[derive(Debug, Clone, Copy, Eq, PartialEq)] -pub struct ChosenMenuItem { - /// The item that was chosen. - pub item: T, - /// Information about the button click that caused this item to be chosen, - /// if present. - pub click: Option, -} - /// A builder of a [`MenuItem`]. pub struct MenuItemBuilder { value: T, @@ -458,9 +448,9 @@ where } } -/// A handler for a [`ChosenMenuItem`]. +/// A handler for a selected [`MenuItem`]. #[derive(Debug, Clone)] -pub struct MenuHandler(Arc>>>); +pub struct MenuHandler(Arc>>); #[derive(Debug)] struct OpenMenu { @@ -769,10 +759,7 @@ where let ItemKind::Item(item) = &self.items[index].item else { return; }; - self.on_click.0.lock().invoke(ChosenMenuItem { - item: item.value.clone(), - click: None, - }); + self.on_click.0.lock().invoke(item.value.clone()); let mut shared = self.shared.lock(); for handle in shared.open_menus.drain() { handle.dismiss();