55package  org.equeim.tremotesf.ui.components 
66
77import  androidx.annotation.StringRes 
8+ import  androidx.compose.foundation.background 
89import  androidx.compose.foundation.layout.IntrinsicSize 
910import  androidx.compose.foundation.layout.fillMaxWidth 
1011import  androidx.compose.foundation.layout.width 
12+ import  androidx.compose.material.icons.Icons 
13+ import  androidx.compose.material.icons.filled.Check 
1114import  androidx.compose.material3.DropdownMenuItem 
1215import  androidx.compose.material3.ExperimentalMaterial3Api 
1316import  androidx.compose.material3.ExposedDropdownMenuAnchorType 
1417import  androidx.compose.material3.ExposedDropdownMenuBox 
1518import  androidx.compose.material3.ExposedDropdownMenuDefaults 
19+ import  androidx.compose.material3.Icon 
20+ import  androidx.compose.material3.MaterialTheme 
21+ import  androidx.compose.material3.MenuDefaults 
1622import  androidx.compose.material3.OutlinedTextField 
1723import  androidx.compose.material3.Text 
1824import  androidx.compose.runtime.Composable 
@@ -22,6 +28,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
2228import  androidx.compose.runtime.setValue 
2329import  androidx.compose.ui.Modifier 
2430import  androidx.compose.ui.res.stringResource 
31+ import  org.equeim.tremotesf.R 
2532
2633@OptIn(ExperimentalMaterial3Api ::class )
2734@Composable
@@ -44,7 +51,9 @@ fun <T> TremotesfComboBox(
4451        OutlinedTextField (
4552            value =  itemDisplayString(currentItem()),
4653            onValueChange =  {},
47-             modifier =  Modifier .fillMaxWidth().menuAnchor(ExposedDropdownMenuAnchorType .PrimaryNotEditable , enabled),
54+             modifier =  Modifier 
55+                 .fillMaxWidth()
56+                 .menuAnchor(ExposedDropdownMenuAnchorType .PrimaryNotEditable , enabled),
4857            enabled =  enabled,
4958            readOnly =  true ,
5059            label =  label.takeIf  { it !=  0  }?.let  { { Text (stringResource(label)) } },
@@ -53,16 +62,52 @@ fun <T> TremotesfComboBox(
5362        )
5463        ExposedDropdownMenu (expanded =  expanded, onDismissRequest =  { expanded =  false  }) {
5564            for  (item in  items) {
65+                 val  selected =  (item ==  currentItem())
5666                DropdownMenuItem (
5767                    text =  { Text (itemDisplayString(item)) },
58-                     leadingIcon =  leadingIcon?.let  { { it(item) } },
68+                     leadingIcon =  when  {
69+                         leadingIcon !=  null  ->  {
70+                             { leadingIcon(item) }
71+                         }
72+ 
73+                         selected ->  {
74+                             { SelectedIcon () }
75+                         }
76+ 
77+                         else  ->  null 
78+                     },
79+                     trailingIcon =  if  (selected &&  leadingIcon !=  null ) {
80+                         { SelectedIcon () }
81+                     } else  {
82+                         null 
83+                     },
5984                    onClick =  {
6085                        updateCurrentItem(item)
6186                        expanded =  false 
6287                    },
6388                    contentPadding =  ExposedDropdownMenuDefaults .ItemContentPadding ,
89+                     colors =  if  (selected) {
90+                         val  contentColor =  MaterialTheme .colorScheme.onSecondaryContainer
91+                         MenuDefaults .itemColors(
92+                             textColor =  contentColor,
93+                             leadingIconColor =  contentColor,
94+                             trailingIconColor =  contentColor
95+                         )
96+                     } else  {
97+                         MenuDefaults .itemColors()
98+                     },
99+                     modifier =  if  (selected) {
100+                         Modifier .background(MaterialTheme .colorScheme.secondaryContainer)
101+                     } else  {
102+                         Modifier 
103+                     }
64104                )
65105            }
66106        }
67107    }
68108}
109+ 
110+ @Composable
111+ private  fun  SelectedIcon () {
112+     Icon (Icons .Filled .Check , contentDescription =  stringResource(R .string.selected))
113+ }
0 commit comments