Adds a third "Diagnostics" button to the bench screen's top row, filling the existing benchmark-report TextEdit (so the existing "Copy report" button and clipboard path work on it unchanged) with adapter identity, font resolution, atlas view count, wgpu errors seen so far and the frame report -- RUST.md's P0 box, "a named Diagnostics control ... copy this and send it to Iris." Logs the same font-resolution summary once at startup too. Wires BenchClient::on_insets_changed (the new AndroidAppState hook) to rebuild the top button row with Padding::top(insets.top), through a WidgetPtr slot (top_bar) so it can be swapped once the status-bar inset is known -- fixes RUST.md's P0 box, "the status-bar inset is not applied," where the two top buttons sat directly under the status bar because nothing in this file read insets().top at all. cargo fmt --all across the touched files. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
91 lines
3.2 KiB
Rust
91 lines
3.2 KiB
Rust
use crate::prelude::*;
|
|
use winit::{
|
|
event::{MouseButton, MouseScrollDelta, WindowEvent},
|
|
keyboard::{Key, NamedKey},
|
|
};
|
|
|
|
#[derive(Default)]
|
|
pub struct Input {
|
|
cursor: CursorState,
|
|
pub modifiers: Modifiers,
|
|
}
|
|
|
|
impl Input {
|
|
/// `scale_factor` converts winit's physical-pixel event coordinates
|
|
/// into the same logical units `UiRenderNode`'s window uniform now uses
|
|
/// (`default::render::UiRenderer::new`'s doc comment) -- without it,
|
|
/// a cursor position and the widget tree it's tested against would be
|
|
/// in two different units on any monitor whose scale factor isn't 1.0.
|
|
pub fn event(&mut self, event: &WindowEvent, scale_factor: f32) -> bool {
|
|
match event {
|
|
WindowEvent::CursorMoved { position, .. } => {
|
|
self.cursor.pos = Vec2::new(position.x as f32, position.y as f32) / scale_factor;
|
|
self.cursor.exists = true;
|
|
}
|
|
WindowEvent::MouseInput { state, button, .. } => {
|
|
let buttons = &mut self.cursor.buttons;
|
|
let pressed = state.is_pressed();
|
|
match button {
|
|
MouseButton::Left => buttons.left.update(pressed),
|
|
MouseButton::Right => buttons.right.update(pressed),
|
|
MouseButton::Middle => buttons.middle.update(pressed),
|
|
_ => (),
|
|
}
|
|
}
|
|
WindowEvent::MouseWheel { delta, .. } => {
|
|
let mut delta = match *delta {
|
|
MouseScrollDelta::LineDelta(x, y) => Vec2::new(x, y),
|
|
MouseScrollDelta::PixelDelta(pos) => {
|
|
Vec2::new(pos.x as f32, pos.y as f32) / scale_factor
|
|
}
|
|
};
|
|
if delta.x == 0.0 && self.modifiers.shift {
|
|
delta.x = delta.y;
|
|
delta.y = 0.0;
|
|
}
|
|
self.cursor.scroll_delta = delta;
|
|
}
|
|
WindowEvent::CursorLeft { .. } => {
|
|
self.cursor.exists = false;
|
|
self.modifiers.clear();
|
|
}
|
|
WindowEvent::KeyboardInput { event, .. } => {
|
|
if let Key::Named(named) = event.logical_key {
|
|
let pressed = event.state.is_pressed();
|
|
match named {
|
|
NamedKey::Control => {
|
|
self.modifiers.control = pressed;
|
|
}
|
|
NamedKey::Shift => {
|
|
self.modifiers.shift = pressed;
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
}
|
|
_ => return false,
|
|
}
|
|
true
|
|
}
|
|
|
|
pub fn end_frame(&mut self) {
|
|
self.cursor.end_frame();
|
|
}
|
|
}
|
|
|
|
impl DefaultUiState {
|
|
pub fn window_size(&self) -> Vec2 {
|
|
let window = self.renderer.window();
|
|
let size = window.inner_size();
|
|
let scale_factor = window.scale_factor() as f32;
|
|
Vec2::new(
|
|
size.width as f32 / scale_factor,
|
|
size.height as f32 / scale_factor,
|
|
)
|
|
}
|
|
|
|
pub fn cursor_state(&self) -> &CursorState {
|
|
&self.input.cursor
|
|
}
|
|
}
|