Starts a new frame, returning a [`Ui`] handle for building the element tree.
(
&mut self,
)
| 552 | |
| 553 | /// Starts a new frame, returning a [`Ui`] handle for building the element tree. |
| 554 | pub fn begin( |
| 555 | &mut self, |
| 556 | ) -> Ui<'_, CustomElementData> { |
| 557 | jobs::poll_completions(); |
| 558 | |
| 559 | if !self.headless { |
| 560 | self.context.set_layout_dimensions(Dimensions::new( |
| 561 | macroquad::prelude::screen_width(), |
| 562 | macroquad::prelude::screen_height(), |
| 563 | )); |
| 564 | |
| 565 | // Update timing |
| 566 | self.context.current_time = macroquad::prelude::get_time(); |
| 567 | self.context.frame_delta_time = macroquad::prelude::get_frame_time(); |
| 568 | } |
| 569 | |
| 570 | // Update blink timers for text inputs |
| 571 | self.context.update_text_input_blink_timers(); |
| 572 | |
| 573 | // Auto-update pointer state from macroquad |
| 574 | if !self.headless { |
| 575 | let (mx, my) = macroquad::prelude::mouse_position(); |
| 576 | let is_down = macroquad::prelude::is_mouse_button_down( |
| 577 | macroquad::prelude::MouseButton::Left, |
| 578 | ); |
| 579 | |
| 580 | // Check shift state for text input click-to-cursor |
| 581 | // Must happen AFTER set_pointer_state, since that's what creates pending_text_click. |
| 582 | self.context.set_pointer_state(Vector2::new(mx, my), is_down); |
| 583 | |
| 584 | { |
| 585 | use macroquad::prelude::{is_key_down, KeyCode}; |
| 586 | let shift = is_key_down(KeyCode::LeftShift) || is_key_down(KeyCode::RightShift); |
| 587 | if shift { |
| 588 | // If shift is held and there's a pending text click, update it |
| 589 | if let Some(ref mut pending) = self.context.pending_text_click { |
| 590 | pending.3 = true; |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | let (scroll_x, scroll_y) = macroquad::prelude::mouse_wheel(); |
| 596 | #[cfg(target_arch = "wasm32")] |
| 597 | const SCROLL_SPEED: f32 = 1.0; |
| 598 | #[cfg(not(target_arch = "wasm32"))] |
| 599 | const SCROLL_SPEED: f32 = 20.0; |
| 600 | // Shift+scroll wheel swaps vertical to horizontal scrolling |
| 601 | let scroll_shift = { |
| 602 | use macroquad::prelude::{is_key_down, KeyCode}; |
| 603 | is_key_down(KeyCode::LeftShift) || is_key_down(KeyCode::RightShift) |
| 604 | }; |
| 605 | let scroll_delta = if scroll_shift { |
| 606 | // Shift held: vertical scroll becomes horizontal |
| 607 | Vector2::new( |
| 608 | (scroll_x + scroll_y) * SCROLL_SPEED, |
| 609 | 0.0, |
| 610 | ) |
| 611 | } else { |