Merge branch 'main' into fix-notification-positioning

This commit is contained in:
Conrad Irwin
2024-01-19 12:55:52 -07:00
59 changed files with 1753 additions and 631 deletions
+4 -4
View File
@@ -864,7 +864,7 @@ impl AppContext {
.unwrap()
}
/// Set the value of the global of the given type.
/// Sets the value of the global of the given type.
pub fn set_global<G: Any>(&mut self, global: G) {
let global_type = TypeId::of::<G>();
self.push_effect(Effect::NotifyGlobalObservers { global_type });
@@ -889,7 +889,7 @@ impl AppContext {
.unwrap()
}
/// Update the global of the given type with a closure. Unlike `global_mut`, this method provides
/// Updates the global of the given type with a closure. Unlike `global_mut`, this method provides
/// your closure with mutable access to the `AppContext` and the global simultaneously.
pub fn update_global<G: 'static, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R {
self.update(|cx| {
@@ -1106,7 +1106,7 @@ impl AppContext {
.contains_key(&action.as_any().type_id())
}
/// Set the menu bar for this application. This will replace any existing menu bar.
/// Sets the menu bar for this application. This will replace any existing menu bar.
pub fn set_menus(&mut self, menus: Vec<Menu>) {
self.platform.set_menus(menus, &self.keymap.lock());
}
@@ -1190,7 +1190,7 @@ impl Context for AppContext {
})
}
/// Update the entity referenced by the given model. The function is passed a mutable reference to the
/// Updates the entity referenced by the given model. The function is passed a mutable reference to the
/// entity along with a `ModelContext` for the entity.
fn update_model<T: 'static, R>(
&mut self,
+3 -3
View File
@@ -104,7 +104,7 @@ impl EntityMap {
}
}
/// Return an entity after moving it to the stack.
/// Returns an entity after moving it to the stack.
pub fn end_lease<T>(&mut self, mut lease: Lease<T>) {
self.entities
.insert(lease.model.entity_id, lease.entity.take().unwrap());
@@ -391,7 +391,7 @@ impl<T: 'static> Model<T> {
cx.read_model(self, f)
}
/// Update the entity referenced by this model with the given function.
/// Updates the entity referenced by this model with the given function.
///
/// The update function receives a context appropriate for its environment.
/// When updating in an `AppContext`, it receives a `ModelContext`.
@@ -571,7 +571,7 @@ impl<T: 'static> WeakModel<T> {
Model::upgrade_from(self)
}
/// Update the entity referenced by this model with the given function if
/// Updates the entity referenced by this model with the given function if
/// the referenced entity still exists. Returns an error if the entity has
/// been released.
pub fn update<C, R>(
+1 -1
View File
@@ -189,7 +189,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
}
}
/// Update the given global
/// Updates the given global
pub fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
where
G: 'static,
+1 -1
View File
@@ -578,7 +578,7 @@ impl<'a> VisualTestContext {
self.cx.update_window(self.window, |_, cx| f(cx)).unwrap()
}
/// Create a new VisualTestContext. You would typically shadow the passed in
/// Creates a new VisualTestContext. You would typically shadow the passed in
/// TestAppContext with this, as this is typically more useful.
/// `let cx = VisualTestContext::from_window(window, cx);`
pub fn from_window(window: AnyWindowHandle, cx: &TestAppContext) -> Self {
+1 -1
View File
@@ -46,7 +46,7 @@ pub enum Task<T> {
}
impl<T> Task<T> {
/// Create a new task that will resolve with the value
/// Creates a new task that will resolve with the value
pub fn ready(val: T) -> Self {
Task::Ready(Some(val))
}
+21 -19
View File
@@ -514,25 +514,6 @@ impl MacWindow {
NSArray::arrayWithObject(nil, NSFilenamesPboardType)
];
let screen = native_window.screen();
match options.bounds {
WindowBounds::Fullscreen => {
native_window.toggleFullScreen_(nil);
}
WindowBounds::Maximized => {
native_window.setFrame_display_(screen.visibleFrame(), YES);
}
WindowBounds::Fixed(bounds) => {
let display_bounds = display.bounds();
let frame = if bounds.intersects(&display_bounds) {
global_bounds_to_ns_rect(bounds)
} else {
global_bounds_to_ns_rect(display_bounds)
};
native_window.setFrame_display_(frame, YES);
}
}
let native_view: id = msg_send![VIEW_CLASS, alloc];
let native_view = NSView::init(native_view);
@@ -654,6 +635,27 @@ impl MacWindow {
native_window.orderFront_(nil);
}
let screen = native_window.screen();
match options.bounds {
WindowBounds::Fullscreen => {
// We need to toggle full screen asynchronously as doing so may
// call back into the platform handlers.
window.toggle_full_screen()
}
WindowBounds::Maximized => {
native_window.setFrame_display_(screen.visibleFrame(), YES);
}
WindowBounds::Fixed(bounds) => {
let display_bounds = display.bounds();
let frame = if bounds.intersects(&display_bounds) {
global_bounds_to_ns_rect(bounds)
} else {
global_bounds_to_ns_rect(display_bounds)
};
native_window.setFrame_display_(frame, YES);
}
}
window.0.lock().move_traffic_light();
pool.drain();
+21
View File
@@ -307,6 +307,13 @@ pub trait Styled: Sized {
self
}
/// Sets the initial size of flex items for this element.
/// [Docs](https://tailwindcss.com/docs/flex-basis)
fn flex_basis(mut self, basis: impl Into<Length>) -> Self {
self.style().flex_basis = Some(basis.into());
self
}
/// Sets the element to allow a flex item to grow to fill any available space.
/// [Docs](https://tailwindcss.com/docs/flex-grow)
fn flex_grow(mut self) -> Self {
@@ -314,6 +321,20 @@ pub trait Styled: Sized {
self
}
/// Sets the element to allow a flex item to shrink if needed.
/// [Docs](https://tailwindcss.com/docs/flex-shrink)
fn flex_shrink(mut self) -> Self {
self.style().flex_shrink = Some(1.);
self
}
/// Sets the element to prevent a flex item from shrinking.
/// [Docs](https://tailwindcss.com/docs/flex-shrink#dont-shrink)
fn flex_shrink_0(mut self) -> Self {
self.style().flex_shrink = Some(0.);
self
}
/// Sets the element to align flex items to the start of the container's cross axis.
/// [Docs](https://tailwindcss.com/docs/align-items#start)
fn items_start(mut self) -> Self {
+2 -2
View File
@@ -64,7 +64,7 @@ impl<V: 'static> View<V> {
Entity::downgrade(self)
}
/// Update the view's state with the given function, which is passed a mutable reference and a context.
/// Updates the view's state with the given function, which is passed a mutable reference and a context.
pub fn update<C, R>(
&self,
cx: &mut C,
@@ -156,7 +156,7 @@ impl<V: 'static> WeakView<V> {
Entity::upgrade_from(self)
}
/// Update this view's state if it hasn't been released.
/// Updates this view's state if it hasn't been released.
/// Returns an error if this view has been released.
pub fn update<C, R>(
&self,
+23 -23
View File
@@ -721,7 +721,7 @@ impl<'a> WindowContext<'a> {
subscription
}
/// Create an `AsyncWindowContext`, which has a static lifetime and can be held across
/// Creates an [`AsyncWindowContext`], which has a static lifetime and can be held across
/// await points in async code.
pub fn to_async(&self) -> AsyncWindowContext {
AsyncWindowContext::new(self.app.to_async(), self.window.handle)
@@ -794,7 +794,7 @@ impl<'a> WindowContext<'a> {
.spawn(|app| f(AsyncWindowContext::new(app, self.window.handle)))
}
/// Update the global of the given type. The given closure is given simultaneous mutable
/// Updates the global of the given type. The given closure is given simultaneous mutable
/// access both to the global and the context.
pub fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
where
@@ -913,7 +913,7 @@ impl<'a> WindowContext<'a> {
self.window.platform_window.zoom();
}
/// Update the window's title at the platform level.
/// Updates the window's title at the platform level.
pub fn set_window_title(&mut self, title: &str) {
self.window.platform_window.set_title(title);
}
@@ -1063,14 +1063,14 @@ impl<'a> WindowContext<'a> {
self.window.modifiers
}
/// Update the cursor style at the platform level.
/// Updates the cursor style at the platform level.
pub fn set_cursor_style(&mut self, style: CursorStyle) {
let view_id = self.parent_view_id();
self.window.next_frame.cursor_styles.insert(view_id, style);
self.window.next_frame.requested_cursor_style = Some(style);
}
/// Set a tooltip to be rendered for the upcoming frame
/// Sets a tooltip to be rendered for the upcoming frame
pub fn set_tooltip(&mut self, tooltip: AnyTooltip) {
let view_id = self.parent_view_id();
self.window.next_frame.tooltip_request = Some(TooltipRequest { view_id, tooltip });
@@ -2080,8 +2080,8 @@ impl<'a> WindowContext<'a> {
})
}
/// Update or initialize state for an element with the given id that lives across multiple
/// frames. If an element with this id existed in the rendered frame, its state will be passed
/// Updates or initializes state for an element with the given id that lives across multiple
/// frames. If an element with this ID existed in the rendered frame, its state will be passed
/// to the given closure. The state returned by the closure will be stored so it can be referenced
/// when drawing the next frame.
pub(crate) fn with_element_state<S, R>(
@@ -2182,7 +2182,7 @@ impl<'a> WindowContext<'a> {
.expect("a view should always be on the stack while drawing")
}
/// Set an input handler, such as [`ElementInputHandler`][element_input_handler], which interfaces with the
/// Sets an input handler, such as [`ElementInputHandler`][element_input_handler], which interfaces with the
/// platform to receive textual input with proper integration with concerns such
/// as IME interactions. This handler will be active for the upcoming frame until the following frame is
/// rendered.
@@ -2322,7 +2322,7 @@ impl VisualContext for WindowContext<'_> {
view
}
/// Update the given view. Prefer calling `View::update` instead, which calls this method.
/// Updates the given view. Prefer calling [`View::update`] instead, which calls this method.
fn update_view<T: 'static, R>(
&mut self,
view: &View<T>,
@@ -2491,7 +2491,7 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {
result
}
/// Update the global element offset relative to the current offset. This is used to implement
/// Updates the global element offset relative to the current offset. This is used to implement
/// scrolling.
fn with_element_offset<R>(
&mut self,
@@ -2506,7 +2506,7 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {
self.with_absolute_element_offset(abs_offset, f)
}
/// Update the global element offset based on the given offset. This is used to implement
/// Updates the global element offset based on the given offset. This is used to implement
/// drag handles and other manual painting of elements.
fn with_absolute_element_offset<R>(
&mut self,
@@ -2629,7 +2629,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
&mut self.window_cx
}
/// Set a given callback to be run on the next frame.
/// Sets a given callback to be run on the next frame.
pub fn on_next_frame(&mut self, f: impl FnOnce(&mut V, &mut ViewContext<V>) + 'static)
where
V: 'static,
@@ -2957,7 +2957,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
self.window_cx.spawn(|cx| f(view, cx))
}
/// Update the global state of the given type.
/// Updates the global state of the given type.
pub fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
where
G: 'static,
@@ -3189,7 +3189,7 @@ pub struct WindowHandle<V> {
}
impl<V: 'static + Render> WindowHandle<V> {
/// Create a new handle from a window ID.
/// Creates a new handle from a window ID.
/// This does not check if the root type of the window is `V`.
pub fn new(id: WindowId) -> Self {
WindowHandle {
@@ -3215,7 +3215,7 @@ impl<V: 'static + Render> WindowHandle<V> {
}))
}
/// Update the root view of this window.
/// Updates the root view of this window.
///
/// This will fail if the window has been closed or if the root view's type does not match
pub fn update<C, R>(
@@ -3337,7 +3337,7 @@ impl AnyWindowHandle {
}
}
/// Update the state of the root view of this window.
/// Updates the state of the root view of this window.
///
/// This will fail if the window has been closed.
pub fn update<C, R>(
@@ -3477,7 +3477,7 @@ pub struct PaintQuad {
}
impl PaintQuad {
/// Set the corner radii of the quad.
/// Sets the corner radii of the quad.
pub fn corner_radii(self, corner_radii: impl Into<Corners<Pixels>>) -> Self {
PaintQuad {
corner_radii: corner_radii.into(),
@@ -3485,7 +3485,7 @@ impl PaintQuad {
}
}
/// Set the border widths of the quad.
/// Sets the border widths of the quad.
pub fn border_widths(self, border_widths: impl Into<Edges<Pixels>>) -> Self {
PaintQuad {
border_widths: border_widths.into(),
@@ -3493,7 +3493,7 @@ impl PaintQuad {
}
}
/// Set the border color of the quad.
/// Sets the border color of the quad.
pub fn border_color(self, border_color: impl Into<Hsla>) -> Self {
PaintQuad {
border_color: border_color.into(),
@@ -3501,7 +3501,7 @@ impl PaintQuad {
}
}
/// Set the background color of the quad.
/// Sets the background color of the quad.
pub fn background(self, background: impl Into<Hsla>) -> Self {
PaintQuad {
background: background.into(),
@@ -3510,7 +3510,7 @@ impl PaintQuad {
}
}
/// Create a quad with the given parameters.
/// Creates a quad with the given parameters.
pub fn quad(
bounds: Bounds<Pixels>,
corner_radii: impl Into<Corners<Pixels>>,
@@ -3527,7 +3527,7 @@ pub fn quad(
}
}
/// Create a filled quad with the given bounds and background color.
/// Creates a filled quad with the given bounds and background color.
pub fn fill(bounds: impl Into<Bounds<Pixels>>, background: impl Into<Hsla>) -> PaintQuad {
PaintQuad {
bounds: bounds.into(),
@@ -3538,7 +3538,7 @@ pub fn fill(bounds: impl Into<Bounds<Pixels>>, background: impl Into<Hsla>) -> P
}
}
/// Create a rectangle outline with the given bounds, border color, and a 1px border width
/// Creates a rectangle outline with the given bounds, border color, and a 1px border width
pub fn outline(bounds: impl Into<Bounds<Pixels>>, border_color: impl Into<Hsla>) -> PaintQuad {
PaintQuad {
bounds: bounds.into(),