word selection
This commit is contained in:
2
iris
2
iris
Submodule iris updated: fc89826794...c24c517c60
@@ -15,7 +15,7 @@ use openworm::{
|
|||||||
rsc::DataDir,
|
rsc::DataDir,
|
||||||
};
|
};
|
||||||
use render::Renderer;
|
use render::Renderer;
|
||||||
use std::sync::Arc;
|
use std::{sync::Arc, time::Instant};
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{Ime, WindowEvent},
|
event::{Ime, WindowEvent},
|
||||||
event_loop::{ActiveEventLoop, EventLoopProxy},
|
event_loop::{ActiveEventLoop, EventLoopProxy},
|
||||||
@@ -53,6 +53,7 @@ pub struct Client {
|
|||||||
handle: AppHandle,
|
handle: AppHandle,
|
||||||
error: Option<WidgetId<WidgetPtr>>,
|
error: Option<WidgetId<WidgetPtr>>,
|
||||||
ime: usize,
|
ime: usize,
|
||||||
|
last_click: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
@@ -79,6 +80,7 @@ impl Client {
|
|||||||
clipboard: Clipboard::new().unwrap(),
|
clipboard: Clipboard::new().unwrap(),
|
||||||
error: None,
|
error: None,
|
||||||
ime: 0,
|
ime: 0,
|
||||||
|
last_click: Instant::now(),
|
||||||
};
|
};
|
||||||
ui::init(&mut s);
|
ui::init(&mut s);
|
||||||
s
|
s
|
||||||
@@ -118,10 +120,8 @@ impl Client {
|
|||||||
pub fn window_event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
|
pub fn window_event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
|
||||||
let input_changed = self.input.event(&event);
|
let input_changed = self.input.event(&event);
|
||||||
let cursor_state = self.cursor_state().clone();
|
let cursor_state = self.cursor_state().clone();
|
||||||
if let Some(focus) = &self.focus
|
let old = self.focus.clone();
|
||||||
&& cursor_state.buttons.left.is_start()
|
if cursor_state.buttons.left.is_start() {
|
||||||
{
|
|
||||||
self.ui.text(focus).deselect();
|
|
||||||
self.focus = None;
|
self.focus = None;
|
||||||
}
|
}
|
||||||
if input_changed {
|
if input_changed {
|
||||||
@@ -129,6 +129,11 @@ impl Client {
|
|||||||
self.run_sensors(&cursor_state, window_size);
|
self.run_sensors(&cursor_state, window_size);
|
||||||
self.ui.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 {
|
match event {
|
||||||
WindowEvent::CloseRequested => event_loop.exit(),
|
WindowEvent::CloseRequested => event_loop.exit(),
|
||||||
WindowEvent::RedrawRequested => {
|
WindowEvent::RedrawRequested => {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn error(ui: &mut Ui, msg: &str) -> WidgetId {
|
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) {
|
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
|
client
|
||||||
.ui
|
.ui
|
||||||
.text(&id)
|
.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) {
|
if let Some(region) = client.ui.window_region(&id) {
|
||||||
client.handle.window.set_ime_allowed(true);
|
client.handle.window.set_ime_allowed(true);
|
||||||
client.handle.window.set_ime_cursor_area(
|
client.handle.window.set_ime_cursor_area(
|
||||||
|
|||||||
Reference in New Issue
Block a user