Documentation
¶
Overview ¶
Package segmentedbutton contains Material 3 Segmented Button components.
Reference: [Segmented Button](https://m3.material.io/components/segmented-button/overview) Specs: [Segmented Button Specs](https://m3.material.io/components/segmented-button/specs)
Index ¶
- Constants
- func GetSegmentShape(radius unit.Dp, position SegmentShape) shape.Shape
- type Composable
- func MultiChoiceSegmentedButtonRow(content Composable, options ...SegmentedButtonRowOption) Composable
- func SegmentedButton(checked bool, onCheckedChange func(bool), label string, shape SegmentShape, ...) Composable
- func SingleChoiceSegmentedButtonRow(content Composable, options ...SegmentedButtonRowOption) Composable
- type Composer
- type SegmentOption
- func WithBorder(width unit.Dp, col graphics.Color) SegmentOption
- func WithEnabled(enabled bool) SegmentOption
- func WithIcon(icon Composable) SegmentOption
- func WithModifier(m ui.Modifier) SegmentOption
- func WithSelectedColor(col graphics.Color) SegmentOption
- func WithSelectedIcon(icon Composable) SegmentOption
- func WithShowSelectedIcon(show bool) SegmentOption
- func WithUnselectedColor(col graphics.Color) SegmentOption
- type SegmentOptions
- type SegmentShape
- type SegmentedButtonRowOption
- type SegmentedButtonRowOptions
Constants ¶
const SegmentCornerRadius = unit.Dp(20)
M3 Spec: Fully rounded corners (half of height)
const SegmentHeight = unit.Dp(40)
M3 Spec: Container height is 40dp
const SegmentedButtonNodeID = "Material3SegmentedButton"
const SegmentedButtonRowNodeID = "Material3SegmentedButtonRow"
Variables ¶
This section is empty.
Functions ¶
func GetSegmentShape ¶
func GetSegmentShape(radius unit.Dp, position SegmentShape) shape.Shape
GetSegmentShape returns the appropriate RoundedCornerShape for a segment position. Uses the standard shape.RoundedCornerShape with per-corner radius support, following Jetpack Compose's API pattern.
Types ¶
type Composable ¶
type Composable = api.Composable
Type aliases for convenience
func MultiChoiceSegmentedButtonRow ¶
func MultiChoiceSegmentedButtonRow( content Composable, options ...SegmentedButtonRowOption, ) Composable
MultiChoiceSegmentedButtonRow creates a segmented button row where multiple segments can be selected simultaneously (like checkboxes). The content should contain SegmentedButton composables.
func SegmentedButton ¶
func SegmentedButton( checked bool, onCheckedChange func(bool), label string, shape SegmentShape, options ...SegmentOption, ) Composable
SegmentedButton creates an individual segment within a segmented button row. The `checked` parameter indicates if this segment is currently selected. The `onCheckedChange` callback is invoked when the segment is clicked. The `shape` parameter determines the corner rounding based on position.
func SingleChoiceSegmentedButtonRow ¶
func SingleChoiceSegmentedButtonRow( content Composable, options ...SegmentedButtonRowOption, ) Composable
SingleChoiceSegmentedButtonRow creates a segmented button row where only one segment can be selected at a time (like radio buttons). The content should contain SegmentedButton composables.
type SegmentOption ¶
type SegmentOption func(*SegmentOptions)
func WithBorder ¶
func WithBorder(width unit.Dp, col graphics.Color) SegmentOption
WithBorder sets the border width and color.
func WithEnabled ¶
func WithEnabled(enabled bool) SegmentOption
WithEnabled controls whether the segment is enabled.
func WithIcon ¶
func WithIcon(icon Composable) SegmentOption
WithIcon sets the leading icon for the segment.
func WithModifier ¶
func WithModifier(m ui.Modifier) SegmentOption
WithModifier sets a custom modifier for the segment.
func WithSelectedColor ¶
func WithSelectedColor(col graphics.Color) SegmentOption
WithSelectedColor sets the background color when selected.
func WithSelectedIcon ¶
func WithSelectedIcon(icon Composable) SegmentOption
WithSelectedIcon sets the icon shown when the segment is selected.
func WithShowSelectedIcon ¶
func WithShowSelectedIcon(show bool) SegmentOption
WithShowSelectedIcon controls whether to show the selected icon.
func WithUnselectedColor ¶
func WithUnselectedColor(col graphics.Color) SegmentOption
WithUnselectedColor sets the background color when unselected.
type SegmentOptions ¶
type SegmentOptions struct {
Modifier ui.Modifier
Icon Composable // Optional leading icon
SelectedIcon Composable // Icon shown when selected (default: checkmark)
ShowSelectedIcon bool // Whether to show selected icon
Enabled bool
SelectedColor graphics.Color // Background color when selected
UnselectedColor graphics.Color // Background color when unselected
SelectedContentColor graphics.Color // Content color when selected
UnselectedContentColor graphics.Color // Content color when unselected
BorderColor graphics.Color
BorderWidth unit.Dp
}
SegmentOptions configures an individual segment.
func DefaultSegmentOptions ¶
func DefaultSegmentOptions() SegmentOptions
DefaultSegmentOptions returns default options for a segment.
type SegmentShape ¶
type SegmentShape int
SegmentShape determines the shape of a segment based on its position.
const ( SegmentShapeStart SegmentShape = iota // Rounded left corners (TopStart, BottomStart) SegmentShapeMiddle // No rounded corners SegmentShapeEnd // Rounded right corners (TopEnd, BottomEnd) SegmentShapeOnly // Fully rounded (single segment) )
type SegmentedButtonRowOption ¶
type SegmentedButtonRowOption func(*SegmentedButtonRowOptions)
func WithRowModifier ¶
func WithRowModifier(m ui.Modifier) SegmentedButtonRowOption
WithRowModifier sets a custom modifier for the row.
func WithSpace ¶
func WithSpace(space unit.Dp) SegmentedButtonRowOption
WithSpace sets the space/overlap between segments.
type SegmentedButtonRowOptions ¶
type SegmentedButtonRowOptions struct {
Modifier ui.Modifier
Space unit.Dp // Overlap/space adjustment between segments
}
SegmentedButtonRowOptions configures the segmented button row container.
func DefaultSegmentedButtonRowOptions ¶
func DefaultSegmentedButtonRowOptions() SegmentedButtonRowOptions
DefaultSegmentedButtonRowOptions returns default options for the row container.