Skip to content

Commit 5fb71c1

Browse files
committed
Update documentation for FixedSize
1 parent d072685 commit 5fb71c1

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This library can be simpler solution for small grid UI.
1515
There are benefits of this library:
1616

1717
- **Similar API to LazyGrid**: The GridLayout's APIs are designed to provide similar development experience to LazyGrid.
18-
- **Easy to implement adaptive grid**: There are _"Fixed"_ and _"Adaptive"_ for grid layout management like LazyGrid.
18+
- **Easy to implement various grid**: There are _"Fixed"_, _"Adaptive"_ and _"FixedSize"_ for grid layout management like LazyGrid.
1919
Like LazyGrid, it eliminates dealing with different screen sizes.
2020
- **Simple to use as a part of LazyList**: The GridLayout is not lazy layout. It can be simply placed in lazy layouts.
2121
If only a portion of the full layout is grid, No need to use LazyGrid with span size for full layout.

docs/cell-strategy.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
All grid layout composables take a cell strategy parameter called `SimpleGridCells`.
44
`SimpleGridCells` defines the number of cells and the size of each cell.
55

6-
There are 2 types of cell strategy, `Fixed` and `Adaptive`.
7-
They are similar to LazyGrid's `Fixed` and `Adaptive`.
6+
There are several types of cell strategy, `Fixed`, `Adaptive` and `FixedSize`.
7+
They are similar to LazyGrid's `GridCells.Fixed`, `GridCells.Adaptive` and `GridCells.FixedSize`.
88

99
## Fixed
1010

@@ -94,9 +94,51 @@ And each cells will have 1/3 of 400dp (about 133.333dp) width or height.
9494
If the grid size is expanded to 600dp, the number of cells on each line will be changed to 5
9595
and each cell's size will be 120dp.
9696

97+
## FixedSize
98+
99+
`SimpleGridCells.FixedSize` is a cell strategy for as many cells as possible with exact size.
100+
101+
The API of `FixedSize` looks like this:
102+
103+
```kotlin
104+
class FixedSize(
105+
private val size: Dp,
106+
private val fill: Boolean = true
107+
) : SimpleGridCells
108+
```
109+
110+
There is a parameter called `size`. This is the size of each cell should have.
111+
The `size` must be a positive size. If the size is 0 or below, it occurs an exception.
112+
If the `size` is bigger than container's size, the cell will have the same size to the container.
113+
114+
!!! note
115+
For information about `fill` parameter, read [Fill Option](#fill-option) section.
116+
117+
For example, a grid has 400dp width or height and `FixedSize(120.dp)` is applied.
118+
119+
```kotlin
120+
HorizontalGrid(
121+
rows = SimpleGridCells.FixedSize(120.dp),
122+
modifier = Modifier.height(400.dp)
123+
) { /* content */ }
124+
125+
VerticalGrid(
126+
columns = SimpleGridCells.FixedSize(120.dp),
127+
modifier = Modifier.width(400.dp)
128+
) { /* content */ }
129+
```
130+
131+
![fixed-size-example](./images/fixedsize-example.png)
132+
133+
The grid will have 3 cells on each line and the remaining space will not be used.
134+
If the grid size is expanded to 600dp, the number of cells on each line will be changed to 5.
135+
136+
In other case, `FixedSize(300.dp)` for `VerticalGrid(Modifier.width(200.dp))` means that there
137+
will be only one column and the cell will have 200dp width.
138+
97139
## Fill Option
98140

99-
Both `Fixed` and `Adaptive` have a optional parameter named `fill`.
141+
All cell strategy classes have a optional parameter named `fill`.
100142
The `fill` parameter determines that grid's item composable should fill grid cell's size.
101143

102144
When `fill` is true, grid layout forces item composable to have width or height to fit cell's maximum width or height.

docs/images/fixedsize-example.png

15.5 KB
Loading

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This library can be simpler solution for small grid UI.
1111
There are benefits of this library:
1212

1313
- **Similar API to LazyGrid**: The GridLayout's APIs are designed to provide similar development experience to LazyGrid.
14-
- **Easy to implement adaptive grid**: There are _"Fixed"_ and _"Adaptive"_ for grid layout management like LazyGrid.
14+
- **Easy to implement various grid**: There are _"Fixed"_, _"Adaptive"_ and _"FixedSize"_ for grid layout management like LazyGrid.
1515
Like LazyGrid, it eliminates dealing with different screen sizes.
1616
- **Simple to use as a part of LazyList**: The GridLayout is not lazy layout. It can be simply placed in lazy layouts.
1717
If only a portion of the full layout is grid, No need to use LazyGrid with span size for full layout.

0 commit comments

Comments
 (0)