Просмотр исходного кода

wallet: bugfix editbox, since property mod streams can now distinguish the source, we dont need special logic

darkfi 2 лет назад
Родитель
Сommit
8db50e65e3
2 измененных файлов с 8 добавлено и 13 удалено
  1. 5 1
      bin/darkwallet/src/app.rs
  2. 3 12
      bin/darkwallet/src/ui/editbox.rs

+ 5 - 1
bin/darkwallet/src/app.rs

@@ -27,7 +27,7 @@ use crate::{
     error::Error,
     error::Error,
     expr::Op,
     expr::Op,
     gfx2::{GraphicsEventPublisherPtr, RenderApiPtr, Vertex},
     gfx2::{GraphicsEventPublisherPtr, RenderApiPtr, Vertex},
-    prop::{Property, PropertySubType, PropertyType, Role, PropertyStr},
+    prop::{Property, PropertySubType, PropertyType, Role, PropertyStr, PropertyBool},
     scene::{
     scene::{
         CallArgType, MethodResponseFn, Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId,
         CallArgType, MethodResponseFn, Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId,
         SceneNodeType, Slot
         SceneNodeType, Slot
@@ -637,10 +637,14 @@ impl App {
         //node.set_property_bool(Role::App, "debug", true).unwrap();
         //node.set_property_bool(Role::App, "debug", true).unwrap();
 
 
         let editbox_text = PropertyStr::wrap(node, Role::App, "text", 0).unwrap();
         let editbox_text = PropertyStr::wrap(node, Role::App, "text", 0).unwrap();
+        let editbox_focus = PropertyBool::wrap(node, Role::App, "is_focused", 0).unwrap();
         let task = self.ex.spawn(async move {
         let task = self.ex.spawn(async move {
             while let Ok(_) = btn_click_recvr.recv().await {
             while let Ok(_) = btn_click_recvr.recv().await {
                 let text = editbox_text.get();
                 let text = editbox_text.get();
                 editbox_text.prop().unset(Role::App, 0);
                 editbox_text.prop().unset(Role::App, 0);
+                // Clicking outside the editbox makes it lose focus
+                // So lets focus it again
+                editbox_focus.set(true);
                 debug!(target: "app", "sending text {text}");
                 debug!(target: "app", "sending text {text}");
             }
             }
         });
         });

+ 3 - 12
bin/darkwallet/src/ui/editbox.rs

@@ -357,7 +357,8 @@ impl EditBox {
         let cursor_pos = self.cursor_pos.get() as usize;
         let cursor_pos = self.cursor_pos.get() as usize;
         let cursor_color = self.cursor_color.get();
         let cursor_color = self.cursor_color.get();
         let debug = self.debug.get();
         let debug = self.debug.get();
-        debug!(target: "ui::editbox", "Rendering text '{}' clip={:?}", text, clip);
+        debug!(target: "ui::editbox", "Rendering text '{text}' clip={clip:?}");
+        debug!(target: "ui::editbox", "    cursor_pos={cursor_pos}, is_focused={is_focused}");
 
 
         let glyphs = self.glyphs.lock().unwrap().clone();
         let glyphs = self.glyphs.lock().unwrap().clone();
         let atlas = text2::make_texture_atlas(&self.render_api, &glyphs).await.unwrap();
         let atlas = text2::make_texture_atlas(&self.render_api, &glyphs).await.unwrap();
@@ -655,8 +656,6 @@ impl EditBox {
 
 
         let mouse_pos = Point::from([mouse_x, mouse_y]);
         let mouse_pos = Point::from([mouse_x, mouse_y]);
 
 
-        let mut focus_changed = false;
-
         let Some(rect) = self.get_cached_world_rect().await else { return };
         let Some(rect) = self.get_cached_world_rect().await else { return };
 
 
         // clicking inside box will:
         // clicking inside box will:
@@ -670,7 +669,6 @@ impl EditBox {
             } else {
             } else {
                 debug!(target: "ui::editbox", "EditBox focused");
                 debug!(target: "ui::editbox", "EditBox focused");
                 self.is_focused.set(true);
                 self.is_focused.set(true);
-                focus_changed = true;
             }
             }
 
 
             let cpos = self.find_closest_glyph_idx(mouse_x, &rect);
             let cpos = self.find_closest_glyph_idx(mouse_x, &rect);
@@ -690,19 +688,12 @@ impl EditBox {
             self.is_focused.set(false);
             self.is_focused.set(false);
             self.selected.set_null(Role::Internal, 0).unwrap();
             self.selected.set_null(Role::Internal, 0).unwrap();
             self.selected.set_null(Role::Internal, 1).unwrap();
             self.selected.set_null(Role::Internal, 1).unwrap();
-            focus_changed = true;
         } else {
         } else {
             // Do nothing. Click was outside editbox, and editbox wasn't focused
             // Do nothing. Click was outside editbox, and editbox wasn't focused
             return
             return
         }
         }
 
 
-        // Further on_focus logic change is handled by property modified callback
-        // which calls Self::change_focus()
-        // We still need to redraw if cursor is changed though, but we want to avoid redrawing
-        // twice, so we do this check:
-        if !focus_changed {
-            self.redraw().await;
-        }
+        self.redraw().await;
     }
     }
     fn handle_mouse_btn_up(&self, btn: MouseButton, _mouse_x: f32, _mouse_y: f32) {
     fn handle_mouse_btn_up(&self, btn: MouseButton, _mouse_x: f32, _mouse_y: f32) {
         if btn != MouseButton::Left {
         if btn != MouseButton::Left {