### Path::new Source: https://docs.rs/gpui/latest/gpui/struct.Path.html Creates a new Path with a specified starting point. ```APIDOC ## Path::new ### Description Create a new path with the given starting point. ### Method ``` pub fn new(start: Point) -> Self ``` ### Parameters * **start** (Point) - The starting point of the path. ``` -------------------------------- ### Create New Path Source: https://docs.rs/gpui/latest/gpui/struct.Path.html Creates a new Path instance with a specified starting point. The starting point is of type Point. ```rust pub fn new(start: Point) -> Self ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://docs.rs/gpui/latest/gpui/index.html On macOS, install the Xcode command line tools using the provided command. This is a system dependency for GPUI on macOS. ```bash xcode-select --install ``` -------------------------------- ### Example of Main Function Using anyhow::Result Source: https://docs.rs/gpui/latest/gpui/type.Result.html An example of a `main` function that returns `anyhow::Result<()>`. This pattern allows for concise error propagation using the `?` operator when reading files and deserializing JSON. ```rust use anyhow::Result; fn main() -> Result<()> { let config = std::fs::read_to_string("cluster.json")?; let map: ClusterMap = serde_json::from_str(&config)?; println!("cluster info: {:#?}", map); Ok(()) } ``` -------------------------------- ### KeyContext::new_with_defaults Source: https://docs.rs/gpui/latest/gpui/struct.KeyContext.html Initializes a new KeyContext with default OS information. ```APIDOC ## KeyContext::new_with_defaults ### Description Initialize a new `KeyContext` that contains an `os` key set to either `macos`, `linux`, `windows` or `unknown`. ### Method ``` pub fn new_with_defaults() -> Self ``` ``` -------------------------------- ### AsRawXcbConnection::as_raw_xcb_connection Example Source: https://docs.rs/gpui/latest/gpui/type.InspectorRenderer.html Gets a raw xcb connection pointer from the Box. Available on crate feature `alloc` only. ```rust fn as_raw_xcb_connection(&self) -> *mut xcb_connection_t ``` -------------------------------- ### Run the Application Source: https://docs.rs/gpui/latest/gpui/struct.Application.html Starts the application and provides a callback that will be executed once the app is fully launched. The callback receives a mutable reference to the `App`. ```rust pub fn run(self, on_finish_launching: F) where F: 'static + FnOnce(&mut App), ``` -------------------------------- ### Iterating Over a Slice Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `iter()` to get an immutable iterator over the elements of a slice. The iterator yields items from start to end. ```rust let x = &[1, 2, 4]; let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None); ``` -------------------------------- ### Application::run Source: https://docs.rs/gpui/latest/gpui/struct.Application.html Starts the application. The provided callback function is executed once the application has fully launched. ```APIDOC ## Application::run ### Description Starts the application. The provided callback will be called once the app is fully launched. ### Method `run(self, on_finish_launching: F)` ### Parameters - **on_finish_launching** (F) - A closure that takes a mutable reference to `App` and is executed once the app is fully launched. `F` must be `'static + FnOnce(&mut App)`. ### Returns `()` (This method does not return a value directly, but starts the application lifecycle.) ``` -------------------------------- ### Get Pure Black Color Source: https://docs.rs/gpui/latest/gpui/fn.black.html Use this function to obtain a pure black color represented in Hsla format. No setup or imports are required as it's a const fn. ```rust pub const fn black() -> Hsla ``` -------------------------------- ### Initialize a new Application Source: https://docs.rs/gpui/latest/gpui/struct.Application.html Constructs a new application instance. This is the starting point for configuring your GPUI application. ```rust pub fn new() -> Self ``` -------------------------------- ### Set Xcode Command Line Tools Path Source: https://docs.rs/gpui/latest/gpui/index.html On macOS, ensure that the Xcode command line tools are configured to use your newly installed copy of Xcode. This is a required setup step for GPUI on macOS. ```bash sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer ``` -------------------------------- ### Box::from_raw Example: Manual Allocation Source: https://docs.rs/gpui/latest/gpui/type.InspectorRenderer.html Illustrates manually creating a Box from scratch using the global allocator. This requires careful handling of memory allocation and deallocation. ```rust use std::alloc::{alloc, Layout}; unsafe { let ptr = alloc(Layout::new::()) as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw(ptr); } ``` -------------------------------- ### Iterate Over Mutable Chunks From the End with rchunks_mut Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `rchunks_mut` to get an iterator over mutable slices of a specified `chunk_size`, starting from the end. This allows in-place modification of slice elements within each chunk. Panics if `chunk_size` is zero. ```rust let v = &mut [0, 0, 0, 0, 0]; let mut count = 1; for chunk in v.rchunks_mut(2) { for elem in chunk.iter_mut() { *elem += count; } count += 1; } assert_eq!(v, &[3, 2, 2, 1, 1]); ``` -------------------------------- ### Row Start Auto Source: https://docs.rs/gpui/latest/gpui/struct.StyleRefinement.html Sets the starting row for an element to auto. ```APIDOC ## fn row_start_auto(self) -> Self ### Description Sets the row start of this element to “auto”. ### Parameters None. ``` -------------------------------- ### Example Usage of Bounds::new Source: https://docs.rs/gpui/latest/gpui/struct.Bounds.html Demonstrates creating a Bounds instance using the ::new constructor and asserting its origin and size. ```rust let origin = Point { x: 0, y: 0 }; let size = Size { width: 10, height: 20 }; let bounds = Bounds::new(origin, size); assert_eq!(bounds.origin, origin); assert_eq!(bounds.size, size); ``` -------------------------------- ### Row Start Source: https://docs.rs/gpui/latest/gpui/struct.StyleRefinement.html Sets the starting row for an element within a grid. ```APIDOC ## fn row_start(self, start: i16) -> Self ### Description Sets the row start of this element. ### Parameters - **start** (i16): The starting row index. ``` -------------------------------- ### open_with_system Source: https://docs.rs/gpui/latest/gpui/struct.App.html Opens the specified path with the system’s default application. ```APIDOC ## open_with_system ### Description Opens the specified path with the system’s default application. ### Method `open_with_system(&self, path: &Path)` ``` -------------------------------- ### Column Start Auto Source: https://docs.rs/gpui/latest/gpui/struct.StyleRefinement.html Sets the starting column for an element to auto. ```APIDOC ## fn col_start_auto(self) -> Self ### Description Sets the column start of this element to auto. ### Parameters None. ``` -------------------------------- ### Initialize KeyContext with Defaults Source: https://docs.rs/gpui/latest/gpui/struct.KeyContext.html Initializes a new KeyContext with a default OS key (macos, linux, windows, or unknown). Use this when starting with a standard operating system context. ```rust pub fn new_with_defaults() -> Self ``` -------------------------------- ### Column Start Source: https://docs.rs/gpui/latest/gpui/struct.StyleRefinement.html Sets the starting column for an element within a grid. ```APIDOC ## fn col_start(self, start: i16) -> Self ### Description Sets the column start of this element. ### Parameters - **start** (i16): The starting column index. ``` -------------------------------- ### Timer::interval_at Source: https://docs.rs/gpui/latest/gpui/struct.Timer.html Creates a timer that emits events periodically, starting at `start`. ```APIDOC ## pub fn interval_at(start: Instant, period: Duration) -> Timer ### Description Creates a timer that emits events periodically, starting at `start`. ### Examples ```rust use async_io::Timer; use futures_lite::StreamExt; use std::time::{Duration, Instant}; let start = Instant::now(); let period = Duration::from_secs(1); Timer::interval_at(start, period).next().await; ``` ``` -------------------------------- ### init Source: https://docs.rs/gpui/latest/gpui/enum.ScrollDelta.html Initializes a with the given initializer. ```APIDOC ## init ### Description Initializes a with the given initializer. ### Method `unsafe fn init(init: ::Init) -> usize` ``` -------------------------------- ### fn row_start(self, start: i16) -> Self Source: https://docs.rs/gpui/latest/gpui/struct.Stateful.html Sets the row start of this element. ```APIDOC ## fn row_start(self, start: i16) -> Self ### Description Sets the starting row position for this element within a grid. ### Method (Implicitly called on a Stateful element) ### Endpoint N/A (SDK method) ### Parameters - **start** (i16) - Description: The starting row index. ### Response Returns `Self` (the Stateful element itself) for chaining. ``` -------------------------------- ### AsyncApp::open_window Source: https://docs.rs/gpui/latest/gpui/struct.AsyncApp.html Open a window with the given options based on the root view returned by the given function. ```APIDOC ## AsyncApp::open_window ### Description Open a window with the given options based on the root view returned by the given function. ### Method `&self` ### Parameters * `options` (WindowOptions) - The options for the new window. * `build_root_view` (impl FnOnce(&mut Window, &mut App) -> Entity) - A function that builds the root view for the window. ### Type Parameters * `V`: 'static + Render ### Returns `Result>` ``` -------------------------------- ### SystemWindowTabController::init Source: https://docs.rs/gpui/latest/gpui/struct.SystemWindowTabController.html Initializes the global window tab controller. ```APIDOC ## SystemWindowTabController::init ### Description Initialize the global window tab controller. ### Method `init(cx: &mut App)` ### Parameters - `cx` (App): A mutable reference to the application context. ``` -------------------------------- ### fn col_start(self, start: i16) -> Self Source: https://docs.rs/gpui/latest/gpui/struct.Stateful.html Sets the column start of this element. ```APIDOC ## fn col_start(self, start: i16) -> Self ### Description Sets the starting column position for this element within a grid. ### Method (Implicitly called on a Stateful element) ### Endpoint N/A (SDK method) ### Parameters - **start** (i16) - Description: The starting column index. ### Response Returns `Self` (the Stateful element itself) for chaining. ``` -------------------------------- ### Content: Start Source: https://docs.rs/gpui/latest/gpui/struct.Svg.html Sets the element to pack content items against the start of the container’s cross axis. ```APIDOC ## content_start ### Description Sets the element to pack content items against the start of the container’s cross axis. ### Method `content_start()` ### Parameters None ### Response Returns `Self` to allow chaining. ``` -------------------------------- ### Keymap::new Source: https://docs.rs/gpui/latest/gpui/struct.Keymap.html Creates a new Keymap instance with an initial set of key bindings. ```APIDOC ## Keymap::new ### Description Create a new keymap with the given bindings. ### Method `new` ### Parameters * `bindings` (Vec) - The initial list of key bindings to associate with this keymap. ### Response * Returns a new `Keymap` instance. ``` -------------------------------- ### Content Start Source: https://docs.rs/gpui/latest/gpui/struct.Canvas.html Sets the element to pack content items against the start of the container’s cross axis. ```APIDOC ## fn content_start(self) -> Self ### Description Sets the element to pack content items against the start of the container’s cross axis. ### Method Self ### Endpoint N/A (Method call) ### Parameters None ### Request Example ```rust canvas.content_start() ``` ### Response #### Success Response (Self) Returns the modified Canvas instance. #### Response Example ```rust // Returns a Canvas instance with content aligned to the start on the cross axis ``` ``` -------------------------------- ### Application::new Source: https://docs.rs/gpui/latest/gpui/struct.Application.html Builds an application with the given asset source. This is a constructor for creating a new Application instance. ```APIDOC ## Application::new ### Description Builds an app with the given asset source. ### Method `new()` ### Returns `Self` (an instance of Application) ``` -------------------------------- ### Justify Start Source: https://docs.rs/gpui/latest/gpui/struct.Canvas.html Sets the element to justify flex items against the start of the container’s main axis. ```APIDOC ## fn justify_start(self) -> Self ### Description Sets the element to justify flex items against the start of the container’s main axis. ### Method Self ### Endpoint N/A (Method call) ### Parameters None ### Request Example ```rust canvas.justify_start() ``` ### Response #### Success Response (Self) Returns the modified Canvas instance. #### Response Example ```rust // Returns a Canvas instance with flex items justified to the start ``` ``` -------------------------------- ### Box::from_non_null Example: Manual Allocation Source: https://docs.rs/gpui/latest/gpui/type.InspectorRenderer.html Demonstrates creating a Box from scratch using the global allocator and a NonNull pointer. This is an experimental API and requires unsafe blocks. ```rust #![feature(box_vec_non_null)] use std::alloc::{alloc, Layout}; use std::ptr::NonNull; unsafe { let non_null = NonNull::new(alloc(Layout::new::()).cast::()) .expect("allocation failed"); // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `non_null`. non_null.write(5); let x = Box::from_non_null(non_null); } ``` -------------------------------- ### Window::start_window_resize Source: https://docs.rs/gpui/latest/gpui/struct.Window.html Start a window resize operation. This is typically used on Wayland to initiate interactive resizing. ```APIDOC ## Window::start_window_resize ### Description Start a window resize operation (Wayland) ### Signature `pub fn start_window_resize(&self, edge: ResizeEdge)` ### Parameters - `edge`: The `ResizeEdge` from which to start the resize. ``` -------------------------------- ### Items Start Source: https://docs.rs/gpui/latest/gpui/struct.Canvas.html Sets the element to align flex items to the start of the container’s cross axis. ```APIDOC ## fn items_start(self) -> Self ### Description Sets the element to align flex items to the start of the container’s cross axis. ### Method Self ### Endpoint N/A (Method call) ### Parameters None ### Request Example ```rust canvas.items_start() ``` ### Response #### Success Response (Self) Returns the modified Canvas instance. #### Response Example ```rust // Returns a Canvas instance with flex items aligned to the start ``` ``` -------------------------------- ### Justify Content: Start Source: https://docs.rs/gpui/latest/gpui/struct.Svg.html Sets the element to justify flex items against the start of the container’s main axis. ```APIDOC ## justify_start ### Description Sets the element to justify flex items against the start of the container’s main axis. ### Method `justify_start()` ### Parameters None ### Response Returns `Self` to allow chaining. ``` -------------------------------- ### Allocator::by_ref Example Source: https://docs.rs/gpui/latest/gpui/type.InspectorRenderer.html Creates a reference adapter for an allocator instance. This is a nightly-only experimental API and requires the `allocator_api` feature. ```rust fn by_ref(&self) -> &Self where Self: Sized, ``` -------------------------------- ### pub fn init_colors(&mut self) Source: https://docs.rs/gpui/latest/gpui/struct.Context.html Initializes the default color palette for the GPUI application. ```APIDOC ## pub fn init_colors(&mut self) ### Description Initializes gpui’s default colors for the application. These colors can be accessed through `cx.default_colors()`. ### Method POST (Conceptual) ### Endpoint N/A (Method call) ### Parameters None ### Response None ``` -------------------------------- ### Items Align: Start Source: https://docs.rs/gpui/latest/gpui/struct.Svg.html Sets the element to align flex items to the start of the container’s cross axis. ```APIDOC ## items_start ### Description Sets the element to align flex items to the start of the container’s cross axis. ### Method `items_start()` ### Parameters None ### Response Returns `Self` to allow chaining. ``` -------------------------------- ### App::open_window Source: https://docs.rs/gpui/latest/gpui/struct.Context.html Opens a new window with the specified options and root view. ```APIDOC ## pub fn open_window( &mut self, options: WindowOptions, build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity, ) -> Result> ### Description Opens a new window with the given option and the root view returned by the given function. The function is invoked with a `Window`, which can be used to interact with window-specific functionality. ### Parameters * `options`: WindowOptions - The options for the new window. * `build_root_view`: FnOnce(&mut Window, &mut App) -> Entity - A function that builds the root view for the new window. ``` -------------------------------- ### Pointable::Init Source: https://docs.rs/gpui/latest/gpui/struct.ImageFormatIter.html The type for initializers. ```APIDOC ## type Init = T ### Description The type for initializers. ### Returns - **T**: The type of the initializer. ``` -------------------------------- ### Get Element or Subslice by Index Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `get` to safely access an element or subslice by index. Returns `None` if the index is out of bounds. ```rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Create a Point instance Source: https://docs.rs/gpui/latest/gpui/struct.Point.html Demonstrates creating a Point instance with specific x and y values and printing its representation. ```rust let point = Point { x: 10, y: 20 }; println!("{:?}", point); // Outputs: Point { x: 10, y: 20 } ``` -------------------------------- ### Get Last Element Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `last()` to get an `Option` containing a reference to the last element. Returns `None` if the slice is empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&30), v.last()); let w: &[i32] = &[]; assert_eq!(None, w.last()); ``` -------------------------------- ### Get First Element Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `first()` to get an `Option` containing a reference to the first element. Returns `None` if the slice is empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&10), v.first()); let w: &[i32] = &[]; assert_eq!(None, w.first()); ``` -------------------------------- ### Pointable::init Source: https://docs.rs/gpui/latest/gpui/struct.ImageFormatIter.html Initializes a with the given initializer. ```APIDOC ## unsafe fn init(init: ::Init) -> usize ### Description Initializes a with the given initializer. ### Parameters #### Path Parameters - **init**: The initializer value. ### Returns - **usize**: A pointer to the initialized memory. ``` -------------------------------- ### App::open_window Source: https://docs.rs/gpui/latest/gpui/struct.App.html Opens a new window with the specified options and a root view built by the provided function. ```APIDOC ## App::open_window ### Description Opens a new window with the given option and the root view returned by the given function. The function is invoked with a `Window`, which can be used to interact with window-specific functionality. ### Method `&mut self` ### Parameters - `options`: `WindowOptions` - The options for the new window. - `build_root_view`: `impl FnOnce(&mut Window, &mut App) -> Entity` - A function that builds the root view for the window. ### Type Parameters - `V`: `'static + Render` - The type of the root view. ### Returns `Result>` ``` -------------------------------- ### Get Mutable Last Element Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `last_mut()` to get an `Option` containing a mutable reference to the last element. Allows in-place modification. ```rust let x = &mut [0, 1, 2]; if let Some(last) = x.last_mut() { *last = 10; } assert_eq!(x, &[0, 1, 10]); let y: &mut [i32] = &mut []; assert_eq!(None, y.last_mut()); ``` -------------------------------- ### open_window Source: https://docs.rs/gpui/latest/gpui/struct.AsyncWindowContext.html Opens a new window with specified options and a root view defined by a provided build function. ```APIDOC ## open_window ### Description Open a window with the given options based on the root view returned by the given function. ### Method `&self` ### Parameters - `options: WindowOptions`: Configuration options for the new window. - `build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity`: A closure that builds the root view for the window. ### Response - `Result>`: A handle to the newly created window, or an error if opening failed. ``` -------------------------------- ### Get Mutable First Element Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `first_mut()` to get an `Option` containing a mutable reference to the first element. Allows in-place modification. ```rust let x = &mut [0, 1, 2]; if let Some(first) = x.first_mut() { *first = 5; } assert_eq!(x, &[5, 1, 2]); let y: &mut [i32] = &mut []; assert_eq!(None, y.first_mut()); ``` -------------------------------- ### SIMD Summation Example Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Illustrates a basic SIMD summation function using `as_simd` to process a slice of f32 values. ```rust fn basic_simd_sum(x: &[f32]) -> f32 { use std::ops::Add; let (prefix, middle, suffix) = x.as_simd(); let sums = f32x4::from_array([ prefix.iter().copied().sum(), 0.0, 0.0, suffix.iter().copied().sum(), ]); let sums = middle.iter().copied().fold(f32x4::add, sums); sums.reduce_sum() } ``` -------------------------------- ### on_hover Source: https://docs.rs/gpui/latest/gpui/struct.Interactivity.html Binds a callback to hover start and end events for an element. The callback receives a boolean indicating if the hover has started (true) or ended (false). ```APIDOC ## pub fn on_hover( &mut self, listener: impl Fn(&bool, &mut Window, &mut App) + 'static, ) where Self: Sized, ### Description Bind the given callback on the hover start and end events of this element. Note that the boolean passed to the callback is true when the hover starts and false when it ends. The imperative API equivalent to `StatefulInteractiveElement::on_hover`. ### Parameters - **listener** (impl Fn(&bool, &mut Window, &mut App) + 'static) - A closure that will be called on hover start and end events. ### Context See `Context::listener` to get access to a view’s state from this callback. ``` -------------------------------- ### Split Off Subslice Starting from Third Element Mutably Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Removes and returns a mutable reference to a subslice starting from the third element. The original mutable slice is modified. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd']; let mut tail = slice.split_off_mut(2..).unwrap(); assert_eq!(slice, &mut ['a', 'b']); assert_eq!(tail, &mut ['c', 'd']); ``` -------------------------------- ### Open New Window Source: https://docs.rs/gpui/latest/gpui/struct.AsyncApp.html Opens a new window with specified options and a root view defined by a build function. Returns a handle to the newly created window. ```rust pub fn open_window( &self, options: WindowOptions, build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity, ) -> Result> where V: 'static + Render, ``` -------------------------------- ### Split Off Slice Starting from Third Element Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Removes and returns a subslice starting from the third element. The original slice is modified to contain elements before the split point. ```rust let mut slice: &[_] = &['a', 'b', 'c', 'd']; let mut tail = slice.split_off(2..).unwrap(); assert_eq!(slice, &['a', 'b']); assert_eq!(tail, &['c', 'd']); ``` -------------------------------- ### Start Window Resize Source: https://docs.rs/gpui/latest/gpui/struct.Window.html Initiates a window resize operation, typically used in Wayland environments. Requires specifying the edge from which to resize. ```rust pub fn start_window_resize(&self, edge: ResizeEdge) ``` -------------------------------- ### Get Reflectable Methods for Styled Type Source: https://docs.rs/gpui/latest/gpui/styled_reflection/fn.methods.html Use this function to get all reflectable methods for a concrete type that implements the `Styled` trait. The type `T` must be `'static`. ```rust pub fn methods() -> Vec> ``` -------------------------------- ### KeyBinding::new Source: https://docs.rs/gpui/latest/gpui/struct.KeyBinding.html Constructs a new KeyBinding from a string of keystrokes, an action, and an optional context. Panics if the keystrokes string is invalid. ```APIDOC ## KeyBinding::new ### Description Construct a new keybinding from the given data. Panics on parse error. ### Signature ```rust pub fn new( keystrokes: &str, action: A, context: Option<&str>, ) -> Self ``` ### Parameters * `keystrokes`: A string representing the key combination (e.g., "cmd-k"). * `action`: The action to be performed when the keybinding is triggered. * `context`: An optional string specifying the context in which this keybinding is active. ``` -------------------------------- ### Get Last N Elements of a Slice Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `last_chunk` to get a reference to the last N elements of a slice. Returns `None` if the slice is shorter than N. ```rust let u = [10, 40, 30]; assert_eq!(Some(&[40, 30]), u.last_chunk::<2>()); let v: &[i32] = &[10]; assert_eq!(None, v.last_chunk::<2>()); let w: &[i32] = &[]; assert_eq!(Some(&[]), w.last_chunk::<0>()); ``` -------------------------------- ### Get First Chunk of Slice Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `first_chunk::()` to get an array reference to the first `N` items. Returns `None` if the slice is shorter than `N`. ```rust let u = [10, 40, 30]; assert_eq!(Some(&[10, 40]), u.first_chunk::<2>()); let v: &[i32] = &[10]; assert_eq!(None, v.first_chunk::<2>()); let w: &[i32] = &[]; assert_eq!(Some(&[]), w.first_chunk::<0>()); ``` -------------------------------- ### Open New Window Source: https://docs.rs/gpui/latest/gpui/struct.App.html Opens a new application window with specified options and a root view defined by a builder function. The builder function receives a `Window` for interaction. ```rust pub fn open_window( &mut self, options: WindowOptions, build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity, ) -> Result> ``` -------------------------------- ### Create a Ready Task Source: https://docs.rs/gpui/latest/gpui/struct.Task.html Creates a new Task that will immediately resolve with the provided value. ```rust pub fn ready(val: T) -> Self ``` -------------------------------- ### Get Mutable First Chunk of Slice Source: https://docs.rs/gpui/latest/gpui/struct.GlobalElementId.html Use `first_chunk_mut::()` to get a mutable array reference to the first `N` items. Returns `None` if the slice is shorter than `N`. ```rust let x = &mut [0, 1, 2]; if let Some(first) = x.first_chunk_mut::<2>() { first[0] = 5; first[1] = 4; } assert_eq!(x, &[5, 4, 2]); assert_eq!(None, x.first_chunk_mut::<4>()); ``` -------------------------------- ### Creating and Registering an Entity Source: https://docs.rs/gpui/latest/gpui/_ownership_and_data_flow/index.html Initialize the application and create a new entity, giving ownership to the application context. ```rust Application::new().run(|cx: &mut App| { let _counter: Entity = cx.new(|_cx| Counter { count: 0 }); // ... }); ``` -------------------------------- ### Create a Periodic Timer Starting at a Specific Instant Source: https://docs.rs/gpui/latest/gpui/struct.Timer.html Use `Timer::interval_at()` to create a timer that emits events periodically, starting at a specified `Instant`. Subsequent events are emitted after the `period`. ```rust use async_io::Timer; use futures_lite::StreamExt; use std::time::{Duration, Instant}; let start = Instant::now(); let period = Duration::from_secs(1); Timer::interval_at(start, period).next().await; ``` -------------------------------- ### Size::new Source: https://docs.rs/gpui/latest/gpui/struct.Size.html Creates a new Size instance with the specified width and height. This is a synonym for the `size` constructor. ```APIDOC ## pub fn new(width: T, height: T) -> Self Create a new Size, a synonym for `size`. ``` -------------------------------- ### Timer::set_interval_at Source: https://docs.rs/gpui/latest/gpui/struct.Timer.html Sets the timer to emit events periodically, starting at `start`. Note that resetting a timer is different from creating a new timer because `set_interval_at()` does not remove the waker associated with the task that is polling the timer. ```APIDOC ## pub fn set_interval_at(&mut self, start: Instant, period: Duration) ### Description Sets the timer to emit events periodically, starting at `start`. Note that resetting a timer is different from creating a new timer because `set_interval_at()` does not remove the waker associated with the task that is polling the timer. ### Examples ```rust use async_io::Timer; use futures_lite::StreamExt; use std::time::{Duration, Instant}; let mut t = Timer::after(Duration::from_secs(1)); let start = Instant::now(); let period = Duration::from_secs(2); t.set_interval_at(start, period); ``` ``` -------------------------------- ### type_id Source: https://docs.rs/gpui/latest/gpui/struct.ImageCacheElement.html Gets the `TypeId` of `self`. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Returns `TypeId` - The type identifier of the element. ``` -------------------------------- ### Box::try_clone_from_ref_in Example Source: https://docs.rs/gpui/latest/gpui/type.InspectorRenderer.html Demonstrates cloning a Box from a reference within a specified allocator. Requires the `allocator_api` feature. ```rust let hello: Box = Box::try_clone_from_ref_in("hello", System)?; ``` -------------------------------- ### AnyWindowHandle Methods Source: https://docs.rs/gpui/latest/gpui/struct.AnyWindowHandle.html This section details the methods available on the AnyWindowHandle struct for interacting with windows. ```APIDOC ## AnyWindowHandle ### Description A handle to a window with any root view type, which can be downcast to a window with a specific root view type. ### Methods #### `window_id(&self) -> WindowId` Get the ID of this window. #### `downcast(&self) -> Option>` Attempt to convert this handle to a window handle with a specific root view type. If the types do not match, this will return `None`. #### `update(self, cx: &mut C, update: impl FnOnce(AnyView, &mut Window, &mut App) -> R) -> Result` Updates the state of the root view of this window. This will fail if the window has been closed. #### `read(self, cx: &C, read: impl FnOnce(Entity, &App) -> R) -> Result` Read the state of the root view of this window. This will fail if the window has been closed. ``` -------------------------------- ### type_id for T Source: https://docs.rs/gpui/latest/gpui/struct.Corners.html Gets the TypeId of self. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Source [Link to source documentation] ``` -------------------------------- ### Task::ready Source: https://docs.rs/gpui/latest/gpui/struct.Task.html Creates a new Task that will immediately resolve with the provided value. ```APIDOC ## Task::ready ### Description Creates a new task that will resolve with the given value. ### Signature ```rust pub fn ready(val: T) -> Self ``` ### Parameters * **val** (T) - The value the task will resolve with. ``` -------------------------------- ### nth Source: https://docs.rs/gpui/latest/gpui/struct.Timer.html Gets the `n`th item of the stream. ```APIDOC ## nth(&mut self, n: usize) -> NthFuture<'_, Self> ### Description Gets the `n`th item of the stream. ### Parameters * `n`: The index of the item to retrieve. ### Constraints Requires the stream to be `Unpin`. ### Returns A future that resolves to the `n`th item, or `None` if the stream has fewer than `n+1` items. ``` -------------------------------- ### Box::from_raw Example: Recreating a Box Source: https://docs.rs/gpui/latest/gpui/type.InspectorRenderer.html Demonstrates how to recreate a Box from a raw pointer obtained using Box::into_raw. This is useful for managing memory manually. ```rust let x = Box::new(5); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` -------------------------------- ### marked_text_range Source: https://docs.rs/gpui/latest/gpui/struct.ElementInputHandler.html Gets the range of the currently marked text, if any. ```APIDOC ## marked_text_range ### Description Gets the range of the currently marked text, if any. ### Signature ```rust fn marked_text_range(&mut self, window: &mut Window, cx: &mut App) -> Option> ``` ``` -------------------------------- ### KeyBinding::load Source: https://docs.rs/gpui/latest/gpui/struct.KeyBinding.html Loads a KeyBinding from raw data, including keystrokes, an action, a context predicate, and optional action input. Requires a platform-specific keyboard mapper. ```APIDOC ## KeyBinding::load ### Description Load a keybinding from the given raw data. Returns a Result containing the KeyBinding or an InvalidKeystrokeError. ### Signature ```rust pub fn load( keystrokes: &str, action: Box, context_predicate: Option>, use_key_equivalents: bool, action_input: Option, keyboard_mapper: &dyn PlatformKeyboardMapper, ) -> Result ``` ### Parameters * `keystrokes`: A string representing the key combination. * `action`: The action associated with the keybinding, boxed as a trait object. * `context_predicate`: An optional predicate to determine if the keybinding is active. * `use_key_equivalents`: A boolean indicating whether to use key equivalents. * `action_input`: Optional shared string for action input. * `keyboard_mapper`: A reference to a platform-specific keyboard mapper. ``` -------------------------------- ### display_handle Source: https://docs.rs/gpui/latest/gpui/struct.Window.html Get a handle to the display controller of the windowing system. ```APIDOC ## fn display_handle(&self) -> Result, HandleError> ### Description Get a handle to the display controller of the windowing system. ### Method `&self` (method on Window) ### Return Value - `Result, HandleError>`: A handle to the display controller or an error. ``` -------------------------------- ### ascent Source: https://docs.rs/gpui/latest/gpui/struct.TextSystem.html Gets the recommended distance from the baseline for a given font. ```APIDOC ## pub fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels ### Description Get the recommended distance from the baseline for the given font ### Method GET ### Endpoint /fonts/{font_id}/ascent?font_size={font_size} ### Parameters #### Path Parameters - **font_id** (FontId) - Required - The identifier of the font. #### Query Parameters - **font_size** (Pixels) - Required - The size of the font in pixels. ### Response #### Success Response (200) - **distance** (Pixels) - The recommended distance from the baseline. ``` -------------------------------- ### start_window_move Source: https://docs.rs/gpui/latest/gpui/struct.Window.html Initiates a window move operation, allowing the compositor to take control. Events may not be received during a move operation. This is applicable on Wayland and X11. ```APIDOC ## start_window_move ### Description Tells the compositor to take control of window movement (Wayland and X11) Events may not be received during a move operation. ### Method `&self` ``` -------------------------------- ### activate_window Source: https://docs.rs/gpui/latest/gpui/struct.Window.html Focuses the current window and brings it to the foreground at the platform level. ```APIDOC ## activate_window ### Description Focus the current window and bring it to the foreground at the platform level. ### Method `&self` (This indicates a method that borrows the object immutably, typically associated with a `self` parameter in Rust, implying a call like `window.activate_window()`) ### Endpoint N/A (This is an SDK method, not an HTTP endpoint) ### Parameters None ### Request Example ```rust window.activate_window(); ``` ### Response None (This method performs an action and does not return a value) ``` -------------------------------- ### position_for_index Source: https://docs.rs/gpui/latest/gpui/struct.TextLayout.html Get the pixel position for the given byte index. ```APIDOC ## position_for_index ### Description Get the pixel position for the given byte index. ### Method `position_for_index` ### Signature `pub fn position_for_index(&self, index: usize) -> Option>` ### Parameters - `index` (usize): The byte index to find the corresponding pixel position for. ``` -------------------------------- ### Convert Image to ClipboardEntry Source: https://docs.rs/gpui/latest/gpui/enum.ClipboardEntry.html Shows how to convert an Image into a ClipboardEntry. Use this when you need to place image data onto the clipboard. ```rust impl From for ClipboardEntry { fn from(value: Image) -> Self { // ... implementation details ... } } ``` -------------------------------- ### index_for_position Source: https://docs.rs/gpui/latest/gpui/struct.TextLayout.html Get the byte index into the input of the pixel position. ```APIDOC ## index_for_position ### Description Get the byte index into the input of the pixel position. ### Method `index_for_position` ### Signature `pub fn index_for_position(&self, position: Point) -> Result` ### Parameters - `position` (Point): The pixel position to find the corresponding byte index for. ``` -------------------------------- ### Get KeyBinding Metadata Source: https://docs.rs/gpui/latest/gpui/struct.KeyBinding.html Retrieves the metadata associated with this KeyBinding. ```rust pub fn meta(&self) -> Option ``` -------------------------------- ### Box::new_uninit_in Source: https://docs.rs/gpui/latest/gpui/type.InspectorRenderer.html Constructs a new box with uninitialized contents in the provided allocator. This is a nightly-only experimental API. ```APIDOC ## Box::new_uninit_in ### Description Constructs a new box with uninitialized contents in the provided allocator. ### Method `new_uninit_in` ### Parameters - `alloc` (A) - The allocator to use. ### Request Example ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::new_uninit_in(System); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ``` -------------------------------- ### App::window_appearance Source: https://docs.rs/gpui/latest/gpui/struct.App.html Returns the appearance settings for the application's windows. ```APIDOC ## App::window_appearance ### Description Returns the appearance of the application’s windows. ### Method `&self` ### Returns `WindowAppearance` ``` -------------------------------- ### Get KeyBinding Action Source: https://docs.rs/gpui/latest/gpui/struct.KeyBinding.html Retrieves the action associated with this KeyBinding. ```rust pub fn action(&self) -> &dyn Action ``` -------------------------------- ### SystemWindowTabController::new Source: https://docs.rs/gpui/latest/gpui/struct.SystemWindowTabController.html Creates a new instance of the window tab controller. ```APIDOC ## SystemWindowTabController::new ### Description Create a new instance of the window tab controller. ### Method `new()` ### Returns - `Self`: A new instance of SystemWindowTabController. ``` -------------------------------- ### App::keyboard_layout Source: https://docs.rs/gpui/latest/gpui/struct.App.html Gets the identifier of the current keyboard layout. ```APIDOC ## App::keyboard_layout ### Description Get the id of the current keyboard layout. ### Method `&self` ### Returns `&dyn PlatformKeyboardLayout` ``` -------------------------------- ### Initialize Tiling with All Sides Tiled Source: https://docs.rs/gpui/latest/gpui/struct.Tiling.html Use this function to create a Tiling instance where all four edges are marked as tiled. ```rust pub fn tiled() -> Self ``` -------------------------------- ### NoneValue Source: https://docs.rs/gpui/latest/gpui/enum.Display.html Provides a method for getting the null-equivalent value of a type. ```APIDOC ## type NoneType = T ### Description The type representing the null-equivalent value. ## fn null_value() -> T ### Description The none-equivalent value. ### Method `null_value` ### Response - `T`: The null-equivalent value. ``` -------------------------------- ### prepaint Source: https://docs.rs/gpui/latest/gpui/struct.Interactivity.html Prepares the element for painting by committing its bounds according to interactivity styles. ```APIDOC ## pub fn prepaint( &mut self, global_id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, bounds: Bounds, content_size: Size, window: &mut Window, cx: &mut App, f: impl FnOnce(&Style, Point, Option, &mut Window, &mut App) -> R, ) -> R ### Description Commit the bounds of this element according to this interactivity state’s configured styles. ### Parameters - **global_id** (Option<&GlobalElementId>) - Optional global ID for the element. - **_inspector_id** (Option<&InspectorElementId>) - Optional inspector ID for the element. - **bounds** (Bounds) - The bounds of the element. - **content_size** (Size) - The size of the element's content. - **window** (&mut Window) - Mutable reference to the window. - **cx** (&mut App) - Mutable reference to the app context. - **f** (impl FnOnce(&Style, Point, Option, &mut Window, &mut App) -> R) - A closure that performs pre-paint operations. ```