Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #681 from Parabeac/dev
Browse files Browse the repository at this point in the history
AutoLayout Fixes and Improvements
  • Loading branch information
mergify[bot] committed Jul 4, 2022
2 parents 0d720a6 + 00d7f0b commit 88edb50
Show file tree
Hide file tree
Showing 86 changed files with 6,164 additions and 2,555 deletions.
110 changes: 55 additions & 55 deletions lib/generation/generators/attribute-helper/pb_size_helper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:parabeac_core/generation/generators/attribute-helper/pb_attribute_gen_helper.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/container.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/inherited_container.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/injected_container.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_context.dart';
Expand All @@ -15,81 +14,82 @@ class PBSizeHelper extends PBAttributesHelper {
return '';
}

String heightString, widthString;
final buffer = StringBuffer();

double relativeHeight = source.frame.height;
double relativeWidth = source.frame.width;
buffer.write(getSize(source, context, true));
buffer.write(getSize(source, context, false));

//Add relative sizing if the widget has context
var screenWidth;
var screenHeight;
return buffer.toString();
}

String getSize(PBIntermediateNode source, PBContext context, bool isHeight) {
var dimentionString = isHeight ? 'Height' : 'Width';
var lowerCaseDimentionString = dimentionString.toLowerCase();
String sizeString;
final buffer = StringBuffer();

double relativeSize = isHeight ? source.frame.height : source.frame.width;

// Add relative sizing if the widget has context
num screenSize;

if (context.screenFrame != null) {
screenWidth = context.screenFrame.width;
screenHeight = context.screenFrame.height;
screenSize =
isHeight ? context.screenFrame.height : context.screenFrame.width;
}

if (context.sizingContext == SizingValueContext.ScaleValue) {
// Size for scalevalue
relativeHeight =
(relativeHeight != null && screenHeight != null && screenHeight > 0.0)
? relativeHeight / screenHeight
: relativeHeight;
relativeWidth =
(relativeWidth != null && screenWidth != null && screenWidth > 0.0)
? relativeWidth / screenWidth
: relativeWidth;
var height = source.constraints.fixedHeight
? source.frame.height.toStringAsFixed(3)
: 'MediaQuery.of(context).size.height * ${relativeHeight.toStringAsFixed(3)}';
var width = source.constraints.fixedWidth
? source.frame.width.toStringAsFixed(3)
: 'MediaQuery.of(context).size.width * ${relativeWidth.toStringAsFixed(3)}';

heightString = 'height: $height,';

widthString = 'width: $width,';
relativeSize =
(relativeSize != null && screenSize != null && screenSize > 0.0)
? relativeSize / screenSize
: relativeSize;

var size = (isHeight
? source.constraints.fixedHeight
: source.constraints.fixedWidth)
? (isHeight
? source.frame.height.toString()
: source.frame.width.toString())
: 'MediaQuery.of(context).size.$lowerCaseDimentionString * ${relativeSize.toString()}';

sizeString = '$lowerCaseDimentionString: $size,';
} else if (context.sizingContext == SizingValueContext.LayoutBuilderValue) {
relativeWidth = relativeWidth / screenWidth;
relativeHeight = relativeHeight / screenHeight;
relativeSize = relativeSize / screenSize;

// Size for LayoutBuilder
widthString =
'width: constraints.maxWidth * ${relativeWidth.toStringAsFixed(3)},';

heightString =
'height: constraints.maxHeight * ${relativeHeight.toStringAsFixed(3)},';
sizeString =
'$lowerCaseDimentionString: constraints.max$dimentionString * ${relativeSize.toString()},';
} else if (context.sizingContext ==
SizingValueContext.LayoutBuilderStatefulValue) {
relativeWidth = relativeWidth / screenWidth;
relativeHeight = relativeHeight / screenHeight;

// Size for LayoutBuilder
widthString =
'width: widget.constraints.maxWidth * ${relativeWidth.toStringAsFixed(3)},';

heightString =
'height: widget.constraints.maxHeight * ${relativeHeight.toStringAsFixed(3)},';
// Add case where width and/or height is static
var isFixed = isHeight
? source.constraints.fixedHeight
: source.constraints.fixedWidth;

if (isFixed) {
// Size for constants value
sizeString = '$lowerCaseDimentionString: ${relativeSize.toString()},';
} else {
relativeSize = relativeSize / screenSize;

// Size for LayoutBuilder
sizeString =
'$lowerCaseDimentionString: widget.constraints.max$dimentionString * ${relativeSize.toString()},';
}
} else {
// Size for constants value
widthString = 'width: ${relativeWidth.toStringAsFixed(3)},';

heightString = 'height: ${relativeHeight.toStringAsFixed(3)},';
sizeString = '$lowerCaseDimentionString: ${relativeSize.toString()},';
}

// Determine if it is going to show width and height
var showWidth = true;
var showHeight = true;
var show = true;
if (source is PBContainer) {
showWidth = source.showWidth;
showHeight = source.showHeight;
}
if (relativeWidth != null && relativeWidth > 0 && showWidth) {
buffer.write(widthString);
show = isHeight ? source.showHeight : source.showWidth;
}
if (relativeHeight != null && relativeHeight > 0 && showHeight) {
buffer.write(heightString);

if (relativeSize != null && relativeSize > 0 && show) {
buffer.write(sizeString);
}

return buffer.toString();
Expand Down
2 changes: 1 addition & 1 deletion lib/generation/generators/layouts/pb_layout_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class PBLayoutGenerator extends PBGenerator {
var buffer = StringBuffer();
var children = context.tree.childrenOf(source);
// Write the type of Layout, Column or Row
buffer.write('${type}(');
buffer.write('$type(');
if (children.isNotEmpty) {
var layoutProperties = source.layoutProperties;

Expand Down
53 changes: 32 additions & 21 deletions lib/generation/generators/visual-widgets/pb_container_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PBContainerGenerator extends PBGenerator {
if (source is PBContainer) {
var sourceChildren = context.tree.childrenOf(source);
var buffer = StringBuffer();
// buffer.write('\n \/* ${source.name} *\/ \n');
buffer.write('Container(');

/// Add clip behavior in case children needs to be clipped
Expand All @@ -27,48 +28,51 @@ class PBContainerGenerator extends PBGenerator {
buffer.write('clipBehavior: Clip.hardEdge,');
}

/// Write container padding
if (source.padding != null) {
buffer.write(getPadding(source.padding));
}

//TODO(ivanV): please clean my if statement :(
if (source is InjectedContainer) {
if (source.padding != null) {
buffer.write(getPadding(source.padding));
}
if (source.pointValueHeight &&
if (source.constraints.fixedHeight &&
source.frame.height > 0 &&
source.showHeight) {
buffer.write('height: ${source.frame.height},');
} else if (!source.constraints.fixedHeight) {
buffer.write(PBSizeHelper().getSize(source, context, true));
}
if (source.pointValueWidth &&

if (source.constraints.fixedWidth &&
source.frame.width > 0 &&
source.showWidth) {
buffer.write('width: ${source.frame.width},');
} else if (!source.constraints.fixedWidth) {
buffer.write(PBSizeHelper().getSize(source, context, false));
}
if (!source.pointValueHeight && !source.pointValueWidth) {
buffer.write(PBSizeHelper().generate(source, context));
}
} else if (source is InheritedContainer) {
if (source.padding != null) {
buffer.write(getPadding(source.padding));
}
}

/// If source is [InheritedContainer] get both width and heigt
else if (source is InheritedContainer) {
buffer.write(PBSizeHelper().generate(source, context));
}

/// If border info exists, use box decoration for auxiliary data
if (source.auxiliaryData.borderInfo != null) {
buffer.write(PBBoxDecorationHelper().generate(source, context));
} else {
}

/// Else assing the color through the container
else {
buffer.write(PBColorGenHelper().generate(source, context));
}

// if (source.auxiliaryData.alignment != null) {
// buffer.write(
// 'alignment: Alignment(${(source.auxiliaryData.alignment['alignX'] as double).toStringAsFixed(2)}, ${(source.auxiliaryData.alignment['alignY'] as double).toStringAsFixed(2)}),');
// }
/// Check if container has a child
var child = sourceChildren.isEmpty ? null : sourceChildren.first;
if (child != null) {
child.frame = source.frame;
// source.child.currentContext = source.currentContext;
var statement = child != null
? 'child: ${child.generator.generate(child, context)}'
: '';
var statement = 'child: ${child.generator.generate(child, context)}';

buffer.write(statement);
}
buffer.write(')');
Expand All @@ -78,6 +82,13 @@ class PBContainerGenerator extends PBGenerator {
}

String getPadding(InjectedPadding padding) {
/// If there are no paddings to write, do not write any padding
if ((padding.left == null) &&
(padding.right == null) &&
(padding.top == null) &&
(padding.bottom == null)) {
return '';
}
var buffer = StringBuffer();

buffer.write('padding: EdgeInsets.only(');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class PBPositionedGenerator extends PBGenerator {
/// Getting the boilerplate needed to fill in the generation depending on the [sizingValueContext].
String _getBoilerplate(SizingValueContext sizingValueContext,
_PositionedValue _positionedValue) {
if (_positionedValue.remainPointValue) {
return '';
}

if (sizingValueContext == SizingValueContext.LayoutBuilderValue) {
if (_positionedValue.isXAxis) {
return 'constraints.maxWidth *';
Expand All @@ -88,11 +92,6 @@ class PBPositionedGenerator extends PBGenerator {
}
}

if (_positionedValue.remainPointValue ||
sizingValueContext != SizingValueContext.ScaleValue) {
return '';
}

if (_positionedValue.isXAxis) {
return '${PBGenerator.MEDIAQUERY_HORIZONTAL_BOILERPLATE} * ';
} else {
Expand Down
2 changes: 2 additions & 0 deletions lib/interpret_and_optimize/entities/inherited_polygon.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions lib/interpret_and_optimize/entities/injected_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class InjectedContainer extends PBVisualIntermediateNode
@JsonKey()
String type = 'injected_container';

bool pointValueWidth;
bool pointValueHeight;

@override
bool showWidth;
@override
Expand All @@ -51,8 +48,6 @@ class InjectedContainer extends PBVisualIntermediateNode
String color,
this.prototypeNode,
this.type,
this.pointValueHeight = false,
this.pointValueWidth = false,
PBIntermediateConstraints constraints,
this.showWidth = true,
this.showHeight = true,
Expand Down
4 changes: 0 additions & 4 deletions lib/interpret_and_optimize/entities/injected_container.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 88edb50

Please sign in to comment.