Skip to content

Commit 84f5275

Browse files
update README.md and docs
1 parent 3bad74c commit 84f5275

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ https://user-images.githubusercontent.com/35650605/177825237-6b509ff5-5027-44aa-
1010
A composable that lays out and draws a given `ImageBitmap`. This will attempt to
1111
size the composable according to the `ImageBitmap`'s given width and height.
1212

13-
`ImageScope` contains `Constraints` since `ImageWithConstraints` uses `BoxWithConstraints`
14-
also it contains information about canvas width, height and top left position relative
15-
to parent `BoxWithConstraints`.
13+
`ImageScope` returns constraints, width and height of the drawing area based on `contentScale`
14+
* and rectangle of `imageBitmap` drawn. When a bitmap is displayed scaled to fit area of Composable
15+
* space used for drawing image is represented with `ImageScope.imageWidth` and
16+
* `ImageScope.imageHeight`.
17+
*
18+
* When we display a bitmap 1000x1000px with `ContentScale.Crop` if it's cropped to 500x500px
19+
* `ImageScope.rect` returns `IntRect(250,250,750,750)`.
1620

1721
This composable enables building other `Image` based Composables that require you to know
18-
which section of Composable image is drawn to or which section of Bitmap is drawn to `Canvas`
22+
spaces around `ImageBitmap` with `ContentScale ` or which section of Bitmap is drawn to `Canvas`
1923

2024
```kotlin
2125
@Composable
@@ -76,13 +80,13 @@ interface ImageScope {
7680
7781
/**
7882
* Width of area inside BoxWithConstraints that is scaled based on [ContentScale]
79-
* This is width of the [Canvas] draw draws [ImageBitmap]
83+
* This is width of the [Canvas] draws [ImageBitmap]
8084
*/
8185
val imageWidth: Dp
8286
8387
/**
8488
* Height of area inside BoxWithConstraints that is scaled based on [ContentScale]
85-
* This is height of the [Canvas] draw draws [ImageBitmap]
89+
* This is height of the [Canvas] draws [ImageBitmap]
8690
*/
8791
val imageHeight: Dp
8892
@@ -93,8 +97,9 @@ interface ImageScope {
9397
}
9498
```
9599

96-
* drawImage param is to set whether this Composable should draw on Canvas or `content` param
97-
should get scope parameter and draw it
100+
* drawImage param is to set whether this Composable should draw on Canvas. `ImageWithConstraints`
101+
can be used not only for drawing but providing required info for its `content` or child
102+
Composables so child can draw `ImageBitmap` as required by developer.
98103

99104
## ImageWithThumbnail
100105
`ImageWithThumbnail` displays thumbnail of bitmap it draws in corner specified

image/src/main/java/com/smarttoolfactory/image/ImageWithConstraints.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ import androidx.compose.ui.unit.*
2323

2424
/**
2525
* A composable that lays out and draws a given [ImageBitmap]. This will attempt to
26-
* size the composable according to the [ImageBitmap]'s given width and height.
26+
* size the composable according to the [ImageBitmap]'s given width and height. However, an
27+
* optional [Modifier] parameter can be provided to adjust sizing or draw additional content (ex.
28+
* background). Any unspecified dimension will leverage the [ImageBitmap]'s size as a minimum
29+
* constraint.
2730
*
28-
* [ImageScope] contains [Constraints] since [ImageWithConstraints] uses [BoxWithConstraints]
29-
* also it contains information about canvas width, height and top left position relative
30-
* to parent [BoxWithConstraints].
31+
* [ImageScope] returns constraints, width and height of the drawing area based on [contentScale]
32+
* and rectangle of [imageBitmap] drawn. When a bitmap is displayed scaled to fit area of Composable
33+
* space used for drawing image is represented with [ImageScope.imageWidth] and
34+
* [ImageScope.imageHeight].
35+
*
36+
* When we display a bitmap 1000x1000px with [ContentScale.Crop] if it's cropped to 500x500px
37+
* [ImageScope.rect] returns `IntRect(250,250,750,750)`.
3138
*
3239
* @param alignment determines where image will be aligned inside [BoxWithConstraints]
3340
* This is observable when bitmap image/width ratio differs from [Canvas] that draws [ImageBitmap]

0 commit comments

Comments
 (0)