Scoop API

scoop:scoop.ui:0.1.0

src/text/handles/host.scoop

Selected production source · src/text/handles/host.scoop

1package scoop.ui.text
3import scoop.graphics.*
4import scoop.graphics.text.*
5import scoop.surface.*
6import scoop.ui.*
8internal fun createEditorSelectionHandles(host: TextEditHost): TextSelectionHandles =
9 TextSelectionHandles(
10 host.scope,
11 host.area,
12 host.focus,
13 host.options.enabled,
14 host.options.touch,
15 { editorTouchReady(host) },
16 { EditorSelection(host.current.anchor, host.current.cursor) },
17 { position -> host.caret(position) },
18 {
19 point ->
20 val frame = host.accepted!!
21 frame.display.documentPosition(
22 frame.display.mapping.reverse(frame.layout.hitTest(point))
23 )
24 },
25 {
26 selection -> host.perform(
27 { editorSetSelection(host, selection) },
28 endComposition = true,
29 cancelContacts = false
30 )
31 },
32 {
33 editorStopDrag(host, false)
34 host.keyboard.touch()
35 host.touchPress.cancel()
36 host.touchPan.cancel()
37 host.focus.node.root.focus.cancel(host.focus)
38 host.revealNeeded = false
39 }
40 )
42internal fun createSelectableSelectionHandles(host: SelectableTextHost): TextSelectionHandles =
43 TextSelectionHandles(
44 host.scope,
45 host.area,
46 host.focus,
47 host.options.enabled,
48 host.options.touch,
49 { selectableTouchReady(host) },
50 { host.selected.value },
51 {
52 position -> when (host.inputFrame()) {
53 case Some(val frame) -> frame.layout.caret(position)
54 case None -> None
55 }
56 },
57 { point -> host.inputFrame()!!.layout.hitTest(point) },
58 {
59 selection ->
60 host.preferredX = None
61 host.publishSelection(selection, cancelContacts = false)
62 },
63 {
64 selectableStopDrag(host)
65 host.touchPress.cancel()
66 host.focus.node.root.focus.cancel(host.focus)
67 }
68 )
70internal fun editorSelectionHandles(
71 host: TextEditHost,
72 context: SceneContext,
73 frame: EditorFrame,
74 bounds: Rect
75) {
76 val selection = EditorSelection(host.current.anchor, host.current.cursor)
77 host.touchHandles.scene(
78 context,
79 bounds,
80 selection,
81 frame.caretStyle.caret(
82 frame.layout,
83 editorVisualPosition(frame.layout, frame.display.toDisplay(selection.anchor))
84 ),
85 frame.caretStyle.caret(
86 frame.layout,
87 editorVisualPosition(frame.layout, frame.display.toDisplay(selection.cursor))
88 ),
89 host.appearance.caretColor
90 )
93internal fun selectableSelectionHandles(
94 host: SelectableTextHost,
95 context: SceneContext,
96 frame: SelectableFrame,
97 bounds: Rect
98) {
99 val selection = host.selected.value
100 val color = host.options.selectionColor
101 host.touchHandles.scene(
102 context,
103 bounds,
104 selection,
105 frame.layout.caret(selection.anchor),
106 frame.layout.caret(selection.cursor),
107 Color(color.red, color.green, color.blue, 1.0)
108 )