feat: build a resizable native developer workspace with console and network inspection
Verify Tessera GUI / verify (push) Failing after 7m12s
Verify Tessera GUI / verify (push) Failing after 7m12s
This commit is contained in:
+154
-18
@@ -6,14 +6,15 @@ use std::{
|
||||
use softbuffer::{Context, Surface};
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
dpi::{LogicalSize, PhysicalPosition},
|
||||
event::{ElementState, MouseButton, WindowEvent},
|
||||
event_loop::ActiveEventLoop,
|
||||
dpi::{LogicalPosition, LogicalSize, PhysicalPosition},
|
||||
event::{ElementState, Ime, MouseButton, MouseScrollDelta, WindowEvent},
|
||||
event_loop::{ActiveEventLoop, EventLoopProxy},
|
||||
keyboard::{Key, ModifiersState, NamedKey},
|
||||
window::{Window, WindowAttributes, WindowId},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
activity::Activity,
|
||||
developer_tools::DeveloperToolsState,
|
||||
document::NamespaceState,
|
||||
geometry::Point,
|
||||
@@ -24,6 +25,7 @@ use crate::{
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum AppEvent {
|
||||
DocumentUpdated,
|
||||
ConsoleFailed { message: String, source: String },
|
||||
}
|
||||
|
||||
pub struct TesseraApp {
|
||||
@@ -35,19 +37,29 @@ pub struct TesseraApp {
|
||||
layout: SceneLayout,
|
||||
pointer: Point,
|
||||
modifiers: ModifiersState,
|
||||
activity: Activity,
|
||||
}
|
||||
|
||||
impl TesseraApp {
|
||||
pub fn new(namespace: Arc<RwLock<NamespaceState>>) -> Self {
|
||||
pub fn new(
|
||||
namespace: Arc<RwLock<NamespaceState>>,
|
||||
activity: Activity,
|
||||
proxy: EventLoopProxy<AppEvent>,
|
||||
) -> Self {
|
||||
Self {
|
||||
window: None,
|
||||
context: None,
|
||||
surface: None,
|
||||
namespace,
|
||||
developer_tools: DeveloperToolsState::default(),
|
||||
developer_tools: {
|
||||
let mut state = DeveloperToolsState::default();
|
||||
state.proxy = Some(proxy);
|
||||
state
|
||||
},
|
||||
layout: SceneLayout::default(),
|
||||
pointer: Point::default(),
|
||||
modifiers: ModifiersState::default(),
|
||||
activity,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +84,7 @@ impl TesseraApp {
|
||||
}
|
||||
|
||||
fn handle_keyboard(&mut self, event: &winit::event::KeyEvent) {
|
||||
if event.state != ElementState::Pressed || event.repeat {
|
||||
if event.state != ElementState::Pressed {
|
||||
return;
|
||||
}
|
||||
let is_f12 = matches!(event.logical_key, Key::Named(NamedKey::F12));
|
||||
@@ -81,15 +93,62 @@ impl TesseraApp {
|
||||
let mac_shortcut = self.modifiers.super_key() && self.modifiers.alt_key() && is_i;
|
||||
let other_shortcut = self.modifiers.control_key() && self.modifiers.shift_key() && is_i;
|
||||
if is_f12 || mac_shortcut || other_shortcut {
|
||||
self.toggle_developer_tools();
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_click(&mut self) {
|
||||
let Some(node_id) = self.layout.developer_tools.node_at(self.pointer) else {
|
||||
if !event.repeat {
|
||||
self.toggle_developer_tools();
|
||||
}
|
||||
return;
|
||||
};
|
||||
self.developer_tools.selected_node_id = Some(node_id.to_owned());
|
||||
}
|
||||
if !self.developer_tools.open || self.developer_tools.focus.is_none() {
|
||||
return;
|
||||
}
|
||||
let command = self.modifiers.super_key() || self.modifiers.control_key();
|
||||
if command && let Key::Character(value) = &event.logical_key {
|
||||
match value.to_lowercase().as_str() {
|
||||
"a" => self.developer_tools.selection = true,
|
||||
"v" => {
|
||||
#[cfg(target_os = "macos")]
|
||||
if let Ok(output) = std::process::Command::new("pbpaste").output()
|
||||
&& output.status.success()
|
||||
{
|
||||
self.developer_tools
|
||||
.insert(&String::from_utf8_lossy(&output.stdout));
|
||||
}
|
||||
}
|
||||
"c" | "x" => {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use std::io::Write;
|
||||
let selected = self.developer_tools.selected_text();
|
||||
if !selected.is_empty()
|
||||
&& let Ok(mut child) = std::process::Command::new("pbcopy")
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
{
|
||||
if let Some(mut stdin) = child.stdin.take() {
|
||||
let _ = stdin.write_all(selected.as_bytes());
|
||||
}
|
||||
let _ = child.wait();
|
||||
if value.eq_ignore_ascii_case("x") {
|
||||
self.developer_tools.insert("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else if let Key::Named(key) = &event.logical_key {
|
||||
if !self.developer_tools.preedit.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.developer_tools
|
||||
.key(key, self.modifiers.shift_key(), command);
|
||||
} else if !command
|
||||
&& self.developer_tools.preedit.is_empty()
|
||||
&& let Some(text) = &event.text
|
||||
{
|
||||
let text: String = text.chars().filter(|c| !c.is_control()).collect();
|
||||
self.developer_tools.insert(&text);
|
||||
}
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
@@ -112,10 +171,18 @@ impl TesseraApp {
|
||||
size.height,
|
||||
window.scale_factor() as f32,
|
||||
&namespace.document,
|
||||
&self.developer_tools,
|
||||
&mut self.developer_tools,
|
||||
&self.activity,
|
||||
);
|
||||
drop(namespace);
|
||||
self.layout = scene.layout;
|
||||
let ime = self
|
||||
.developer_tools
|
||||
.ime_position(&self.layout.developer_tools);
|
||||
window.set_ime_cursor_area(
|
||||
LogicalPosition::new(ime.x as f64, ime.y as f64),
|
||||
LogicalSize::new(1.0, 19.0),
|
||||
);
|
||||
|
||||
surface
|
||||
.resize(width, height)
|
||||
@@ -145,6 +212,7 @@ impl ApplicationHandler<AppEvent> for TesseraApp {
|
||||
let surface =
|
||||
Surface::new(&context, window.clone()).expect("create software-rendering surface");
|
||||
|
||||
window.set_ime_allowed(true);
|
||||
self.window = Some(window.clone());
|
||||
self.context = Some(context);
|
||||
self.surface = Some(surface);
|
||||
@@ -154,6 +222,14 @@ impl ApplicationHandler<AppEvent> for TesseraApp {
|
||||
fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: AppEvent) {
|
||||
match event {
|
||||
AppEvent::DocumentUpdated => self.document_updated(),
|
||||
AppEvent::ConsoleFailed { message, source } => {
|
||||
self.developer_tools.input_error = format!("Request failed: {message}");
|
||||
if self.developer_tools.input.is_empty() {
|
||||
self.developer_tools.input = source;
|
||||
self.developer_tools.cursor = self.developer_tools.input.len();
|
||||
}
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,12 +254,72 @@ impl ApplicationHandler<AppEvent> for TesseraApp {
|
||||
WindowEvent::CursorMoved {
|
||||
position: PhysicalPosition { x, y },
|
||||
..
|
||||
} => self.pointer = Point::new(x as f32, y as f32),
|
||||
} => {
|
||||
let scale = window.scale_factor() as f32;
|
||||
let next = Point::new(x as f32 / scale, y as f32 / scale);
|
||||
let delta = Point::new(next.x - self.pointer.x, next.y - self.pointer.y);
|
||||
self.pointer = next;
|
||||
self.developer_tools.move_pointer(
|
||||
next,
|
||||
delta,
|
||||
&self.layout.developer_tools,
|
||||
window.inner_size().width as f32 / scale,
|
||||
);
|
||||
window.set_cursor(
|
||||
self.developer_tools
|
||||
.cursor_kind(&self.layout.developer_tools, next),
|
||||
);
|
||||
window.request_redraw();
|
||||
}
|
||||
WindowEvent::MouseInput {
|
||||
state: ElementState::Released,
|
||||
state,
|
||||
button: MouseButton::Left,
|
||||
..
|
||||
} => self.handle_click(),
|
||||
} => {
|
||||
if state == ElementState::Pressed {
|
||||
self.developer_tools.press(
|
||||
&self.layout.developer_tools,
|
||||
self.pointer,
|
||||
&self.activity,
|
||||
);
|
||||
} else {
|
||||
self.developer_tools.release();
|
||||
}
|
||||
window.request_redraw();
|
||||
}
|
||||
WindowEvent::MouseWheel { delta, .. } => {
|
||||
let (mut dx, mut dy) = match delta {
|
||||
MouseScrollDelta::LineDelta(x, y) => (x * 38.0, y * 38.0),
|
||||
MouseScrollDelta::PixelDelta(p) => (
|
||||
p.x as f32 / window.scale_factor() as f32,
|
||||
p.y as f32 / window.scale_factor() as f32,
|
||||
),
|
||||
};
|
||||
if self.modifiers.shift_key() && dx.abs() < 0.1 {
|
||||
dx = dy;
|
||||
dy = 0.0;
|
||||
}
|
||||
self.developer_tools
|
||||
.wheel(&self.layout.developer_tools, self.pointer, dx, dy);
|
||||
window.request_redraw();
|
||||
}
|
||||
WindowEvent::Ime(Ime::Preedit(value, _)) => {
|
||||
self.developer_tools.preedit = value;
|
||||
window.request_redraw();
|
||||
}
|
||||
WindowEvent::Ime(Ime::Commit(value)) => {
|
||||
self.developer_tools.preedit.clear();
|
||||
if self.developer_tools.open {
|
||||
self.developer_tools.insert(&value);
|
||||
}
|
||||
window.request_redraw();
|
||||
}
|
||||
WindowEvent::Focused(false) => {
|
||||
self.developer_tools.release();
|
||||
self.developer_tools.focus = None;
|
||||
self.developer_tools.preedit.clear();
|
||||
self.modifiers = ModifiersState::default();
|
||||
}
|
||||
WindowEvent::ModifiersChanged(modifiers) => self.modifiers = modifiers.state(),
|
||||
WindowEvent::KeyboardInput { event, .. } => self.handle_keyboard(&event),
|
||||
WindowEvent::RedrawRequested => self.redraw(),
|
||||
|
||||
Reference in New Issue
Block a user