diff --git a/corcovado/src/event_imp.rs b/corcovado/src/event_imp.rs index 34eb3eb8..96cbe8ef 100644 --- a/corcovado/src/event_imp.rs +++ b/corcovado/src/event_imp.rs @@ -14,12 +14,12 @@ use {Poll, Token}; /// There are two types of `Evented` values. /// /// * **System** handles, which are backed by sockets or other system handles. -/// These `Evented` handles will be monitored by the system selector. In this -/// case, an implementation of `Evented` delegates to a lower level handle. +/// These `Evented` handles will be monitored by the system selector. In this +/// case, an implementation of `Evented` delegates to a lower level handle. /// /// * **User** handles, which are driven entirely in user space using -/// [`Registration`] and [`SetReadiness`]. In this case, the implementer takes -/// responsibility for driving the readiness state changes. +/// [`Registration`] and [`SetReadiness`]. In this case, the implementer takes +/// responsibility for driving the readiness state changes. /// /// [`Poll`]: ../struct.Poll.html /// [`Registration`]: ../struct.Registration.html diff --git a/frontends/rioterm/src/context/grid.rs b/frontends/rioterm/src/context/grid.rs index 3237a615..f4fb8041 100644 --- a/frontends/rioterm/src/context/grid.rs +++ b/frontends/rioterm/src/context/grid.rs @@ -212,6 +212,7 @@ impl ContextGrid { target.push(Object::RichText(RichText { id: item.val.rich_text_id, position: [self.margin.x, self.margin.top_y], + lines: None, })); } } else { @@ -234,6 +235,7 @@ impl ContextGrid { objects.push(Object::RichText(RichText { id: item.val.rich_text_id, position: [self.margin.x, self.margin.top_y], + lines: None, })); } } else { @@ -341,6 +343,7 @@ impl ContextGrid { objects.push(Object::RichText(RichText { id: item.val.rich_text_id, position: [margin.x, margin.top_y], + lines: None, })); let scale = self.inner[self.current].val.dimension.dimension.scale; @@ -1109,6 +1112,7 @@ pub mod test { vec![Object::RichText(RichText { id: rich_text_id, position: [10., 20.], + lines: None, },)] ); } @@ -1174,6 +1178,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); grid.split_right(second_context); @@ -1184,12 +1189,14 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [0.0, 0.0], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [0.0, 800.0], [598., 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [598.0, 0.0], [1.0, 800.0]), Object::RichText(RichText { id: second_context_id, - position: [600., 0.0] + position: [600., 0.0], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [600.0, 800.0], [600.0, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [1200.0, 0.0], [1.0, 800.0]), @@ -1219,18 +1226,21 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [0.0, 0.0], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [0.0, 800.0], [598., 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [598.0, 0.0], [1.0, 800.0]), Object::RichText(RichText { id: second_context_id, - position: [600.0, 0.0] + position: [600.0, 0.0], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [600.0, 800.0], [298.0, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [898.0, 0.0], [1.0, 800.0]), Object::RichText(RichText { id: third_context_id, - position: [900.0, 0.0] + position: [900.0, 0.0], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [900.0, 800.0], [300.0, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [1200.0, 0.0], [1.0, 800.0]), @@ -1299,6 +1309,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [margin.x, margin.top_y], + lines: None, },)] ); grid.split_right(second_context); @@ -1332,12 +1343,14 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [margin.x, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: second_context_id, - position: [167.0, margin.top_y] + position: [167.0, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [145.0, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [312.0, margin.top_y], [1.0, 300.0]), @@ -1367,18 +1380,21 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [margin.x, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: second_context_id, - position: [167.0, margin.top_y] + position: [167.0, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [65.5, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [232.5, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: third_context_id, - position: [236.5, margin.top_y] + position: [236.5, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [236.5, 330.0], [67.5, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [304.0, margin.top_y], [1.0, 300.0]), @@ -1432,24 +1448,28 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [margin.x, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: second_context_id, - position: [167.0, margin.top_y] + position: [167.0, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [25.75, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [192.75, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: fourth_context_id, - position: [196.75, margin.top_y] + position: [196.75, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [196.75, 330.0], [27.75, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [224.5, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: third_context_id, - position: [228.5, margin.top_y] + position: [228.5, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [228.5, 330.0], [67.5, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [296.0, margin.top_y], [1.0, 300.0]), @@ -1518,6 +1538,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [margin.x, margin.top_y], + lines: None, },)] ); @@ -1710,6 +1731,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [margin.x, margin.top_y], + lines: None, },)] ); @@ -1835,6 +1857,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); grid.split_down(second_context); @@ -1845,11 +1868,13 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [0.0, 0.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), Object::RichText(RichText { id: second_context_id, - position: [0.0, 202.0] + position: [0.0, 202.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), @@ -1909,18 +1934,21 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [0.0, 0.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [298.0, 1.0]), Object::RichText(RichText { id: second_context_id, - position: [0.0, 202.0] + position: [0.0, 202.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), create_border([0.0, 0.0, 1.0, 0.0], [298.0, 0.0], [1.0, 198.0]), Object::RichText(RichText { id: third_context_id, - position: [302.0, 0.0] + position: [302.0, 0.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [302.0, 198.0], [300.0, 1.0]), create_border([0.0, 0.0, 1.0, 0.0], [602.0, 0.0], [1.0, 198.0]), @@ -1989,6 +2017,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [margin.x, margin.top_y], + lines: None, },)] ); grid.split_right(second_context); @@ -2068,24 +2097,28 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [margin.x, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.], [143.0, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: second_context_id, - position: [167.0, margin.top_y] + position: [167.0, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.], [25.75, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [192.75, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: fourth_context_id, - position: [196.75, margin.top_y] + position: [196.75, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [196.75, 330.], [27.75, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [224.5, margin.top_y], [1.0, 300.0]), Object::RichText(RichText { id: third_context_id, - position: [228.5, margin.top_y] + position: [228.5, margin.top_y], + lines: None, },), create_border([1.0, 0.0, 0.0, 0.0], [228.5, 330.], [67.5, 1.0]), create_border([1.0, 0.0, 0.0, 0.0], [296.0, margin.top_y], [1.0, 300.0]), @@ -2187,6 +2220,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); grid.split_down(second_context); @@ -2197,11 +2231,13 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [0.0, 0.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), Object::RichText(RichText { id: second_context_id, - position: [0.0, 202.0] + position: [0.0, 202.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), @@ -2232,16 +2268,19 @@ pub mod test { Object::RichText(RichText { id: first_context_id, position: [0.0, 0.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), Object::RichText(RichText { id: second_context_id, - position: [0.0, 202.0] + position: [0.0, 202.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 300.0], [600.0, 1.0]), Object::RichText(RichText { id: third_context_id, - position: [0.0, 304.0] + position: [0.0, 304.0], + lines: None, },), create_border([0.0, 0.0, 1.0, 0.0], [0.0, 404.0], [600.0, 1.0]), create_border([0.0, 0.0, 1.0, 0.0], [600.0, 304.0], [1.0, 100.0]), @@ -2327,6 +2366,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -2430,6 +2470,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -2521,6 +2562,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -2618,6 +2660,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -2729,6 +2772,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -2820,6 +2864,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -2917,6 +2962,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -3088,6 +3134,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -3305,6 +3352,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); @@ -3621,6 +3669,7 @@ pub mod test { vec![Object::RichText(RichText { id: first_context_id, position: [0., 0.], + lines: None, },)] ); diff --git a/frontends/rioterm/src/renderer/navigation.rs b/frontends/rioterm/src/renderer/navigation.rs index 0fd36eb0..d1437255 100644 --- a/frontends/rioterm/src/renderer/navigation.rs +++ b/frontends/rioterm/src/renderer/navigation.rs @@ -266,6 +266,7 @@ impl ScreenNavigation { objects.push(Object::RichText(RichText { id: tab, position: [initial_position_x + 4., position_y], + lines: None, })); initial_position_x += name_modifier + 40.; diff --git a/frontends/rioterm/src/renderer/search.rs b/frontends/rioterm/src/renderer/search.rs index 6d5029e1..6d071512 100644 --- a/frontends/rioterm/src/renderer/search.rs +++ b/frontends/rioterm/src/renderer/search.rs @@ -22,5 +22,6 @@ pub fn draw_search_bar( objects.push(Object::RichText(RichText { id: rich_text_id, position: [4., position_y], + lines: None, })); } diff --git a/frontends/rioterm/src/router/routes/assistant.rs b/frontends/rioterm/src/router/routes/assistant.rs index b26e7a65..cbd180ad 100644 --- a/frontends/rioterm/src/router/routes/assistant.rs +++ b/frontends/rioterm/src/router/routes/assistant.rs @@ -120,17 +120,20 @@ pub fn screen( objects.push(Object::RichText(RichText { id: paragraph, position: [70., context_dimension.margin.top_y + 140.], + lines: None, })); } objects.push(Object::RichText(RichText { id: heading, position: [70., context_dimension.margin.top_y + 30.], + lines: None, })); objects.push(Object::RichText(RichText { id: paragraph_action, position: [70., context_dimension.margin.top_y + 70.], + lines: None, })); sugarloaf.set_objects(objects); diff --git a/frontends/rioterm/src/router/routes/dialog.rs b/frontends/rioterm/src/router/routes/dialog.rs index 7d53c358..7af1cc1f 100644 --- a/frontends/rioterm/src/router/routes/dialog.rs +++ b/frontends/rioterm/src/router/routes/dialog.rs @@ -64,6 +64,7 @@ pub fn screen( objects.push(Object::RichText(RichText { id: heading, position: [70., context_dimension.margin.top_y + 30.], + lines: None, })); let confirm_line = content.sel(confirm); @@ -83,6 +84,7 @@ pub fn screen( objects.push(Object::RichText(RichText { id: confirm, position: [70., context_dimension.margin.top_y + 100.], + lines: None, })); let quit_line = content.sel(quit); @@ -102,6 +104,7 @@ pub fn screen( objects.push(Object::RichText(RichText { id: quit, position: [70., context_dimension.margin.top_y + 140.], + lines: None, })); sugarloaf.set_objects(objects); diff --git a/frontends/rioterm/src/router/routes/welcome.rs b/frontends/rioterm/src/router/routes/welcome.rs index 0356ac50..078552bd 100644 --- a/frontends/rioterm/src/router/routes/welcome.rs +++ b/frontends/rioterm/src/router/routes/welcome.rs @@ -116,16 +116,19 @@ pub fn screen(sugarloaf: &mut Sugarloaf, context_dimension: &ContextDimension) { objects.push(Object::RichText(RichText { id: heading, position: [70., context_dimension.margin.top_y + 30.], + lines: None, })); objects.push(Object::RichText(RichText { id: paragraph_action, position: [70., context_dimension.margin.top_y + 70.], + lines: None, })); objects.push(Object::RichText(RichText { id: paragraph, position: [70., context_dimension.margin.top_y + 140.], + lines: None, })); sugarloaf.set_objects(objects); diff --git a/rio-window/src/event.rs b/rio-window/src/event.rs index 3bac43bd..3acfec0e 100644 --- a/rio-window/src/event.rs +++ b/rio-window/src/event.rs @@ -590,11 +590,11 @@ pub struct KeyEvent { /// ## Caveats /// /// - Certain niche hardware will shuffle around physical key positions, e.g. a keyboard that - /// implements DVORAK in hardware (or firmware) + /// implements DVORAK in hardware (or firmware) /// - Your application will likely have to handle keyboards which are missing keys that your - /// own keyboard has. + /// own keyboard has. /// - Certain `KeyCode`s will move between a couple of different positions depending on what - /// layout the keyboard was manufactured to support. + /// layout the keyboard was manufactured to support. /// /// **Because of these caveats, it is important that you provide users with a way to configure /// most (if not all) keybinds in your application.** @@ -617,7 +617,7 @@ pub struct KeyEvent { /// This has two use cases: /// - Allows querying whether the current input is a Dead key. /// - Allows handling key-bindings on platforms which don't - /// support [`key_without_modifiers`]. + /// support [`key_without_modifiers`]. /// /// If you use this field (or [`key_without_modifiers`] for that matter) for keyboard /// shortcuts, **it is important that you provide users with a way to configure your @@ -626,7 +626,7 @@ pub struct KeyEvent { /// /// ## Platform-specific /// - **Web:** Dead keys might be reported as the real key instead - /// of `Dead` depending on the browser/OS. + /// of `Dead` depending on the browser/OS. /// /// [`key_without_modifiers`]: crate::platform::modifier_supplement::KeyEventExtModifierSupplement::key_without_modifiers pub logical_key: keyboard::Key, diff --git a/rio-window/src/platform/pump_events.rs b/rio-window/src/platform/pump_events.rs index cb759616..835b00f4 100644 --- a/rio-window/src/platform/pump_events.rs +++ b/rio-window/src/platform/pump_events.rs @@ -51,19 +51,19 @@ pub trait EventLoopExtPumpEvents { /// buffered and handled outside of Winit include: /// - `RedrawRequested` events, used to schedule rendering. /// - /// macOS for example uses a `drawRect` callback to drive rendering - /// within applications and expects rendering to be finished before - /// the `drawRect` callback returns. + /// macOS for example uses a `drawRect` callback to drive rendering + /// within applications and expects rendering to be finished before + /// the `drawRect` callback returns. /// - /// For portability it's strongly recommended that applications should - /// keep their rendering inside the closure provided to Winit. + /// For portability it's strongly recommended that applications should + /// keep their rendering inside the closure provided to Winit. /// - Any lifecycle events, such as `Suspended` / `Resumed`. /// - /// The handling of these events needs to be synchronized with the - /// operating system and it would never be appropriate to buffer a - /// notification that your application has been suspended or resumed and - /// then handled that later since there would always be a chance that - /// other lifecycle events occur while the event is buffered. + /// The handling of these events needs to be synchronized with the + /// operating system and it would never be appropriate to buffer a + /// notification that your application has been suspended or resumed and + /// then handled that later since there would always be a chance that + /// other lifecycle events occur while the event is buffered. /// /// ## Supported Platforms /// @@ -75,20 +75,20 @@ pub trait EventLoopExtPumpEvents { /// ## Unsupported Platforms /// /// - **Web:** This API is fundamentally incompatible with the event-based way in which - /// Web browsers work because it's not possible to have a long-running external - /// loop that would block the browser and there is nothing that can be - /// polled to ask for new new events. Events are delivered via callbacks based - /// on an event loop that is internal to the browser itself. + /// Web browsers work because it's not possible to have a long-running external + /// loop that would block the browser and there is nothing that can be + /// polled to ask for new new events. Events are delivered via callbacks based + /// on an event loop that is internal to the browser itself. /// - **iOS:** It's not possible to stop and start an `NSApplication` repeatedly on iOS so - /// there's no way to support the same approach to polling as on MacOS. + /// there's no way to support the same approach to polling as on MacOS. /// /// ## Platform-specific /// /// - **Windows**: The implementation will use `PeekMessage` when checking for window messages - /// to avoid blocking your external event loop. + /// to avoid blocking your external event loop. /// /// - **MacOS**: The implementation works in terms of stopping the global application whenever - /// the application `RunLoop` indicates that it is preparing to block and wait for new events. + /// the application `RunLoop` indicates that it is preparing to block and wait for new events. /// /// This is very different to the polling APIs that are available on other /// platforms (the lower level polling primitives on MacOS are private diff --git a/rio-window/src/window.rs b/rio-window/src/window.rs index f32dbbf2..456de8f8 100644 --- a/rio-window/src/window.rs +++ b/rio-window/src/window.rs @@ -416,7 +416,7 @@ impl WindowAttributes { /// ## Platform-specific /// /// - **macOS**: if `false`, [`NSWindowSharingNone`] is used but doesn't completely - /// prevent all apps from reading the window content, for instance, QuickTime. + /// prevent all apps from reading the window content, for instance, QuickTime. /// - **iOS / Android / Web / x11 / Orbital:** Ignored. /// /// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone @@ -512,9 +512,9 @@ impl Window { /// provided by XRandR. /// /// If `WINIT_X11_SCALE_FACTOR` is set to `randr`, it'll ignore the `Xft.dpi` field and use - /// the XRandR scaling method. Generally speaking, you should try to configure the - /// standard system variables to do what you want before resorting to - /// `WINIT_X11_SCALE_FACTOR`. + /// the XRandR scaling method. Generally speaking, you should try to configure the + /// standard system variables to do what you want before resorting to + /// `WINIT_X11_SCALE_FACTOR`. /// - **Wayland:** The scale factor is suggested by the compositor for each window individually /// by using the wp-fractional-scale protocol if available. Falls back to integer-scale /// factors otherwise. @@ -1419,7 +1419,7 @@ impl Window { /// ## Platform-specific /// /// - **macOS**: if `false`, [`NSWindowSharingNone`] is used but doesn't completely - /// prevent all apps from reading the window content, for instance, QuickTime. + /// prevent all apps from reading the window content, for instance, QuickTime. /// - **iOS / Android / x11 / Wayland / Web / Orbital:** Unsupported. /// /// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone diff --git a/sugarloaf/examples/layer.rs b/sugarloaf/examples/layer.rs index 25d66343..971553bb 100644 --- a/sugarloaf/examples/layer.rs +++ b/sugarloaf/examples/layer.rs @@ -157,6 +157,7 @@ impl ApplicationHandler for Application { Object::RichText(RichText { id: self.rich_text, position: [10., 10.], + lines: None, }), Object::Quad(Quad { position: [10., 10.], @@ -167,6 +168,7 @@ impl ApplicationHandler for Application { Object::RichText(RichText { id: self.second_rich_text, position: [10., 60.], + lines: None, }), Object::Quad(Quad { position: [10., 80.], @@ -183,6 +185,7 @@ impl ApplicationHandler for Application { Object::RichText(RichText { id: self.rich_text, position: [100., 100.], + lines: None, }), ]); sugarloaf.render(); diff --git a/sugarloaf/examples/line_height.rs b/sugarloaf/examples/line_height.rs index 6c85b208..b1180a0f 100644 --- a/sugarloaf/examples/line_height.rs +++ b/sugarloaf/examples/line_height.rs @@ -198,6 +198,7 @@ impl ApplicationHandler for Application { sugarloaf.set_objects(vec![Object::RichText(RichText { id: 0, position: [10., 0.], + lines: None, })]); sugarloaf.render(); event_loop.set_control_flow(ControlFlow::Wait); diff --git a/sugarloaf/examples/multi_text.rs b/sugarloaf/examples/multi_text.rs index aa416f9d..ff805cda 100644 --- a/sugarloaf/examples/multi_text.rs +++ b/sugarloaf/examples/multi_text.rs @@ -123,6 +123,7 @@ impl ApplicationHandler for Application { Object::RichText(RichText { id: self.rich_texts[0], position: [5., 5.], + lines: None, }), Object::Quad(Quad { color: [1.0, 0.5, 0.5, 0.5], @@ -138,6 +139,7 @@ impl ApplicationHandler for Application { Object::RichText(RichText { id: self.rich_texts[1], position: [220., 5.], + lines: None, }), Object::Quad(Quad { color: [1.0, 0.5, 0.5, 0.5], @@ -153,6 +155,7 @@ impl ApplicationHandler for Application { Object::RichText(RichText { id: self.rich_texts[2], position: [440., 5.], + lines: None, }), ]; diff --git a/sugarloaf/examples/text.rs b/sugarloaf/examples/text.rs index fa074725..da9587f8 100644 --- a/sugarloaf/examples/text.rs +++ b/sugarloaf/examples/text.rs @@ -263,6 +263,7 @@ impl ApplicationHandler for Application { sugarloaf.set_objects(vec![Object::RichText(RichText { id: self.rich_text, position: [10., 0.], + lines: None, })]); sugarloaf.render(); event_loop.set_control_flow(ControlFlow::Wait); diff --git a/sugarloaf/src/components/rich_text/mod.rs b/sugarloaf/src/components/rich_text/mod.rs index 1f59d4e6..ef311a1a 100644 --- a/sugarloaf/src/components/rich_text/mod.rs +++ b/sugarloaf/src/components/rich_text/mod.rs @@ -11,6 +11,7 @@ use crate::font::FontLibrary; use crate::layout::{BuilderStateUpdate, RichTextLayout, SugarDimensions}; use crate::sugarloaf::graphics::GraphicRenderRequest; use crate::Graphics; +use crate::RichTextLinesRange; use compositor::{Compositor, Rect, Vertex}; use std::collections::HashSet; use std::{borrow::Cow, mem}; @@ -274,6 +275,7 @@ impl RichTextBrush { self.draw_layout( rich_text.id, // Pass the rich text ID for caching &rt.lines, + &rich_text.lines, Some(position), library, Some(&rt.layout), @@ -299,19 +301,25 @@ impl RichTextBrush { self.comp.begin(); let lines = vec![render_data.clone()]; - self.draw_layout(0, &lines, None, font_library, None, graphics) + self.draw_layout(0, &lines, &None, None, font_library, None, graphics) } #[inline] + #[allow(clippy::too_many_arguments)] fn draw_layout( &mut self, rich_text_id: usize, lines: &Vec, + selected_lines: &Option, pos: Option<(f32, f32)>, font_library: &FontLibrary, rte_layout: Option<&RichTextLayout>, graphics: &mut Graphics, ) -> Option { + if lines.is_empty() { + return None; + } + // let start = std::time::Instant::now(); let comp = &mut self.comp; let caches = (&mut self.images, &mut self.glyphs); @@ -323,7 +331,7 @@ impl RichTextBrush { let is_dimensions_only = pos.is_none() || rte_layout.is_none(); // For dimensions mode, we only process the first line - let lines_to_process = if is_dimensions_only && !lines.is_empty() { + let lines_to_process = if is_dimensions_only { std::slice::from_ref(&lines[0]) } else { lines.as_slice() @@ -362,12 +370,25 @@ impl RichTextBrush { let descent = first_run.descent.round(); let leading = (first_run.leading).round() * 2.; + // Initialize from first run if available + current_font = first_run.span.font_id; + current_font_size = first_run.size; + // Calculate line height with modifier if available let line_height_without_mod = ascent + descent + leading; let line_height_mod = rte_layout.map_or(1.0, |layout| layout.line_height); let line_height = line_height_without_mod * line_height_mod; - for (line_idx, line) in lines_to_process.iter().enumerate() { + let skip_count = selected_lines.map_or(0, |range| range.start); + let take_count = selected_lines + .map_or(lines_to_process.len(), |range| range.end - range.start); + + for (line_idx, line) in lines_to_process + .iter() + .enumerate() + .skip(skip_count) + .take(take_count) + { if line.render_data.runs.is_empty() { continue; } diff --git a/sugarloaf/src/sugarloaf/primitives.rs b/sugarloaf/src/sugarloaf/primitives.rs index 4595cc94..39c49f28 100644 --- a/sugarloaf/src/sugarloaf/primitives.rs +++ b/sugarloaf/src/sugarloaf/primitives.rs @@ -28,10 +28,17 @@ pub struct ImageProperties { pub y: f32, } +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct RichTextLinesRange { + pub start: usize, + pub end: usize, +} + #[derive(Clone, Copy, Debug, PartialEq)] pub struct RichText { pub id: usize, pub position: [f32; 2], + pub lines: Option, } #[derive(Clone, Debug, PartialEq)]