Browse Source

fix: textbox element lost while editirng, text field adjustment

Raihan Rizal 1 month ago
parent
commit
9bbec5235a
1 changed files with 20 additions and 4 deletions
  1. 20 4
      lib/widgets/elements.dart

+ 20 - 4
lib/widgets/elements.dart

280
             bool isElmHeightExceedCanvas = height > canvas.height;
280
             bool isElmHeightExceedCanvas = height > canvas.height;
281
         
281
         
282
             // Check if the object is out of the canvas
282
             // Check if the object is out of the canvas
283
+            // ? top side
283
             if (element.position.top < 0) {
284
             if (element.position.top < 0) {
284
               setState(() {
285
               setState(() {
285
                 element.position.top = 0;
286
                 element.position.top = 0;
286
               });
287
               });
287
         
288
         
288
               print('object is out of canvas');
289
               print('object is out of canvas');
290
+              log('Adjusting Top Position');
289
               return;
291
               return;
290
             }
292
             }
291
-        
293
+
294
+            // ? left side
292
             if (element.position.left < 0) {
295
             if (element.position.left < 0) {
293
               setState(() {
296
               setState(() {
294
                 element.position.left = 0;
297
                 element.position.left = 0;
295
               });
298
               });
296
         
299
         
297
               print('object is out of canvas');
300
               print('object is out of canvas');
301
+              log('Adjusting Left Position');
298
               return;
302
               return;
299
             }
303
             }
300
             
304
             
305
+            // ? bottom side
301
             if (!isElmHeightExceedCanvas && bottom > canvas.height) {
306
             if (!isElmHeightExceedCanvas && bottom > canvas.height) {
302
               setState(() {
307
               setState(() {
303
                 element.position.top = (canvas.height - height).roundToDouble() - 1;
308
                 element.position.top = (canvas.height - height).roundToDouble() - 1;
304
               });
309
               });
305
-        
310
+              log('Adjusting Bottom Position, if !isElmHeightExceedCanvas');
306
               print('object is out of canvas');
311
               print('object is out of canvas');
307
               return;
312
               return;
308
             }
313
             }
309
         
314
         
310
-        
315
+            // ? right side
311
             if (!isElmWidthExceedCanvas && right > canvas.width) {
316
             if (!isElmWidthExceedCanvas && right > canvas.width) {
312
               setState(() {
317
               setState(() {
313
                 element.position.left = (canvas.width - width).roundToDouble() - 1;
318
                 element.position.left = (canvas.width - width).roundToDouble() - 1;
314
               });
319
               });
315
         
320
         
316
               print('object is out of canvas');
321
               print('object is out of canvas');
322
+              log('Adjusting right position, if isElmHeightExceedCanvas');
317
               return;
323
               return;
318
             }
324
             }
319
         
325
         
338
             
344
             
339
             double right = element.position.left + width;
345
             double right = element.position.left + width;
340
             double bottom = element.position.top + height;
346
             double bottom = element.position.top + height;
347
+
348
+            bool isElmWidthExceedCanvas = width > canvas.width; 
349
+            bool isElmHeightExceedCanvas = height > canvas.height;
341
         
350
         
342
         
351
         
343
             if (element.position.top < 0) {
352
             if (element.position.top < 0) {
348
                 adjustedElementPosition.left = 0;
357
                 adjustedElementPosition.left = 0;
349
             }
358
             }
350
         
359
         
351
-            if ((element.position.top + height) > canvas.height) {
360
+            if (!isElmHeightExceedCanvas && (element.position.top + height) > canvas.height) {
352
                 adjustedElementPosition.top = (canvas.height - height).roundToDouble() - 1;
361
                 adjustedElementPosition.top = (canvas.height - height).roundToDouble() - 1;
362
+
363
+            } else if (isElmHeightExceedCanvas && (element.position.top + height) > canvas.height) {
364
+                adjustedElementPosition.top = 0;
353
             }
365
             }
354
         
366
         
355
             if ((element.position.left + width) > canvas.width) {
367
             if ((element.position.left + width) > canvas.width) {
572
     if (Provider.of<Editor>(context, listen: true).isEditing && (Provider.of<Editor>(context, listen: true).selectedElmId == element.id)) {
584
     if (Provider.of<Editor>(context, listen: true).isEditing && (Provider.of<Editor>(context, listen: true).selectedElmId == element.id)) {
573
       return IntrinsicWidth(
585
       return IntrinsicWidth(
574
         child: TextField(
586
         child: TextField(
587
+          textInputAction: TextInputAction.done,
575
           controller: element.valueController,
588
           controller: element.valueController,
576
           autofocus: true,
589
           autofocus: true,
577
           keyboardType: TextInputType.multiline,
590
           keyboardType: TextInputType.multiline,
597
 
610
 
598
             setState(() {});
611
             setState(() {});
599
           },
612
           },
613
+          onEditingComplete: () => Provider.of<Editor>(context, listen: false).unSelectElm(),
614
+          
600
         ),
615
         ),
601
       );
616
       );
602
     }
617
     }
614
     return Text(
629
     return Text(
615
       element.valueController.text,
630
       element.valueController.text,
616
       style: CanvasStyle.getTextStyle(element.fontScale),
631
       style: CanvasStyle.getTextStyle(element.fontScale),
632
+      // maxLines: 1,
617
     );
633
     );
618
     
634
     
619
   }
635
   }