chore: adapt latest changes from GPUI and nostr-sdk
This commit is contained in:
@@ -268,7 +268,7 @@ impl Dock {
|
||||
) -> impl IntoElement {
|
||||
let axis = self.placement.axis();
|
||||
let neg_offset = -HANDLE_PADDING;
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
|
||||
div()
|
||||
.id("resize-handle")
|
||||
@@ -336,7 +336,7 @@ impl Dock {
|
||||
|
||||
// Get the size of the left dock if it's open and not the current dock
|
||||
if let Some(left_dock) = &dock_area.left_dock {
|
||||
if left_dock.entity_id() != cx.model().entity_id() {
|
||||
if left_dock.entity_id() != cx.entity().entity_id() {
|
||||
let left_dock_read = left_dock.read(cx);
|
||||
if left_dock_read.is_open() {
|
||||
left_dock_size = left_dock_read.size;
|
||||
@@ -346,7 +346,7 @@ impl Dock {
|
||||
|
||||
// Get the size of the right dock if it's open and not the current dock
|
||||
if let Some(right_dock) = &dock_area.right_dock {
|
||||
if right_dock.entity_id() != cx.model().entity_id() {
|
||||
if right_dock.entity_id() != cx.entity().entity_id() {
|
||||
let right_dock_read = right_dock.read(cx);
|
||||
if right_dock_read.is_open() {
|
||||
right_dock_size = right_dock_read.size;
|
||||
@@ -409,7 +409,7 @@ impl Render for Dock {
|
||||
})
|
||||
.child(self.render_resize_handle(window, cx))
|
||||
.child(DockElement {
|
||||
view: cx.model().clone(),
|
||||
view: cx.entity().clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ impl DockArea {
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.subscribe_item(&panel, window, cx);
|
||||
let weak_self = cx.model().downgrade();
|
||||
let weak_self = cx.entity().downgrade();
|
||||
self.left_dock = Some(cx.new(|cx| {
|
||||
let mut dock = Dock::left(weak_self.clone(), window, cx);
|
||||
if let Some(size) = size {
|
||||
@@ -377,7 +377,7 @@ impl DockArea {
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.subscribe_item(&panel, window, cx);
|
||||
let weak_self = cx.model().downgrade();
|
||||
let weak_self = cx.entity().downgrade();
|
||||
self.bottom_dock = Some(cx.new(|cx| {
|
||||
let mut dock = Dock::bottom(weak_self.clone(), window, cx);
|
||||
if let Some(size) = size {
|
||||
@@ -399,7 +399,7 @@ impl DockArea {
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.subscribe_item(&panel, window, cx);
|
||||
let weak_self = cx.model().downgrade();
|
||||
let weak_self = cx.entity().downgrade();
|
||||
self.right_dock = Some(cx.new(|cx| {
|
||||
let mut dock = Dock::right(weak_self.clone(), window, cx);
|
||||
if let Some(size) = size {
|
||||
@@ -534,7 +534,7 @@ impl DockArea {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let weak_self = cx.model().downgrade();
|
||||
let weak_self = cx.entity().downgrade();
|
||||
match placement {
|
||||
DockPlacement::Left => {
|
||||
if let Some(dock) = self.left_dock.as_ref() {
|
||||
@@ -577,7 +577,7 @@ impl DockArea {
|
||||
}
|
||||
DockPlacement::Center => {
|
||||
self.items
|
||||
.add_panel(panel, &cx.model().downgrade(), window, cx);
|
||||
.add_panel(panel, &cx.entity().downgrade(), window, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -717,7 +717,7 @@ impl EventEmitter<DockEvent> for DockArea {}
|
||||
|
||||
impl Render for DockArea {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
|
||||
div()
|
||||
.id("dock-area")
|
||||
|
||||
@@ -191,7 +191,7 @@ impl StackPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
|
||||
window.defer(cx, {
|
||||
let panel = panel.clone();
|
||||
@@ -289,7 +289,7 @@ impl StackPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
if let Some(parent) = self.parent.as_ref() {
|
||||
_ = parent.update(cx, |parent, cx| {
|
||||
parent.remove_panel(Arc::new(view.clone()), window, cx);
|
||||
|
||||
@@ -284,7 +284,7 @@ impl TabPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
let tab_view = cx.model().clone();
|
||||
let tab_view = cx.entity().clone();
|
||||
|
||||
if let Some(stack_panel) = self.stack_panel.as_ref() {
|
||||
_ = stack_panel.update(cx, |view, cx| {
|
||||
@@ -353,7 +353,7 @@ impl TabPanel {
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
let is_zoomed = self.is_zoomed && state.zoomable;
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
let build_popup_menu = move |this, cx: &App| view.read(cx).popup_menu(this, cx);
|
||||
|
||||
// TODO: Do not show MenuButton if there is no menu items
|
||||
@@ -413,7 +413,7 @@ impl TabPanel {
|
||||
return None;
|
||||
}
|
||||
|
||||
let view_entity_id = cx.model().entity_id();
|
||||
let view_entity_id = cx.entity().entity_id();
|
||||
let toggle_button_panels = dock_area.toggle_button_panels;
|
||||
|
||||
// Check if current TabPanel's entity_id matches the one stored in DockArea for this placement
|
||||
@@ -486,7 +486,7 @@ impl TabPanel {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
|
||||
let Some(dock_area) = self.dock_area.upgrade() else {
|
||||
return div().into_any_element();
|
||||
@@ -800,7 +800,7 @@ impl TabPanel {
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let panel = drag.panel.clone();
|
||||
let is_same_tab = drag.tab_panel == cx.model();
|
||||
let is_same_tab = drag.tab_panel == cx.entity();
|
||||
|
||||
// If target is same tab, and it is only one panel, do nothing.
|
||||
if is_same_tab && ix.is_none() {
|
||||
@@ -863,7 +863,7 @@ impl TabPanel {
|
||||
|
||||
let ix = stack_panel
|
||||
.read(cx)
|
||||
.index_of_panel(Arc::new(cx.model().clone()))
|
||||
.index_of_panel(Arc::new(cx.entity().clone()))
|
||||
.unwrap_or_default();
|
||||
|
||||
if parent_axis.is_vertical() && placement.is_vertical() {
|
||||
@@ -892,10 +892,10 @@ impl TabPanel {
|
||||
});
|
||||
} else {
|
||||
// 1. Create new StackPanel with new axis
|
||||
// 2. Move cx.model() from parent StackPanel to the new StackPanel
|
||||
// 2. Move cx.entity() from parent StackPanel to the new StackPanel
|
||||
// 3. Add the new TabPanel to the new StackPanel at the correct index
|
||||
// 4. Add new StackPanel to the parent StackPanel at the correct index
|
||||
let tab_panel = cx.model().clone();
|
||||
let tab_panel = cx.entity().clone();
|
||||
|
||||
// Try to use the old stack panel, not just create a new one, to avoid too many nested stack panels
|
||||
let new_stack_panel = if stack_panel.read(cx).panels_len() <= 1 {
|
||||
|
||||
@@ -328,7 +328,7 @@ where
|
||||
let focus_handle = cx.focus_handle();
|
||||
let delegate = DropdownListDelegate {
|
||||
delegate,
|
||||
dropdown: cx.model().downgrade(),
|
||||
dropdown: cx.entity().downgrade(),
|
||||
selected_index,
|
||||
};
|
||||
|
||||
@@ -589,7 +589,7 @@ where
|
||||
{
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let is_focused = self.focus_handle.is_focused(window);
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
let bounds = self.bounds;
|
||||
let allow_open = !(self.open || self.disabled);
|
||||
let outline_visible = self.open || is_focused && !self.disabled;
|
||||
|
||||
@@ -271,12 +271,14 @@ impl TextElement {
|
||||
|
||||
// print_points_as_svg_path(&line_corners, &points);
|
||||
|
||||
let first_p = *points.first().unwrap();
|
||||
let mut path = gpui::Path::new(bounds.origin + first_p);
|
||||
let first_p = *points.get(0).unwrap();
|
||||
let mut builder = gpui::PathBuilder::fill();
|
||||
builder.move_to(bounds.origin + first_p);
|
||||
for p in points.iter().skip(1) {
|
||||
path.line_to(bounds.origin + *p);
|
||||
builder.line_to(bounds.origin + *p);
|
||||
}
|
||||
Some(path)
|
||||
|
||||
builder.build().ok()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,7 +425,7 @@ impl Element for TextElement {
|
||||
|
||||
let lines = window
|
||||
.text_system()
|
||||
.shape_text(display_text, font_size, &runs, wrap_width)
|
||||
.shape_text(display_text, font_size, &runs, wrap_width, None)
|
||||
.unwrap();
|
||||
|
||||
// `position_for_index` for example
|
||||
|
||||
@@ -1492,14 +1492,14 @@ impl Render for TextInput {
|
||||
.id("TextElement")
|
||||
.flex_grow()
|
||||
.overflow_x_hidden()
|
||||
.child(TextElement::new(cx.model().clone())),
|
||||
.child(TextElement::new(cx.entity().clone())),
|
||||
)
|
||||
.when(self.loading, |this| {
|
||||
this.child(Indicator::new().color(cx.theme().base.step(cx, ColorScaleStep::ELEVEN)))
|
||||
})
|
||||
.children(suffix)
|
||||
.when(self.is_multi_line(), |this| {
|
||||
let entity_id = cx.model().entity_id();
|
||||
let entity_id = cx.entity().entity_id();
|
||||
if self.last_layout.is_some() {
|
||||
let scroll_size = self.scroll_size;
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ where
|
||||
}
|
||||
|
||||
Some(Scrollbar::uniform_scroll(
|
||||
cx.model().entity_id(),
|
||||
cx.entity().entity_id(),
|
||||
self.scrollbar_state.clone(),
|
||||
self.vertical_scroll_handle.clone(),
|
||||
))
|
||||
@@ -431,7 +431,7 @@ where
|
||||
D: ListDelegate,
|
||||
{
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
let vertical_scroll_handle = self.vertical_scroll_handle.clone();
|
||||
let items_count = self.delegate.items_count(cx);
|
||||
let sizing_behavior = if self.max_height.is_some() {
|
||||
|
||||
@@ -39,7 +39,7 @@ pub struct Modal {
|
||||
}
|
||||
|
||||
impl Modal {
|
||||
pub fn new(window: &mut Window, cx: &mut App) -> Self {
|
||||
pub fn new(_window: &mut Window, cx: &mut App) -> Self {
|
||||
let base = v_flex()
|
||||
.bg(cx.theme().background)
|
||||
.border_1()
|
||||
|
||||
@@ -328,7 +328,8 @@ impl PopupMenu {
|
||||
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
||||
) -> Self {
|
||||
let submenu = PopupMenu::build(window, cx, f);
|
||||
let parent_menu = cx.model().downgrade();
|
||||
let parent_menu = cx.entity().downgrade();
|
||||
|
||||
submenu.update(cx, |view, _| {
|
||||
view.parent_menu = Some(parent_menu);
|
||||
});
|
||||
@@ -506,7 +507,7 @@ impl Focusable for PopupMenu {
|
||||
|
||||
impl Render for PopupMenu {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
let has_icon = self.menu_items.iter().any(|item| item.has_icon());
|
||||
let items_count = self.menu_items.len();
|
||||
let max_width = self.max_width;
|
||||
|
||||
@@ -108,7 +108,7 @@ impl ResizablePanelGroup {
|
||||
) {
|
||||
let mut panel = panel;
|
||||
panel.axis = self.axis;
|
||||
panel.group = Some(cx.model().downgrade());
|
||||
panel.group = Some(cx.entity().downgrade());
|
||||
self.sizes.push(panel.initial_size.unwrap_or_default());
|
||||
self.panels.push(cx.new(|_| panel));
|
||||
}
|
||||
@@ -122,7 +122,7 @@ impl ResizablePanelGroup {
|
||||
) {
|
||||
let mut panel = panel;
|
||||
panel.axis = self.axis;
|
||||
panel.group = Some(cx.model().downgrade());
|
||||
panel.group = Some(cx.entity().downgrade());
|
||||
|
||||
self.sizes
|
||||
.insert(ix, panel.initial_size.unwrap_or_default());
|
||||
@@ -148,7 +148,7 @@ impl ResizablePanelGroup {
|
||||
panel.initial_size = old_panel_initial_size;
|
||||
panel.size_ratio = old_panel_size_ratio;
|
||||
panel.axis = self.axis;
|
||||
panel.group = Some(cx.model().downgrade());
|
||||
panel.group = Some(cx.entity().downgrade());
|
||||
self.sizes[ix] = panel.initial_size.unwrap_or_default();
|
||||
self.panels[ix] = cx.new(|_| panel);
|
||||
cx.notify()
|
||||
@@ -172,7 +172,7 @@ impl ResizablePanelGroup {
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
resize_handle(("resizable-handle", ix), self.axis).on_drag(
|
||||
DragPanel((cx.entity_id(), ix, self.axis)),
|
||||
move |drag_panel, _, _window, cx| {
|
||||
@@ -273,7 +273,7 @@ impl EventEmitter<ResizablePanelEvent> for ResizablePanelGroup {}
|
||||
|
||||
impl Render for ResizablePanelGroup {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
let container = if self.axis.is_horizontal() {
|
||||
h_flex()
|
||||
} else {
|
||||
@@ -301,7 +301,7 @@ impl Render for ResizablePanelGroup {
|
||||
.size_full()
|
||||
})
|
||||
.child(ResizePanelGroupElement {
|
||||
view: cx.model().clone(),
|
||||
view: cx.entity().clone(),
|
||||
axis: self.axis,
|
||||
})
|
||||
}
|
||||
@@ -370,7 +370,7 @@ impl ResizablePanel {
|
||||
self.bounds = bounds;
|
||||
self.size = Some(new_size);
|
||||
|
||||
let panel_view = cx.model().clone();
|
||||
let panel_view = cx.entity().clone();
|
||||
if let Some(group) = self.group.as_ref() {
|
||||
_ = group.update(cx, |view, _| {
|
||||
if let Some(ix) = view
|
||||
@@ -390,7 +390,7 @@ impl FluentBuilder for ResizablePanel {}
|
||||
|
||||
impl Render for ResizablePanel {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.model().clone();
|
||||
let view = cx.entity().clone();
|
||||
let total_size = self
|
||||
.group
|
||||
.as_ref()
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::{
|
||||
window_border,
|
||||
};
|
||||
use gpui::{
|
||||
div, AnyView, App, AppContext, Context, DefiniteLength, Entity, FocusHandle,
|
||||
InteractiveElement, IntoElement, ParentElement as _, Render, Styled, Window,
|
||||
div, AnyView, App, AppContext, Context, Entity, FocusHandle, InteractiveElement, IntoElement,
|
||||
ParentElement as _, Render, Styled, Window,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
@@ -195,14 +195,14 @@ impl Root {
|
||||
where
|
||||
F: FnOnce(&mut Self, &mut Window, &mut Context<Self>) + 'static,
|
||||
{
|
||||
if let Some(Some(root)) = window.root_model::<Root>() {
|
||||
if let Some(Some(root)) = window.root::<Root>() {
|
||||
root.update(cx, |root, cx| f(root, window, cx));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read<'a>(window: &'a mut Window, cx: &'a mut App) -> &'a Self {
|
||||
window
|
||||
.root_model::<Root>()
|
||||
.root::<Root>()
|
||||
.expect("The window root view should be of type `ui::Root`.")
|
||||
.unwrap()
|
||||
.read(cx)
|
||||
@@ -219,15 +219,14 @@ impl Root {
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Option<impl IntoElement> {
|
||||
let root = window.root_model::<Root>()??;
|
||||
let root = window.root::<Root>()??;
|
||||
|
||||
Some(div().child(root.read(cx).notification.clone()))
|
||||
}
|
||||
|
||||
/// Render the Modal layer.
|
||||
pub fn render_modal_layer(window: &mut Window, cx: &mut App) -> Option<impl IntoElement> {
|
||||
let root = window.root_model::<Root>()??;
|
||||
|
||||
let root = window.root::<Root>()??;
|
||||
let active_modals = root.read(cx).active_modals.clone();
|
||||
let mut has_overlay = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user