|
|
@@ -40,8 +40,8 @@ use crate::{
|
|
|
},
|
|
|
mesh::MeshBuilder,
|
|
|
prop::{
|
|
|
- PropertyAtomicGuard, PropertyBool, PropertyColor, PropertyFloat32, PropertyPtr,
|
|
|
- PropertyRect, PropertyStr, PropertyUint32, Role,
|
|
|
+ BatchGuardId, BatchGuardPtr, PropertyAtomicGuard, PropertyBool, PropertyColor,
|
|
|
+ PropertyFloat32, PropertyPtr, PropertyRect, PropertyStr, PropertyUint32, Role,
|
|
|
},
|
|
|
scene::{MethodCallSub, Pimpl, SceneNodePtr, SceneNodeWeak},
|
|
|
text2::{self, Editor},
|
|
|
@@ -492,14 +492,15 @@ impl ChatEdit {
|
|
|
mesh.append(verts, indices);
|
|
|
}
|
|
|
|
|
|
- async fn change_focus(self: Arc<Self>) {
|
|
|
+ async fn change_focus(self: Arc<Self>, batch: BatchGuardPtr) {
|
|
|
if !self.is_active.get() {
|
|
|
return
|
|
|
}
|
|
|
t!("Focus changed");
|
|
|
|
|
|
+ let atom = &mut batch.spawn();
|
|
|
// Cursor visibility will change so just redraw everything lol
|
|
|
- self.redraw().await;
|
|
|
+ self.redraw(atom).await;
|
|
|
}
|
|
|
|
|
|
async fn handle_shortcut(
|
|
|
@@ -549,7 +550,7 @@ impl ChatEdit {
|
|
|
_ => return false,
|
|
|
}
|
|
|
|
|
|
- self.redraw().await;
|
|
|
+ self.redraw(atom).await;
|
|
|
true
|
|
|
}
|
|
|
|
|
|
@@ -678,7 +679,7 @@ impl ChatEdit {
|
|
|
|
|
|
self.apply_cursor_scrolling(atom).await;
|
|
|
self.pause_blinking();
|
|
|
- self.redraw().await;
|
|
|
+ self.redraw(atom).await;
|
|
|
|
|
|
return true
|
|
|
}
|
|
|
@@ -788,7 +789,7 @@ impl ChatEdit {
|
|
|
|
|
|
async fn handle_touch_move(&self, mut touch_pos: Point) -> bool {
|
|
|
//t!("handle_touch_move({touch_pos:?})");
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ let atom = &mut self.render_api.make_guard();
|
|
|
// We must update with non relative touch_pos bcos when doing vertical scrolling
|
|
|
// we will modify the scroll, which is used by abs_to_local(), which is used
|
|
|
// to then calculate the max scroll. So it ends up jumping around.
|
|
|
@@ -806,7 +807,7 @@ impl ChatEdit {
|
|
|
} else {
|
|
|
self.abs_to_local(&mut touch_pos);
|
|
|
self.start_touch_select(touch_pos, atom).await;
|
|
|
- self.redraw_select().await;
|
|
|
+ self.redraw_select(atom.batch_id).await;
|
|
|
}
|
|
|
d!("touch state: StartSelect -> Select");
|
|
|
self.touch_info.lock().state = TouchStateAction::Select;
|
|
|
@@ -852,7 +853,7 @@ impl ChatEdit {
|
|
|
editor.set_selection(select.start, select.end);
|
|
|
drop(editor);
|
|
|
|
|
|
- self.redraw_select().await;
|
|
|
+ self.redraw_select(atom.batch_id).await;
|
|
|
}
|
|
|
TouchStateAction::ScrollVert { start_pos, scroll_start } => {
|
|
|
let y_dist = start_pos.y - touch_pos.y;
|
|
|
@@ -862,7 +863,7 @@ impl ChatEdit {
|
|
|
return true
|
|
|
}
|
|
|
self.scroll.set(atom, scroll);
|
|
|
- self.redraw_scroll().await;
|
|
|
+ self.redraw_scroll(atom.batch_id).await;
|
|
|
}
|
|
|
TouchStateAction::SetCursorPos => {
|
|
|
// TBH I can't even see the cursor under my thumb so I'll just
|
|
|
@@ -872,7 +873,7 @@ impl ChatEdit {
|
|
|
}
|
|
|
true
|
|
|
}
|
|
|
- async fn handle_touch_end(&self, mut touch_pos: Point) -> bool {
|
|
|
+ async fn handle_touch_end(&self, atom: &mut PropertyAtomicGuard, mut touch_pos: Point) -> bool {
|
|
|
//t!("handle_touch_end({touch_pos:?})");
|
|
|
self.abs_to_local(&mut touch_pos);
|
|
|
|
|
|
@@ -880,8 +881,8 @@ impl ChatEdit {
|
|
|
match state {
|
|
|
TouchStateAction::Inactive => return false,
|
|
|
TouchStateAction::Started { pos: _, instant: _ } | TouchStateAction::SetCursorPos => {
|
|
|
- self.touch_set_cursor_pos(touch_pos).await;
|
|
|
- self.redraw().await;
|
|
|
+ self.touch_set_cursor_pos(atom, touch_pos).await;
|
|
|
+ self.redraw(atom).await;
|
|
|
}
|
|
|
_ => {}
|
|
|
}
|
|
|
@@ -891,7 +892,7 @@ impl ChatEdit {
|
|
|
true
|
|
|
}
|
|
|
|
|
|
- async fn touch_set_cursor_pos(&self, touch_pos: Point) {
|
|
|
+ async fn touch_set_cursor_pos(&self, atom: &mut PropertyAtomicGuard, touch_pos: Point) {
|
|
|
t!("touch_set_cursor_pos({touch_pos:?})");
|
|
|
|
|
|
let mut editor = self.lock_editor().await;
|
|
|
@@ -900,7 +901,7 @@ impl ChatEdit {
|
|
|
drop(editor);
|
|
|
|
|
|
self.pause_blinking();
|
|
|
- self.finish_select(&mut PropertyAtomicGuard::new());
|
|
|
+ self.finish_select(atom);
|
|
|
}
|
|
|
|
|
|
fn finish_select(&self, atom: &mut PropertyAtomicGuard) {
|
|
|
@@ -937,16 +938,15 @@ impl ChatEdit {
|
|
|
self.cursor_is_visible.store(true, Ordering::Relaxed);
|
|
|
}
|
|
|
|
|
|
- async fn redraw(&self) {
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ async fn redraw(&self, atom: &mut PropertyAtomicGuard) {
|
|
|
let trace_id = rand::random();
|
|
|
let timest = unixtime();
|
|
|
let draw_update = self.make_draw_calls(trace_id, atom).await;
|
|
|
- self.render_api.replace_draw_calls(timest, draw_update.draw_calls);
|
|
|
+ self.render_api.replace_draw_calls(atom.batch_id, timest, draw_update.draw_calls);
|
|
|
}
|
|
|
|
|
|
/// Called when scroll changes. Moves content up or down. Nothing more.
|
|
|
- async fn redraw_scroll(&self) {
|
|
|
+ async fn redraw_scroll(&self, batch_id: BatchGuardId) {
|
|
|
let timest = unixtime();
|
|
|
let rect = self.rect.get();
|
|
|
let scroll = self.scroll.get();
|
|
|
@@ -975,18 +975,18 @@ impl ChatEdit {
|
|
|
GfxDrawCall::new(phone_sel_instrs, vec![], 1, "chatedit_phone_sel_scroll"),
|
|
|
),
|
|
|
];
|
|
|
- self.render_api.replace_draw_calls(timest, draw_main);
|
|
|
+ self.render_api.replace_draw_calls(batch_id, timest, draw_main);
|
|
|
}
|
|
|
|
|
|
- async fn redraw_cursor(&self) {
|
|
|
+ async fn redraw_cursor(&self, batch_id: BatchGuardId) {
|
|
|
let timest = unixtime();
|
|
|
let instrs = self.get_cursor_instrs().await;
|
|
|
let draw_calls =
|
|
|
vec![(self.cursor_dc_key, GfxDrawCall::new(instrs, vec![], 2, "curs_redr"))];
|
|
|
- self.render_api.replace_draw_calls(timest, draw_calls);
|
|
|
+ self.render_api.replace_draw_calls(batch_id, timest, draw_calls);
|
|
|
}
|
|
|
|
|
|
- async fn redraw_select(&self) {
|
|
|
+ async fn redraw_select(&self, batch_id: BatchGuardId) {
|
|
|
let timest = unixtime();
|
|
|
let sel_instrs = self.regen_select_mesh().await;
|
|
|
let phone_sel_instrs = self.regen_phone_select_handle_mesh().await;
|
|
|
@@ -997,7 +997,7 @@ impl ChatEdit {
|
|
|
GfxDrawCall::new(phone_sel_instrs, vec![], 1, "chatedit_phone_sel_redraw_sel"),
|
|
|
),
|
|
|
];
|
|
|
- self.render_api.replace_draw_calls(timest, draw_calls);
|
|
|
+ self.render_api.replace_draw_calls(batch_id, timest, draw_calls);
|
|
|
}
|
|
|
|
|
|
async fn get_cursor_instrs(&self) -> Vec<GfxDrawInstruction> {
|
|
|
@@ -1104,6 +1104,7 @@ impl ChatEdit {
|
|
|
// First we evaluate the width based off the parent dimensions
|
|
|
self.rect
|
|
|
.eval_with(
|
|
|
+ atom,
|
|
|
vec![2],
|
|
|
vec![
|
|
|
("parent_w".to_string(), parent_rect.w),
|
|
|
@@ -1128,6 +1129,7 @@ impl ChatEdit {
|
|
|
// Finally calculate the position
|
|
|
self.rect
|
|
|
.eval_with(
|
|
|
+ atom,
|
|
|
vec![0, 1],
|
|
|
vec![
|
|
|
("parent_w".to_string(), parent_rect.w),
|
|
|
@@ -1238,9 +1240,9 @@ impl ChatEdit {
|
|
|
panic!("self destroyed before insert_text_method_task was stopped!");
|
|
|
};
|
|
|
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ let atom = &mut self_.render_api.make_guard();
|
|
|
self_.insert(&text, atom).await;
|
|
|
- self_.redraw().await;
|
|
|
+ self_.redraw(atom).await;
|
|
|
true
|
|
|
}
|
|
|
|
|
|
@@ -1337,8 +1339,12 @@ impl ChatEdit {
|
|
|
|
|
|
impl Drop for ChatEdit {
|
|
|
fn drop(&mut self) {
|
|
|
- self.render_api
|
|
|
- .replace_draw_calls(unixtime(), vec![(self.text_dc_key, Default::default())]);
|
|
|
+ let atom = self.render_api.make_guard();
|
|
|
+ self.render_api.replace_draw_calls(
|
|
|
+ atom.batch_id,
|
|
|
+ unixtime(),
|
|
|
+ vec![(self.text_dc_key, Default::default())],
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1387,18 +1393,20 @@ impl UIObject for ChatEdit {
|
|
|
|
|
|
// When text has been changed.
|
|
|
// Cursor and selection might be invalidated.
|
|
|
- async fn reset(self_: Arc<ChatEdit>) {
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ async fn reset(self_: Arc<ChatEdit>, batch: BatchGuardPtr) {
|
|
|
+ let atom = &mut batch.spawn();
|
|
|
//self_.select_text.set_null(Role::Internal, 0).unwrap();
|
|
|
self_.scroll.set(atom, 0.);
|
|
|
- self_.redraw().await;
|
|
|
+ self_.redraw(atom).await;
|
|
|
}
|
|
|
- async fn redraw(self_: Arc<ChatEdit>) {
|
|
|
- self_.redraw().await;
|
|
|
+ async fn redraw(self_: Arc<ChatEdit>, batch: BatchGuardPtr) {
|
|
|
+ let atom = &mut batch.spawn();
|
|
|
+ self_.redraw(atom).await;
|
|
|
}
|
|
|
- async fn set_text(self_: Arc<ChatEdit>) {
|
|
|
+ async fn set_text(self_: Arc<ChatEdit>, batch: BatchGuardPtr) {
|
|
|
self_.lock_editor().await.on_text_prop_changed().await;
|
|
|
- self_.redraw().await;
|
|
|
+ let atom = &mut batch.spawn();
|
|
|
+ self_.redraw(atom).await;
|
|
|
}
|
|
|
|
|
|
on_modify.when_change(self.rect.prop(), redraw);
|
|
|
@@ -1423,7 +1431,7 @@ impl UIObject for ChatEdit {
|
|
|
on_modify.when_change(self.z_index.prop(), redraw);
|
|
|
on_modify.when_change(self.debug.prop(), redraw);
|
|
|
|
|
|
- async fn regen_cursor(self_: Arc<ChatEdit>) {
|
|
|
+ async fn regen_cursor(self_: Arc<ChatEdit>, _batch: BatchGuardPtr) {
|
|
|
// Free the cache
|
|
|
*self_.cursor_mesh.lock() = None;
|
|
|
}
|
|
|
@@ -1452,7 +1460,8 @@ impl UIObject for ChatEdit {
|
|
|
|
|
|
// Invert the bool
|
|
|
self_.cursor_is_visible.fetch_not(Ordering::Relaxed);
|
|
|
- self_.redraw_cursor().await;
|
|
|
+ let atom = &mut self_.render_api.make_guard();
|
|
|
+ self_.redraw_cursor(atom.batch_id).await;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -1523,7 +1532,7 @@ impl UIObject for ChatEdit {
|
|
|
repeater.key_down(PressedKey::Char(key), repeat)
|
|
|
};
|
|
|
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ let atom = &mut self.render_api.make_guard();
|
|
|
|
|
|
if mods.ctrl || mods.alt || mods.logo {
|
|
|
if repeat {
|
|
|
@@ -1540,7 +1549,7 @@ impl UIObject for ChatEdit {
|
|
|
t!("Key {:?} has {} actions", key, actions);
|
|
|
let key_str = key.to_string().repeat(actions as usize);
|
|
|
self.insert(&key_str, atom).await;
|
|
|
- self.redraw().await;
|
|
|
+ self.redraw(atom).await;
|
|
|
true
|
|
|
}
|
|
|
|
|
|
@@ -1566,7 +1575,7 @@ impl UIObject for ChatEdit {
|
|
|
t!("Key {:?} has {} actions", key, actions);
|
|
|
}
|
|
|
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ let atom = &mut self.render_api.make_guard();
|
|
|
|
|
|
let mut is_handled = false;
|
|
|
for _ in 0..actions {
|
|
|
@@ -1598,7 +1607,7 @@ impl UIObject for ChatEdit {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ let atom = &mut self.render_api.make_guard();
|
|
|
|
|
|
// clicking inside box will:
|
|
|
// 1. make it active
|
|
|
@@ -1627,7 +1636,7 @@ impl UIObject for ChatEdit {
|
|
|
self.mouse_btn_held.store(true, Ordering::Relaxed);
|
|
|
|
|
|
self.pause_blinking();
|
|
|
- self.redraw().await;
|
|
|
+ self.redraw(atom).await;
|
|
|
true
|
|
|
}
|
|
|
|
|
|
@@ -1653,7 +1662,7 @@ impl UIObject for ChatEdit {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ let atom = &mut self.render_api.make_guard();
|
|
|
|
|
|
// if active and selection_active, then use x to modify the selection.
|
|
|
// also implement scrolling when cursor is to the left or right
|
|
|
@@ -1679,9 +1688,9 @@ impl UIObject for ChatEdit {
|
|
|
|
|
|
self.pause_blinking();
|
|
|
self.apply_cursor_scrolling(atom).await;
|
|
|
- self.redraw_scroll().await;
|
|
|
- self.redraw_cursor().await;
|
|
|
- self.redraw_select().await;
|
|
|
+ self.redraw_scroll(atom.batch_id).await;
|
|
|
+ self.redraw_cursor(atom.batch_id).await;
|
|
|
+ self.redraw_select(atom.batch_id).await;
|
|
|
true
|
|
|
}
|
|
|
|
|
|
@@ -1690,13 +1699,13 @@ impl UIObject for ChatEdit {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- let atom = &mut PropertyAtomicGuard::new();
|
|
|
+ let atom = &mut self.render_api.make_guard();
|
|
|
|
|
|
let mut scroll = self.scroll.get() - wheel_pos.y * self.scroll_speed.get();
|
|
|
scroll = scroll.clamp(0., self.max_scroll());
|
|
|
t!("handle_mouse_wheel({wheel_pos:?}) [scroll={scroll}]");
|
|
|
self.scroll.set(atom, scroll);
|
|
|
- self.redraw_scroll().await;
|
|
|
+ self.redraw_scroll(atom.batch_id).await;
|
|
|
|
|
|
true
|
|
|
}
|
|
|
@@ -1711,10 +1720,12 @@ impl UIObject for ChatEdit {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+ let atom = &mut self.render_api.make_guard();
|
|
|
+
|
|
|
match phase {
|
|
|
TouchPhase::Started => self.handle_touch_start(touch_pos).await,
|
|
|
TouchPhase::Moved => self.handle_touch_move(touch_pos).await,
|
|
|
- TouchPhase::Ended => self.handle_touch_end(touch_pos).await,
|
|
|
+ TouchPhase::Ended => self.handle_touch_end(atom, touch_pos).await,
|
|
|
TouchPhase::Cancelled => false,
|
|
|
}
|
|
|
}
|