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