Explorar el Código

app: edit widget fix phone select handle

darkfi hace 10 meses
padre
commit
3c3a914337

+ 4 - 0
bin/app/java/MainActivity.java

@@ -124,8 +124,12 @@ public boolean setSelection(int id, int start, int end) {
     }
 
     iv.inputConnection.beginBatchEdit();
+    // Not sure if this is needed
+    //if (start != end)
+    //  iv.inputConnection.finishComposingText();
     iv.inputConnection.setSelection(start, end);
     iv.inputConnection.endBatchEdit();
+
     return true;
 }
 public boolean commitText(int id, String txt) {

+ 2 - 1
bin/app/java/autosuggest/CustomInputConnection.java

@@ -279,10 +279,11 @@ public class CustomInputConnection extends BaseInputConnection {
 
     @Override
     public boolean finishComposingText() {
-        log("finishComposingText()");
         if (getComposingSpanStart(mEditable) == getComposingSpanEnd(mEditable)) {
+            log("finishComposingText() [DISABLED]");
             return true;
         }
+        log("finishComposingText()");
         super.finishComposingText();
         onFinishCompose(id);
         return true;

+ 6 - 6
bin/app/src/app/schema/test.rs

@@ -385,8 +385,8 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     */
 
     // Text edit
-    //let node = create_singleline_edit("editz");
-    let node = create_multiline_edit("editz");
+    let node = create_singleline_edit("editz");
+    //let node = create_multiline_edit("editz");
     node.set_property_bool(atom, Role::App, "is_active", true).unwrap();
     node.set_property_bool(atom, Role::App, "is_focused", true).unwrap();
 
@@ -397,8 +397,8 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     //prop.set_expr(atom, Role::App, 2, expr::load_var("parent_w")).unwrap();
 
     // Only used in singleline edit
-    prop.set_f32(atom, Role::App, 2, 400.).unwrap();
-    prop.set_f32(atom, Role::App, 3, 100.).unwrap();
+    prop.set_f32(atom, Role::App, 2, 600.).unwrap();
+    prop.set_f32(atom, Role::App, 3, 200.).unwrap();
 
     node.set_property_bool(atom, Role::App, "debug", true).unwrap();
 
@@ -461,8 +461,8 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
                 me,
                 window_scale.clone(),
                 app.render_api.clone(),
-                //BaseEditType::SingleLine,
-                BaseEditType::MultiLine,
+                BaseEditType::SingleLine,
+                //BaseEditType::MultiLine,
             )
         })
         .await;

+ 3 - 1
bin/app/src/text2/editor/android.rs

@@ -104,9 +104,11 @@ impl Editor {
         //android::focus(self.composer_id).unwrap();
         //let atxt = "A berry is small 😊 and pulpy.";
         //let atxt = "A berry is a small, pulpy, and often edible fruit. Typically, berries are juicy, rounded, brightly colored, sweet, sour or tart, and do not have a stone or pit, although many pips or seeds may be present. Common examples of berries in the culinary sense are strawberries, raspberries, blueberries, blackberries, white currants, blackcurrants, and redcurrants. In Britain, soft fruit is a horticultural term for such fruits. The common usage of the term berry is different from the scientific or botanical definition of a berry, which refers to a fruit produced from the ovary of a single flower where the outer layer of the ovary wall develops into an edible fleshy portion (pericarp). The botanical definition includes many fruits that are not commonly known or referred to as berries, such as grapes, tomatoes, cucumbers, eggplants, bananas, and chili peppers.";
+        //let atxt = "small berry terry";
         //android::set_text(self.composer_id, atxt);
         //self.set_selection(2, 7);
-        //self.on_buffer_changed(&mut PropertyAtomicGuard::new()).await;
+        // Call this after:
+        //self.on_buffer_changed(&mut PropertyAtomicGuard::none()).await;
     }
     /// Called on `AndroidSuggestEvent::CreateInputConnect`, which only happens after the View
     /// is focused for the first time.

+ 33 - 34
bin/app/src/ui/edit/mod.rs

@@ -452,8 +452,7 @@ impl BaseEdit {
         mesh.alloc(&self.render_api).draw_untextured()
     }
 
-    fn draw_phone_select_handle(&self, mesh: &mut MeshBuilder, pos: Point, side: f32) {
-        let scroll = self.scroll.get();
+    fn draw_phone_select_handle(&self, mesh: &mut MeshBuilder, mut pos: Point, side: f32) {
         let baseline = self.baseline.get();
         let select_ascent = self.select_ascent.get();
         let handle_descent = self.handle_descent.get();
@@ -462,12 +461,11 @@ impl BaseEdit {
         let mut color_trans = color.clone();
         color_trans[3] = 0.;
 
+        pos += self.behave.inner_pos();
         let x = pos.x;
         let mut y = pos.y + baseline;
 
-        if y - scroll < 0. {
-            return
-        }
+        // We can cache this
 
         // Vertical line downwards. We use this instead of draw_box() so we have a fade.
         let verts = vec![
@@ -908,6 +906,7 @@ impl BaseEdit {
     }
 
     fn finish_select(&self, atom: &mut PropertyAtomicGuard) {
+        t!("finish_select()");
         self.is_phone_select.store(false, Ordering::Relaxed);
         self.hide_cursor.store(false, Ordering::Relaxed);
         self.select_text.clone().set_null(atom, Role::Internal, 0).unwrap();
@@ -938,21 +937,20 @@ impl BaseEdit {
         content_instrs.append(&mut bg_instrs);
         content_instrs.push(DrawInstruction::Move(self.behave.scroll()));
 
-        let draw_main = vec![
-            (
-                self.content_dc_key,
-                DrawCall::new(
-                    content_instrs,
-                    vec![self.text_dc_key, self.cursor_dc_key, self.select_dc_key],
-                    0,
-                    "chatedit_content",
-                ),
-            ),
-            (
-                self.phone_select_handle_dc_key,
-                DrawCall::new(phone_sel_instrs, vec![], 1, "chatedit_phone_sel_scroll"),
+        let draw_main = vec![(
+            self.content_dc_key,
+            DrawCall::new(
+                content_instrs,
+                vec![
+                    self.text_dc_key,
+                    self.phone_select_handle_dc_key,
+                    self.cursor_dc_key,
+                    self.select_dc_key,
+                ],
+                0,
+                "chatedit_content",
             ),
-        ];
+        )];
         self.render_api.replace_draw_calls(batch_id, timest, draw_main);
     }
 
@@ -1046,6 +1044,7 @@ impl BaseEdit {
 
     async fn regen_phone_select_handle_mesh(&self) -> Vec<DrawInstruction> {
         if !self.is_phone_select.load(Ordering::Relaxed) {
+            //t!("regen_phone_select_handle_mesh() [DISABLED]");
             return vec![]
         }
         //t!("regen_phone_select_handle_mesh()");
@@ -1055,16 +1054,11 @@ impl BaseEdit {
         let sel = editor.selection();
         assert!(!sel.is_collapsed());
 
-        let pos = self.behave.inner_pos() + self.behave.scroll();
-
         // We could cache this and use Move instead but why bother?
         let mut mesh = MeshBuilder::new(gfxtag!("chatedit_phone_select_handle"));
         self.draw_phone_select_handle(&mut mesh, first, -1.);
         self.draw_phone_select_handle(&mut mesh, last, 1.);
-        vec![
-            DrawInstruction::Move(pos),
-            DrawInstruction::Draw(mesh.alloc(&self.render_api).draw_untextured()),
-        ]
+        vec![DrawInstruction::Draw(mesh.alloc(&self.render_api).draw_untextured())]
     }
 
     fn bounded_height(&self, height: f32) -> f32 {
@@ -1094,13 +1088,11 @@ impl BaseEdit {
         // -+ content (apply view)
         //  └╴select
         //  └╴text
+        //  └╴phone_handle
         //  └╴cursor
-        // - phone_handle
 
         // Why do we have such a complicated layout?
-        // Firstly phone select handles should never be clipped. So we must draw them outside
-        // of ApplyView.
-        // Then when adjusting selection, it's slow to redraw everything, so the selection
+        // When adjusting selection, it's slow to redraw everything, so the selection
         // must be drawn separately.
         // Lastly the cursor is blinking and that's on top but with clipping.
 
@@ -1111,7 +1103,7 @@ impl BaseEdit {
                     self.root_dc_key,
                     DrawCall::new(
                         vec![DrawInstruction::Move(rect.pos())],
-                        vec![self.content_dc_key, self.phone_select_handle_dc_key],
+                        vec![self.content_dc_key],
                         self.z_index.get(),
                         "chatedit_root",
                     ),
@@ -1120,7 +1112,12 @@ impl BaseEdit {
                     self.content_dc_key,
                     DrawCall::new(
                         content_instrs,
-                        vec![self.text_dc_key, self.cursor_dc_key, self.select_dc_key],
+                        vec![
+                            self.text_dc_key,
+                            self.phone_select_handle_dc_key,
+                            self.cursor_dc_key,
+                            self.select_dc_key,
+                        ],
                         0,
                         "chatedit_content",
                     ),
@@ -1229,8 +1226,7 @@ impl BaseEdit {
                 //self.hide_cursor.store(true, Ordering::Relaxed);
 
                 // Debug code if we set text in editor.init()
-                //let atom = &mut PropertyAtomicGuard::new();
-                //editor.on_buffer_changed(atom).await;
+                //editor.on_buffer_changed(&mut PropertyAtomicGuard::none()).await;
                 return
             }
             AndroidSuggestEvent::CreateInputConnect => {
@@ -1239,7 +1235,6 @@ impl BaseEdit {
             }
             // Destructive text edits
             AndroidSuggestEvent::ComposeRegion { .. } |
-            AndroidSuggestEvent::FinishCompose |
             AndroidSuggestEvent::Compose { .. } |
             AndroidSuggestEvent::DeleteSurroundingText { .. } => {
                 // Any editing will collapse selections
@@ -1254,6 +1249,10 @@ impl BaseEdit {
 
                 self.behave.apply_cursor_scroll(atom).await;
             }
+            AndroidSuggestEvent::FinishCompose => {
+                let mut editor = self.lock_editor().await;
+                editor.on_buffer_changed(atom).await;
+            }
         }
 
         // Only redraw once we have the parent_rect