Now we can have custom horizontal alignment and corner radius on MainMenuButton

pull/8/head
Rémi REGNAULT 11 months ago
parent 97b93d5612
commit 0de2f7d46c

@ -13,6 +13,15 @@ struct MainMenuButton: View {
var text: String
@State private var isHovered: Bool = false
// Button Alignment
var horizontalAlignment: Alignment = .center
// Button corner radius
var topLeftCorner: CGFloat = 0
var topRightCorner: CGFloat = 0
var bottomLeftCorner: CGFloat = 0
var bottomRightCorner: CGFloat = 0
var body: some View {
Button(action: {
// Action du bouton
@ -26,11 +35,11 @@ struct MainMenuButton: View {
.background(
Colors.Button
.clipShape(RoundedRectangle(cornerSize: CGSize(width: 0, height: 0)))
.mask(RoundedCornersShape(cornerRadii: (topLeft: 0, topRight: 10, bottomLeft: 0, bottomRight: 10)))
.mask(RoundedCornersShape(cornerRadii: (topLeft: topLeftCorner, topRight: topRightCorner, bottomLeft: bottomLeftCorner, bottomRight: bottomRightCorner)))
)
})
.frame(width: UIScreen.main.bounds.width / 1.7)
.frame(maxWidth: .infinity, alignment: .leading)
.frame(maxWidth: .infinity, alignment: horizontalAlignment)
.scaleEffect(isHovered ? 1.1 : 1.0)
.animation(.easeInOut(duration: 0.2), value: isHovered)
.onHover { hovering in
@ -85,6 +94,6 @@ struct RoundedCornersShape: Shape {
struct MainMenuButton_Previews: PreviewProvider {
static var previews: some View {
MainMenuButton(text: "test")
MainMenuButton(text: "test", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
}
}

@ -16,10 +16,10 @@ struct MainMenuView: View {
VStack {
HStack{
VStack(spacing: 25) {
MainMenuButton(text: "Play")
MainMenuButton(text: "Historique")
MainMenuButton(text: "Best Scores")
MainMenuButton(text: "Players")
MainMenuButton(text: "Play", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
MainMenuButton(text: "Historique", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
MainMenuButton(text: "Best Scores", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
MainMenuButton(text: "Players", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
}
Image(AppImages.SemiLion)
.resizable()

Loading…
Cancel
Save