Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e12bdae0 authored by Wes Okuhara's avatar Wes Okuhara
Browse files

Screen Capture: Create RadioIconButtonGroup component

Creates a component which hosts a variable number of icon buttons where
any single icon button is selected at a time. The selected and
unselected button colors can be customized via argument. This is
intended to be used for the capture area selection in the toolbar.

Bug: 412722889
Test: Screenshot tests in topic
Flag: com.android.systemui.desktop_screen_capture
Change-Id: Ice184ed60a4602c9c032131d3bd6c602ea0f78b8
parent 821640fd
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

@file:OptIn(ExperimentalMaterial3ExpressiveApi::class)

package com.android.systemui.screencapture.ui.compose

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ButtonGroupDefaults
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.ToggleButton
import androidx.compose.material3.ToggleButtonColors
import androidx.compose.material3.ToggleButtonDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.android.systemui.common.shared.model.Icon as IconModel
import com.android.systemui.common.ui.compose.Icon

/** A group of N icon buttons where any single icon button is selected at a time. */
@Composable
fun RadioIconButtonGroup(
    icons: List<IconModel>,
    selectedIndex: Int,
    onSelect: (index: Int) -> Unit,
    modifier: Modifier = Modifier,
    colors: ToggleButtonColors = ToggleButtonDefaults.toggleButtonColors(),
) {
    Row(
        modifier = modifier,
        horizontalArrangement = Arrangement.spacedBy(ButtonGroupDefaults.ConnectedSpaceBetween),
    ) {
        icons.forEachIndexed { index, item ->
            ToggleButton(
                colors = colors,
                shapes =
                    when (index) {
                        0 -> ButtonGroupDefaults.connectedLeadingButtonShapes()
                        icons.lastIndex -> ButtonGroupDefaults.connectedTrailingButtonShapes()
                        else -> ButtonGroupDefaults.connectedMiddleButtonShapes()
                    },
                checked = (index == selectedIndex),
                onCheckedChange = { onSelect(index) },
            ) {
                Icon(icon = item, modifier = Modifier.size(20.dp))
            }
        }
    }
}