Add menu button

main
CAPEL Maxime 2023-12-21 11:08:12 +01:00
parent 01fcd8690b
commit bdf9492185
2 changed files with 76 additions and 0 deletions

View File

@ -125,6 +125,26 @@ fun homePage(
}
}
}
// Example usage with text options
dropdownButtonComponent(
items = listOf("Glossaire", "Code à vérifier", "Comparer")
) { selectedOption ->
// Handle the selected option
when (selectedOption) {
"Glossaire" -> onProjectClick()
"Code à vérifier" -> onCodeToVerifyClick()
"Comparer" -> {
if (mostUsedWordList.isEmpty()) {
noFileSnackbarVisibleState.value = true
println("Veuillez d'abord importer un fichier")
return@dropdownButtonComponent
} else {
isCompareClicked = true
}
}
}
}
}
var selectedProject by remember { mutableStateOf<Project?>(null) }

View File

@ -0,0 +1,56 @@
package main
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
@Composable
fun dropdownButtonComponent(
modifier: Modifier = Modifier,
items: List<String>,
onItemSelected: (String) -> Unit
) {
var expanded by remember { mutableStateOf(false) }
var selectedIndex by remember { mutableStateOf(0) }
Box(modifier = modifier) {
Button(
onClick = { expanded = true },
modifier = Modifier
.padding(16.dp),
contentPadding = PaddingValues(8.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor
)
) {
Icon(
imageVector = Icons.Default.Menu, // Use Menu icon for hamburger
contentDescription = "Menu",
tint = Color.White
)
Spacer(modifier = Modifier.width(8.dp))
Text(text = "Menu", color = Color.White)
Spacer(modifier = Modifier.width(8.dp))
}
DropdownMenu(
modifier = Modifier.width(200.dp),
expanded = expanded,
onDismissRequest = { expanded = false }
) {
items.forEachIndexed { index, s ->
DropdownMenuItem(onClick = {
selectedIndex = index
expanded = false
onItemSelected(s)
}) {
Text(text = s)
}
}
}
}
}