@@ -33,21 +33,21 @@ import androidx.compose.ui.text.style.TextAlign
3333import androidx.compose.ui.text.style.TextOverflow
3434import androidx.compose.ui.unit.dp
3535import com.enaboapps.switchify.R
36- import com.enaboapps.switchify.pc.PcMouseCommand
36+ import com.enaboapps.switchify.pc.PcControlCommand
3737
3838data class PcMouseControlSpec (
3939 @param:StringRes val labelResId : Int ,
40- val command : PcMouseCommand
40+ val command : PcControlCommand
4141)
4242
4343@Composable
44- fun PcMouseCommandGrid (
44+ fun PcControlCommandGrid (
4545 connected : Boolean ,
4646 movementStep : Int ,
47- onCommandSelected : (PcMouseCommand ) -> Unit ,
47+ onCommandSelected : (PcControlCommand ) -> Unit ,
4848 modifier : Modifier = Modifier
4949) {
50- PcMouseCommandSections (
50+ PcControlCommandSections (
5151 connected = connected,
5252 movementStep = movementStep,
5353 onCommandSelected = onCommandSelected,
@@ -101,10 +101,10 @@ fun PcMovementSizeSection(
101101}
102102
103103@Composable
104- fun PcMouseCommandSections (
104+ fun PcControlCommandSections (
105105 connected : Boolean ,
106106 movementStep : Int ,
107- onCommandSelected : (PcMouseCommand ) -> Unit ,
107+ onCommandSelected : (PcControlCommand ) -> Unit ,
108108 modifier : Modifier = Modifier
109109) {
110110 Column (
@@ -146,9 +146,9 @@ fun PcTypingCommandSection(
146146 modifier = Modifier .fillMaxWidth(),
147147 horizontalArrangement = Arrangement .spacedBy(10 .dp)
148148 ) {
149- PcCommandTile (
149+ PcScannedCommandTile (
150150 labelResId = R .string.pc_typing_type_text,
151- connected = connected,
151+ enabled = connected,
152152 onClick = onOpenTyping,
153153 minHeightDp = 72 ,
154154 modifier = Modifier .weight(1f )
@@ -163,7 +163,7 @@ fun PcTypingCommandSection(
163163private fun PcMovementCommandSection (
164164 connected : Boolean ,
165165 movementStep : Int ,
166- onCommandSelected : (PcMouseCommand ) -> Unit
166+ onCommandSelected : (PcControlCommand ) -> Unit
167167) {
168168 val controls = pcMovementControlSpecs(movementStep)
169169 Column (verticalArrangement = Arrangement .spacedBy(10 .dp)) {
@@ -208,7 +208,7 @@ private fun PcButtonCommandSection(
208208 @StringRes titleResId : Int ,
209209 specs : List <PcMouseControlSpec >,
210210 connected : Boolean ,
211- onCommandSelected : (PcMouseCommand ) -> Unit
211+ onCommandSelected : (PcControlCommand ) -> Unit
212212) {
213213 Column (verticalArrangement = Arrangement .spacedBy(10 .dp)) {
214214 PcCommandSectionTitle (titleResId)
@@ -234,7 +234,7 @@ private fun PcCommandSectionTitle(@StringRes titleResId: Int) {
234234private fun PcCommandButtonRow (
235235 specs : List <PcMouseControlSpec >,
236236 connected : Boolean ,
237- onCommandSelected : (PcMouseCommand ) -> Unit ,
237+ onCommandSelected : (PcControlCommand ) -> Unit ,
238238 minHeightDp : Int
239239) {
240240 Row (
@@ -257,52 +257,60 @@ private fun PcCommandButtonRow(
257257private fun PcCommandButton (
258258 spec : PcMouseControlSpec ,
259259 connected : Boolean ,
260- onCommandSelected : (PcMouseCommand ) -> Unit ,
260+ onCommandSelected : (PcControlCommand ) -> Unit ,
261261 minHeightDp : Int ,
262262 modifier : Modifier = Modifier
263263) {
264- PcCommandTile (
264+ PcScannedCommandTile (
265265 labelResId = spec.labelResId,
266- connected = connected,
266+ enabled = connected,
267267 onClick = { onCommandSelected(spec.command) },
268268 minHeightDp = minHeightDp,
269269 modifier = modifier
270270 )
271271}
272272
273273@Composable
274- private fun PcCommandTile (
274+ fun PcScannedCommandTile (
275275 @StringRes labelResId : Int ,
276- connected : Boolean ,
276+ enabled : Boolean ,
277277 onClick : () -> Unit ,
278- minHeightDp : Int ,
279- modifier : Modifier = Modifier
278+ modifier : Modifier = Modifier ,
279+ minHeightDp : Int = 72,
280+ square : Boolean = true
280281) {
281282 val interactionSource = remember { MutableInteractionSource () }
282283 val pressed by interactionSource.collectIsPressedAsState()
283284 val backgroundColor = when {
284- ! connected -> MaterialTheme .colorScheme.surfaceVariant
285+ ! enabled -> MaterialTheme .colorScheme.surfaceVariant
285286 pressed -> MaterialTheme .colorScheme.primaryContainer
286287 else -> MaterialTheme .colorScheme.surface
287288 }
288- val borderColor = if (connected ) {
289+ val borderColor = if (enabled ) {
289290 MaterialTheme .colorScheme.outline
290291 } else {
291292 MaterialTheme .colorScheme.outlineVariant
292293 }
293- val contentColor = if (connected ) {
294+ val contentColor = if (enabled ) {
294295 MaterialTheme .colorScheme.onSurface
295296 } else {
296297 MaterialTheme .colorScheme.onSurfaceVariant
297298 }
298-
299- Surface (
300- modifier = modifier
299+ val tileModifier = if (square) {
300+ modifier
301301 .fillMaxWidth()
302302 .aspectRatio(1f )
303303 .heightIn(min = minHeightDp.dp)
304+ } else {
305+ modifier
306+ .fillMaxWidth()
307+ .heightIn(min = minHeightDp.dp)
308+ }
309+
310+ Surface (
311+ modifier = tileModifier
304312 .clickable(
305- enabled = connected ,
313+ enabled = enabled ,
306314 role = Role .Button ,
307315 interactionSource = interactionSource,
308316 indication = null ,
@@ -367,29 +375,29 @@ fun pcMouseControlSpecs(moveStep: Int): List<PcMouseControlSpec> {
367375fun pcMovementControlSpecs (moveStep : Int ): List <PcMouseControlSpec > {
368376 val step = moveStep.coerceAtLeast(1 )
369377 return listOf (
370- PcMouseControlSpec (R .string.pc_mouse_up_left, PcMouseCommand .Move (- step, - step)),
371- PcMouseControlSpec (R .string.pc_mouse_up, PcMouseCommand .Move (0 , - step)),
372- PcMouseControlSpec (R .string.pc_mouse_up_right, PcMouseCommand .Move (step, - step)),
373- PcMouseControlSpec (R .string.pc_mouse_left, PcMouseCommand .Move (- step, 0 )),
374- PcMouseControlSpec (R .string.pc_mouse_right, PcMouseCommand .Move (step, 0 )),
375- PcMouseControlSpec (R .string.pc_mouse_down_left, PcMouseCommand .Move (- step, step)),
376- PcMouseControlSpec (R .string.pc_mouse_down, PcMouseCommand .Move (0 , step)),
377- PcMouseControlSpec (R .string.pc_mouse_down_right, PcMouseCommand .Move (step, step))
378+ PcMouseControlSpec (R .string.pc_mouse_up_left, PcControlCommand .Move (- step, - step)),
379+ PcMouseControlSpec (R .string.pc_mouse_up, PcControlCommand .Move (0 , - step)),
380+ PcMouseControlSpec (R .string.pc_mouse_up_right, PcControlCommand .Move (step, - step)),
381+ PcMouseControlSpec (R .string.pc_mouse_left, PcControlCommand .Move (- step, 0 )),
382+ PcMouseControlSpec (R .string.pc_mouse_right, PcControlCommand .Move (step, 0 )),
383+ PcMouseControlSpec (R .string.pc_mouse_down_left, PcControlCommand .Move (- step, step)),
384+ PcMouseControlSpec (R .string.pc_mouse_down, PcControlCommand .Move (0 , step)),
385+ PcMouseControlSpec (R .string.pc_mouse_down_right, PcControlCommand .Move (step, step))
378386 )
379387}
380388
381389fun pcClickControlSpecs (): List <PcMouseControlSpec > {
382390 return listOf (
383- PcMouseControlSpec (R .string.pc_mouse_click, PcMouseCommand .LeftClick ),
384- PcMouseControlSpec (R .string.pc_mouse_double_click, PcMouseCommand .DoubleClick ),
385- PcMouseControlSpec (R .string.pc_mouse_right_click, PcMouseCommand .RightClick )
391+ PcMouseControlSpec (R .string.pc_mouse_click, PcControlCommand .LeftClick ),
392+ PcMouseControlSpec (R .string.pc_mouse_double_click, PcControlCommand .DoubleClick ),
393+ PcMouseControlSpec (R .string.pc_mouse_right_click, PcControlCommand .RightClick )
386394 )
387395}
388396
389397fun pcScrollControlSpecs (): List <PcMouseControlSpec > {
390398 val scrollStep = 5
391399 return listOf (
392- PcMouseControlSpec (R .string.pc_mouse_scroll_up, PcMouseCommand .Scroll (0 , scrollStep)),
393- PcMouseControlSpec (R .string.pc_mouse_scroll_down, PcMouseCommand .Scroll (0 , - scrollStep))
400+ PcMouseControlSpec (R .string.pc_mouse_scroll_up, PcControlCommand .Scroll (0 , scrollStep)),
401+ PcMouseControlSpec (R .string.pc_mouse_scroll_down, PcControlCommand .Scroll (0 , - scrollStep))
394402 )
395403}
0 commit comments