FINALLY transition events to global; slow text sending bug tho
This commit is contained in:
@@ -2,20 +2,22 @@ use crate::{default::UiState, prelude::*};
|
||||
use std::time::{Duration, Instant};
|
||||
use winit::dpi::{LogicalPosition, LogicalSize};
|
||||
|
||||
event_ctx!(UiState);
|
||||
|
||||
pub struct Selector;
|
||||
|
||||
impl<W: 'static> WidgetAttr<W> for Selector {
|
||||
impl<W: Widget + 'static> WidgetAttr<W> for Selector {
|
||||
type Input = WidgetRef<TextEdit>;
|
||||
|
||||
fn run(ui: &mut Ui, container: WidgetRef<W>, id: Self::Input) {
|
||||
ui.register_event(container, CursorSense::click_or_drag(), move |mut ctx| {
|
||||
let ui = ctx.ui;
|
||||
container.on(CursorSense::click_or_drag(), move |ctx| {
|
||||
let ui = &mut ctx.data.ui;
|
||||
let region = ui.window_region(&id).unwrap();
|
||||
let id_pos = region.top_left;
|
||||
let container_pos = ui.window_region(&container).unwrap().top_left;
|
||||
ctx.data.cursor += container_pos - id_pos;
|
||||
ctx.data.size = region.size();
|
||||
select(ui, id, ctx.state, ctx.data);
|
||||
let pos = ctx.data.pos + container_pos - id_pos;
|
||||
let size = region.size();
|
||||
select(ui, id, ctx.state, pos, size, ctx.data.sense.is_dragging());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -26,18 +28,31 @@ impl WidgetAttr<TextEdit> for Selectable {
|
||||
type Input = ();
|
||||
|
||||
fn run(ui: &mut Ui, id: WidgetRef<TextEdit>, _: Self::Input) {
|
||||
ui.register_event(id, CursorSense::click_or_drag(), move |ctx| {
|
||||
select(ctx.ui, id, ctx.state, ctx.data);
|
||||
id.on(CursorSense::click_or_drag(), move |ctx| {
|
||||
select(
|
||||
ctx.data.ui,
|
||||
id,
|
||||
ctx.state,
|
||||
ctx.data.pos,
|
||||
ctx.data.size,
|
||||
ctx.data.sense.is_dragging(),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn select(ui: &mut Ui, id: WidgetRef<TextEdit>, state: &mut UiState, data: CursorData) {
|
||||
fn select(
|
||||
ui: &mut Ui,
|
||||
id: WidgetRef<TextEdit>,
|
||||
state: &mut UiState,
|
||||
pos: Vec2,
|
||||
size: Vec2,
|
||||
dragging: bool,
|
||||
) {
|
||||
let now = Instant::now();
|
||||
let recent = (now - state.last_click) < Duration::from_millis(300);
|
||||
state.last_click = now;
|
||||
id.get_mut()
|
||||
.select(data.cursor, data.size, data.sense.is_dragging(), recent);
|
||||
id.get_mut().select(pos, size, dragging, recent);
|
||||
if let Some(region) = ui.window_region(&id) {
|
||||
state.window.set_ime_allowed(true);
|
||||
state.window.set_ime_cursor_area(
|
||||
|
||||
Reference in New Issue
Block a user