Pull out fluent builder helpers into re-usable trait

This commit is contained in:
Mikayla 2024-01-18 15:31:31 -08:00
parent a5084510a1
commit 903176d8ff
No known key found for this signature in database
8 changed files with 77 additions and 82 deletions

View file

@ -42,6 +42,8 @@ impl FocusableView for ContextMenu {
impl EventEmitter<DismissEvent> for ContextMenu {}
impl FluentBuilder for ContextMenu {}
impl ContextMenu {
pub fn build(
cx: &mut WindowContext,
@ -68,34 +70,6 @@ impl ContextMenu {
})
}
pub fn if_some<T>(self, condition: Option<T>, f: impl FnOnce(Self, T) -> Self) -> Self {
if let Some(t) = condition {
f(self, t)
} else {
self
}
}
pub fn then_if_else(self, condition: bool, then: impl FnOnce(Self) -> Self, otherwise: impl FnOnce(Self) -> Self) -> Self {
if condition {
then(self)
} else {
otherwise(self)
}
}
pub fn then_if(self, condition: bool, f: impl FnOnce(Self) -> Self) -> Self {
if condition {
f(self)
} else {
self
}
}
pub fn map(self, f: impl FnOnce(Self) -> Self) -> Self {
f(self)
}
pub fn context(mut self, focus: FocusHandle) -> Self {
self.action_context = Some(focus);
self

View file

@ -1,9 +1,9 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{
overlay, point, px, rems, AnchorCorner, AnyElement, Bounds, DismissEvent, DispatchPhase,
Element, ElementId, InteractiveBounds, IntoElement, LayoutId, ManagedView, MouseDownEvent,
ParentElement, Pixels, Point, View, VisualContext, WindowContext,
overlay, point, prelude::FluentBuilder, px, rems, AnchorCorner, AnyElement, Bounds,
DismissEvent, DispatchPhase, Element, ElementId, InteractiveBounds, IntoElement, LayoutId,
ManagedView, MouseDownEvent, ParentElement, Pixels, Point, View, VisualContext, WindowContext,
};
use crate::{Clickable, Selectable};