blob: efb9f96e3779b36367009ff2bfaccbda0d691bac [file] [log] [blame]
<html devsite="true">
<head>
<title>OffsetKt</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>OffsetKt</h1>
<p>
<pre>public final class <a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a></pre>
</p>
<hr>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>static&nbsp;final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a></code></td>
<td>
<div><code><a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a>.<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html#(androidx.compose.ui.Modifier).absoluteOffset(kotlin.Function1)">absoluteOffset</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Density.html">Density</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/IntOffset.html">IntOffset</a>&gt;&nbsp;offset<br>)</code></div>
<p>Offset the content by <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(kotlin.Function1)">offset</a></code> px.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a></code></td>
<td>
<div><code><a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a>.<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">absoluteOffset</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Dp.html">Dp</a>&nbsp;x,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Dp.html">Dp</a>&nbsp;y<br>)</code></div>
<p>Offset the content by (<code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">x</a></code> dp, <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">y</a></code> dp).</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a></code></td>
<td>
<div><code><a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a>.<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html#(androidx.compose.ui.Modifier).offset(kotlin.Function1)">offset</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Density.html">Density</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/IntOffset.html">IntOffset</a>&gt;&nbsp;offset<br>)</code></div>
<p>Offset the content by <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(kotlin.Function1)">offset</a></code> px.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a></code></td>
<td>
<div><code><a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a>.<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">offset</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;receiver,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Dp.html">Dp</a>&nbsp;x,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Dp.html">Dp</a>&nbsp;y)</code></div>
<p>Offset the content by (<code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">x</a></code> dp, <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">y</a></code> dp).</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public methods</h2>
<div class="api-item"><a name="-androidx.compose.ui.Modifier-.absoluteOffset-kotlin.Function1-"></a><a name="absoluteoffset"></a>
<h3 class="api-name" id="(androidx.compose.ui.Modifier).absoluteOffset(kotlin.Function1)">OffsetKt.absoluteOffset</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a>.<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html#(androidx.compose.ui.Modifier).absoluteOffset(kotlin.Function1)">absoluteOffset</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Density.html">Density</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/IntOffset.html">IntOffset</a>&gt;&nbsp;offset<br>)</pre>
<p>Offset the content by <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(kotlin.Function1)">offset</a></code> px. The offsets can be positive as well as non-positive. Applying an offset only changes the position of the content, without interfering with its size measurement.</p>
<p>This modifier is designed to be used for offsets that change, possibly due to user interactions. It avoids recomposition when the offset is changing, and also adds a graphics layer that prevents unnecessary redrawing of the context when the offset is changing.</p>
<p>This modifier will not consider layout direction when calculating the position of the content: a positive horizontal offset will always move the content to the right. For a modifier that considers layout direction when applying the offset, see <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(kotlin.Function1)">offset</a></code>.</p>
<pre class="prettyprint">
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.absoluteOffset
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.IntOffset
// This text will be offset in steps of 10.dp from the top left of the available space.
var offset by remember { mutableStateOf(0) }
Text(
&quot;Layout offset modifier sample&quot;,
Modifier
.clickable { offset += 10 }
.absoluteOffset { IntOffset(offset, offset) }
)</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(kotlin.Function1)">absoluteOffset</a></code></td>
<td>
<p>Example usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp, androidx.compose.ui.unit.Dp)"></a><a name="-androidx.compose.ui.Modifier-.absoluteOffset-androidx.compose.ui.unit.Dp-androidx.compose.ui.unit.Dp-"></a><a name="absoluteoffset"></a>
<h3 class="api-name" id="(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">OffsetKt.absoluteOffset</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a>.<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">absoluteOffset</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Dp.html">Dp</a>&nbsp;x,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Dp.html">Dp</a>&nbsp;y<br>)</pre>
<p>Offset the content by (<code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">x</a></code> dp, <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">y</a></code> dp). The offsets can be positive as well as non-positive. Applying an offset only changes the position of the content, without interfering with its size measurement.</p>
<p>This modifier will not consider layout direction when calculating the position of the content: a positive <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">x</a></code> offset will always move the content to the right. For a modifier that considers the layout direction when applying the offset, see <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">offset</a></code>.</p>
<pre class="prettyprint">
import androidx.compose.foundation.layout.absoluteOffset
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.Text
// This text will be offset (10.dp, 20.dp) from the center of the available space.
Text(
&quot;Layout offset modifier sample&quot;,
Modifier.fillMaxSize()
.wrapContentSize(Alignment.Center)
.absoluteOffset(10.dp, 20.dp)
)</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">offset</a></code></td>
<td>
<p>Example usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="-androidx.compose.ui.Modifier-.offset-kotlin.Function1-"></a><a name="offset"></a>
<h3 class="api-name" id="(androidx.compose.ui.Modifier).offset(kotlin.Function1)">OffsetKt.offset</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a>.<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html#(androidx.compose.ui.Modifier).offset(kotlin.Function1)">offset</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Density.html">Density</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/IntOffset.html">IntOffset</a>&gt;&nbsp;offset<br>)</pre>
<p>Offset the content by <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(kotlin.Function1)">offset</a></code> px. The offsets can be positive as well as non-positive. Applying an offset only changes the position of the content, without interfering with its size measurement.</p>
<p>This modifier is designed to be used for offsets that change, possibly due to user interactions. It avoids recomposition when the offset is changing, and also adds a graphics layer that prevents unnecessary redrawing of the context when the offset is changing.</p>
<p>This modifier will automatically adjust the horizontal offset according to the layout direction: when the LD is LTR, positive horizontal offsets will move the content to the right and when the LD is RTL, positive horizontal offsets will move the content to the left. For a modifier that offsets without considering layout direction, see <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">absoluteOffset</a></code>.</p>
<pre class="prettyprint">
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.offset
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.IntOffset
// This text will be offset in steps of 10.dp from the top left of the available space in
// left-to-right context, and from top right in right-to-left context.
var offset by remember { mutableStateOf(0) }
Text(
&quot;Layout offset modifier sample&quot;,
Modifier
.clickable { offset += 10 }
.offset { IntOffset(offset, offset) }
)</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">absoluteOffset</a></code></td>
<td>
<p>Example usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp, androidx.compose.ui.unit.Dp)"></a><a name="-androidx.compose.ui.Modifier-.offset-androidx.compose.ui.unit.Dp-androidx.compose.ui.unit.Dp-"></a><a name="offset"></a>
<h3 class="api-name" id="(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">OffsetKt.offset</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html">OffsetKt</a>.<a href="/reference/androidx/compose/foundation/layout/OffsetKt.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">offset</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;receiver,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Dp.html">Dp</a>&nbsp;x,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/unit/Dp.html">Dp</a>&nbsp;y)</pre>
<p>Offset the content by (<code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">x</a></code> dp, <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">y</a></code> dp). The offsets can be positive as well as non-positive. Applying an offset only changes the position of the content, without interfering with its size measurement.</p>
<p>This modifier will automatically adjust the horizontal offset according to the layout direction: when the layout direction is LTR, positive <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">x</a></code> offsets will move the content to the right and when the layout direction is RTL, positive <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).offset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">x</a></code> offsets will move the content to the left. For a modifier that offsets without considering layout direction, see <code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">absoluteOffset</a></code>.</p>
<pre class="prettyprint">
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.Text
// This text will be offset (10.dp, 20.dp) from the center of the available space. In the
// right-to-left context, the offset will be (-10.dp, 20.dp).
Text(
&quot;Layout offset modifier sample&quot;,
Modifier.fillMaxSize()
.wrapContentSize(Alignment.Center)
.offset(10.dp, 20.dp)
)</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/androidx/compose/foundation/layout/package-summary.html#(androidx.compose.ui.Modifier).absoluteOffset(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)">absoluteOffset</a></code></td>
<td>
<p>Example usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>