Skip to content

Commit

Permalink
Make DefaultCursorThickness an expect val and draw cursor without b…
Browse files Browse the repository at this point in the history
…lurring.

This is needed to allow a different cursor thickness on the desktop. See #103

RelNote: "We are ever slightly changing the way cursor is drawn. You can use LocalCursorBlinkEnabled to disable the cursor drawing in tests."

Test: No additional tests needed; TextFieldCursorTest is passing.

Change-Id: I4c6979903bec329287ec25093f55b83668d674ea
  • Loading branch information
m-sasha committed Nov 12, 2024
1 parent f9c8772 commit af15879
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.foundation.text

import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

internal actual val DefaultCursorThickness: Dp = 2.dp
internal actual val DefaultCursorThickness: Dp = 2.dp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal fun Modifier.cursor(
// When cursor width is odd, draw it in the middle of a pixel,
// to avoid blurring due to antialiasing.
if (cursorWidth.toInt() % 2 == 1) {
floor(it) + 0.5f // round to nearest n+0.5
floor(it) + 0.5f // round to nearest n+0.5
} else round(it)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ internal class TextFieldSelectionState(
// When cursor width is odd, draw it in the middle of a pixel,
// to avoid blurring due to antialiasing.
if (cursorWidth.toInt() % 2 == 1) {
floor(it) + 0.5f // round to nearest n+0.5
floor(it) + 0.5f // round to nearest n+0.5
} else round(it)
}

Expand Down

0 comments on commit af15879

Please sign in to comment.