|
1 | | -use crate::widget::measure_lines; |
2 | | -use crate::widget::update_text_field_attributes; |
3 | | -use crate::widget::TextSubmission; |
4 | | -use crate::ComputedNode; |
5 | | -use crate::Node; |
6 | | -use crate::UiGlobalTransform; |
7 | | -use crate::UiScale; |
8 | | -use crate::UiSystems; |
9 | | -use bevy_app::Plugin; |
10 | | -use bevy_app::PostUpdate; |
11 | | -use bevy_color::palettes::tailwind::BLUE_900; |
12 | | -use bevy_color::palettes::tailwind::GRAY_300; |
13 | | -use bevy_color::palettes::tailwind::GRAY_400; |
14 | | -use bevy_color::palettes::tailwind::GRAY_950; |
15 | | -use bevy_color::palettes::tailwind::SKY_300; |
16 | | -use bevy_color::Color; |
17 | | -use bevy_derive::Deref; |
18 | | -use bevy_derive::DerefMut; |
19 | | -use bevy_ecs::change_detection::DetectChangesMut; |
20 | | -use bevy_ecs::component::Component; |
21 | | -use bevy_ecs::entity::Entity; |
22 | | -use bevy_ecs::event::EventReader; |
23 | | -use bevy_ecs::lifecycle::HookContext; |
24 | | -use bevy_ecs::observer::Observer; |
25 | | -use bevy_ecs::observer::On; |
26 | | -use bevy_ecs::query::Has; |
27 | | -use bevy_ecs::resource::Resource; |
28 | | -use bevy_ecs::schedule::IntoScheduleConfigs; |
29 | | -use bevy_ecs::system::Commands; |
30 | | -use bevy_ecs::system::Query; |
31 | | -use bevy_ecs::system::Res; |
32 | | -use bevy_ecs::system::ResMut; |
33 | | -use bevy_ecs::world::DeferredWorld; |
34 | | -use bevy_input::keyboard::Key; |
35 | | -use bevy_input::keyboard::KeyboardInput; |
36 | | -use bevy_input::mouse::MouseScrollUnit; |
37 | | -use bevy_input::mouse::MouseWheel; |
38 | | -use bevy_input::ButtonInput; |
39 | | -use bevy_input_focus::tab_navigation::NavAction; |
40 | | -use bevy_input_focus::FocusedInput; |
41 | | -use bevy_input_focus::InputFocus; |
42 | | -use bevy_math::IVec2; |
43 | | -use bevy_math::Rect; |
44 | | -use bevy_math::Vec2; |
45 | | -use bevy_picking::events::Click; |
46 | | -use bevy_picking::events::Drag; |
47 | | -use bevy_picking::events::Move; |
48 | | -use bevy_picking::events::Pointer; |
49 | | -use bevy_picking::events::Press; |
50 | | -use bevy_picking::hover::HoverMap; |
51 | | -use bevy_picking::pointer::PointerButton; |
52 | | -use bevy_text::Justify; |
53 | | -use bevy_text::LineBreak; |
54 | | -use bevy_text::Motion; |
55 | | -use bevy_text::TextFont; |
56 | | -use bevy_text::TextEdit; |
57 | | -use bevy_text::TextEdits; |
58 | | -use bevy_text::TextInputAttributes; |
59 | | -use bevy_text::TextInputBuffer; |
60 | | -use bevy_text::TextInputSystems; |
61 | | -use bevy_text::TextInputTarget; |
| 1 | +use crate::{ |
| 2 | + widget::{measure_lines, update_text_field_attributes, TextSubmission}, |
| 3 | + ComputedNode, Node, UiGlobalTransform, UiScale, UiSystems, |
| 4 | +}; |
| 5 | +use bevy_app::{Plugin, PostUpdate}; |
| 6 | +use bevy_color::{ |
| 7 | + palettes::tailwind::{BLUE_900, GRAY_300, GRAY_400, GRAY_950, SKY_300}, |
| 8 | + Color, |
| 9 | +}; |
| 10 | +use bevy_derive::{Deref, DerefMut}; |
| 11 | +use bevy_ecs::{ |
| 12 | + change_detection::DetectChangesMut, |
| 13 | + component::Component, |
| 14 | + entity::Entity, |
| 15 | + event::EventReader, |
| 16 | + lifecycle::HookContext, |
| 17 | + observer::{Observer, On}, |
| 18 | + query::Has, |
| 19 | + resource::Resource, |
| 20 | + schedule::IntoScheduleConfigs, |
| 21 | + system::{Commands, Query, Res, ResMut}, |
| 22 | + world::DeferredWorld, |
| 23 | +}; |
| 24 | +use bevy_input::{ |
| 25 | + keyboard::{Key, KeyboardInput}, |
| 26 | + mouse::{MouseScrollUnit, MouseWheel}, |
| 27 | + ButtonInput, |
| 28 | +}; |
| 29 | +use bevy_input_focus::{tab_navigation::NavAction, FocusedInput, InputFocus}; |
| 30 | +use bevy_math::{IVec2, Rect, Vec2}; |
| 31 | +use bevy_picking::{ |
| 32 | + events::{Click, Drag, Move, Pointer, Press}, |
| 33 | + hover::HoverMap, |
| 34 | + pointer::PointerButton, |
| 35 | +}; |
| 36 | +use bevy_text::{ |
| 37 | + Justify, LineBreak, Motion, TextEdit, TextEdits, TextFont, TextInputAttributes, |
| 38 | + TextInputBuffer, TextInputSystems, TextInputTarget, |
| 39 | +}; |
62 | 40 | use bevy_time::Time; |
63 | 41 | use core::time::Duration; |
64 | 42 |
|
@@ -149,7 +127,7 @@ impl Default for TextUnderCursorColor { |
149 | 127 | TextInputStyle, |
150 | 128 | TextInputMultiClickCounter, |
151 | 129 | TextInputBuffer, |
152 | | - TextCursorBlinkTimer, |
| 130 | + TextCursorBlinkTimer |
153 | 131 | )] |
154 | 132 | #[component( |
155 | 133 | on_add = on_add_text_input_node, |
@@ -342,32 +320,31 @@ fn on_multi_click_set_selection( |
342 | 320 | }; |
343 | 321 |
|
344 | 322 | let now = time.elapsed_secs(); |
345 | | - if let Ok(mut multi_click_data) = multi_click_data.get_mut(click.entity()) { |
346 | | - if now - multi_click_data.last_click_time |
| 323 | + if let Ok(mut multi_click_data) = multi_click_data.get_mut(click.entity()) |
| 324 | + && now - multi_click_data.last_click_time |
347 | 325 | <= multi_click_delay.as_secs_f32() * multi_click_data.click_count as f32 |
348 | | - { |
349 | | - let rect = Rect::from_center_size(transform.translation, node.size()); |
| 326 | + { |
| 327 | + let rect = Rect::from_center_size(transform.translation, node.size()); |
350 | 328 |
|
351 | | - let position = |
352 | | - click.pointer_location.position * node.inverse_scale_factor().recip() - rect.min; |
| 329 | + let position = |
| 330 | + click.pointer_location.position * node.inverse_scale_factor().recip() - rect.min; |
353 | 331 |
|
354 | | - match multi_click_data.click_count { |
355 | | - 1 => { |
356 | | - multi_click_data.click_count += 1; |
357 | | - multi_click_data.last_click_time = now; |
| 332 | + match multi_click_data.click_count { |
| 333 | + 1 => { |
| 334 | + multi_click_data.click_count += 1; |
| 335 | + multi_click_data.last_click_time = now; |
358 | 336 |
|
359 | | - actions.queue(TextEdit::DoubleClick(position.as_ivec2())); |
360 | | - return; |
361 | | - } |
362 | | - 2 => { |
363 | | - actions.queue(TextEdit::TripleClick(position.as_ivec2())); |
364 | | - if let Ok(mut entity) = commands.get_entity(click.entity()) { |
365 | | - entity.try_remove::<TextInputMultiClickCounter>(); |
366 | | - } |
367 | | - return; |
| 337 | + actions.queue(TextEdit::DoubleClick(position.as_ivec2())); |
| 338 | + return; |
| 339 | + } |
| 340 | + 2 => { |
| 341 | + actions.queue(TextEdit::TripleClick(position.as_ivec2())); |
| 342 | + if let Ok(mut entity) = commands.get_entity(click.entity()) { |
| 343 | + entity.try_remove::<TextInputMultiClickCounter>(); |
368 | 344 | } |
369 | | - _ => (), |
| 345 | + return; |
370 | 346 | } |
| 347 | + _ => (), |
371 | 348 | } |
372 | 349 | } |
373 | 350 | if let Ok(mut entity) = commands.get_entity(click.entity()) { |
@@ -429,7 +406,12 @@ impl Default for NextFocus { |
429 | 406 | pub fn on_focused_keyboard_input( |
430 | 407 | mut trigger: On<FocusedInput<KeyboardInput>>, |
431 | 408 | mut commands: Commands, |
432 | | - mut query: Query<(&mut TextEdits, Has<SingleLineInputField>, &TextBox, &TextInputBuffer)>, |
| 409 | + mut query: Query<( |
| 410 | + &mut TextEdits, |
| 411 | + Has<SingleLineInputField>, |
| 412 | + &TextBox, |
| 413 | + &TextInputBuffer, |
| 414 | + )>, |
433 | 415 | mut modifiers: Option<ResMut<GlobalTextInputState>>, |
434 | 416 | keyboard_state: Res<ButtonInput<Key>>, |
435 | 417 | ) { |
@@ -500,10 +482,7 @@ pub fn on_focused_keyboard_input( |
500 | 482 | } |
501 | 483 | } |
502 | 484 | Key::Home => { |
503 | | - actions.queue(TextEdit::motion( |
504 | | - Motion::BufferStart, |
505 | | - is_shift_pressed, |
506 | | - )); |
| 485 | + actions.queue(TextEdit::motion(Motion::BufferStart, is_shift_pressed)); |
507 | 486 | } |
508 | 487 | Key::End => { |
509 | 488 | actions.queue(TextEdit::motion(Motion::BufferEnd, is_shift_pressed)); |
|
0 commit comments