Skip to content

Commit

Permalink
Convert button shaper to use density instead of draw scope
Browse files Browse the repository at this point in the history
Closes #21
  • Loading branch information
kirill-grouchnikov committed Mar 27, 2022
1 parent 9b06006 commit 0eaf322
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fun AuroraBoxWithHighlights(
extraInsets = 0.5f,
isInner = false,
sides = sides,
drawScope = this
density = this
)

val outlineBoundingRect = outline.bounds
Expand Down Expand Up @@ -289,7 +289,7 @@ fun AuroraBoxWithHighlights(
extraInsets = 1.0f,
isInner = true,
sides = sides,
drawScope = this
density = this
) else null

borderPainter.paintBorder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ internal fun <E> AuroraComboBox(
extraInsets = 0.5f,
isInner = false,
sides = Sides(),
drawScope = this
density = this
)

val outlineBoundingRect = outline.bounds
Expand Down Expand Up @@ -377,7 +377,7 @@ internal fun <E> AuroraComboBox(
extraInsets = 1.0f,
isInner = true,
sides = Sides(),
drawScope = this
density = this
) else null

borderPainter.paintBorder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ internal fun AuroraCommandButton(
extraInsets = 0.5f,
isInner = false,
sides = presentationModel.sides,
drawScope = this
density = this
)

val outlineBoundingRect = outline.bounds
Expand Down Expand Up @@ -829,7 +829,7 @@ internal fun AuroraCommandButton(
extraInsets = 1.0f,
isInner = true,
sides = presentationModel.sides,
drawScope = this
density = this
) else null

borderPainter.paintBorder(
Expand Down Expand Up @@ -983,7 +983,7 @@ internal fun AuroraCommandButton(
extraInsets = 0.5f,
isInner = false,
sides = presentationModel.sides,
drawScope = this
density = this
)

val outlineBoundingRect = outline.bounds
Expand Down Expand Up @@ -1025,7 +1025,7 @@ internal fun AuroraCommandButton(
extraInsets = 1.0f,
isInner = true,
sides = presentationModel.sides,
drawScope = this
density = this
) else null

borderPainter.paintBorder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private fun CommandButtonGroupTitle(groupModelIndex: Int, groupModel: CommandGro
extraInsets = 0.5f,
isInner = false,
sides = Sides(straightSides = Side.values().toSet()),
drawScope = this
density = this
)

val outlineBoundingRect = outline.bounds
Expand All @@ -535,7 +535,7 @@ private fun CommandButtonGroupTitle(groupModelIndex: Int, groupModel: CommandGro
extraInsets = 1.0f,
isInner = true,
sides = Sides(straightSides = Side.values().toSet()),
drawScope = this
density = this
) else null

withTransform({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.pushingpixels.aurora.theming.shaper
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Outline
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.unit.Density
import org.pushingpixels.aurora.theming.AuroraTrait
import org.pushingpixels.aurora.theming.Sides

Expand All @@ -30,7 +31,7 @@ interface AuroraButtonShaper : AuroraTrait {
/** Returns the outline path. */
fun getButtonOutline(
width: Float, height: Float, extraInsets: Float,
isInner: Boolean, sides: Sides, drawScope: DrawScope
isInner: Boolean, sides: Sides, density: Density
): Outline

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package org.pushingpixels.aurora.theming.shaper

import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Outline
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import org.pushingpixels.aurora.theming.Sides
import org.pushingpixels.aurora.theming.utils.getBaseOutline
Expand All @@ -37,9 +37,9 @@ class ClassicButtonShaper : AuroraButtonShaper, RectangularButtonShaper {
extraInsets: Float,
isInner: Boolean,
sides: Sides,
drawScope: DrawScope
density: Density
): Outline {
var radius = getCornerRadius(width, height, extraInsets, drawScope)
var radius = getCornerRadius(width, height, extraInsets, density)
if (isInner) {
radius -= 1.0f
if (radius < 0.0f) radius = 0.0f
Expand All @@ -51,8 +51,8 @@ class ClassicButtonShaper : AuroraButtonShaper, RectangularButtonShaper {
)
}

override fun getCornerRadius(width: Float, height: Float, insets: Float, drawScope: DrawScope): Float {
with(drawScope) {
override fun getCornerRadius(width: Float, height: Float, insets: Float, density: Density): Float {
with(density) {
return 3.0f.dp.toPx()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package org.pushingpixels.aurora.theming.shaper

import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Outline
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.unit.Density
import org.pushingpixels.aurora.theming.Sides
import org.pushingpixels.aurora.theming.utils.getBaseOutline

Expand All @@ -36,9 +36,9 @@ class PillButtonShaper : AuroraButtonShaper, RectangularButtonShaper {
extraInsets: Float,
isInner: Boolean,
sides: Sides,
drawScope: DrawScope
density: Density
): Outline {
var radius = getCornerRadius(width, height, extraInsets, drawScope)
var radius = getCornerRadius(width, height, extraInsets, density)
if (isInner) {
radius -= 1.0f
if (radius < 0.0f) radius = 0.0f
Expand All @@ -50,7 +50,7 @@ class PillButtonShaper : AuroraButtonShaper, RectangularButtonShaper {
)
}

override fun getCornerRadius(width: Float, height: Float, insets: Float, drawScope: DrawScope): Float {
override fun getCornerRadius(width: Float, height: Float, insets: Float, density: Density): Float {
return if (width > height) {
(height - 2 * insets) / 2.0f
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.pushingpixels.aurora.theming.shaper

import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.unit.Density

/**
* Interface for rectangular-based button shapers.
Expand All @@ -29,5 +29,5 @@ interface RectangularButtonShaper {
* @param insets Button insets.
* @return Corner radius of a button.
*/
fun getCornerRadius(width: Float, height: Float, insets: Float, drawScope: DrawScope): Float
fun getCornerRadius(width: Float, height: Float, insets: Float, density: Density): Float
}

0 comments on commit 0eaf322

Please sign in to comment.