Iris: "the organization of the rust rewrite is a mess right now... there shouldn't be anything related to the app inside of iris. Iris is supposed to be the UI framework alone." And, on the crate count: "I'm confused why the app only code needs more than one crate though." Nine cargo workspaces become three, and the port's project code -- which sat in five places, four of them inside the framework -- becomes one crate, `ai-app`, in `app-rust/`: client-core -> app-rust/src/client iris/transcript-ui -> app-rust/src/ui iris/transcript-fixture -> app-rust/src/ui/fixture.rs + tests/ + touch/ iris/desktop-app -> app-rust/src/desktop + src/bin_desktop.rs iris/android-app -> app-rust/src/android + android-project/ android-shell -> app-rust/src/shell iris/ keeps core, macro, the iris crate, tabs-ui and rig-input, and now mentions no session, transcript, setup or server anywhere. Only two of the old splits had a reason that survived reading. event-model stays a crate at the repo root because server/ depends on it too, so a crate is what makes the backend and the app agree by construction. The two Android .so names looked like a hard constraint -- a package produces one library artifact -- until P2 turned out to already plan merging those two Android apps into one; both faces now come out of libai_app.so, picked apart by features so `--no-default-features --features shell` keeps wgpu, parley and iris out of the Compose app's APK. docs/RUST.md's "One app crate" has the rest, including what each remaining feature is for. DECISIONS.md and SUBAGENTS.md move into docs/ with everything else. Verified: ./run-tests.sh and `cd iris && cargo test` green, clippy and fmt clean in all five workspaces, `cargo ndk -t x86_64` links libai_app.so, build-apk.sh produces an APK that installs and launches on this checkout's emulator (Gl ... virgl, as expected), and the phone-sized headless screenshot renders the transcript unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
95 lines
3.5 KiB
Rust
95 lines
3.5 KiB
Rust
// `CursorState::time` is the sample's own time on every backend. winit
|
|
// carries no timestamp on a pointer event, so the moment it is handed to
|
|
// us is the closest measurement available here -- which is also what the
|
|
// drag code used to do for itself with `Instant::now()`, before Android's
|
|
// batched samples made the difference matter (see `sense::CursorState`).
|
|
use crate::prelude::*;
|
|
use std::time::Instant;
|
|
use winit::{
|
|
event::{MouseButton, MouseScrollDelta, WindowEvent},
|
|
keyboard::{Key, NamedKey},
|
|
};
|
|
|
|
#[derive(Default)]
|
|
pub struct Input {
|
|
cursor: CursorState,
|
|
pub modifiers: Modifiers,
|
|
}
|
|
|
|
impl Input {
|
|
/// winit's pointer coordinates are physical pixels, which is the
|
|
/// space the whole tree is laid out and hit-tested in -- see
|
|
/// `default::content_scale`. Nothing is converted here; `dp(...)`
|
|
/// resolves against the density at layout time instead.
|
|
pub fn event(&mut self, event: &WindowEvent) -> bool {
|
|
match event {
|
|
WindowEvent::CursorMoved { position, .. } => {
|
|
self.cursor.pos = Vec2::new(position.x as f32, position.y as f32);
|
|
self.cursor.exists = true;
|
|
self.cursor.time = Instant::now();
|
|
}
|
|
WindowEvent::MouseInput { state, button, .. } => {
|
|
self.cursor.time = Instant::now();
|
|
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),
|
|
};
|
|
if delta.x == 0.0 && self.modifiers.shift {
|
|
delta.x = delta.y;
|
|
delta.y = 0.0;
|
|
}
|
|
self.cursor.scroll_delta = delta;
|
|
self.cursor.time = Instant::now();
|
|
}
|
|
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 {
|
|
/// Physical pixels, matching `WindowEvent::Resized` (what
|
|
/// `UiRenderState::resize` is given) and the swapchain -- see
|
|
/// `default::content_scale`.
|
|
pub fn window_size(&self) -> Vec2 {
|
|
let size = self.renderer.window().inner_size();
|
|
Vec2::new(size.width as f32, size.height as f32)
|
|
}
|
|
|
|
pub fn cursor_state(&self) -> &CursorState {
|
|
&self.input.cursor
|
|
}
|
|
}
|