mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-23 18:32:17 +00:00
Relax bounds on View type parameter
This will allow elements to work with non-views.
This commit is contained in:
parent
268f4b1939
commit
e2d88ab007
47 changed files with 2271 additions and 286 deletions
|
@ -1218,7 +1218,7 @@ impl CollabTitlebarItem {
|
|||
style
|
||||
}
|
||||
|
||||
fn render_face<V: View>(
|
||||
fn render_face<V: 'static>(
|
||||
avatar: Arc<ImageData>,
|
||||
avatar_style: AvatarStyle,
|
||||
background_color: Color,
|
||||
|
|
|
@ -2,14 +2,14 @@ use client::User;
|
|||
use gpui::{
|
||||
elements::*,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
AnyElement, Element, View, ViewContext,
|
||||
AnyElement, Element, ViewContext,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
enum Dismiss {}
|
||||
enum Button {}
|
||||
|
||||
pub fn render_user_notification<F, V>(
|
||||
pub fn render_user_notification<F, V: 'static>(
|
||||
user: Arc<User>,
|
||||
title: &'static str,
|
||||
body: Option<&'static str>,
|
||||
|
@ -19,7 +19,6 @@ pub fn render_user_notification<F, V>(
|
|||
) -> AnyElement<V>
|
||||
where
|
||||
F: 'static + Fn(&mut V, &mut ViewContext<V>),
|
||||
V: View,
|
||||
{
|
||||
let theme = theme::current(cx).clone();
|
||||
let theme = &theme.contact_notification;
|
||||
|
|
|
@ -538,7 +538,7 @@ impl ProjectDiagnosticsEditor {
|
|||
}
|
||||
|
||||
impl Item for ProjectDiagnosticsEditor {
|
||||
fn tab_content<T: View>(
|
||||
fn tab_content<T: 'static>(
|
||||
&self,
|
||||
_detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
|
@ -735,7 +735,7 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn render_summary<T: View>(
|
||||
pub(crate) fn render_summary<T: 'static>(
|
||||
summary: &DiagnosticSummary,
|
||||
text_style: &TextStyle,
|
||||
theme: &theme::ProjectDiagnostics,
|
||||
|
|
|
@ -11,7 +11,7 @@ use gpui::{
|
|||
|
||||
const DEAD_ZONE: f32 = 4.;
|
||||
|
||||
enum State<V: View> {
|
||||
enum State<V> {
|
||||
Down {
|
||||
region_offset: Vector2F,
|
||||
region: RectF,
|
||||
|
@ -31,7 +31,7 @@ enum State<V: View> {
|
|||
Canceled,
|
||||
}
|
||||
|
||||
impl<V: View> Clone for State<V> {
|
||||
impl<V> Clone for State<V> {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
&State::Down {
|
||||
|
@ -68,12 +68,12 @@ impl<V: View> Clone for State<V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct DragAndDrop<V: View> {
|
||||
pub struct DragAndDrop<V> {
|
||||
containers: HashSet<WeakViewHandle<V>>,
|
||||
currently_dragged: Option<State<V>>,
|
||||
}
|
||||
|
||||
impl<V: View> Default for DragAndDrop<V> {
|
||||
impl<V> Default for DragAndDrop<V> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
containers: Default::default(),
|
||||
|
@ -82,7 +82,7 @@ impl<V: View> Default for DragAndDrop<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> DragAndDrop<V> {
|
||||
impl<V: 'static> DragAndDrop<V> {
|
||||
pub fn register_container(&mut self, handle: WeakViewHandle<V>) {
|
||||
self.containers.insert(handle);
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ impl<V: View> DragAndDrop<V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait Draggable<V: View> {
|
||||
pub trait Draggable<V> {
|
||||
fn as_draggable<D: View, P: Any>(
|
||||
self,
|
||||
payload: P,
|
||||
|
@ -301,7 +301,7 @@ pub trait Draggable<V: View> {
|
|||
Self: Sized;
|
||||
}
|
||||
|
||||
impl<Tag, V: View> Draggable<V> for MouseEventHandler<Tag, V> {
|
||||
impl<Tag, V: 'static> Draggable<V> for MouseEventHandler<Tag, V> {
|
||||
fn as_draggable<D: View, P: Any>(
|
||||
self,
|
||||
payload: P,
|
||||
|
|
|
@ -561,7 +561,7 @@ impl Item for Editor {
|
|||
}
|
||||
}
|
||||
|
||||
fn tab_content<T: View>(
|
||||
fn tab_content<T: 'static>(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
|
|
|
@ -268,7 +268,7 @@ impl Item for FeedbackEditor {
|
|||
Some("Send Feedback".into())
|
||||
}
|
||||
|
||||
fn tab_content<T: View>(
|
||||
fn tab_content<T: 'static>(
|
||||
&self,
|
||||
_: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
|
|
63
crates/gpui/playground/src/playground.rs
Normal file
63
crates/gpui/playground/src/playground.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use gpui::{
|
||||
platform::{TitlebarOptions, WindowOptions},
|
||||
AnyElement, Element, Entity, View,
|
||||
};
|
||||
use log::LevelFilter;
|
||||
use simplelog::SimpleLogger;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
// dymod! {
|
||||
// #[path = "../ui/src/playground_ui.rs"]
|
||||
// pub mod ui {
|
||||
// // fn workspace<V>(theme: &ThemeColors) -> impl Element<V>;
|
||||
// }
|
||||
// }
|
||||
|
||||
fn main() {
|
||||
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||
|
||||
gpui::App::new(()).unwrap().run(|cx| {
|
||||
cx.platform().activate(true);
|
||||
cx.add_window(
|
||||
WindowOptions {
|
||||
titlebar: Some(TitlebarOptions {
|
||||
appears_transparent: true,
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
|_| Playground::default(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct Playground(playground_ui::Playground<Self>);
|
||||
|
||||
impl Deref for Playground {
|
||||
type Target = playground_ui::Playground<Self>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Playground {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for Playground {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
impl View for Playground {
|
||||
fn ui_name() -> &'static str {
|
||||
"PlaygroundView"
|
||||
}
|
||||
|
||||
fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> AnyElement<Playground> {
|
||||
self.0.clone().into_any()
|
||||
}
|
||||
}
|
165
crates/gpui/playground/ui/src/editor_layout_demo.rs
Normal file
165
crates/gpui/playground/ui/src/editor_layout_demo.rs
Normal file
|
@ -0,0 +1,165 @@
|
|||
use gpui::{AnyElement, Element, LayoutContext, View, ViewContext};
|
||||
|
||||
#[derive(Element, Clone, Default)]
|
||||
pub struct Playground<V>(PhantomData<V>);
|
||||
|
||||
// example layout design here: https://www.figma.com/file/5QLTmxjO0xQpDD3CD4hR6T/Untitled?type=design&node-id=0%3A1&mode=design&t=SoJieVVIvDDDKagv-1
|
||||
|
||||
impl<V> Playground<V> {
|
||||
pub fn render(&mut self, _: &mut V, _: &mut gpui::ViewContext<V>) -> impl Element<V> {
|
||||
col() // fullscreen container with header and main in it
|
||||
.width(flex(1.))
|
||||
.height(flex(1.))
|
||||
.fill(colors(gray.900))
|
||||
.children([
|
||||
row() // header container
|
||||
.fill(colors(gray.900))
|
||||
.width(flex(1.))
|
||||
.children([
|
||||
row() // tab bar
|
||||
.width(flex(1.))
|
||||
.gap(spacing(2))
|
||||
.padding(spacing(3))
|
||||
.overflow_x(scroll())
|
||||
.chidren([
|
||||
row() // tab
|
||||
.padding_x(spacing(3))
|
||||
.padding_y(spacing(2))
|
||||
.corner_radius(6.)
|
||||
.gap(spacing(3))
|
||||
.align(center())
|
||||
.fill(colors(gray.800))
|
||||
.children([text("Tab title 1"), svg("icon_name")]),
|
||||
row() // tab
|
||||
.padding_x(spacing(3))
|
||||
.padding_y(spacing(2))
|
||||
.corner_radius(6.)
|
||||
.gap(spacing(3))
|
||||
.align(center())
|
||||
.fill(colors(gray.800))
|
||||
.children([text("Tab title 2"), svg("icon_name")]),
|
||||
row() // tab
|
||||
.padding_x(spacing(3))
|
||||
.padding_y(spacing(2))
|
||||
.corner_radius(6.)
|
||||
.gap(spacing(3))
|
||||
.align(center())
|
||||
.fill(colors(gray.800))
|
||||
.children([text("Tab title 3"), svg("icon_name")]),
|
||||
]),
|
||||
row() // tab bar actions
|
||||
.border_left(colors(gray.700))
|
||||
.gap(spacing(2))
|
||||
.padding(spacing(3))
|
||||
.chidren([
|
||||
row()
|
||||
.width(spacing(8))
|
||||
.height(spacing(8))
|
||||
.corner_radius(6.)
|
||||
.justify(center())
|
||||
.align(center())
|
||||
.fill(colors(gray.800))
|
||||
.child(svg(icon_name)),
|
||||
row()
|
||||
.width(spacing(8))
|
||||
.height(spacing(8))
|
||||
.corner_radius(6.)
|
||||
.justify(center())
|
||||
.align(center())
|
||||
.fill(colors(gray.800))
|
||||
.child(svg(icon_name)),
|
||||
row()
|
||||
.width(spacing(8))
|
||||
.height(spacing(8))
|
||||
.corner_radius(6.)
|
||||
.justify(center())
|
||||
.align(center())
|
||||
.fill(colors(gray.800))
|
||||
.child(svg(icon_name)),
|
||||
]),
|
||||
]),
|
||||
row() // main container
|
||||
.width(flex(1.))
|
||||
.height(flex(1.))
|
||||
.children([
|
||||
col() // left sidebar
|
||||
.fill(colors(gray.800))
|
||||
.border_right(colors(gray.700))
|
||||
.height(flex(1.))
|
||||
.width(260.)
|
||||
.children([
|
||||
col() // containter to hold list items and notification alert box
|
||||
.justify(between())
|
||||
.padding_x(spacing(6))
|
||||
.padding_bottom(3)
|
||||
.padding_top(spacing(6))
|
||||
.children([
|
||||
col().gap(spacing(3)).children([ // sidebar list
|
||||
text("Item"),
|
||||
text("Item"),
|
||||
text("Item"),
|
||||
text("Item"),
|
||||
text("Item"),
|
||||
text("Item"),
|
||||
text("Item"),
|
||||
text("Item"),
|
||||
]),
|
||||
col().align(center()).gap(spacing(1)).children([ // notification alert box
|
||||
text("Title text").size("lg"),
|
||||
text("Description text goes here")
|
||||
.text_color(colors(rose.200)),
|
||||
]),
|
||||
]),
|
||||
row()
|
||||
.padding_x(spacing(3))
|
||||
.padding_y(spacing(2))
|
||||
.border_top(1., colors(gray.700))
|
||||
.align(center())
|
||||
.gap(spacing(2))
|
||||
.fill(colors(gray.900))
|
||||
.children([
|
||||
row() // avatar container
|
||||
.width(spacing(8))
|
||||
.height(spacing(8))
|
||||
.corner_radius(spacing(8))
|
||||
.justify(center())
|
||||
.align(center())
|
||||
.child(image(image_url)),
|
||||
text("FirstName Lastname"), // user name
|
||||
]),
|
||||
]),
|
||||
col() // primary content container
|
||||
.align(center())
|
||||
.justify(center())
|
||||
.child(
|
||||
col().justify(center()).gap(spacing(8)).children([ // detail container wrapper for center positioning
|
||||
col() // blue rectangle
|
||||
.width(rem(30.))
|
||||
.height(rem(20.))
|
||||
.corner_radius(16.)
|
||||
.fill(colors(blue.200)),
|
||||
col().gap(spacing(1)).children([ // center content text items
|
||||
text("This is a title").size("lg"),
|
||||
text("This is a description").text_color(colors(gray.500)),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
col(), // right sidebar
|
||||
]),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
// row(
|
||||
// padding(),
|
||||
// width(),
|
||||
// fill(),
|
||||
// )
|
||||
|
||||
// .width(flex(1.))
|
||||
// .height(flex(1.))
|
||||
// .justify(end())
|
||||
// .align(start()) // default
|
||||
// .fill(green)
|
||||
// .child(other_tab_bar())
|
||||
// .child(profile_menu())
|
1565
crates/gpui/playground/ui/src/frame.rs
Normal file
1565
crates/gpui/playground/ui/src/frame.rs
Normal file
File diff suppressed because it is too large
Load diff
200
crates/gpui/playground/ui/src/playground_ui.rs
Normal file
200
crates/gpui/playground/ui/src/playground_ui.rs
Normal file
|
@ -0,0 +1,200 @@
|
|||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
use frame::{length::auto, *};
|
||||
use gpui::{AnyElement, Element, LayoutContext, ViewContext};
|
||||
use std::{borrow::Cow, cell::RefCell, marker::PhantomData, rc::Rc};
|
||||
use themes::{rose_pine, ThemeColors};
|
||||
use tokens::{margin::m4, text::lg};
|
||||
|
||||
mod color;
|
||||
mod frame;
|
||||
mod themes;
|
||||
mod tokens;
|
||||
|
||||
#[derive(Element, Clone, Default)]
|
||||
pub struct Playground<V: 'static>(PhantomData<V>);
|
||||
|
||||
impl<V> Frame<V> {}
|
||||
|
||||
impl<V> Playground<V> {
|
||||
pub fn render(&mut self, _: &mut V, _: &mut gpui::ViewContext<V>) -> impl Element<V> {
|
||||
workspace(&rose_pine::dawn())
|
||||
}
|
||||
}
|
||||
|
||||
fn workspace<V: 'static>(theme: &ThemeColors) -> impl Element<V> {
|
||||
column()
|
||||
.size(auto())
|
||||
.fill(theme.base(0.1))
|
||||
.child(title_bar(theme))
|
||||
.child(stage(theme))
|
||||
.child(status_bar(theme))
|
||||
}
|
||||
|
||||
fn title_bar<V: 'static>(theme: &ThemeColors) -> impl Element<V> {
|
||||
row().fill(theme.surface(1.0))
|
||||
}
|
||||
|
||||
fn stage<V: 'static>(theme: &ThemeColors) -> impl Element<V> {
|
||||
row().fill(theme.surface(0.9))
|
||||
}
|
||||
|
||||
fn status_bar<V: 'static>(theme: &ThemeColors) -> impl Element<V> {
|
||||
row().fill(theme.surface(0.1))
|
||||
}
|
||||
|
||||
pub trait DialogDelegate<V>: 'static {}
|
||||
|
||||
impl<V> DialogDelegate<V> for () {}
|
||||
|
||||
#[derive(Element)]
|
||||
pub struct Dialog<V: 'static, D: DialogDelegate<V>> {
|
||||
title: Cow<'static, str>,
|
||||
description: Cow<'static, str>,
|
||||
delegate: Option<Rc<RefCell<D>>>,
|
||||
buttons: Vec<Box<dyn FnOnce() -> AnyElement<V>>>,
|
||||
view_type: PhantomData<V>,
|
||||
}
|
||||
|
||||
pub fn dialog<V>(
|
||||
title: impl Into<Cow<'static, str>>,
|
||||
description: impl Into<Cow<'static, str>>,
|
||||
) -> Dialog<V, ()> {
|
||||
Dialog {
|
||||
title: title.into(),
|
||||
description: description.into(),
|
||||
delegate: None,
|
||||
buttons: Vec::new(),
|
||||
view_type: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
impl<V, D: DialogDelegate<V>> Dialog<V, D> {
|
||||
pub fn delegate(mut self, delegate: D) -> Dialog<V, D> {
|
||||
let old_delegate = self.delegate.replace(Rc::new(RefCell::new(delegate)));
|
||||
debug_assert!(old_delegate.is_none(), "delegate already set");
|
||||
self
|
||||
}
|
||||
|
||||
pub fn button<L, Data, H>(mut self, label: L, data: Data, handler: H) -> Self
|
||||
where
|
||||
L: 'static + Into<Cow<'static, str>>,
|
||||
Data: 'static + Clone,
|
||||
H: ClickHandler<V, Data>,
|
||||
{
|
||||
let label = label.into();
|
||||
self.buttons.push(Box::new(move || {
|
||||
button(label).data(data).click(handler).into_any()
|
||||
}));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Element)]
|
||||
struct Button<V: 'static, D: 'static, H: ClickHandler<V, D>> {
|
||||
label: Cow<'static, str>,
|
||||
click_handler: Option<H>,
|
||||
data: Option<D>,
|
||||
view_type: PhantomData<V>,
|
||||
}
|
||||
|
||||
pub trait ClickHandler<V, D>: 'static {
|
||||
fn handle(&self, view: &mut V, data: &D, cx: &mut ViewContext<V>);
|
||||
}
|
||||
|
||||
impl<V, M, F: 'static + Fn(&mut V, &M, &mut ViewContext<V>)> ClickHandler<V, M> for F {
|
||||
fn handle(&self, view: &mut V, data: &M, cx: &mut ViewContext<V>) {
|
||||
self(view, data, cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V, D> ClickHandler<V, D> for () {
|
||||
fn handle(&self, view: &mut V, data: &D, cx: &mut ViewContext<V>) {}
|
||||
}
|
||||
|
||||
fn button<V>(label: impl Into<Cow<'static, str>>) -> Button<V, (), ()> {
|
||||
Button {
|
||||
label: label.into(),
|
||||
click_handler: None,
|
||||
data: None,
|
||||
view_type: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
impl<V, D, F> Button<V, D, F>
|
||||
where
|
||||
F: ClickHandler<V, D>,
|
||||
{
|
||||
fn render(&mut self, _: &mut V, _: &mut LayoutContext<V>) -> AnyElement<V> {
|
||||
// TODO! Handle click etc
|
||||
row().child(text(self.label.clone())).into_any()
|
||||
}
|
||||
}
|
||||
|
||||
// impl<V, D, F> Button<V, D, F>
|
||||
// where
|
||||
// V,
|
||||
// F: ClickHandler<V, D>,
|
||||
// {
|
||||
// fn render(&mut self, _: &mut V, _: &mut LayoutContext<V>) -> impl Element<V> {
|
||||
// // TODO! Handle click etc
|
||||
// row()
|
||||
// .fill(theme.colors.primary(5))
|
||||
// .child(text(self.label.clone()).text_color(theme.colors.on_primary()))
|
||||
// }
|
||||
// }
|
||||
|
||||
// struct Tab<V> {
|
||||
// active: bool,
|
||||
// }
|
||||
|
||||
// impl<V> Tab<V>
|
||||
// where
|
||||
// V,
|
||||
// {
|
||||
// fn tab(&mut self, _: &mut V, _: &mut LayoutContext<V>) -> impl Element<V> {
|
||||
// let theme = todo!();
|
||||
// // TODO! Handle click etc
|
||||
// row()
|
||||
// .fill(theme.colors.neutral(6))
|
||||
// .child(text(self.label.clone()).text_color(theme.colors.on_neutral()))
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<V> Button<V, (), ()> {
|
||||
fn data<D>(self, data: D) -> Button<V, D, ()>
|
||||
where
|
||||
D: 'static,
|
||||
{
|
||||
Button {
|
||||
label: self.label,
|
||||
click_handler: self.click_handler,
|
||||
data: Some(data),
|
||||
view_type: self.view_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V, D> Button<V, D, ()> {
|
||||
fn click<H>(self, handler: H) -> Button<V, D, H>
|
||||
where
|
||||
H: 'static + ClickHandler<V, D>,
|
||||
{
|
||||
Button {
|
||||
label: self.label,
|
||||
click_handler: Some(handler),
|
||||
data: self.data,
|
||||
view_type: self.view_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V, D: DialogDelegate<V>> Dialog<V, D> {
|
||||
pub fn render(&mut self, _: &mut V, _: &mut gpui::ViewContext<V>) -> AnyElement<V> {
|
||||
column()
|
||||
.child(text(self.title.clone()).text_size(lg()))
|
||||
.child(text(self.description.clone()).margins((m4(), auto())))
|
||||
.child(row().children(self.buttons.drain(..).map(|button| (button)())))
|
||||
.into_any()
|
||||
}
|
||||
}
|
|
@ -7,42 +7,6 @@ pub mod test_app_context;
|
|||
pub(crate) mod window;
|
||||
mod window_input_handler;
|
||||
|
||||
use std::{
|
||||
any::{type_name, Any, TypeId},
|
||||
cell::RefCell,
|
||||
fmt::{self, Debug},
|
||||
hash::{Hash, Hasher},
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
ops::{Deref, DerefMut, Range},
|
||||
path::{Path, PathBuf},
|
||||
pin::Pin,
|
||||
rc::{self, Rc},
|
||||
sync::{Arc, Weak},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use derive_more::Deref;
|
||||
use parking_lot::Mutex;
|
||||
use postage::oneshot;
|
||||
use smallvec::SmallVec;
|
||||
use smol::prelude::*;
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub use action::*;
|
||||
use callback_collection::CallbackCollection;
|
||||
use collections::{hash_map::Entry, BTreeMap, HashMap, HashSet, VecDeque};
|
||||
pub use menu::*;
|
||||
use platform::Event;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
use ref_counts::LeakDetector;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub use test_app_context::{ContextHandle, TestAppContext};
|
||||
use window_input_handler::WindowInputHandler;
|
||||
|
||||
use crate::{
|
||||
elements::{AnyElement, AnyRootElement, RootElement},
|
||||
executor::{self, Task},
|
||||
|
@ -57,8 +21,39 @@ use crate::{
|
|||
window::{Window, WindowContext},
|
||||
AssetCache, AssetSource, ClipboardItem, FontCache, MouseRegionId,
|
||||
};
|
||||
|
||||
use self::ref_counts::RefCounts;
|
||||
pub use action::*;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use callback_collection::CallbackCollection;
|
||||
use collections::{hash_map::Entry, BTreeMap, HashMap, HashSet, VecDeque};
|
||||
use derive_more::Deref;
|
||||
pub use menu::*;
|
||||
use parking_lot::Mutex;
|
||||
use platform::Event;
|
||||
use postage::oneshot;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
use ref_counts::LeakDetector;
|
||||
use ref_counts::RefCounts;
|
||||
use smallvec::SmallVec;
|
||||
use smol::prelude::*;
|
||||
use std::{
|
||||
any::{type_name, Any, TypeId},
|
||||
cell::RefCell,
|
||||
fmt::{self, Debug},
|
||||
hash::{Hash, Hasher},
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
ops::{Deref, DerefMut, Range},
|
||||
path::{Path, PathBuf},
|
||||
pin::Pin,
|
||||
rc::{self, Rc},
|
||||
sync::{Arc, Weak},
|
||||
time::Duration,
|
||||
};
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub use test_app_context::{ContextHandle, TestAppContext};
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
use window_input_handler::WindowInputHandler;
|
||||
|
||||
pub trait Entity: 'static {
|
||||
type Event;
|
||||
|
@ -632,7 +627,7 @@ impl AppContext {
|
|||
pub fn add_action<A, V, F, R>(&mut self, handler: F)
|
||||
where
|
||||
A: Action,
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: 'static + FnMut(&mut V, &A, &mut ViewContext<V>) -> R,
|
||||
{
|
||||
self.add_action_internal(handler, false)
|
||||
|
@ -641,7 +636,7 @@ impl AppContext {
|
|||
pub fn capture_action<A, V, F>(&mut self, handler: F)
|
||||
where
|
||||
A: Action,
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: 'static + FnMut(&mut V, &A, &mut ViewContext<V>),
|
||||
{
|
||||
self.add_action_internal(handler, true)
|
||||
|
@ -650,7 +645,7 @@ impl AppContext {
|
|||
fn add_action_internal<A, V, F, R>(&mut self, mut handler: F, capture: bool)
|
||||
where
|
||||
A: Action,
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: 'static + FnMut(&mut V, &A, &mut ViewContext<V>) -> R,
|
||||
{
|
||||
let handler = Box::new(
|
||||
|
@ -691,7 +686,7 @@ impl AppContext {
|
|||
pub fn add_async_action<A, V, F>(&mut self, mut handler: F)
|
||||
where
|
||||
A: Action,
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: 'static + FnMut(&mut V, &A, &mut ViewContext<V>) -> Option<Task<Result<()>>>,
|
||||
{
|
||||
self.add_action(move |view, action, cx| {
|
||||
|
@ -890,8 +885,8 @@ impl AppContext {
|
|||
|
||||
fn observe_focus<F, V>(&mut self, handle: &ViewHandle<V>, mut callback: F) -> Subscription
|
||||
where
|
||||
V: 'static,
|
||||
F: 'static + FnMut(ViewHandle<V>, bool, &mut WindowContext) -> bool,
|
||||
V: View,
|
||||
{
|
||||
let subscription_id = post_inc(&mut self.next_subscription_id);
|
||||
let observed = handle.downgrade();
|
||||
|
@ -1374,15 +1369,15 @@ impl AppContext {
|
|||
self.windows.keys().copied()
|
||||
}
|
||||
|
||||
pub fn read_view<T: View>(&self, handle: &ViewHandle<T>) -> &T {
|
||||
pub fn read_view<V: 'static>(&self, handle: &ViewHandle<V>) -> &V {
|
||||
if let Some(view) = self.views.get(&(handle.window, handle.view_id)) {
|
||||
view.as_any().downcast_ref().expect("downcast is type safe")
|
||||
} else {
|
||||
panic!("circular view reference for type {}", type_name::<T>());
|
||||
panic!("circular view reference for type {}", type_name::<V>());
|
||||
}
|
||||
}
|
||||
|
||||
fn upgrade_view_handle<T: View>(&self, handle: &WeakViewHandle<T>) -> Option<ViewHandle<T>> {
|
||||
fn upgrade_view_handle<V: 'static>(&self, handle: &WeakViewHandle<V>) -> Option<ViewHandle<V>> {
|
||||
if self.ref_counts.lock().is_entity_alive(handle.view_id) {
|
||||
Some(ViewHandle::new(
|
||||
handle.window,
|
||||
|
@ -2535,10 +2530,7 @@ pub trait AnyView {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V> AnyView for V
|
||||
where
|
||||
V: View,
|
||||
{
|
||||
impl<V: View> AnyView for V {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
@ -2870,7 +2862,7 @@ pub struct ViewContext<'a, 'b, T: ?Sized> {
|
|||
view_type: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, T: View> Deref for ViewContext<'a, 'b, T> {
|
||||
impl<'a, 'b, V> Deref for ViewContext<'a, 'b, V> {
|
||||
type Target = WindowContext<'a>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -2878,13 +2870,13 @@ impl<'a, 'b, T: View> Deref for ViewContext<'a, 'b, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: View> DerefMut for ViewContext<'_, '_, T> {
|
||||
impl<'a, 'b, V> DerefMut for ViewContext<'a, 'b, V> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.window_context
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, V: View> ViewContext<'a, 'b, V> {
|
||||
impl<'a, 'b, V: 'static> ViewContext<'a, 'b, V> {
|
||||
pub(crate) fn mutable(window_context: &'b mut WindowContext<'a>, view_id: usize) -> Self {
|
||||
Self {
|
||||
window_context: Reference::Mutable(window_context),
|
||||
|
@ -2905,6 +2897,12 @@ impl<'a, 'b, V: View> ViewContext<'a, 'b, V> {
|
|||
&mut self.window_context
|
||||
}
|
||||
|
||||
pub fn notify(&mut self) {
|
||||
let window = self.window_handle;
|
||||
let view_id = self.view_id;
|
||||
self.window_context.notify_view(window, view_id);
|
||||
}
|
||||
|
||||
pub fn handle(&self) -> ViewHandle<V> {
|
||||
ViewHandle::new(
|
||||
self.window_handle,
|
||||
|
@ -3218,21 +3216,6 @@ impl<'a, 'b, V: View> ViewContext<'a, 'b, V> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn emit(&mut self, payload: V::Event) {
|
||||
self.window_context
|
||||
.pending_effects
|
||||
.push_back(Effect::Event {
|
||||
entity_id: self.view_id,
|
||||
payload: Box::new(payload),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn notify(&mut self) {
|
||||
let window = self.window_handle;
|
||||
let view_id = self.view_id;
|
||||
self.window_context.notify_view(window, view_id);
|
||||
}
|
||||
|
||||
pub fn defer(&mut self, callback: impl 'static + FnOnce(&mut V, &mut ViewContext<V>)) {
|
||||
let handle = self.handle();
|
||||
self.window_context
|
||||
|
@ -3321,6 +3304,17 @@ impl<'a, 'b, V: View> ViewContext<'a, 'b, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> ViewContext<'_, '_, V> {
|
||||
pub fn emit(&mut self, payload: V::Event) {
|
||||
self.window_context
|
||||
.pending_effects
|
||||
.push_back(Effect::Event {
|
||||
entity_id: self.view_id,
|
||||
payload: Box::new(payload),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> BorrowAppContext for ViewContext<'_, '_, V> {
|
||||
fn read_with<T, F: FnOnce(&AppContext) -> T>(&self, f: F) -> T {
|
||||
BorrowAppContext::read_with(&*self.window_context, f)
|
||||
|
@ -3361,7 +3355,7 @@ impl<V> BorrowWindowContext for ViewContext<'_, '_, V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct LayoutContext<'a, 'b, 'c, V: View> {
|
||||
pub struct LayoutContext<'a, 'b, 'c, V> {
|
||||
view_context: &'c mut ViewContext<'a, 'b, V>,
|
||||
new_parents: &'c mut HashMap<usize, usize>,
|
||||
views_to_notify_if_ancestors_change: &'c mut HashMap<usize, SmallVec<[usize; 2]>>,
|
||||
|
@ -3369,7 +3363,7 @@ pub struct LayoutContext<'a, 'b, 'c, V: View> {
|
|||
pub refreshing: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'c, V: View> LayoutContext<'a, 'b, 'c, V> {
|
||||
impl<'a, 'b, 'c, V> LayoutContext<'a, 'b, 'c, V> {
|
||||
pub fn new(
|
||||
view_context: &'c mut ViewContext<'a, 'b, V>,
|
||||
new_parents: &'c mut HashMap<usize, usize>,
|
||||
|
@ -3452,7 +3446,7 @@ impl<'a, 'b, 'c, V: View> LayoutContext<'a, 'b, 'c, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'c, V: View> Deref for LayoutContext<'a, 'b, 'c, V> {
|
||||
impl<'a, 'b, 'c, V> Deref for LayoutContext<'a, 'b, 'c, V> {
|
||||
type Target = ViewContext<'a, 'b, V>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -3460,13 +3454,13 @@ impl<'a, 'b, 'c, V: View> Deref for LayoutContext<'a, 'b, 'c, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> DerefMut for LayoutContext<'_, '_, '_, V> {
|
||||
impl<V> DerefMut for LayoutContext<'_, '_, '_, V> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.view_context
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> BorrowAppContext for LayoutContext<'_, '_, '_, V> {
|
||||
impl<V> BorrowAppContext for LayoutContext<'_, '_, '_, V> {
|
||||
fn read_with<T, F: FnOnce(&AppContext) -> T>(&self, f: F) -> T {
|
||||
BorrowAppContext::read_with(&*self.view_context, f)
|
||||
}
|
||||
|
@ -3476,7 +3470,7 @@ impl<V: View> BorrowAppContext for LayoutContext<'_, '_, '_, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> BorrowWindowContext for LayoutContext<'_, '_, '_, V> {
|
||||
impl<V> BorrowWindowContext for LayoutContext<'_, '_, '_, V> {
|
||||
type Result<T> = T;
|
||||
|
||||
fn read_window<T, F: FnOnce(&WindowContext) -> T>(&self, window: AnyWindowHandle, f: F) -> T {
|
||||
|
@ -3506,12 +3500,12 @@ impl<V: View> BorrowWindowContext for LayoutContext<'_, '_, '_, V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct PaintContext<'a, 'b, 'c, V: View> {
|
||||
pub struct PaintContext<'a, 'b, 'c, V> {
|
||||
view_context: &'c mut ViewContext<'a, 'b, V>,
|
||||
text_style_stack: Vec<Arc<TextStyle>>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'c, V: View> PaintContext<'a, 'b, 'c, V> {
|
||||
impl<'a, 'b, 'c, V> PaintContext<'a, 'b, 'c, V> {
|
||||
pub fn new(view_context: &'c mut ViewContext<'a, 'b, V>) -> Self {
|
||||
Self {
|
||||
view_context,
|
||||
|
@ -3538,7 +3532,7 @@ impl<'a, 'b, 'c, V: View> PaintContext<'a, 'b, 'c, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'c, V: View> Deref for PaintContext<'a, 'b, 'c, V> {
|
||||
impl<'a, 'b, 'c, V> Deref for PaintContext<'a, 'b, 'c, V> {
|
||||
type Target = ViewContext<'a, 'b, V>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -3546,13 +3540,13 @@ impl<'a, 'b, 'c, V: View> Deref for PaintContext<'a, 'b, 'c, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> DerefMut for PaintContext<'_, '_, '_, V> {
|
||||
impl<V> DerefMut for PaintContext<'_, '_, '_, V> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.view_context
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> BorrowAppContext for PaintContext<'_, '_, '_, V> {
|
||||
impl<V> BorrowAppContext for PaintContext<'_, '_, '_, V> {
|
||||
fn read_with<T, F: FnOnce(&AppContext) -> T>(&self, f: F) -> T {
|
||||
BorrowAppContext::read_with(&*self.view_context, f)
|
||||
}
|
||||
|
@ -3562,7 +3556,7 @@ impl<V: View> BorrowAppContext for PaintContext<'_, '_, '_, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> BorrowWindowContext for PaintContext<'_, '_, '_, V> {
|
||||
impl<V> BorrowWindowContext for PaintContext<'_, '_, '_, V> {
|
||||
type Result<T> = T;
|
||||
|
||||
fn read_window<T, F>(&self, window: AnyWindowHandle, f: F) -> Self::Result<T>
|
||||
|
@ -3594,12 +3588,12 @@ impl<V: View> BorrowWindowContext for PaintContext<'_, '_, '_, V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct EventContext<'a, 'b, 'c, V: View> {
|
||||
pub struct EventContext<'a, 'b, 'c, V> {
|
||||
view_context: &'c mut ViewContext<'a, 'b, V>,
|
||||
pub(crate) handled: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'c, V: View> EventContext<'a, 'b, 'c, V> {
|
||||
impl<'a, 'b, 'c, V> EventContext<'a, 'b, 'c, V> {
|
||||
pub(crate) fn new(view_context: &'c mut ViewContext<'a, 'b, V>) -> Self {
|
||||
EventContext {
|
||||
view_context,
|
||||
|
@ -3612,7 +3606,7 @@ impl<'a, 'b, 'c, V: View> EventContext<'a, 'b, 'c, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'c, V: View> Deref for EventContext<'a, 'b, 'c, V> {
|
||||
impl<'a, 'b, 'c, V> Deref for EventContext<'a, 'b, 'c, V> {
|
||||
type Target = ViewContext<'a, 'b, V>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -3620,13 +3614,13 @@ impl<'a, 'b, 'c, V: View> Deref for EventContext<'a, 'b, 'c, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> DerefMut for EventContext<'_, '_, '_, V> {
|
||||
impl<V> DerefMut for EventContext<'_, '_, '_, V> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.view_context
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> BorrowAppContext for EventContext<'_, '_, '_, V> {
|
||||
impl<V> BorrowAppContext for EventContext<'_, '_, '_, V> {
|
||||
fn read_with<T, F: FnOnce(&AppContext) -> T>(&self, f: F) -> T {
|
||||
BorrowAppContext::read_with(&*self.view_context, f)
|
||||
}
|
||||
|
@ -3636,7 +3630,7 @@ impl<V: View> BorrowAppContext for EventContext<'_, '_, '_, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> BorrowWindowContext for EventContext<'_, '_, '_, V> {
|
||||
impl<V> BorrowWindowContext for EventContext<'_, '_, '_, V> {
|
||||
type Result<T> = T;
|
||||
|
||||
fn read_window<T, F: FnOnce(&WindowContext) -> T>(&self, window: AnyWindowHandle, f: F) -> T {
|
||||
|
@ -3964,7 +3958,7 @@ impl<V> Clone for WindowHandle<V> {
|
|||
|
||||
impl<V> Copy for WindowHandle<V> {}
|
||||
|
||||
impl<V: View> WindowHandle<V> {
|
||||
impl<V: 'static> WindowHandle<V> {
|
||||
fn new(window_id: usize) -> Self {
|
||||
WindowHandle {
|
||||
any_handle: AnyWindowHandle::new(window_id, TypeId::of::<V>()),
|
||||
|
@ -4002,7 +3996,9 @@ impl<V: View> WindowHandle<V> {
|
|||
.update(cx, update)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> WindowHandle<V> {
|
||||
pub fn replace_root<C, F>(&self, cx: &mut C, build_root: F) -> C::Result<ViewHandle<V>>
|
||||
where
|
||||
C: BorrowWindowContext,
|
||||
|
@ -4082,7 +4078,7 @@ impl AnyWindowHandle {
|
|||
self.update(cx, |cx| cx.add_view(build_view))
|
||||
}
|
||||
|
||||
pub fn downcast<V: View>(self) -> Option<WindowHandle<V>> {
|
||||
pub fn downcast<V: 'static>(self) -> Option<WindowHandle<V>> {
|
||||
if self.root_view_type == TypeId::of::<V>() {
|
||||
Some(WindowHandle {
|
||||
any_handle: self,
|
||||
|
@ -4093,7 +4089,7 @@ impl AnyWindowHandle {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn root_is<V: View>(&self) -> bool {
|
||||
pub fn root_is<V: 'static>(&self) -> bool {
|
||||
self.root_view_type == TypeId::of::<V>()
|
||||
}
|
||||
|
||||
|
@ -4171,9 +4167,9 @@ impl AnyWindowHandle {
|
|||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct ViewHandle<T> {
|
||||
pub struct ViewHandle<V> {
|
||||
any_handle: AnyViewHandle,
|
||||
view_type: PhantomData<T>,
|
||||
view_type: PhantomData<V>,
|
||||
}
|
||||
|
||||
impl<T> Deref for ViewHandle<T> {
|
||||
|
@ -4184,15 +4180,15 @@ impl<T> Deref for ViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: View> ViewHandle<T> {
|
||||
impl<V: 'static> ViewHandle<V> {
|
||||
fn new(window: AnyWindowHandle, view_id: usize, ref_counts: &Arc<Mutex<RefCounts>>) -> Self {
|
||||
Self {
|
||||
any_handle: AnyViewHandle::new(window, view_id, TypeId::of::<T>(), ref_counts.clone()),
|
||||
any_handle: AnyViewHandle::new(window, view_id, TypeId::of::<V>(), ref_counts.clone()),
|
||||
view_type: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn downgrade(&self) -> WeakViewHandle<T> {
|
||||
pub fn downgrade(&self) -> WeakViewHandle<V> {
|
||||
WeakViewHandle::new(self.window, self.view_id)
|
||||
}
|
||||
|
||||
|
@ -4208,14 +4204,14 @@ impl<T: View> ViewHandle<T> {
|
|||
self.view_id
|
||||
}
|
||||
|
||||
pub fn read<'a>(&self, cx: &'a AppContext) -> &'a T {
|
||||
pub fn read<'a>(&self, cx: &'a AppContext) -> &'a V {
|
||||
cx.read_view(self)
|
||||
}
|
||||
|
||||
pub fn read_with<C, F, S>(&self, cx: &C, read: F) -> C::Result<S>
|
||||
where
|
||||
C: BorrowWindowContext,
|
||||
F: FnOnce(&T, &ViewContext<T>) -> S,
|
||||
F: FnOnce(&V, &ViewContext<V>) -> S,
|
||||
{
|
||||
cx.read_window(self.window, |cx| {
|
||||
let cx = ViewContext::immutable(cx, self.view_id);
|
||||
|
@ -4226,7 +4222,7 @@ impl<T: View> ViewHandle<T> {
|
|||
pub fn update<C, F, S>(&self, cx: &mut C, update: F) -> C::Result<S>
|
||||
where
|
||||
C: BorrowWindowContext,
|
||||
F: FnOnce(&mut T, &mut ViewContext<T>) -> S,
|
||||
F: FnOnce(&mut V, &mut ViewContext<V>) -> S,
|
||||
{
|
||||
let mut update = Some(update);
|
||||
|
||||
|
@ -4362,8 +4358,8 @@ impl AnyViewHandle {
|
|||
TypeId::of::<T>() == self.view_type
|
||||
}
|
||||
|
||||
pub fn downcast<T: View>(self) -> Option<ViewHandle<T>> {
|
||||
if self.is::<T>() {
|
||||
pub fn downcast<V: 'static>(self) -> Option<ViewHandle<V>> {
|
||||
if self.is::<V>() {
|
||||
Some(ViewHandle {
|
||||
any_handle: self,
|
||||
view_type: PhantomData,
|
||||
|
@ -4373,8 +4369,8 @@ impl AnyViewHandle {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn downcast_ref<T: View>(&self) -> Option<&ViewHandle<T>> {
|
||||
if self.is::<T>() {
|
||||
pub fn downcast_ref<V: 'static>(&self) -> Option<&ViewHandle<V>> {
|
||||
if self.is::<V>() {
|
||||
Some(unsafe { mem::transmute(self) })
|
||||
} else {
|
||||
None
|
||||
|
@ -4573,7 +4569,7 @@ impl<T> WeakHandle for WeakViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> WeakViewHandle<V> {
|
||||
impl<V: 'static> WeakViewHandle<V> {
|
||||
fn new(window: AnyWindowHandle, view_id: usize) -> Self {
|
||||
Self {
|
||||
any_handle: AnyWeakViewHandle {
|
||||
|
@ -4613,7 +4609,7 @@ impl<V: View> WeakViewHandle<V> {
|
|||
cx.read(|cx| {
|
||||
let handle = cx
|
||||
.upgrade_view_handle(self)
|
||||
.ok_or_else(|| anyhow!("view {} was dropped", V::ui_name()))?;
|
||||
.ok_or_else(|| anyhow!("view was dropped"))?;
|
||||
cx.read_window(self.window, |cx| handle.read_with(cx, read))
|
||||
.ok_or_else(|| anyhow!("window was removed"))
|
||||
})
|
||||
|
@ -4627,14 +4623,14 @@ impl<V: View> WeakViewHandle<V> {
|
|||
cx.update(|cx| {
|
||||
let handle = cx
|
||||
.upgrade_view_handle(self)
|
||||
.ok_or_else(|| anyhow!("view {} was dropped", V::ui_name()))?;
|
||||
.ok_or_else(|| anyhow!("view was dropped"))?;
|
||||
cx.update_window(self.window, |cx| handle.update(cx, update))
|
||||
.ok_or_else(|| anyhow!("window was removed"))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for WeakViewHandle<T> {
|
||||
impl<V> Deref for WeakViewHandle<V> {
|
||||
type Target = AnyWeakViewHandle;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -4642,7 +4638,7 @@ impl<T> Deref for WeakViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for WeakViewHandle<T> {
|
||||
impl<V> Clone for WeakViewHandle<V> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
any_handle: self.any_handle.clone(),
|
||||
|
|
|
@ -67,8 +67,8 @@ impl Window {
|
|||
build_view: F,
|
||||
) -> Self
|
||||
where
|
||||
F: FnOnce(&mut ViewContext<V>) -> V,
|
||||
V: View,
|
||||
F: FnOnce(&mut ViewContext<V>) -> V,
|
||||
{
|
||||
let titlebar_height = platform_window.titlebar_height();
|
||||
let appearance = platform_window.appearance();
|
||||
|
@ -242,14 +242,11 @@ impl<'a> WindowContext<'a> {
|
|||
Some(result)
|
||||
}
|
||||
|
||||
pub(crate) fn update_view<T, S>(
|
||||
pub(crate) fn update_view<V: 'static, S>(
|
||||
&mut self,
|
||||
handle: &ViewHandle<T>,
|
||||
update: &mut dyn FnMut(&mut T, &mut ViewContext<T>) -> S,
|
||||
) -> S
|
||||
where
|
||||
T: View,
|
||||
{
|
||||
handle: &ViewHandle<V>,
|
||||
update: &mut dyn FnMut(&mut V, &mut ViewContext<V>) -> S,
|
||||
) -> S {
|
||||
self.update_any_view(handle.view_id, |view, cx| {
|
||||
let mut cx = ViewContext::mutable(cx, handle.view_id);
|
||||
update(
|
||||
|
@ -1393,7 +1390,7 @@ impl ChildView {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for ChildView {
|
||||
impl<V: 'static> Element<V> for ChildView {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ use json::ToJson;
|
|||
use smallvec::SmallVec;
|
||||
use std::{any::Any, borrow::Cow, mem, ops::Range};
|
||||
|
||||
pub trait Element<V: View>: 'static {
|
||||
pub trait Element<V: 'static>: 'static {
|
||||
type LayoutState;
|
||||
type PaintState;
|
||||
|
||||
|
@ -201,7 +201,7 @@ pub trait Element<V: View>: 'static {
|
|||
}
|
||||
}
|
||||
|
||||
trait AnyElementState<V: View> {
|
||||
trait AnyElementState<V> {
|
||||
fn layout(
|
||||
&mut self,
|
||||
constraint: SizeConstraint,
|
||||
|
@ -232,7 +232,7 @@ trait AnyElementState<V: View> {
|
|||
fn metadata(&self) -> Option<&dyn Any>;
|
||||
}
|
||||
|
||||
enum ElementState<V: View, E: Element<V>> {
|
||||
enum ElementState<V: 'static, E: Element<V>> {
|
||||
Empty,
|
||||
Init {
|
||||
element: E,
|
||||
|
@ -253,7 +253,7 @@ enum ElementState<V: View, E: Element<V>> {
|
|||
},
|
||||
}
|
||||
|
||||
impl<V: View, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
|
||||
impl<V, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
|
||||
fn layout(
|
||||
&mut self,
|
||||
constraint: SizeConstraint,
|
||||
|
@ -427,18 +427,18 @@ impl<V: View, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View, E: Element<V>> Default for ElementState<V, E> {
|
||||
impl<V, E: Element<V>> Default for ElementState<V, E> {
|
||||
fn default() -> Self {
|
||||
Self::Empty
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AnyElement<V: View> {
|
||||
pub struct AnyElement<V> {
|
||||
state: Box<dyn AnyElementState<V>>,
|
||||
name: Option<Cow<'static, str>>,
|
||||
}
|
||||
|
||||
impl<V: View> AnyElement<V> {
|
||||
impl<V> AnyElement<V> {
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.name.as_deref()
|
||||
}
|
||||
|
@ -506,7 +506,7 @@ impl<V: View> AnyElement<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for AnyElement<V> {
|
||||
impl<V: 'static> Element<V> for AnyElement<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
@ -564,12 +564,12 @@ impl<V: View> Element<V> for AnyElement<V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct RootElement<V: View> {
|
||||
pub struct RootElement<V> {
|
||||
element: AnyElement<V>,
|
||||
view: WeakViewHandle<V>,
|
||||
}
|
||||
|
||||
impl<V: View> RootElement<V> {
|
||||
impl<V> RootElement<V> {
|
||||
pub fn new(element: AnyElement<V>, view: WeakViewHandle<V>) -> Self {
|
||||
Self { element, view }
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ impl<V: View> AnyRootElement for RootElement<V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait ParentElement<'a, V: View>: Extend<AnyElement<V>> + Sized {
|
||||
pub trait ParentElement<'a, V: 'static>: Extend<AnyElement<V>> + Sized {
|
||||
fn add_children<E: Element<V>>(&mut self, children: impl IntoIterator<Item = E>) {
|
||||
self.extend(children.into_iter().map(|child| child.into_any()));
|
||||
}
|
||||
|
@ -697,7 +697,12 @@ pub trait ParentElement<'a, V: View>: Extend<AnyElement<V>> + Sized {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, V: View, T> ParentElement<'a, V> for T where T: Extend<AnyElement<V>> {}
|
||||
impl<'a, V, T> ParentElement<'a, V> for T
|
||||
where
|
||||
V: 'static,
|
||||
T: Extend<AnyElement<V>>,
|
||||
{
|
||||
}
|
||||
|
||||
pub fn constrain_size_preserving_aspect_ratio(max_size: Vector2F, size: Vector2F) -> Vector2F {
|
||||
if max_size.x().is_infinite() && max_size.y().is_infinite() {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
|
||||
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
|
||||
ViewContext,
|
||||
};
|
||||
use json::ToJson;
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
pub struct Align<V: View> {
|
||||
pub struct Align<V> {
|
||||
child: AnyElement<V>,
|
||||
alignment: Vector2F,
|
||||
}
|
||||
|
||||
impl<V: View> Align<V> {
|
||||
impl<V> Align<V> {
|
||||
pub fn new(child: AnyElement<V>) -> Self {
|
||||
Self {
|
||||
child,
|
||||
|
@ -41,7 +41,7 @@ impl<V: View> Align<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Align<V> {
|
||||
impl<V: 'static> Element<V> for Align<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::marker::PhantomData;
|
|||
use super::Element;
|
||||
use crate::{
|
||||
json::{self, json},
|
||||
PaintContext, SceneBuilder, View, ViewContext,
|
||||
PaintContext, SceneBuilder, ViewContext,
|
||||
};
|
||||
use json::ToJson;
|
||||
use pathfinder_geometry::{
|
||||
|
@ -15,7 +15,6 @@ pub struct Canvas<V, F>(F, PhantomData<V>);
|
|||
|
||||
impl<V, F> Canvas<V, F>
|
||||
where
|
||||
V: View,
|
||||
F: FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>),
|
||||
{
|
||||
pub fn new(f: F) -> Self {
|
||||
|
@ -23,7 +22,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View, F> Element<V> for Canvas<V, F>
|
||||
impl<V: 'static, F> Element<V> for Canvas<V, F>
|
||||
where
|
||||
F: 'static + FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>),
|
||||
{
|
||||
|
|
|
@ -4,21 +4,21 @@ use pathfinder_geometry::{rect::RectF, vector::Vector2F};
|
|||
use serde_json::json;
|
||||
|
||||
use crate::{
|
||||
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
|
||||
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
|
||||
ViewContext,
|
||||
};
|
||||
|
||||
pub struct Clipped<V: View> {
|
||||
pub struct Clipped<V> {
|
||||
child: AnyElement<V>,
|
||||
}
|
||||
|
||||
impl<V: View> Clipped<V> {
|
||||
impl<V> Clipped<V> {
|
||||
pub fn new(child: AnyElement<V>) -> Self {
|
||||
Self { child }
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Clipped<V> {
|
||||
impl<V: 'static> Element<V> for Clipped<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -5,21 +5,21 @@ use serde_json::json;
|
|||
|
||||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
|
||||
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
|
||||
ViewContext,
|
||||
};
|
||||
|
||||
pub struct ConstrainedBox<V: View> {
|
||||
pub struct ConstrainedBox<V> {
|
||||
child: AnyElement<V>,
|
||||
constraint: Constraint<V>,
|
||||
}
|
||||
|
||||
pub enum Constraint<V: View> {
|
||||
pub enum Constraint<V> {
|
||||
Static(SizeConstraint),
|
||||
Dynamic(Box<dyn FnMut(SizeConstraint, &mut V, &mut LayoutContext<V>) -> SizeConstraint>),
|
||||
}
|
||||
|
||||
impl<V: View> ToJson for Constraint<V> {
|
||||
impl<V> ToJson for Constraint<V> {
|
||||
fn to_json(&self) -> serde_json::Value {
|
||||
match self {
|
||||
Constraint::Static(constraint) => constraint.to_json(),
|
||||
|
@ -28,7 +28,7 @@ impl<V: View> ToJson for Constraint<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> ConstrainedBox<V> {
|
||||
impl<V: 'static> ConstrainedBox<V> {
|
||||
pub fn new(child: impl Element<V>) -> Self {
|
||||
Self {
|
||||
child: child.into_any(),
|
||||
|
@ -132,7 +132,7 @@ impl<V: View> ConstrainedBox<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for ConstrainedBox<V> {
|
||||
impl<V: 'static> Element<V> for ConstrainedBox<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -10,8 +10,7 @@ use crate::{
|
|||
json::ToJson,
|
||||
platform::CursorStyle,
|
||||
scene::{self, Border, CursorRegion, Quad},
|
||||
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
|
||||
ViewContext,
|
||||
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
@ -37,12 +36,12 @@ pub struct ContainerStyle {
|
|||
pub cursor: Option<CursorStyle>,
|
||||
}
|
||||
|
||||
pub struct Container<V: View> {
|
||||
pub struct Container<V> {
|
||||
child: AnyElement<V>,
|
||||
style: ContainerStyle,
|
||||
}
|
||||
|
||||
impl<V: View> Container<V> {
|
||||
impl<V> Container<V> {
|
||||
pub fn new(child: AnyElement<V>) -> Self {
|
||||
Self {
|
||||
child,
|
||||
|
@ -186,7 +185,7 @@ impl<V: View> Container<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Container<V> {
|
||||
impl<V: 'static> Element<V> for Container<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
json::{json, ToJson},
|
||||
LayoutContext, PaintContext, SceneBuilder, View, ViewContext,
|
||||
LayoutContext, PaintContext, SceneBuilder, ViewContext,
|
||||
};
|
||||
use crate::{Element, SizeConstraint};
|
||||
|
||||
|
@ -26,7 +26,7 @@ impl Empty {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Empty {
|
||||
impl<V: 'static> Element<V> for Empty {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -2,18 +2,18 @@ use std::ops::Range;
|
|||
|
||||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
|
||||
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
|
||||
ViewContext,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
pub struct Expanded<V: View> {
|
||||
pub struct Expanded<V> {
|
||||
child: AnyElement<V>,
|
||||
full_width: bool,
|
||||
full_height: bool,
|
||||
}
|
||||
|
||||
impl<V: View> Expanded<V> {
|
||||
impl<V: 'static> Expanded<V> {
|
||||
pub fn new(child: impl Element<V>) -> Self {
|
||||
Self {
|
||||
child: child.into_any(),
|
||||
|
@ -35,7 +35,7 @@ impl<V: View> Expanded<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Expanded<V> {
|
||||
impl<V: 'static> Element<V> for Expanded<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{any::Any, cell::Cell, f32::INFINITY, ops::Range, rc::Rc};
|
|||
use crate::{
|
||||
json::{self, ToJson, Value},
|
||||
AnyElement, Axis, Element, ElementStateHandle, LayoutContext, PaintContext, SceneBuilder,
|
||||
SizeConstraint, Vector2FExt, View, ViewContext,
|
||||
SizeConstraint, Vector2FExt, ViewContext,
|
||||
};
|
||||
use pathfinder_geometry::{
|
||||
rect::RectF,
|
||||
|
@ -17,14 +17,14 @@ struct ScrollState {
|
|||
scroll_position: Cell<f32>,
|
||||
}
|
||||
|
||||
pub struct Flex<V: View> {
|
||||
pub struct Flex<V> {
|
||||
axis: Axis,
|
||||
children: Vec<AnyElement<V>>,
|
||||
scroll_state: Option<(ElementStateHandle<Rc<ScrollState>>, usize)>,
|
||||
child_alignment: f32,
|
||||
}
|
||||
|
||||
impl<V: View> Flex<V> {
|
||||
impl<V: 'static> Flex<V> {
|
||||
pub fn new(axis: Axis) -> Self {
|
||||
Self {
|
||||
axis,
|
||||
|
@ -115,13 +115,13 @@ impl<V: View> Flex<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Extend<AnyElement<V>> for Flex<V> {
|
||||
impl<V> Extend<AnyElement<V>> for Flex<V> {
|
||||
fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
|
||||
self.children.extend(children);
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Flex<V> {
|
||||
impl<V: 'static> Element<V> for Flex<V> {
|
||||
type LayoutState = f32;
|
||||
type PaintState = ();
|
||||
|
||||
|
@ -401,12 +401,12 @@ struct FlexParentData {
|
|||
float: bool,
|
||||
}
|
||||
|
||||
pub struct FlexItem<V: View> {
|
||||
pub struct FlexItem<V> {
|
||||
metadata: FlexParentData,
|
||||
child: AnyElement<V>,
|
||||
}
|
||||
|
||||
impl<V: View> FlexItem<V> {
|
||||
impl<V: 'static> FlexItem<V> {
|
||||
pub fn new(child: impl Element<V>) -> Self {
|
||||
FlexItem {
|
||||
metadata: FlexParentData {
|
||||
|
@ -428,7 +428,7 @@ impl<V: View> FlexItem<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for FlexItem<V> {
|
||||
impl<V: 'static> Element<V> for FlexItem<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -3,16 +3,15 @@ use std::ops::Range;
|
|||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json::json,
|
||||
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
|
||||
ViewContext,
|
||||
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
|
||||
};
|
||||
|
||||
pub struct Hook<V: View> {
|
||||
pub struct Hook<V> {
|
||||
child: AnyElement<V>,
|
||||
after_layout: Option<Box<dyn FnMut(Vector2F, &mut ViewContext<V>)>>,
|
||||
}
|
||||
|
||||
impl<V: View> Hook<V> {
|
||||
impl<V: 'static> Hook<V> {
|
||||
pub fn new(child: impl Element<V>) -> Self {
|
||||
Self {
|
||||
child: child.into_any(),
|
||||
|
@ -29,7 +28,7 @@ impl<V: View> Hook<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Hook<V> {
|
||||
impl<V: 'static> Element<V> for Hook<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
},
|
||||
json::{json, ToJson},
|
||||
scene, Border, Element, ImageData, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
|
||||
View, ViewContext,
|
||||
ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
@ -57,7 +57,7 @@ impl Image {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Image {
|
||||
impl<V: 'static> Element<V> for Image {
|
||||
type LayoutState = Option<Arc<ImageData>>;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ impl KeystrokeLabel {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for KeystrokeLabel {
|
||||
impl<V: 'static> Element<V> for KeystrokeLabel {
|
||||
type LayoutState = AnyElement<V>;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
},
|
||||
json::{ToJson, Value},
|
||||
text_layout::{Line, RunStyle},
|
||||
Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
@ -128,7 +128,7 @@ impl Label {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Label {
|
||||
impl<V: 'static> Element<V> for Label {
|
||||
type LayoutState = Line;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -5,16 +5,16 @@ use crate::{
|
|||
},
|
||||
json::json,
|
||||
AnyElement, Element, LayoutContext, MouseRegion, PaintContext, SceneBuilder, SizeConstraint,
|
||||
View, ViewContext,
|
||||
ViewContext,
|
||||
};
|
||||
use std::{cell::RefCell, collections::VecDeque, fmt::Debug, ops::Range, rc::Rc};
|
||||
use sum_tree::{Bias, SumTree};
|
||||
|
||||
pub struct List<V: View> {
|
||||
pub struct List<V> {
|
||||
state: ListState<V>,
|
||||
}
|
||||
|
||||
pub struct ListState<V: View>(Rc<RefCell<StateInner<V>>>);
|
||||
pub struct ListState<V>(Rc<RefCell<StateInner<V>>>);
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum Orientation {
|
||||
|
@ -22,7 +22,7 @@ pub enum Orientation {
|
|||
Bottom,
|
||||
}
|
||||
|
||||
struct StateInner<V: View> {
|
||||
struct StateInner<V> {
|
||||
last_layout_width: Option<f32>,
|
||||
render_item: Box<dyn FnMut(&mut V, usize, &mut ViewContext<V>) -> AnyElement<V>>,
|
||||
rendered_range: Range<usize>,
|
||||
|
@ -40,13 +40,13 @@ pub struct ListOffset {
|
|||
pub offset_in_item: f32,
|
||||
}
|
||||
|
||||
enum ListItem<V: View> {
|
||||
enum ListItem<V> {
|
||||
Unrendered,
|
||||
Rendered(Rc<RefCell<AnyElement<V>>>),
|
||||
Removed(f32),
|
||||
}
|
||||
|
||||
impl<V: View> Clone for ListItem<V> {
|
||||
impl<V> Clone for ListItem<V> {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
Self::Unrendered => Self::Unrendered,
|
||||
|
@ -56,7 +56,7 @@ impl<V: View> Clone for ListItem<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Debug for ListItem<V> {
|
||||
impl<V> Debug for ListItem<V> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Unrendered => write!(f, "Unrendered"),
|
||||
|
@ -86,13 +86,13 @@ struct UnrenderedCount(usize);
|
|||
#[derive(Clone, Debug, Default)]
|
||||
struct Height(f32);
|
||||
|
||||
impl<V: View> List<V> {
|
||||
impl<V> List<V> {
|
||||
pub fn new(state: ListState<V>) -> Self {
|
||||
Self { state }
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for List<V> {
|
||||
impl<V: 'static> Element<V> for List<V> {
|
||||
type LayoutState = ListOffset;
|
||||
type PaintState = ();
|
||||
|
||||
|
@ -347,7 +347,7 @@ impl<V: View> Element<V> for List<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> ListState<V> {
|
||||
impl<V: 'static> ListState<V> {
|
||||
pub fn new<D, F>(
|
||||
element_count: usize,
|
||||
orientation: Orientation,
|
||||
|
@ -440,13 +440,13 @@ impl<V: View> ListState<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Clone for ListState<V> {
|
||||
impl<V> Clone for ListState<V> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> StateInner<V> {
|
||||
impl<V: 'static> StateInner<V> {
|
||||
fn render_item(
|
||||
&mut self,
|
||||
ix: usize,
|
||||
|
@ -560,7 +560,7 @@ impl<V: View> StateInner<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> ListItem<V> {
|
||||
impl<V> ListItem<V> {
|
||||
fn remove(&self) -> Self {
|
||||
match self {
|
||||
ListItem::Unrendered => ListItem::Unrendered,
|
||||
|
@ -570,7 +570,7 @@ impl<V: View> ListItem<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> sum_tree::Item for ListItem<V> {
|
||||
impl<V> sum_tree::Item for ListItem<V> {
|
||||
type Summary = ListItemSummary;
|
||||
|
||||
fn summary(&self) -> Self::Summary {
|
||||
|
@ -944,7 +944,7 @@ mod tests {
|
|||
type Event = ();
|
||||
}
|
||||
|
||||
impl View for TestView {
|
||||
impl crate::View for TestView {
|
||||
fn ui_name() -> &'static str {
|
||||
"TestView"
|
||||
}
|
||||
|
@ -968,7 +968,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for TestElement {
|
||||
impl<V: 'static> Element<V> for TestElement {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -11,12 +11,12 @@ use crate::{
|
|||
MouseHover, MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut,
|
||||
},
|
||||
AnyElement, Element, EventContext, LayoutContext, MouseRegion, MouseState, PaintContext,
|
||||
SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
SceneBuilder, SizeConstraint, ViewContext,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::{marker::PhantomData, ops::Range};
|
||||
|
||||
pub struct MouseEventHandler<Tag: 'static, V: View> {
|
||||
pub struct MouseEventHandler<Tag: 'static, V> {
|
||||
child: AnyElement<V>,
|
||||
region_id: usize,
|
||||
cursor_style: Option<CursorStyle>,
|
||||
|
@ -31,7 +31,7 @@ pub struct MouseEventHandler<Tag: 'static, V: View> {
|
|||
|
||||
/// Element which provides a render_child callback with a MouseState and paints a mouse
|
||||
/// region under (or above) it for easy mouse event handling.
|
||||
impl<Tag, V: View> MouseEventHandler<Tag, V> {
|
||||
impl<Tag, V: 'static> MouseEventHandler<Tag, V> {
|
||||
pub fn for_child(child: impl Element<V>, region_id: usize) -> Self {
|
||||
Self {
|
||||
child: child.into_any(),
|
||||
|
@ -236,7 +236,7 @@ impl<Tag, V: View> MouseEventHandler<Tag, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Tag, V: View> Element<V> for MouseEventHandler<Tag, V> {
|
||||
impl<Tag, V: 'static> Element<V> for MouseEventHandler<Tag, V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@ use crate::{
|
|||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json::ToJson,
|
||||
AnyElement, Axis, Element, LayoutContext, MouseRegion, PaintContext, SceneBuilder,
|
||||
SizeConstraint, View, ViewContext,
|
||||
SizeConstraint, ViewContext,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
pub struct Overlay<V: View> {
|
||||
pub struct Overlay<V> {
|
||||
child: AnyElement<V>,
|
||||
anchor_position: Option<Vector2F>,
|
||||
anchor_corner: AnchorCorner,
|
||||
|
@ -73,7 +73,7 @@ impl AnchorCorner {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Overlay<V> {
|
||||
impl<V: 'static> Overlay<V> {
|
||||
pub fn new(child: impl Element<V>) -> Self {
|
||||
Self {
|
||||
child: child.into_any(),
|
||||
|
@ -117,7 +117,7 @@ impl<V: View> Overlay<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Overlay<V> {
|
||||
impl<V: 'static> Element<V> for Overlay<V> {
|
||||
type LayoutState = Vector2F;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
platform::{CursorStyle, MouseButton},
|
||||
scene::MouseDrag,
|
||||
AnyElement, Axis, Element, LayoutContext, MouseRegion, PaintContext, SceneBuilder,
|
||||
SizeConstraint, View, ViewContext,
|
||||
SizeConstraint, ViewContext,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -69,7 +69,7 @@ impl HandleSide {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Resizable<V: View> {
|
||||
pub struct Resizable<V> {
|
||||
child: AnyElement<V>,
|
||||
handle_side: HandleSide,
|
||||
handle_size: f32,
|
||||
|
@ -78,7 +78,7 @@ pub struct Resizable<V: View> {
|
|||
|
||||
const DEFAULT_HANDLE_SIZE: f32 = 4.0;
|
||||
|
||||
impl<V: View> Resizable<V> {
|
||||
impl<V: 'static> Resizable<V> {
|
||||
pub fn new(
|
||||
child: AnyElement<V>,
|
||||
handle_side: HandleSide,
|
||||
|
@ -105,7 +105,7 @@ impl<V: View> Resizable<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Resizable<V> {
|
||||
impl<V: 'static> Element<V> for Resizable<V> {
|
||||
type LayoutState = SizeConstraint;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -3,17 +3,16 @@ use std::ops::Range;
|
|||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json::{self, json, ToJson},
|
||||
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
|
||||
ViewContext,
|
||||
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
|
||||
};
|
||||
|
||||
/// Element which renders it's children in a stack on top of each other.
|
||||
/// The first child determines the size of the others.
|
||||
pub struct Stack<V: View> {
|
||||
pub struct Stack<V> {
|
||||
children: Vec<AnyElement<V>>,
|
||||
}
|
||||
|
||||
impl<V: View> Default for Stack<V> {
|
||||
impl<V> Default for Stack<V> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
children: Vec::new(),
|
||||
|
@ -21,13 +20,13 @@ impl<V: View> Default for Stack<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Stack<V> {
|
||||
impl<V> Stack<V> {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Stack<V> {
|
||||
impl<V: 'static> Element<V> for Stack<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
@ -99,7 +98,7 @@ impl<V: View> Element<V> for Stack<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Extend<AnyElement<V>> for Stack<V> {
|
||||
impl<V> Extend<AnyElement<V>> for Stack<V> {
|
||||
fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
|
||||
self.children.extend(children)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
rect::RectF,
|
||||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
scene, Element, LayoutContext, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
scene, Element, LayoutContext, SceneBuilder, SizeConstraint, ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde_derive::Deserialize;
|
||||
|
@ -27,7 +27,7 @@ impl Svg {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn for_style<V: View>(style: SvgStyle) -> impl Element<V> {
|
||||
pub fn for_style<V: 'static>(style: SvgStyle) -> impl Element<V> {
|
||||
Self::new(style.asset)
|
||||
.with_color(style.color)
|
||||
.constrained()
|
||||
|
@ -41,7 +41,7 @@ impl Svg {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Svg {
|
||||
impl<V: 'static> Element<V> for Svg {
|
||||
type LayoutState = Option<usvg::Tree>;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
json::{ToJson, Value},
|
||||
text_layout::{Line, RunStyle, ShapedBoundary},
|
||||
AppContext, Element, FontCache, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
|
||||
TextLayoutCache, View, ViewContext,
|
||||
TextLayoutCache, ViewContext,
|
||||
};
|
||||
use log::warn;
|
||||
use serde_json::json;
|
||||
|
@ -70,7 +70,7 @@ impl Text {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Text {
|
||||
impl<V: 'static> Element<V> for Text {
|
||||
type LayoutState = LayoutState;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json::json,
|
||||
Action, Axis, ElementStateHandle, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
|
||||
Task, View, ViewContext,
|
||||
Task, ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
@ -21,7 +21,7 @@ use util::ResultExt;
|
|||
|
||||
const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(500);
|
||||
|
||||
pub struct Tooltip<V: View> {
|
||||
pub struct Tooltip<V> {
|
||||
child: AnyElement<V>,
|
||||
tooltip: Option<AnyElement<V>>,
|
||||
_state: ElementStateHandle<Rc<TooltipState>>,
|
||||
|
@ -51,8 +51,8 @@ pub struct KeystrokeStyle {
|
|||
text: TextStyle,
|
||||
}
|
||||
|
||||
impl<V: View> Tooltip<V> {
|
||||
pub fn new<Tag: 'static, T: View>(
|
||||
impl<V: 'static> Tooltip<V> {
|
||||
pub fn new<Tag: 'static, T: 'static>(
|
||||
id: usize,
|
||||
text: String,
|
||||
action: Option<Box<dyn Action>>,
|
||||
|
@ -166,7 +166,7 @@ impl<V: View> Tooltip<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Tooltip<V> {
|
||||
impl<V: 'static> Element<V> for Tooltip<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
},
|
||||
json::{self, json},
|
||||
platform::ScrollWheelEvent,
|
||||
AnyElement, LayoutContext, MouseRegion, PaintContext, SceneBuilder, View, ViewContext,
|
||||
AnyElement, LayoutContext, MouseRegion, PaintContext, SceneBuilder, ViewContext,
|
||||
};
|
||||
use json::ToJson;
|
||||
use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
|
||||
|
@ -36,13 +36,13 @@ struct StateInner {
|
|||
scroll_to: Option<ScrollTarget>,
|
||||
}
|
||||
|
||||
pub struct UniformListLayoutState<V: View> {
|
||||
pub struct UniformListLayoutState<V> {
|
||||
scroll_max: f32,
|
||||
item_height: f32,
|
||||
items: Vec<AnyElement<V>>,
|
||||
}
|
||||
|
||||
pub struct UniformList<V: View> {
|
||||
pub struct UniformList<V> {
|
||||
state: UniformListState,
|
||||
item_count: usize,
|
||||
#[allow(clippy::type_complexity)]
|
||||
|
@ -53,7 +53,7 @@ pub struct UniformList<V: View> {
|
|||
view_id: usize,
|
||||
}
|
||||
|
||||
impl<V: View> UniformList<V> {
|
||||
impl<V: 'static> UniformList<V> {
|
||||
pub fn new<F>(
|
||||
state: UniformListState,
|
||||
item_count: usize,
|
||||
|
@ -61,7 +61,6 @@ impl<V: View> UniformList<V> {
|
|||
append_items: F,
|
||||
) -> Self
|
||||
where
|
||||
V: View,
|
||||
F: 'static + Fn(&mut V, Range<usize>, &mut Vec<AnyElement<V>>, &mut ViewContext<V>),
|
||||
{
|
||||
Self {
|
||||
|
@ -151,7 +150,7 @@ impl<V: View> UniformList<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for UniformList<V> {
|
||||
impl<V: 'static> Element<V> for UniformList<V> {
|
||||
type LayoutState = UniformListLayoutState<V>;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{platform::MouseButton, window::WindowContext, EventContext, View, ViewContext};
|
||||
use crate::{platform::MouseButton, window::WindowContext, EventContext, ViewContext};
|
||||
use collections::HashMap;
|
||||
use pathfinder_geometry::rect::RectF;
|
||||
use smallvec::SmallVec;
|
||||
|
@ -64,7 +64,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_down<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseDown, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_down(button, handler);
|
||||
|
@ -73,7 +73,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_up<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseUp, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_up(button, handler);
|
||||
|
@ -82,7 +82,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_click<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_click(button, handler);
|
||||
|
@ -91,7 +91,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_click_out<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseClickOut, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_click_out(button, handler);
|
||||
|
@ -100,7 +100,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_down_out<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseDownOut, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_down_out(button, handler);
|
||||
|
@ -109,7 +109,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_up_out<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseUpOut, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_up_out(button, handler);
|
||||
|
@ -118,7 +118,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_drag<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseDrag, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_drag(button, handler);
|
||||
|
@ -127,7 +127,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_hover<V, F>(mut self, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseHover, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_hover(handler);
|
||||
|
@ -136,7 +136,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_move<V, F>(mut self, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseMove, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_move(handler);
|
||||
|
@ -145,7 +145,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_move_out<V, F>(mut self, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseMoveOut, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_move_out(handler);
|
||||
|
@ -154,7 +154,7 @@ impl MouseRegion {
|
|||
|
||||
pub fn on_scroll<V, F>(mut self, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseScrollWheel, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.handlers = self.handlers.on_scroll(handler);
|
||||
|
@ -310,7 +310,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_move<V, F>(mut self, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseMove, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::move_disc(), None,
|
||||
|
@ -332,7 +332,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_move_out<V, F>(mut self, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseMoveOut, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::move_out_disc(), None,
|
||||
|
@ -354,7 +354,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_down<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseDown, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::down_disc(), Some(button),
|
||||
|
@ -376,7 +376,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_up<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseUp, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::up_disc(), Some(button),
|
||||
|
@ -398,7 +398,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_click<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::click_disc(), Some(button),
|
||||
|
@ -420,7 +420,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_click_out<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseClickOut, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::click_out_disc(), Some(button),
|
||||
|
@ -442,7 +442,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_down_out<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseDownOut, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::down_out_disc(), Some(button),
|
||||
|
@ -464,7 +464,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_up_out<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseUpOut, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::up_out_disc(), Some(button),
|
||||
|
@ -486,7 +486,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_drag<V, F>(mut self, button: MouseButton, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseDrag, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::drag_disc(), Some(button),
|
||||
|
@ -508,7 +508,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_hover<V, F>(mut self, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseHover, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::hover_disc(), None,
|
||||
|
@ -530,7 +530,7 @@ impl HandlerSet {
|
|||
|
||||
pub fn on_scroll<V, F>(mut self, handler: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseScrollWheel, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
self.insert(MouseEvent::scroll_wheel_disc(), None,
|
||||
|
|
|
@ -450,7 +450,7 @@ impl View for LspLogView {
|
|||
}
|
||||
|
||||
impl Item for LspLogView {
|
||||
fn tab_content<V: View>(
|
||||
fn tab_content<V: 'static>(
|
||||
&self,
|
||||
_: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
|
|
|
@ -451,7 +451,7 @@ impl View for SyntaxTreeView {
|
|||
}
|
||||
|
||||
impl Item for SyntaxTreeView {
|
||||
fn tab_content<V: View>(
|
||||
fn tab_content<V: 'static>(
|
||||
&self,
|
||||
_: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
|
|
|
@ -1320,7 +1320,7 @@ impl ProjectPanel {
|
|||
}
|
||||
}
|
||||
|
||||
fn render_entry_visual_element<V: View>(
|
||||
fn render_entry_visual_element<V: 'static>(
|
||||
details: &EntryDetails,
|
||||
editor: Option<&ViewHandle<Editor>>,
|
||||
padding: f32,
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::path::Path;
|
|||
use fuzzy::StringMatch;
|
||||
use gpui::{
|
||||
elements::{Label, LabelStyle},
|
||||
AnyElement, Element, View,
|
||||
AnyElement, Element,
|
||||
};
|
||||
use util::paths::PathExt;
|
||||
use workspace::WorkspaceLocation;
|
||||
|
@ -43,7 +43,7 @@ impl HighlightedText {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn render<V: View>(self, style: impl Into<LabelStyle>) -> AnyElement<V> {
|
||||
pub fn render<V: 'static>(self, style: impl Into<LabelStyle>) -> AnyElement<V> {
|
||||
Label::new(self.text, style)
|
||||
.with_highlights(self.highlight_positions)
|
||||
.into_any()
|
||||
|
|
|
@ -395,7 +395,7 @@ impl Item for ProjectSearchView {
|
|||
.update(cx, |editor, cx| editor.deactivated(cx));
|
||||
}
|
||||
|
||||
fn tab_content<T: View>(
|
||||
fn tab_content<T: 'static>(
|
||||
&self,
|
||||
_detail: Option<usize>,
|
||||
tab_theme: &theme::Tab,
|
||||
|
|
|
@ -657,7 +657,7 @@ impl Item for TerminalView {
|
|||
Some(self.terminal().read(cx).title().into())
|
||||
}
|
||||
|
||||
fn tab_content<T: View>(
|
||||
fn tab_content<T: 'static>(
|
||||
&self,
|
||||
_detail: Option<usize>,
|
||||
tab_theme: &theme::Tab,
|
||||
|
|
|
@ -10,7 +10,7 @@ use gpui::{
|
|||
platform,
|
||||
platform::MouseButton,
|
||||
scene::MouseClick,
|
||||
Action, Element, EventContext, MouseState, View, ViewContext,
|
||||
Action, Element, EventContext, MouseState, ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
@ -37,7 +37,7 @@ pub fn checkbox<Tag, V, F>(
|
|||
) -> MouseEventHandler<Tag, V>
|
||||
where
|
||||
Tag: 'static,
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: 'static + Fn(&mut V, bool, &mut EventContext<V>),
|
||||
{
|
||||
let label = Label::new(label, style.label.text.clone())
|
||||
|
@ -57,7 +57,7 @@ pub fn checkbox_with_label<Tag, D, V, F>(
|
|||
where
|
||||
Tag: 'static,
|
||||
D: Element<V>,
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: 'static + Fn(&mut V, bool, &mut EventContext<V>),
|
||||
{
|
||||
MouseEventHandler::new(id, cx, |state, _| {
|
||||
|
@ -93,7 +93,7 @@ where
|
|||
.with_cursor_style(platform::CursorStyle::PointingHand)
|
||||
}
|
||||
|
||||
pub fn svg<V: View>(style: &SvgStyle) -> ConstrainedBox<V> {
|
||||
pub fn svg<V: 'static>(style: &SvgStyle) -> ConstrainedBox<V> {
|
||||
Svg::new(style.asset.clone())
|
||||
.with_color(style.color)
|
||||
.constrained()
|
||||
|
@ -107,11 +107,11 @@ pub struct IconStyle {
|
|||
pub container: ContainerStyle,
|
||||
}
|
||||
|
||||
pub fn icon<V: View>(style: &IconStyle) -> Container<V> {
|
||||
pub fn icon<V: 'static>(style: &IconStyle) -> Container<V> {
|
||||
svg(&style.icon).contained().with_style(style.container)
|
||||
}
|
||||
|
||||
pub fn keystroke_label<V: View>(
|
||||
pub fn keystroke_label<V: 'static>(
|
||||
label_text: &'static str,
|
||||
label_style: &ContainedText,
|
||||
keystroke_style: &ContainedText,
|
||||
|
@ -147,7 +147,7 @@ pub fn cta_button<Tag, L, V, F>(
|
|||
where
|
||||
Tag: 'static,
|
||||
L: Into<Cow<'static, str>>,
|
||||
V: View,
|
||||
V: 'static,
|
||||
F: Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
|
||||
{
|
||||
MouseEventHandler::<Tag, V>::new(0, cx, |state, _| {
|
||||
|
@ -186,9 +186,9 @@ pub fn modal<Tag, V, I, D, F>(
|
|||
) -> impl Element<V>
|
||||
where
|
||||
Tag: 'static,
|
||||
V: View,
|
||||
I: Into<Cow<'static, str>>,
|
||||
D: Element<V>,
|
||||
V: 'static,
|
||||
F: FnOnce(&mut gpui::ViewContext<V>) -> D,
|
||||
{
|
||||
const TITLEBAR_HEIGHT: f32 = 28.;
|
||||
|
|
|
@ -232,7 +232,7 @@ impl Item for WelcomePage {
|
|||
Some("Welcome to Zed!".into())
|
||||
}
|
||||
|
||||
fn tab_content<T: View>(
|
||||
fn tab_content<T: 'static>(
|
||||
&self,
|
||||
_detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
|
|
|
@ -101,7 +101,7 @@ pub trait Item: View {
|
|||
fn tab_description<'a>(&'a self, _: usize, _: &'a AppContext) -> Option<Cow<str>> {
|
||||
None
|
||||
}
|
||||
fn tab_content<V: View>(
|
||||
fn tab_content<V: 'static>(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
|
@ -943,7 +943,7 @@ pub mod test {
|
|||
})
|
||||
}
|
||||
|
||||
fn tab_content<V: View>(
|
||||
fn tab_content<V: 'static>(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
_: &theme::Tab,
|
||||
|
|
|
@ -1864,12 +1864,12 @@ impl NavHistoryState {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct PaneBackdrop<V: View> {
|
||||
pub struct PaneBackdrop<V> {
|
||||
child_view: usize,
|
||||
child: AnyElement<V>,
|
||||
}
|
||||
|
||||
impl<V: View> PaneBackdrop<V> {
|
||||
impl<V> PaneBackdrop<V> {
|
||||
pub fn new(pane_item_view: usize, child: AnyElement<V>) -> Self {
|
||||
PaneBackdrop {
|
||||
child,
|
||||
|
@ -1878,7 +1878,7 @@ impl<V: View> PaneBackdrop<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for PaneBackdrop<V> {
|
||||
impl<V: 'static> Element<V> for PaneBackdrop<V> {
|
||||
type LayoutState = ();
|
||||
|
||||
type PaintState = ();
|
||||
|
|
|
@ -7,7 +7,7 @@ use gpui::{
|
|||
geometry::{rect::RectF, vector::Vector2F},
|
||||
platform::MouseButton,
|
||||
scene::MouseUp,
|
||||
AppContext, Element, EventContext, MouseState, Quad, View, ViewContext, WeakViewHandle,
|
||||
AppContext, Element, EventContext, MouseState, Quad, ViewContext, WeakViewHandle,
|
||||
};
|
||||
use project::ProjectEntryId;
|
||||
|
||||
|
@ -107,7 +107,7 @@ where
|
|||
handler
|
||||
}
|
||||
|
||||
pub fn handle_dropped_item<V: View>(
|
||||
pub fn handle_dropped_item<V: 'static>(
|
||||
event: MouseUp,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
pane: &WeakViewHandle<Pane>,
|
||||
|
|
|
@ -104,7 +104,7 @@ impl Item for SharedScreen {
|
|||
}
|
||||
}
|
||||
|
||||
fn tab_content<V: View>(
|
||||
fn tab_content<V: 'static>(
|
||||
&self,
|
||||
_: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
|
|
Loading…
Reference in a new issue