Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hexagon icon shape #4697

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lawnchair/res/values-pl-rPL/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<string name="icon_shape_egg">Jajko</string>
<string name="icon_shape_cupertino">iOS</string>
<string name="icon_shape_octagon">Ośmiokątny</string>
<string name="icon_shape_hexagon">Sześciokątny</string>
SelfRef marked this conversation as resolved.
Show resolved Hide resolved
<string name="icon_shape_sammy">One UI</string>
<string name="icon_shape_rounded_square">Rounded square</string>
<string name="icon_shape_sharp_square">Sharp square</string>
Expand Down
1 change: 1 addition & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<string name="icon_shape_egg">Egg</string>
<string name="icon_shape_cupertino">iOS</string>
<string name="icon_shape_octagon">Octagon</string>
<string name="icon_shape_hexagon">Hexagon</string>
<string name="icon_shape_sammy">One UI</string>
<string name="icon_shape_rounded_square">Rounded square</string>
<string name="icon_shape_sharp_square">Sharp square</string>
Expand Down
37 changes: 37 additions & 0 deletions lawnchair/src/app/lawnchair/icons/shape/IconCornerShape.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.graphics.Path
import android.graphics.PointF
import com.android.app.animation.Interpolators.LINEAR
import com.android.launcher3.Utilities
import kotlin.math.sqrt

sealed class IconCornerShape {

Expand Down Expand Up @@ -97,6 +98,41 @@ sealed class IconCornerShape {
override fun toString(): String = "cut"
}

object CutHex : BaseBezierPath() {

override fun addCorner(
path: Path,
position: Position,
size: PointF,
progress: Float,
offsetX: Float,
offsetY: Float,
) {
if (progress == 0f) {
val paddingX = size.x - (size.x * sqrt(3.0) / 2).toFloat()
var newOffsetX = offsetX

when (position) {
Position.BottomLeft -> newOffsetX += paddingX
Position.BottomRight -> path.rMoveTo(-paddingX, 0f)
Position.TopLeft -> path.setLastPoint(paddingX + offsetX, size.y + offsetY)
Position.TopRight -> newOffsetX -= paddingX
}

path.lineTo(
position.endX * size.x + newOffsetX,
position.endY * size.y + offsetY,
)
} else {
super.addCorner(path, position, size, progress, offsetX, offsetY)
}
}

override fun toString(): String {
return "cuthex"
}
}

object LightSquircle : BaseBezierPath() {

override val controlDistance: Float = .1f
Expand Down Expand Up @@ -276,6 +312,7 @@ sealed class IconCornerShape {
fun fromString(value: String): IconCornerShape {
return when (value) {
"cut" -> Cut
"cuthex" -> CutHex
"lightsquircle" -> LightSquircle
"cubic", "squircle" -> Squircle
"strongsquircle" -> StrongSquircle
Expand Down
17 changes: 17 additions & 0 deletions lawnchair/src/app/lawnchair/icons/shape/IconShape.kt
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,22 @@ open class IconShape(
}
}

object Hexagon : IconShape(
IconCornerShape.CutHex,
IconCornerShape.CutHex,
IconCornerShape.CutHex,
IconCornerShape.CutHex,
PointF(1f, .5f),
PointF(1f, .5f),
PointF(1f, .5f),
PointF(1f, .5f),
) {

override fun toString(): String {
return "hexagon"
}
}

object Diamond : IconShape(
IconCornerShape.Cut,
IconCornerShape.Cut,
Expand Down Expand Up @@ -470,6 +486,7 @@ open class IconShape(
"cylinder" -> Cylinder
"cupertino" -> Cupertino
"octagon" -> Octagon
"hexagon" -> Hexagon
"diamond" -> Diamond
"egg" -> Egg
"" -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fun iconShapeEntries(context: Context): List<ListPreferenceEntry<IconShape>> {
ListPreferenceEntry(IconShape.Egg) { stringResource(id = R.string.icon_shape_egg) },
ListPreferenceEntry(IconShape.Cupertino) { stringResource(id = R.string.icon_shape_cupertino) },
ListPreferenceEntry(IconShape.Octagon) { stringResource(id = R.string.icon_shape_octagon) },
ListPreferenceEntry(IconShape.Hexagon) { stringResource(id = R.string.icon_shape_hexagon) },
ListPreferenceEntry(IconShape.Sammy) { stringResource(id = R.string.icon_shape_sammy) },
ListPreferenceEntry(IconShape.RoundedSquare) { stringResource(id = R.string.icon_shape_rounded_square) },
ListPreferenceEntry(IconShape.SharpSquare) { stringResource(id = R.string.icon_shape_sharp_square) },
Expand Down