word selection

This commit is contained in:
2025-11-22 15:33:36 -05:00
parent 2928482322
commit 4faa1b601a
3 changed files with 17 additions and 7 deletions

2
iris

Submodule iris updated: fc89826794...c24c517c60

View File

@@ -15,7 +15,7 @@ use openworm::{
rsc::DataDir,
};
use render::Renderer;
use std::sync::Arc;
use std::{sync::Arc, time::Instant};
use winit::{
event::{Ime, WindowEvent},
event_loop::{ActiveEventLoop, EventLoopProxy},
@@ -53,6 +53,7 @@ pub struct Client {
handle: AppHandle,
error: Option<WidgetId<WidgetPtr>>,
ime: usize,
last_click: Instant,
}
impl Client {
@@ -79,6 +80,7 @@ impl Client {
clipboard: Clipboard::new().unwrap(),
error: None,
ime: 0,
last_click: Instant::now(),
};
ui::init(&mut s);
s
@@ -118,10 +120,8 @@ impl Client {
pub fn window_event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
let input_changed = self.input.event(&event);
let cursor_state = self.cursor_state().clone();
if let Some(focus) = &self.focus
&& cursor_state.buttons.left.is_start()
{
self.ui.text(focus).deselect();
let old = self.focus.clone();
if cursor_state.buttons.left.is_start() {
self.focus = None;
}
if input_changed {
@@ -129,6 +129,11 @@ impl Client {
self.run_sensors(&cursor_state, window_size);
self.ui.run_sensors(&cursor_state, window_size);
}
if old != self.focus
&& let Some(old) = old
{
self.ui.text(&old).deselect();
}
match event {
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::RedrawRequested => {

View File

@@ -1,3 +1,5 @@
use std::time::{Duration, Instant};
use super::*;
pub fn error(ui: &mut Ui, msg: &str) -> WidgetId {
@@ -49,10 +51,13 @@ impl WidgetAttr<TextEdit> for Selectable {
}
fn select(id: WidgetId<TextEdit>, client: &mut Client, data: CursorData) {
let now = Instant::now();
let recent = (now - client.last_click) < Duration::from_millis(300);
client.last_click = now;
client
.ui
.text(&id)
.select(data.cursor, data.size, data.sense.is_dragging());
.select(data.cursor, data.size, data.sense.is_dragging(), recent);
if let Some(region) = client.ui.window_region(&id) {
client.handle.window.set_ime_allowed(true);
client.handle.window.set_ime_cursor_area(