Scoop API

scoop:scoop.ui.component:0.1.0

src/tabs/values.scoop

Selected production source · src/tabs/values.scoop

1package scoop.ui.component
3import scoop.graphics.text.FontCollection
4import scoop.ui.*
5import scoop.ui.style.*
7public enum TabActivation {
8 Auto, Manual
9}
11public enum TabsVariant {
12 Default, Line
15public class TabEntry<T: Equals<T>> public constructor(
16 public val choice: Choice<T>,
17 public val content: View,
18 public val trigger: ButtonContent? = None,
19 public val focus: FocusOptions = FocusOptions(),
20 public val retention: ContentRetention? = None,
21 public val triggerStyle: ButtonStyle? = None,
22 public val panelStyle: StyleOverride = styleOverride(),
23 public val semantics: ComponentSemantics = ComponentSemantics()
26public class TabsProps<T: Equals<T>> public constructor(
27 public val entries: Array<TabEntry<T>>,
28 public val selected: Binding<T?>,
29 public val activation: TabActivation = TabActivation.Auto,
30 public val axis: FlexAxis = FlexAxis.Horizontal,
31 public val variant: TabsVariant = TabsVariant.Default,
32 public val retention: ContentRetention = ContentRetention.Dispose,
33 public val enabled: Boolean = true,
34 public val loop: Boolean = true,
35 public val spacing: Double = 8.0,
36 public val fonts: FontCollection? = None,
37 public val theme: ThemeSource? = None,
38 public val style: StyleOverride = styleOverride(),
39 public val listStyle: StyleOverride = styleOverride(),
40 public val onValueChange: (T?) -> Unit = {},
41 public val semantics: ComponentSemantics = ComponentSemantics()
42) {
43 init {
44 nonnegative(spacing, "tabs spacing must be finite and nonnegative")
45 validateChoices(Array<Choice<T>>(entries.size) { index -> entries[index].choice })
46 }
49internal fun <T: Equals<T>> tabsIndex(entries: Array<TabEntry<T>>, selected: T?): Long? {
50 for (index in 0L ..< entries.size)
51 if (selected == Some(entries[index].choice.value))
52 return Some(index)
53 return None
56internal fun <T: Equals<T>> selectTab(input: TabsProps<T>, key: ViewKey): Boolean {
57 if (!input.enabled)
58 return false
59 for (entry in input.entries) {
60 if (entry.choice.key != key || !entry.choice.enabled)
61 continue
62 val previous = input.selected.value
63 val desired = Some(entry.choice.value)
64 if (previous == desired)
65 return false
66 input.selected.value = desired
67 return input.selected.value != previous
68 }
69 return false