Removed ChosenMenuItem

Also updated the changelog
This commit is contained in:
Jonathan Johnson 2024-05-10 12:15:33 -07:00
parent c5f1832b3e
commit 07f1febe9f
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
2 changed files with 10 additions and 18 deletions

View file

@ -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<ButtonClick>` 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

View file

@ -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<F>(self, selected: F) -> Menu<T>
where
F: FnMut(ChosenMenuItem<T>) + Send + 'static,
F: FnMut(T) + Send + 'static,
{
Menu {
items: self.items,
@ -234,16 +234,6 @@ impl OpenMenuHandle {
}
}
/// The selected item of a shown [`Menu<T>`].
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct ChosenMenuItem<T> {
/// 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<ButtonClick>,
}
/// A builder of a [`MenuItem<T>`].
pub struct MenuItemBuilder<T, Contents = ()> {
value: T,
@ -458,9 +448,9 @@ where
}
}
/// A handler for a [`ChosenMenuItem<T>`].
/// A handler for a selected [`MenuItem<T>`].
#[derive(Debug, Clone)]
pub struct MenuHandler<T>(Arc<Mutex<Callback<ChosenMenuItem<T>>>>);
pub struct MenuHandler<T>(Arc<Mutex<Callback<T>>>);
#[derive(Debug)]
struct OpenMenu<T> {
@ -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();