Skip to content

Commit

Permalink
Merge pull request #3 from touchlane/develop
Browse files Browse the repository at this point in the history
0.9.0
  • Loading branch information
landarskiy authored Jun 5, 2023
2 parents 39514eb + 8f3ccf2 commit bb89bc6
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
**grid_pad** is a Flutter library that allows you to place UI elements in a predefined grid,
manage spans in two dimensions, have flexible controls to manage row and column sizes.

[![Pub Version](https://img.shields.io/pub/v/grid_pad?color=blue)](https://pub.dev/packages/grid_pad)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://github.com/touchlane/gridpad_flutter/actions/workflows/quality.yml/badge.svg)](https://github.com/touchlane/gridpad_flutter/actions)
[![codecov](https://codecov.io/gh/touchlane/gridpad_flutter/branch/master/graph/badge.svg?token=MIUHAFNRPI)](https://codecov.io/gh/touchlane/gridpad_flutter)

# Usage

GridPad is inspired by Row and Column APIs, which makes its use intuitive.
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "0.9.0"
js:
dependency: transitive
description:
Expand Down
12 changes: 10 additions & 2 deletions lib/grid_pad_placement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class GridPadSpanAnchor {
return GridPadSpanAnchor(
horizontal: horizontalAnchor, vertical: verticalAnchor);
}

@override
String toString() {
return 'GridPadSpanAnchor{horizontal: $horizontal, vertical: $vertical}';
}
}

/// Horizontal anchor position for cells.
Expand Down Expand Up @@ -391,9 +396,12 @@ extension GridPadCellsExt on GridPadCells {
/// Checks if the [column] with the span = [columnSpan] and specific [anchor]
/// is outside the defined grid.
bool isColumnOutsideOfGrid(
int column, int columnSpan, GridPadSpanAnchor anchor) {
int column,
int columnSpan,
GridPadSpanAnchor anchor,
) {
final left = anchor.leftBound(column, columnSpan);
final right = anchor.bottomBound(column, columnSpan);
final right = anchor.rightBound(column, columnSpan);
return left < 0 || right >= columnCount;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/grid_pad_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class GridPad extends StatelessWidget {
delegate: _GridPadDelegate(
gridPadCells,
_content,
Directionality.of(context),
Directionality.maybeOf(context) ?? TextDirection.ltr,
),
children: <Widget>[
for (var i = 0; i < _content.length; i++)
Expand Down
24 changes: 22 additions & 2 deletions test/grid_pad_cells_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:grid_pad/grid_pad_cells.dart';

void main() {
test('Check equals(and hashCode for the same GridPadCells', () {
test('Check equals and hashCode for the same GridPadCells', () {
final left = GridPadCellsBuilder(rowCount: 2, columnCount: 4)
.columnSize(1, const Weight(2))
.rowSize(0, const Fixed(24))
Expand All @@ -39,6 +39,17 @@ void main() {
expect(left, right);
});

test('Check equals and hashCode for the same TotalSize ', () {
const weight = 1.0;
const fixed = 2.0;
// ignore: prefer_const_constructors
final left = TotalSize(weight: weight, fixed: fixed);
// ignore: prefer_const_constructors
final right = TotalSize(weight: weight, fixed: fixed);
expect(left.hashCode, right.hashCode);
expect(left, right);
});

test('Check internal fields', () {
final cells = GridPadCellsBuilder(rowCount: 2, columnCount: 4)
.rowSize(0, const Weight(3))
Expand Down Expand Up @@ -114,12 +125,21 @@ void main() {
);
});

test('Check errors', () {
test('Check errors. Invalid size options.', () {
expect(() {
Fixed(0);
}, throwsAssertionError);
expect(() {
Weight(0);
}, throwsAssertionError);
expect(() {
[
const Fixed(1),
const Weight(2),
CustomGriPadCellSize(),
].calculateTotalSize();
}, throwsArgumentError);
});
}

class CustomGriPadCellSize extends GridPadCellSize {}
39 changes: 39 additions & 0 deletions test/grid_pad_diagnostic_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* MIT License
*
* Copyright (c) 2023 Touchlane LLC [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import 'package:flutter_test/flutter_test.dart';
import 'package:grid_pad/grid_pad_diagnostic.dart';

void main() {
test('Check diagnostic callback', () {
String receivedMessage = "";
callback(String message) {
receivedMessage = message;
}

GridPadDiagnosticLogger().skippingItemCallback = callback;
GridPadDiagnosticLogger().onItemSkipped("message");
expect(receivedMessage, "message");
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,41 @@
* SOFTWARE.
*/

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:grid_pad/grid_pad_placement.dart';

void main() {
test('Check equals and hashCode for the same GridPadPlacementPolicy', () {
final left = GridPadPlacementPolicy(
mainAxis: Axis.horizontal,
verticalPolicy: VerticalPolicy.topBottom,
horizontalPolicy: HorizontalPolicy.endStart,
);
final right = GridPadPlacementPolicy(
mainAxis: Axis.horizontal,
verticalPolicy: VerticalPolicy.topBottom,
horizontalPolicy: HorizontalPolicy.endStart,
);
expect(left.hashCode, right.hashCode);
expect(left, right);
});

test('Check equals and hashCode for the same GridPadSpanAnchor ', () {
// ignore: prefer_const_constructors
final left = GridPadSpanAnchor(
horizontal: HorizontalAnchor.start,
vertical: VerticalAnchor.bottom,
);
// ignore: prefer_const_constructors
final right = GridPadSpanAnchor(
horizontal: HorizontalAnchor.start,
vertical: VerticalAnchor.bottom,
);
expect(left.hashCode, right.hashCode);
expect(left, right);
});

test('Test anchor default initialization', () {
final policy = GridPadPlacementPolicy();
expect(
Expand Down
Loading

0 comments on commit bb89bc6

Please sign in to comment.