### Rgba::opacity method examples Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/color.rs.html Examples demonstrating how to scale the existing alpha channel of an Rgba color by a factor. ```rust use gpui::rgba; let color = rgba(0xFF0000FF); // Fully opaque red let faded = color.opacity(0.5); assert_eq!(faded.a, 0.5); ``` ```rust use gpui::rgba; let color = rgba(0x3399FFCC); // A light blue with 80% opacity let faded = color.opacity(0.5); assert!((faded.a - 0.4).abs() < 1e-6); ``` -------------------------------- ### Box::into_raw Example Source: https://docs.rs/gpui-pre/0.3.4/gpui/type.InspectorRenderer.html Examples demonstrating how to consume a Box and return a raw pointer. ```rust let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` ```rust use std::alloc::{dealloc, Layout}; use std::ptr; let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); unsafe { ptr::drop_in_place(ptr); dealloc(ptr as *mut u8, Layout::new::()); } ``` ```rust let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); unsafe { drop(Box::from_raw(ptr)); } ``` -------------------------------- ### Rgba::alpha method examples Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/color.rs.html Examples demonstrating how to set a specific alpha value for an Rgba color. ```rust use gpui::rgba; let color = rgba(0xFF0000FF); let faded = color.alpha(0.25); assert_eq!(faded.a, 0.25); ``` ```rust use gpui::rgba; let color = rgba(0x3399FFCC); let transparent = color.alpha(0.0); assert_eq!(transparent.a, 0.0); ``` -------------------------------- ### trim_start_matches example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Example usage of trim_start_matches to remove characters from the start of a string. ```rust let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12"); ``` -------------------------------- ### ASCII validation examples Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples demonstrating the use of ASCII validation checks. ```rust assert!(ascii.is_ascii()); assert!(!non_ascii.is_ascii()); ``` -------------------------------- ### is_ascii example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Example showing strings that are and are not within the ASCII range. ```rust let ascii = "hello!\n"; let non_ascii = "Grüße, Jürgen ❤"; ``` -------------------------------- ### Example usage of block_on Source: https://docs.rs/gpui-pre/0.3.4/gpui/fn.block_on.html A minimal example that creates an async block and passes it to `block_on` to execute it synchronously. ```rust let my_fut = async {}; let result = pollster::block_on(my_fut); ``` -------------------------------- ### point usage example Source: https://docs.rs/gpui-pre/0.3.4/gpui/fn.point.html Example usage of the `point` function. It creates a point with coordinates (10, 20) and asserts the x and y fields. ```rust use gpui::point; let p = point(10, 20); assert_eq!(p.x, 10); assert_eq!(p.y, 20); ``` -------------------------------- ### str::get example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Returns a subslice of str without panicking. The example shows getting a valid subslice and getting None for invalid indices. ```rust let v = String::from("🗻∈🌏"); assert_eq!(Some("🗻"), v.get(0..4)); // indices not on UTF-8 sequence boundaries assert!(v.get(1..).is_none()); assert!(v.get(..8).is_none()); // out of bounds assert!(v.get(..42).is_none()); ``` -------------------------------- ### Create a GPUI application with Application::run Source: https://docs.rs/gpui-pre/0.3.4/gpui/index.html Starts a standalone GPUI app by creating an Application with gpui_platform::application() and running a callback that receives an App context. ```rust use gpui::*; fn main() { gpui_platform::application().run(|cx: &mut App| { // .. }); } ``` -------------------------------- ### Application::run Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Application.html Starts the application. The provided callback will be called once the app is fully launched. ```APIDOC ## Application::run ### Description Starts the application. The provided callback will be called once the app is fully launched. ### Method `pub fn run(self, on_finish_launching: F) where F: 'static + FnOnce(&mut App)` ### Parameters - **on_finish_launching** (`F`) - Required - The callback to invoke once the app is fully launched. ``` -------------------------------- ### Anchor::other_side_along example Source: https://docs.rs/gpui-pre/0.3.4/gpui/enum.Anchor.html Shows how to use the other_side_along method to get the corner across from a given corner along a specified axis. The example moves TopLeft along the horizontal axis to get TopRight. ```rust let result = Anchor::TopLeft.other_side_along(Axis::Horizontal); assert_eq!(result, Anchor::TopRight); ``` -------------------------------- ### new_with_defaults Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.KeyContext.html Initializes a new KeyContext with an 'os' key set to the current operating system. ```APIDOC ## new_with_defaults ### Description Initializes a new `KeyContext` that contains an `os` key set to either `macos`, `linux`, `windows` or `unknown`. ### Method `pub fn new_with_defaults() -> Self` ### Parameters None ### Returns - `Self` - A new `KeyContext` instance with the `os` key set. ``` -------------------------------- ### str::is_char_boundary example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Checks if a byte index is a valid UTF-8 code point boundary. The example shows boundaries at the start, at a multi-byte character start, and at the end, and non-boundaries inside multi-byte characters. ```rust let s = "Löwe 老虎 Léopard"; assert!(s.is_char_boundary(0)); // start of `老` assert!(s.is_char_boundary(6)); assert!(s.is_char_boundary(s.len())); // second byte of `ö` assert!(!s.is_char_boundary(2)); // third byte of `老` assert!(!s.is_char_boundary(8)); ``` -------------------------------- ### init Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SystemWindowTabController.html Initializes the global window tab controller. ```APIDOC ## init ### Description Initializes the global window tab controller. ### Method `pub fn init(cx: &mut App)` ### Parameters - `cx` (`&mut App`) - The application context. ### Returns None ``` -------------------------------- ### str::as_ptr example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Converts a string slice to a raw pointer to the first byte. The example shows getting the pointer for a string. ```rust let s = "Hello"; let ptr = s.as_ptr(); ``` -------------------------------- ### Manually create a Box from scratch Source: https://docs.rs/gpui-pre/0.3.4/gpui/type.ExternalDragPayloadSource.html Shows how to manually allocate memory and initialize a Box using the system allocator. ```rust #![feature(allocator_api, slice_ptr_get)] use std::alloc::{Allocator, Layout, System}; unsafe { let ptr = System.allocate(Layout::new::())?.as_mut_ptr() 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_in(ptr, System); } ``` -------------------------------- ### str::len example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Shows how to get the length of a string in bytes, not characters. The example demonstrates that 'ƒoo' has length 4 bytes but 3 characters. ```rust let len = "foo".len(); assert_eq!(3, len); assert_eq!("ƒoo".len(), 4); // fancy f! assert_eq!("ƒoo".chars().count(), 3); ``` -------------------------------- ### Anchor::opposite example Source: https://docs.rs/gpui-pre/0.3.4/gpui/enum.Anchor.html Shows how to use the opposite method to get the directly opposite corner. The example asserts that TopLeft's opposite is BottomRight. ```rust assert_eq!(Anchor::TopLeft.opposite(), Anchor::BottomRight); ``` -------------------------------- ### Size::scale Method Example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Size.html Demonstrates scaling a Size by a factor to produce a Size. ```rust let size = Size { width: Pixels::from(100.0), height: Pixels::from(50.0) }; let scaled_size = size.scale(2.0); assert_eq!(scaled_size, Size { width: ScaledPixels::from(200.0), height: ScaledPixels::from(100.0) }); ``` -------------------------------- ### Set up app menu platform callbacks (on_will_open_app_menu, on_validate_app_menu_command, on_app_menu_action) Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/platform/app_menu.rs.html Registers three platform callbacks: on_will_open_app_menu clears pending keystrokes, on_validate_app_menu_command checks if an action is available, and on_app_menu_action dispatches the action. Each callback upgrades the async app handle and updates the app context. ```rust platform.on_will_open_app_menu(Box::new({ let cx = cx.to_async(); move || { if let Some(app) = cx.app.upgrade() { app.borrow_mut().update(|cx| cx.clear_pending_keystrokes()); } } })); ``` ```rust platform.on_validate_app_menu_command(Box::new({ let cx = cx.to_async(); move |action| { cx.app .upgrade() .map(|app| app.borrow_mut().update(|cx| cx.is_action_available(action))) .unwrap_or(false) } })); ``` ```rust platform.on_app_menu_action(Box::new({ let cx = cx.to_async(); move |action| { if let Some(app) = cx.app.upgrade() { app.borrow_mut().update(|cx| cx.dispatch_action(action)); } } })); ``` -------------------------------- ### Match indices in string Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples of using match_indices to retrieve both the match and its starting index. ```rust let v: Vec<_> = "abcXXXabcYYYabc".match_indices("abc").collect(); assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]); let v: Vec<_> = "1abcabc2".match_indices("abc").collect(); assert_eq!(v, [(1, "abc"), (4, "abc")]); let v: Vec<_> = "ababa".match_indices("aba").collect(); assert_eq!(v, [(0, "aba")]); // only the first `aba` ``` -------------------------------- ### size function usage example Source: https://docs.rs/gpui-pre/0.3.4/gpui/fn.size.html Demonstrates how to initialize a Size object and verify its width and height components. ```rust use gpui::size; let my_size = size(10, 20); assert_eq!(my_size.width, 10); assert_eq!(my_size.height, 20); ``` -------------------------------- ### str::get_unchecked example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Returns an unchecked subslice of str. The example shows using unsafe to get subslices at valid boundaries. Callers must ensure indices are within bounds and on UTF-8 boundaries. ```rust let v = "🗻∈🌏"; unsafe { assert_eq!("🗻", v.get_unchecked(0..4)); assert_eq!("∈", v.get_unchecked(4..7)); assert_eq!("🌏", v.get_unchecked(7..11)); } ``` -------------------------------- ### Trim start of string Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples of using trim_start to remove leading whitespace, considering string directionality. ```rust let s = "\n Hello\tworld\t\n"; assert_eq!("Hello\tworld\t\n", s.trim_start()); ``` ```rust let s = " English "; assert!(Some('E') == s.trim_start().chars().next()); ``` -------------------------------- ### open_with_system Source: https://docs.rs/gpui-pre/0.3.4/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. ### Signature pub fn open_with_system(&self, path: &Path) ### Parameters - **path** (&Path) - Required - The path to open. ``` -------------------------------- ### GlobalElementId composition from parent and child IDs Source: https://docs.rs/gpui-pre/0.3.4/gpui/_accessibility/index.html Demonstrates how `GlobalElementId` is formed by composing non-`None` IDs of ancestors. The example shows that `inner` gets a global ID `["outer-id", "inner-id"]`, while `middle` has no global ID since it lacks an ID. ```rust let inner = div().id("inner-id"); let middle = div().child(inner); // no ID let outer = div().id("outer-id").child(middle); ``` -------------------------------- ### Setup functions for pending input tests Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/key_dispatch.rs.html Helper functions to initialize test environments with specific key bindings and view configurations. ```rust fn setup_pending_input_test( cx: &mut TestAppContext, bindings: impl IntoIterator, ) -> (&mut VisualTestContext, Rc>, Rc>) { cx.update(|cx| cx.bind_keys(bindings)); let action_count = Rc::new(Cell::new(0)); let secondary_action_count = Rc::new(Cell::new(0)); let (view, cx) = cx.add_window_view(|_, cx| PendingInputTestView { focus_handle: cx.focus_handle(), action_count: action_count.clone(), secondary_action_count: secondary_action_count.clone(), }); let focus_handle = cx.update(|_, cx| view.read(cx).focus_handle.clone()); cx.update(|window, cx| { window.focus(&focus_handle, cx); window.activate_window(); }); (cx, action_count, secondary_action_count) } fn setup_pending_input_timeout_test( cx: &mut TestAppContext, ) -> (&mut VisualTestContext, Rc>, Rc>) { setup_pending_input_test( cx, [ KeyBinding::new("ctrl-b", TestAction, Some("Terminal")), KeyBinding::new("ctrl-b h", SecondaryTestAction, Some("Terminal")), KeyBinding::new("ctrl-b h j", TestAction, Some("Terminal")), ], ) } ``` -------------------------------- ### get Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.KeyContext.html Gets the associated value for a given identifier or key. ```APIDOC ## get ### Description Get the associated value for a given identifier or key. ### Method `pub fn get(&self, key: &str) -> Option<&SharedString>` ### Parameters - **key** (`&str`) - The identifier or key to look up. ### Returns - `Option<&SharedString>` - The associated value, if present. ``` -------------------------------- ### App::new_app Constructor Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/app.rs.html Initializes a new GPUI application instance, setting up executors, text systems, and entity maps. ```rust impl App { #[allow(clippy::new_ret_no_self)] pub(crate) fn new_app( platform: Rc, asset_source: Arc, http_client: Arc, ) -> Rc { let background_executor = platform.background_executor(); let foreground_executor = platform.foreground_executor(); assert!( background_executor.is_main_thread(), "must construct App on main thread" ); #[cfg(feature = "profiler")] let foreground_journal = crate::profiler::journal::install_foreground_journal(); let synced_animation_epoch = background_executor.now(); let text_system = Arc::new(TextSystem::new(platform.text_system())); let entities = EntityMap::new(); let keyboard_layout = platform.keyboard_layout(); let keyboard_mapper = platform.keyboard_mapper(); #[cfg(any(test, feature = "leak-detection"))] let _ref_counts = entities.ref_counts_drop_handle(); let app = Rc::new_cyclic(|this| AppCell { app: RefCell::new(App { this: this.clone(), platform: platform.clone(), text_system, text_rendering_mode: Rc::new(Cell::new(TextRenderingMode::default())), mode: GpuiMode::Production, actions: Rc::new(ActionRegistry::default()), flushing_effects: false, pending_updates: 0, active_drag: None, platform_owned_drag: None, background_executor, foreground_executor, #[cfg(feature = "profiler")] foreground_journal, svg_renderer: SvgRenderer::new(asset_source.clone()), loading_assets: Default::default(), asset_source, http_client, globals_by_type: Default::default(), entities, new_entity_observers: SubscriberSet::new(), windows: SlotMap::with_key(), window_update_stack: Vec::new(), window_handles: FxHashMap::default(), focus_handles: Arc::new(RwLock::new(SlotMap::with_key())), keymap: Rc::new(RefCell::new(Keymap::default())), keyboard_layout, keyboard_mapper, global_action_listeners: Default::default(), pending_effects: VecDeque::new(), pending_notifications: FxHashSet::default(), pending_global_notifications: Default::default(), observers: SubscriberSet::new(), tracked_entities: FxHashMap::default(), window_invalidators_by_entity: FxHashMap::default(), current_window_by_entity: FxHashMap::default(), event_listeners: SubscriberSet::new(), release_listeners: SubscriberSet::new(), keystroke_observers: SubscriberSet::new(), keystroke_interceptors: SubscriberSet::new(), keyboard_layout_observers: SubscriberSet::new(), thermal_state_observers: SubscriberSet::new(), system_wake_observers: SubscriberSet::new(), global_observers: SubscriberSet::new(), quit_observers: SubscriberSet::new(), ``` -------------------------------- ### eq_ignore_ascii_case examples Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples showing ASCII case-insensitive string comparison. ```rust assert!("Ferris".eq_ignore_ascii_case("FERRIS")); assert!("Ferrös".eq_ignore_ascii_case("FERRöS")); assert!(!"Ferrös".eq_ignore_ascii_case("FERRÖS")); ``` -------------------------------- ### Creating Bounds with new Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Bounds.html Example showing how to instantiate a new Bounds object using the new constructor. ```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); ``` -------------------------------- ### strip_circumfix example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples of using strip_circumfix to remove both a prefix and a suffix. ```rust assert_eq!("bar:hello:foo".strip_circumfix("bar:", ":foo"), Some("hello")); assert_eq!("bar:foo".strip_circumfix("foo", "foo"), None); assert_eq!("foo:bar;".strip_circumfix("foo:", ';'), Some("bar")); assert_eq!("foo:bar:baz".strip_circumfix("foo:bar:", ":bar:baz"), None); ``` -------------------------------- ### strip_suffix example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples of using strip_suffix to remove a suffix exactly once. ```rust assert_eq!("bar:foo".strip_suffix(":foo"), Some("bar")); assert_eq!("bar:foo".strip_suffix("bar"), None); assert_eq!("foofoo".strip_suffix("foo"), Some("foo")); ``` -------------------------------- ### trim_start_matches Example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Demonstrates removing prefixes that match a pattern. ```rust assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11"); assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123"); ``` -------------------------------- ### strip_prefix example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples of using strip_prefix to remove a prefix exactly once. ```rust assert_eq!("foo:bar".strip_prefix("foo:"), Some("bar")); assert_eq!("foo:bar".strip_prefix("bar"), None); assert_eq!("foofoo".strip_prefix("foo"), Some("foo")); ``` -------------------------------- ### Path::new Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Path.html Creates a new path with the given starting point. ```APIDOC ## Path::new ### Description Creates a new path with the given starting point. ### Method new ### Signature pub fn new(start: Point) -> Self ### Parameters - **start** (Point) - Required - The starting point of the path. ### Returns - **Self** - A new Path instance. ``` -------------------------------- ### eq_ignore_case_unnormalized non-normalization example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Example illustrating that eq_ignore_case_unnormalized does not perform NFC normalization. ```rust #![feature(casefold)] // These two strings are visually and semantically identical... let comp = "Å"; let decomp = "Å"; // ... but not codepoint-for-codepoint equal. assert_eq!(comp, "\u{C5}"); assert_eq!(decomp, "A\u{030A}"); ``` -------------------------------- ### Manually create a Box from scratch with NonNull Source: https://docs.rs/gpui-pre/0.3.4/gpui/type.ExternalDragPayloadSource.html Shows how to manually allocate memory and initialize a Box using a NonNull pointer and the system allocator. ```rust #![feature(allocator_api)] use std::alloc::{Allocator, Layout, System}; unsafe { let non_null = System.allocate(Layout::new::())?.cast::(); // 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_in(non_null, System); } ``` -------------------------------- ### eq_ignore_case_unnormalized examples Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples demonstrating Unicode-aware caseless matching without normalization. ```rust #![feature(casefold)] assert!("Ferris".eq_ignore_case_unnormalized("FERRIS")); assert!("Ferrös".eq_ignore_case_unnormalized("FERRÖS")); assert!("ẞ".eq_ignore_case_unnormalized("ss")); ``` -------------------------------- ### Initialize follow-tail test view Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/elements/list.rs.html This snippet shows the setup for testing follow-tail re-engagement, defining a simple TestView that renders a list. ```rust #[gpui::test] fn test_pause_following_tail_reengages_when_still_at_bottom(cx: &mut TestAppContext) { let cx = cx.add_empty_window(); // 10 items × 50px = 500px total, 200px viewport. let state = ListState::new(10, crate::ListAlignment::Top, px(0.)); struct TestView(ListState); impl Render for TestView { fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { list(self.0.clone(), |_, _, _| { ``` -------------------------------- ### new Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SystemWindowTabController.html Creates a new instance of the window tab controller. ```APIDOC ## new ### Description Creates a new instance of the window tab controller. ### Method `pub fn new() -> Self` ### Parameters None ### Returns - `Self` - A new `SystemWindowTabController` instance. ``` -------------------------------- ### split: Simple patterns Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Demonstrates `split` with various patterns: a `char`, a `&str`, and closures. Shows that if there are no matches, the full string is returned as the only item. ```rust let v: Vec<&str> = "Mary had a little lamb".split(' ').collect(); assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]); let v: Vec<&str> = "".split('X').collect(); assert_eq!(v, [""]); let v: Vec<&str> = "lionXXtigerXleopard".split('X').collect(); assert_eq!(v, ["lion", "", "tiger", "leopard"]); let v: Vec<&str> = "lion::tiger::leopard".split("::").collect(); assert_eq!(v, ["lion", "tiger", "leopard"]); let v: Vec<&str> = "AABBCC".split("DD").collect(); assert_eq!(v, ["AABBCC"]); let v: Vec<&str> = "abc1def2ghi".split(char::is_numeric).collect(); assert_eq!(v, ["abc", "def", "ghi"]); let v: Vec<&str> = "lionXtigerXleopard".split(char::is_uppercase).collect(); assert_eq!(v, ["lion", "tiger", "leopard"]); ``` -------------------------------- ### Hsla::alpha Examples Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Hsla.html Examples demonstrating how to set a new alpha value for an HSLA color. ```rust let color = gpui::red(); let red_color = color.alpha(0.25); assert_eq!(red_color.a, 0.25); ``` ```rust use gpui::hsla; let color = hsla(0.7, 1.0, 0.5, 0.7); // A saturated blue let faded_color = color.alpha(0.25); assert_eq!(faded_color.a, 0.25); ``` -------------------------------- ### new Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.WindowTextSystem.html Creates a new WindowTextSystem with the given TextSystem. ```APIDOC ## new ### Description Creates a new WindowTextSystem with the given TextSystem. ### Method new ### Parameters - **text_system** (Arc) - Required - The TextSystem to use. ### Returns Self - A new WindowTextSystem instance. ``` -------------------------------- ### Hsla::opacity Examples Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Hsla.html Examples demonstrating how to multiply the alpha value of an HSLA color by a factor. ```rust let color = gpui::red(); let faded_color = color.opacity(0.5); assert_eq!(faded_color.a, 0.5); ``` ```rust use gpui::hsla; let color = hsla(0.7, 1.0, 0.5, 0.7); // A saturated blue let faded_color = color.opacity(0.16); assert!((faded_color.a - 0.112).abs() < 1e-6); ``` -------------------------------- ### Create an entity with App::new Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/_ownership_and_data_flow.rs.html Demonstrates initializing an entity within the application run loop, which grants ownership to the App. ```rust # use gpui::{App, AppContext, Application, Entity}; # struct Counter { # count: usize, # } gpui_platform::application().run(|cx: &mut App| { let _counter: Entity = cx.new(|_cx| Counter { count: 0 }); // ... }); ``` -------------------------------- ### split_at example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Shows how to divide a string slice into two parts at a byte offset using `split_at`. The offset must be on a UTF-8 boundary; otherwise it panics. ```rust let s = "Per Martin-Löf"; let (first, last) = s.split_at(3); assert_eq!("Per", first); assert_eq!(" Martin-Löf", last); ``` -------------------------------- ### trim_left_matches examples Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples of using trim_left_matches with various patterns. Note that this method is deprecated since 1.33.0. ```rust assert_eq!("11foo1bar11".trim_left_matches('1'), "foo1bar11"); assert_eq!("123foo1bar123".trim_left_matches(char::is_numeric), "foo1bar123"); let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_left_matches(x), "foo1bar12"); ``` -------------------------------- ### WindowTextSystem::new constructor Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/text_system.rs.html Creates a new WindowTextSystem instance with the provided TextSystem. ```rust impl WindowTextSystem { /// Create a new WindowTextSystem with the given TextSystem. pub fn new(text_system: Arc) -> Self { Self { line_layout_cache: LineLayoutCache::new(text_system.platform_text_system.clone()), text_system, } } ``` -------------------------------- ### Edges Initialization Example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Edges.html Basic usage of the Edges struct to define edge sizes. ```rust let edges = Edges { top: 10.0, right: 20.0, bottom: 30.0, left: 40.0, }; assert_eq!(edges.top, 10.0); assert_eq!(edges.right, 20.0); assert_eq!(edges.bottom, 30.0); assert_eq!(edges.left, 40.0); ``` -------------------------------- ### trim_suffix example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples of using the nightly-only trim_suffix method, which returns the original string if the suffix is absent. ```rust #![feature(trim_prefix_suffix)] // Suffix present - removes it assert_eq!("bar:foo".trim_suffix(":foo"), "bar"); assert_eq!("foofoo".trim_suffix("foo"), "foo"); // Suffix absent - returns original string assert_eq!("bar:foo".trim_suffix("bar"), "bar:foo"); ``` -------------------------------- ### trim_prefix example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Examples of using the nightly-only trim_prefix method, which returns the original string if the prefix is absent. ```rust #![feature(trim_prefix_suffix)] // Prefix present - removes it assert_eq!("foo:bar".trim_prefix("foo:"), "bar"); assert_eq!("foofoo".trim_prefix("foo"), "foo"); // Prefix absent - returns original string assert_eq!("foo:bar".trim_prefix("bar"), "foo:bar"); // Method chaining example assert_eq!("".trim_prefix('<').trim_suffix('>'), "https://example.com/"); ``` -------------------------------- ### KeyBinding::new Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.KeyBinding.html Constructs a new keybinding from the given keystrokes, action, and optional context. Panics on parse error. ```APIDOC ## KeyBinding::new ### Description Construct a new keybinding from the given data. Panics on parse error. ### Signature pub fn new(keystrokes: &str, action: A, context: Option<&str>) -> Self ### Parameters - **keystrokes** (&str) - The keystrokes for the keybinding. - **action** (A) - The action to associate with the keybinding. - **context** (Option<&str>) - Optional context for the keybinding. ### Returns - **Self** - The constructed KeyBinding. ### Panics Panics on parse error. ``` -------------------------------- ### Size::min Method Example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Size.html Compares two Size instances and returns a new Size containing the minimum width and height. ```rust let size1 = Size { width: 30, height: 40 }; let size2 = Size { width: 50, height: 20 }; let min_size = size1.min(&size2); assert_eq!(min_size, Size { width: 30, height: 20 }); ``` -------------------------------- ### new(platform_text_system: Arc) -> Self Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.TextSystem.html Creates a new TextSystem with the given platform text system. ```APIDOC ## new(platform_text_system: Arc) -> Self ### Description Creates a new TextSystem with the given platform text system. ### Method new ### Parameters - **platform_text_system** (Arc) - Required - The platform text system to use. ### Returns - **Self** - The new TextSystem instance. ``` -------------------------------- ### split: Separators at start or end Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Shows that separators at the start or end of a string are neighbored by empty strings. ```rust let d: Vec<_> = "010".split("0").collect(); assert_eq!(d, &["", "1", ""]); ``` -------------------------------- ### Creating Bounds from Corners Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.Bounds.html Example showing how to construct a Bounds object from top-left and bottom-right corner points. ```rust let top_left = Point { x: 0, y: 0 }; let bottom_right = Point { x: 10, y: 10 }; let bounds = Bounds::from_corners(top_left, bottom_right); assert_eq!(bounds.origin, top_left); assert_eq!(bounds.size.width, 10); assert_eq!(bounds.size.height, 10); ``` -------------------------------- ### str::is_empty example Source: https://docs.rs/gpui-pre/0.3.4/gpui/struct.SharedUri.html Checks if a string has zero length. The example shows that an empty string is empty, and a non-empty string is not. ```rust let s = ""; assert!(s.is_empty()); let s = "not empty"; assert!(!s.is_empty()); ``` -------------------------------- ### SystemWindowTab::new Source: https://docs.rs/gpui-pre/0.3.4/src/gpui/app.rs.html Creates a new instance of the window tab. ```APIDOC ## SystemWindowTab::new ### Description Creates a new instance of the window tab. ### Method Signature pub fn new(title: SharedString, handle: AnyWindowHandle) -> Self ### Parameters - **title** (SharedString) - Required - The title of the window tab. - **handle** (AnyWindowHandle) - Required - The handle to the window. ### Returns - **Self** - A new SystemWindowTab instance. ``` -------------------------------- ### Configure gpui_platform for Linux/FreeBSD Source: https://docs.rs/gpui-pre/0.3.4/gpui/index.html Enables wayland and x11 windowing backends for Linux/FreeBSD; these features also compile the renderer and text system. ```toml gpui_platform = { version = "*", features = ["wayland", "x11"] } ```