Scoop API

scoop:scoop.ui.component:0.1.0

src/tree/actions.scoop

Selected production source · src/tree/actions.scoop

1package scoop.ui.component
3import scoop.surface.*
4import scoop.ui.*
5import scoop.ui.style.*
6import scoop.window.*
7import scoop.window.accessibility.*
9internal class TreeActionInput(
10 val content: View,
11 val name: String,
12 val enabled: Boolean,
13 val theme: ThemeSource?,
14 val activate: (TreeChangeOrigin) -> Boolean,
15 val tabStop: Boolean,
16 val size: ButtonSize
19/** Retains the ordinary button's press behavior and reports the actual action source. */
20private class TreeAction(private val props: Props<TreeActionInput>, scope: ComponentScope) :
21 Component(scope) {
22 private var origin = TreeChangeOrigin.Pointer
23 init {
24 scope
25 .resource {
26 scope
27 .input
28 .addEventHandler { context, event ->
29 if (context.phase ==
30 RoutedPhase.Capture ||
31 context.phase ==
32 RoutedPhase.Target
33 )
34 when (event) {
35 case Keyboard(_) -> origin = TreeChangeOrigin.Keyboard
36 case Pointer(_) -> origin = TreeChangeOrigin.Pointer
37 case Contact(_) -> origin = TreeChangeOrigin.Pointer
38 else -> {}
39 }
40 }
41 }
42 }
43 public override fun render(): View {
44 val input = props.value
45 return semanticButton(
46 ButtonProps(
47 ButtonContent.Custom(input.content), { input.activate(origin) },
48 enabled = input.enabled, theme = input.theme,
49 focus = FocusOptions(tabStop = input.tabStop), variant = ButtonVariant.Ghost,
50 size = input.size, style = buttonStyle {
51 this.surface { this.padding = Some(Insets.all(0.0)) }
52 },
53 semantics = ComponentSemantics(name = Some(input.name))
54 ),
55 SemanticRole.Button, SemanticProperties(
56 name = Some(input.name),
57 enabled = input.enabled
58 ),
59 SemanticActions(
60 invoke = Some {
61 treeAction(input.enabled && input.activate(TreeChangeOrigin.Accessibility))
62 }
63 )
64 )
65 }
68internal fun treeActionButton(
69 content: View,
70 name: String,
71 enabled: Boolean,
72 theme: ThemeSource?,
73 activate: (TreeChangeOrigin) -> Boolean,
74 tabStop: Boolean = false,
75 size: ButtonSize = ButtonSize.IconSm
76): View = component(
77 TreeActionInput(content, name, enabled, theme, activate, tabStop, size),
78 { value, scope -> TreeAction(value, scope) }