Skip to content

Commit

Permalink
chore: Update GPUI with AnchorCorner renamed to Corner.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Dec 18, 2024
1 parent 4f7ca4b commit 35fc639
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 86 deletions.
23 changes: 11 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/story/src/list_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl ListDelegate for CompanyListDelegate {
.cloned()
.collect();

Task::Ready(Some(()))
Task::ready(())
}

fn confirm(&mut self, ix: Option<usize>, cx: &mut ViewContext<List<Self>>) {
Expand Down
8 changes: 4 additions & 4 deletions crates/story/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl StoryWorkspace {
let theme_color_picker = cx.new_view(|cx| {
let mut picker = ColorPicker::new("theme-color-picker", cx)
.xsmall()
.anchor(AnchorCorner::TopRight)
.anchor(Corner::TopRight)
.label("Theme Color");
picker.set_value(cx.theme().primary, cx);
picker
Expand Down Expand Up @@ -461,7 +461,7 @@ impl Render for StoryWorkspace {
Box::new(AddPanel(DockPlacement::Bottom)),
)
})
.anchor(AnchorCorner::TopRight),
.anchor(Corner::TopRight),
)
.child(
Button::new("theme-mode")
Expand Down Expand Up @@ -567,7 +567,7 @@ impl Render for LocaleSelector {
Box::new(SelectLocale("zh-CN".into())),
)
})
.anchor(AnchorCorner::TopRight),
.anchor(Corner::TopRight),
)
}
}
Expand Down Expand Up @@ -630,7 +630,7 @@ impl Render for FontSizeSelector {
Box::new(SelectScrollbarShow(ScrollbarShow::Hover)),
)
})
.anchor(AnchorCorner::TopRight),
.anchor(Corner::TopRight),
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/story/src/popup_story.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gpui::{
actions, div, impl_actions, px, AnchorCorner, AppContext, DismissEvent, Element, EventEmitter,
actions, div, impl_actions, px, AppContext, Corner, DismissEvent, Element, EventEmitter,
FocusHandle, FocusableView, InteractiveElement, IntoElement, KeyBinding, MouseButton,
ParentElement as _, Render, SharedString, Styled as _, View, ViewContext, VisualContext,
WindowContext,
Expand Down Expand Up @@ -234,7 +234,7 @@ impl Render for PopupStory {
)
.child(
Popover::new("info-top-right")
.anchor(AnchorCorner::TopRight)
.anchor(Corner::TopRight)
.trigger(Button::new("info-top-right").label("Top Right"))
.content(|cx| {
cx.new_view(|cx| {
Expand Down Expand Up @@ -302,7 +302,7 @@ impl Render for PopupStory {
.child(
Button::new("popup-menu-11112")
.label("Scrollable Menu")
.popup_menu_with_anchor(AnchorCorner::TopRight, move |this, _| {
.popup_menu_with_anchor(Corner::TopRight, move |this, _| {
let mut this = this.scrollable();
for i in 0..100 {
this = this.menu(
Expand All @@ -323,13 +323,13 @@ impl Render for PopupStory {
.justify_between()
.child(
Popover::new("info-bottom-left")
.anchor(AnchorCorner::BottomLeft)
.anchor(Corner::BottomLeft)
.trigger(Button::new("pop").label("Popup with Form").w(px(300.)))
.content(move |_| form.clone()),
)
.child(
Popover::new("info-bottom-right")
.anchor(AnchorCorner::BottomRight)
.anchor(Corner::BottomRight)
.mouse_button(MouseButton::Right)
.trigger(Button::new("pop").label("Mouse Right Click").w(px(300.)))
.content(|cx| {
Expand Down
38 changes: 16 additions & 22 deletions crates/ui/src/color_picker.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use gpui::{
anchored, canvas, deferred, div, prelude::FluentBuilder as _, px, relative, AnchorCorner,
AppContext, Bounds, ElementId, EventEmitter, FocusHandle, FocusableView, Hsla,
InteractiveElement as _, IntoElement, KeyBinding, MouseButton, ParentElement, Pixels, Point,
Render, SharedString, StatefulInteractiveElement as _, Styled, View, ViewContext,
VisualContext,
anchored, canvas, deferred, div, prelude::FluentBuilder as _, px, relative, AppContext, Bounds,
Corner, ElementId, EventEmitter, FocusHandle, FocusableView, Hsla, InteractiveElement as _,
IntoElement, KeyBinding, MouseButton, ParentElement, Pixels, Point, Render, SharedString,
StatefulInteractiveElement as _, Styled, View, ViewContext, VisualContext,
};

use crate::{
Expand Down Expand Up @@ -63,7 +62,7 @@ pub struct ColorPicker {
hovered_color: Option<Hsla>,
label: Option<SharedString>,
size: Size,
anchor: AnchorCorner,
anchor: Corner,
color_input: View<TextInput>,

open: bool,
Expand Down Expand Up @@ -112,7 +111,7 @@ impl ColorPicker {
hovered_color: None,
size: Size::Medium,
label: None,
anchor: AnchorCorner::TopLeft,
anchor: Corner::TopLeft,
color_input,
open: false,
bounds: Bounds::default(),
Expand Down Expand Up @@ -149,8 +148,8 @@ impl ColorPicker {

/// Set the anchor corner of the color picker.
///
/// Default is `AnchorCorner::TopLeft`.
pub fn anchor(mut self, anchor: AnchorCorner) -> Self {
/// Default is `Corner::TopLeft`.
pub fn anchor(mut self, anchor: Corner) -> Self {
self.anchor = anchor;
self
}
Expand Down Expand Up @@ -262,13 +261,12 @@ impl ColorPicker {
}

fn resolved_corner(&self, bounds: Bounds<Pixels>) -> Point<Pixels> {
match self.anchor {
AnchorCorner::TopLeft => AnchorCorner::BottomLeft,
AnchorCorner::TopRight => AnchorCorner::BottomRight,
AnchorCorner::BottomLeft => AnchorCorner::TopLeft,
AnchorCorner::BottomRight => AnchorCorner::TopRight,
}
.corner(bounds)
bounds.corner(match self.anchor {
Corner::TopLeft => Corner::BottomLeft,
Corner::TopRight => Corner::BottomRight,
Corner::BottomLeft => Corner::TopLeft,
Corner::BottomRight => Corner::TopRight,
})
}
}

Expand Down Expand Up @@ -347,12 +345,8 @@ impl Render for ColorPicker {
div()
.occlude()
.map(|this| match self.anchor {
AnchorCorner::TopLeft | AnchorCorner::TopRight => {
this.mt_1p5()
}
AnchorCorner::BottomLeft | AnchorCorner::BottomRight => {
this.mb_1p5()
}
Corner::TopLeft | Corner::TopRight => this.mt_1p5(),
Corner::BottomLeft | Corner::BottomRight => this.mb_1p5(),
})
.w_72()
.overflow_hidden()
Expand Down
6 changes: 3 additions & 3 deletions crates/ui/src/context_menu.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{cell::RefCell, rc::Rc};

use gpui::{
anchored, deferred, div, prelude::FluentBuilder, px, relative, AnchorCorner, AnyElement,
anchored, deferred, div, prelude::FluentBuilder, px, relative, AnyElement, Corner,
DismissEvent, DispatchPhase, Element, ElementId, Focusable, GlobalElementId,
InteractiveElement, IntoElement, MouseButton, MouseDownEvent, ParentElement, Pixels, Point,
Position, Stateful, Style, View, ViewContext, WindowContext,
Expand All @@ -25,15 +25,15 @@ impl<E> ContextMenuExt for Focusable<E> where E: ParentElement {}
pub struct ContextMenu {
id: ElementId,
menu: Option<Box<dyn Fn(PopupMenu, &mut ViewContext<PopupMenu>) -> PopupMenu + 'static>>,
anchor: AnchorCorner,
anchor: Corner,
}

impl ContextMenu {
pub fn new(id: impl Into<ElementId>) -> Self {
Self {
id: id.into(),
menu: None,
anchor: AnchorCorner::TopLeft,
anchor: Corner::TopLeft,
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/ui/src/dock/tab_panel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use gpui::{
div, prelude::FluentBuilder, px, rems, AnchorCorner, AppContext, DefiniteLength, DismissEvent,
div, prelude::FluentBuilder, px, rems, AppContext, Corner, DefiniteLength, DismissEvent,
DragMoveEvent, Empty, Entity, EventEmitter, FocusHandle, FocusableView,
InteractiveElement as _, IntoElement, ParentElement, Pixels, Render, ScrollHandle,
SharedString, StatefulInteractiveElement, Styled, View, ViewContext, VisualContext as _,
Expand Down Expand Up @@ -375,7 +375,7 @@ impl TabPanel {
.menu(t!("Dock.Close"), Box::new(ClosePanel))
})
})
.anchor(AnchorCorner::TopRight),
.anchor(Corner::TopRight),
)
}

Expand Down
12 changes: 5 additions & 7 deletions crates/ui/src/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub trait DropdownDelegate: Sized {
}

fn perform_search(&mut self, _query: &str, _cx: &mut ViewContext<Dropdown<Self>>) -> Task<()> {
Task::Ready(Some(()))
Task::ready(())
}
}

Expand Down Expand Up @@ -179,11 +179,9 @@ where
}

fn perform_search(&mut self, query: &str, cx: &mut ViewContext<List<Self>>) -> Task<()> {
self.dropdown
.upgrade()
.map_or(Task::Ready(None), |dropdown| {
dropdown.update(cx, |_, cx| self.delegate.perform_search(query, cx))
})
self.dropdown.upgrade().map_or(Task::ready(()), |dropdown| {
dropdown.update(cx, |_, cx| self.delegate.perform_search(query, cx))
})
}

fn set_selected_index(&mut self, ix: Option<usize>, _: &mut ViewContext<List<Self>>) {
Expand Down Expand Up @@ -284,7 +282,7 @@ impl<T: DropdownItem + Clone> DropdownDelegate for SearchableVec<T> {
.cloned()
.collect();

Task::Ready(Some(()))
Task::ready(())
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/ui/src/list/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait ListDelegate: Sized + 'static {
/// When Query Input change, this method will be called.
/// You can perform search here.
fn perform_search(&mut self, query: &str, cx: &mut ViewContext<List<Self>>) -> Task<()> {
Task::Ready(Some(()))
Task::ready(())
}

/// Return the number of items in the list.
Expand Down Expand Up @@ -126,7 +126,7 @@ where
enable_scrollbar: true,
loading: false,
size: Size::default(),
_search_task: Task::Ready(None),
_search_task: Task::ready(()),
}
}

Expand Down
Loading

0 comments on commit 35fc639

Please sign in to comment.