Rename build_view to new_view and build_model to new_model (#3823)
The word "new" is shorter and blends in with `new` constructors that are common in Rust. Been meaning to do this for a while. Release Notes: - N/A
This commit is contained in:
@@ -1105,7 +1105,7 @@ impl Context for AppContext {
|
||||
/// Build an entity that is owned by the application. The given function will be invoked with
|
||||
/// a `ModelContext` and must return an object representing the entity. A `Model` will be returned
|
||||
/// which can be used to access the entity in a context.
|
||||
fn build_model<T: 'static>(
|
||||
fn new_model<T: 'static>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
||||
) -> Model<T> {
|
||||
|
||||
@@ -17,7 +17,7 @@ pub struct AsyncAppContext {
|
||||
impl Context for AsyncAppContext {
|
||||
type Result<T> = Result<T>;
|
||||
|
||||
fn build_model<T: 'static>(
|
||||
fn new_model<T: 'static>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
||||
) -> Self::Result<Model<T>>
|
||||
@@ -29,7 +29,7 @@ impl Context for AsyncAppContext {
|
||||
.upgrade()
|
||||
.ok_or_else(|| anyhow!("app was released"))?;
|
||||
let mut app = app.borrow_mut();
|
||||
Ok(app.build_model(build_model))
|
||||
Ok(app.new_model(build_model))
|
||||
}
|
||||
|
||||
fn update_model<T: 'static, R>(
|
||||
@@ -230,15 +230,14 @@ impl AsyncWindowContext {
|
||||
impl Context for AsyncWindowContext {
|
||||
type Result<T> = Result<T>;
|
||||
|
||||
fn build_model<T>(
|
||||
fn new_model<T>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
||||
) -> Result<Model<T>>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
self.window
|
||||
.update(self, |_, cx| cx.build_model(build_model))
|
||||
self.window.update(self, |_, cx| cx.new_model(build_model))
|
||||
}
|
||||
|
||||
fn update_model<T: 'static, R>(
|
||||
@@ -281,7 +280,7 @@ impl Context for AsyncWindowContext {
|
||||
}
|
||||
|
||||
impl VisualContext for AsyncWindowContext {
|
||||
fn build_view<V>(
|
||||
fn new_view<V>(
|
||||
&mut self,
|
||||
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
||||
) -> Self::Result<View<V>>
|
||||
@@ -289,7 +288,7 @@ impl VisualContext for AsyncWindowContext {
|
||||
V: 'static + Render,
|
||||
{
|
||||
self.window
|
||||
.update(self, |_, cx| cx.build_view(build_view_state))
|
||||
.update(self, |_, cx| cx.new_view(build_view_state))
|
||||
}
|
||||
|
||||
fn update_view<V: 'static, R>(
|
||||
|
||||
@@ -215,11 +215,11 @@ impl<'a, T> ModelContext<'a, T> {
|
||||
impl<'a, T> Context for ModelContext<'a, T> {
|
||||
type Result<U> = U;
|
||||
|
||||
fn build_model<U: 'static>(
|
||||
fn new_model<U: 'static>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, U>) -> U,
|
||||
) -> Model<U> {
|
||||
self.app.build_model(build_model)
|
||||
self.app.new_model(build_model)
|
||||
}
|
||||
|
||||
fn update_model<U: 'static, R>(
|
||||
|
||||
@@ -23,7 +23,7 @@ pub struct TestAppContext {
|
||||
impl Context for TestAppContext {
|
||||
type Result<T> = T;
|
||||
|
||||
fn build_model<T: 'static>(
|
||||
fn new_model<T: 'static>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
||||
) -> Self::Result<Model<T>>
|
||||
@@ -31,7 +31,7 @@ impl Context for TestAppContext {
|
||||
T: 'static,
|
||||
{
|
||||
let mut app = self.app.borrow_mut();
|
||||
app.build_model(build_model)
|
||||
app.new_model(build_model)
|
||||
}
|
||||
|
||||
fn update_model<T: 'static, R>(
|
||||
@@ -134,15 +134,13 @@ impl TestAppContext {
|
||||
V: 'static + Render,
|
||||
{
|
||||
let mut cx = self.app.borrow_mut();
|
||||
cx.open_window(WindowOptions::default(), |cx| cx.build_view(build_window))
|
||||
cx.open_window(WindowOptions::default(), |cx| cx.new_view(build_window))
|
||||
}
|
||||
|
||||
pub fn add_empty_window(&mut self) -> AnyWindowHandle {
|
||||
let mut cx = self.app.borrow_mut();
|
||||
cx.open_window(WindowOptions::default(), |cx| {
|
||||
cx.build_view(|_| EmptyView {})
|
||||
})
|
||||
.any_handle
|
||||
cx.open_window(WindowOptions::default(), |cx| cx.new_view(|_| EmptyView {}))
|
||||
.any_handle
|
||||
}
|
||||
|
||||
pub fn add_window_view<F, V>(&mut self, build_window: F) -> (View<V>, &mut VisualTestContext)
|
||||
@@ -151,7 +149,7 @@ impl TestAppContext {
|
||||
V: 'static + Render,
|
||||
{
|
||||
let mut cx = self.app.borrow_mut();
|
||||
let window = cx.open_window(WindowOptions::default(), |cx| cx.build_view(build_window));
|
||||
let window = cx.open_window(WindowOptions::default(), |cx| cx.new_view(build_window));
|
||||
drop(cx);
|
||||
let view = window.root_view(self).unwrap();
|
||||
let cx = Box::new(VisualTestContext::from_window(*window.deref(), self));
|
||||
@@ -617,11 +615,11 @@ impl<'a> VisualTestContext<'a> {
|
||||
impl<'a> Context for VisualTestContext<'a> {
|
||||
type Result<T> = <TestAppContext as Context>::Result<T>;
|
||||
|
||||
fn build_model<T: 'static>(
|
||||
fn new_model<T: 'static>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
||||
) -> Self::Result<Model<T>> {
|
||||
self.cx.build_model(build_model)
|
||||
self.cx.new_model(build_model)
|
||||
}
|
||||
|
||||
fn update_model<T, R>(
|
||||
@@ -666,7 +664,7 @@ impl<'a> Context for VisualTestContext<'a> {
|
||||
}
|
||||
|
||||
impl<'a> VisualContext for VisualTestContext<'a> {
|
||||
fn build_view<V>(
|
||||
fn new_view<V>(
|
||||
&mut self,
|
||||
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
||||
) -> Self::Result<View<V>>
|
||||
@@ -674,7 +672,7 @@ impl<'a> VisualContext for VisualTestContext<'a> {
|
||||
V: 'static + Render,
|
||||
{
|
||||
self.window
|
||||
.update(self.cx, |_, cx| cx.build_view(build_view))
|
||||
.update(self.cx, |_, cx| cx.new_view(build_view))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
@@ -726,7 +724,7 @@ impl AnyWindowHandle {
|
||||
cx: &mut TestAppContext,
|
||||
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
||||
) -> View<V> {
|
||||
self.update(cx, |_, cx| cx.build_view(build_view)).unwrap()
|
||||
self.update(cx, |_, cx| cx.new_view(build_view)).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ use taffy::TaffyLayoutEngine;
|
||||
pub trait Context {
|
||||
type Result<T>;
|
||||
|
||||
fn build_model<T: 'static>(
|
||||
fn new_model<T: 'static>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
||||
) -> Self::Result<Model<T>>;
|
||||
@@ -120,7 +120,7 @@ pub trait Context {
|
||||
}
|
||||
|
||||
pub trait VisualContext: Context {
|
||||
fn build_view<V>(
|
||||
fn new_view<V>(
|
||||
&mut self,
|
||||
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
||||
) -> Self::Result<View<V>>
|
||||
|
||||
@@ -327,7 +327,7 @@ mod test {
|
||||
fn test_on_events(cx: &mut TestAppContext) {
|
||||
let window = cx.update(|cx| {
|
||||
cx.open_window(Default::default(), |cx| {
|
||||
cx.build_view(|cx| TestView {
|
||||
cx.new_view(|cx| TestView {
|
||||
saw_key_down: false,
|
||||
saw_action: false,
|
||||
focus_handle: cx.focus_handle(),
|
||||
|
||||
@@ -1463,7 +1463,7 @@ impl<'a> WindowContext<'a> {
|
||||
if self.active_drag.is_none() {
|
||||
self.active_drag = Some(AnyDrag {
|
||||
value: Box::new(files.clone()),
|
||||
view: self.build_view(|_| files).into(),
|
||||
view: self.new_view(|_| files).into(),
|
||||
cursor_offset: position,
|
||||
});
|
||||
}
|
||||
@@ -1842,10 +1842,7 @@ impl<'a> WindowContext<'a> {
|
||||
impl Context for WindowContext<'_> {
|
||||
type Result<T> = T;
|
||||
|
||||
fn build_model<T>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
||||
) -> Model<T>
|
||||
fn new_model<T>(&mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T) -> Model<T>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
@@ -1916,7 +1913,7 @@ impl Context for WindowContext<'_> {
|
||||
}
|
||||
|
||||
impl VisualContext for WindowContext<'_> {
|
||||
fn build_view<V>(
|
||||
fn new_view<V>(
|
||||
&mut self,
|
||||
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
||||
) -> Self::Result<View<V>>
|
||||
@@ -1962,7 +1959,7 @@ impl VisualContext for WindowContext<'_> {
|
||||
where
|
||||
V: 'static + Render,
|
||||
{
|
||||
let view = self.build_view(build_view);
|
||||
let view = self.new_view(build_view);
|
||||
self.window.root_view = Some(view.clone().into());
|
||||
self.notify();
|
||||
view
|
||||
@@ -2728,11 +2725,11 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||
impl<V> Context for ViewContext<'_, V> {
|
||||
type Result<U> = U;
|
||||
|
||||
fn build_model<T: 'static>(
|
||||
fn new_model<T: 'static>(
|
||||
&mut self,
|
||||
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
||||
) -> Model<T> {
|
||||
self.window_cx.build_model(build_model)
|
||||
self.window_cx.new_model(build_model)
|
||||
}
|
||||
|
||||
fn update_model<T: 'static, R>(
|
||||
@@ -2774,11 +2771,11 @@ impl<V> Context for ViewContext<'_, V> {
|
||||
}
|
||||
|
||||
impl<V: 'static> VisualContext for ViewContext<'_, V> {
|
||||
fn build_view<W: Render + 'static>(
|
||||
fn new_view<W: Render + 'static>(
|
||||
&mut self,
|
||||
build_view_state: impl FnOnce(&mut ViewContext<'_, W>) -> W,
|
||||
) -> Self::Result<View<W>> {
|
||||
self.window_cx.build_view(build_view_state)
|
||||
self.window_cx.new_view(build_view_state)
|
||||
}
|
||||
|
||||
fn update_view<V2: 'static, R>(
|
||||
|
||||
Reference in New Issue
Block a user