@geastack/elements 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +26 -0
- package/components/CameraView.d.ts +21 -0
- package/components/CameraView.tsx +65 -0
- package/components/VirtualList.d.ts +20 -0
- package/components/VirtualList.tsx +127 -0
- package/components/index.d.ts +5 -0
- package/components/index.ts +2 -0
- package/package.json +46 -0
- package/ui/camera_element.cpp +120 -0
- package/ui/camera_element.h +102 -0
- package/ui/virtual_list.cpp +326 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @geastack/elements
|
|
2
|
+
|
|
3
|
+
Non-intrinsic GeaStack JSX elements, each with its TypeScript component and the
|
|
4
|
+
native backend that renders it.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @geastack/elements
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
- `VirtualList`: a windowed list that materializes only the visible rows from
|
|
11
|
+
an item template.
|
|
12
|
+
- `CameraView`: a live camera preview bound to the host camera service. The
|
|
13
|
+
`CameraController` types are re-exported from `@geastack/core`.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { VirtualList } from '@geastack/elements'
|
|
17
|
+
|
|
18
|
+
<VirtualList items={rows} template={(row) => <Text>{row.title}</Text>} />
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The native backends are compiled into a target through `@geastack/core`'s
|
|
22
|
+
source manifest; apps only import the components.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Apache-2.0. See `LICENSE`.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Component } from '@geastack/core'
|
|
2
|
+
import type { CameraController, CameraFacing, Style } from '@geastack/core'
|
|
3
|
+
|
|
4
|
+
export interface CameraViewProps {
|
|
5
|
+
facing?: CameraFacing
|
|
6
|
+
mirror?: boolean
|
|
7
|
+
device?: string
|
|
8
|
+
width?: number
|
|
9
|
+
height?: number
|
|
10
|
+
fit?: 'cover' | 'contain' | 'fill'
|
|
11
|
+
style?: Style
|
|
12
|
+
onReady?: (cam: CameraController) => void
|
|
13
|
+
onError?: (message: string) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare class CameraView extends Component {
|
|
17
|
+
constructor(props: CameraViewProps)
|
|
18
|
+
template(): any
|
|
19
|
+
onAfterRender(): void
|
|
20
|
+
close(): void
|
|
21
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Camera, Component } from '@geastack/core'
|
|
2
|
+
import type { CameraFacing, CameraController, Style } from '@geastack/core'
|
|
3
|
+
|
|
4
|
+
export interface CameraViewProps {
|
|
5
|
+
facing?: CameraFacing
|
|
6
|
+
/** Mirror the preview horizontally. Defaults to `true` when facing="front". */
|
|
7
|
+
mirror?: boolean
|
|
8
|
+
/** Optional fixed device id from Camera.getDevices(). Overrides `facing`. */
|
|
9
|
+
device?: string
|
|
10
|
+
/** Capture resolution hint. Closest supported size is selected. */
|
|
11
|
+
width?: number
|
|
12
|
+
height?: number
|
|
13
|
+
/** How the frame fills the element box. Defaults to "cover". */
|
|
14
|
+
fit?: 'cover' | 'contain' | 'fill'
|
|
15
|
+
style?: Style
|
|
16
|
+
/** Called once the camera has opened and is producing frames. */
|
|
17
|
+
onReady?: (cam: CameraController) => void
|
|
18
|
+
/** Called if the camera failed to open. */
|
|
19
|
+
onError?: (message: string) => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Declarative preview surface. A thin wrapper over the native `<camera>`
|
|
24
|
+
* element: it sizes/positions the preview with CSS (via `style`) and streams
|
|
25
|
+
* automatically — no manual RAF/`Camera.draw` loop. For captures and controls
|
|
26
|
+
* use the imperative `Camera` class directly.
|
|
27
|
+
*/
|
|
28
|
+
export class CameraView extends Component {
|
|
29
|
+
private props: CameraViewProps
|
|
30
|
+
private notified = false
|
|
31
|
+
|
|
32
|
+
constructor(props: CameraViewProps) {
|
|
33
|
+
super()
|
|
34
|
+
this.props = props
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
template() {
|
|
38
|
+
return (
|
|
39
|
+
<camera
|
|
40
|
+
facing={this.props.facing ?? 'back'}
|
|
41
|
+
device={this.props.device ?? ''}
|
|
42
|
+
width={this.props.width ?? 0}
|
|
43
|
+
height={this.props.height ?? 0}
|
|
44
|
+
fit={this.props.fit ?? 'cover'}
|
|
45
|
+
style={this.props.style}
|
|
46
|
+
/>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
onAfterRender() {
|
|
51
|
+
if (this.notified) return
|
|
52
|
+
this.notified = true
|
|
53
|
+
if (!Camera.isAvailable()) {
|
|
54
|
+
this.props.onError?.('camera unavailable')
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
if (this.props.mirror !== undefined) Camera.setMirror(this.props.mirror)
|
|
58
|
+
this.props.onReady?.(Camera)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Stop the preview and release the camera. */
|
|
62
|
+
close() {
|
|
63
|
+
Camera.close()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ClassValue, TouchEventHandler } from '@geastack/core'
|
|
2
|
+
|
|
3
|
+
export type VirtualListItemTemplate = (index: number, top: number) => any
|
|
4
|
+
|
|
5
|
+
export interface VirtualListProps {
|
|
6
|
+
itemCount: number
|
|
7
|
+
itemHeight: number
|
|
8
|
+
scrollTop: number
|
|
9
|
+
slotCount?: number
|
|
10
|
+
overscan?: number
|
|
11
|
+
id?: string
|
|
12
|
+
class?: ClassValue
|
|
13
|
+
itemClass?: ClassValue
|
|
14
|
+
itemTemplate: VirtualListItemTemplate
|
|
15
|
+
onTouchStart?: TouchEventHandler
|
|
16
|
+
onTouchMove?: TouchEventHandler
|
|
17
|
+
onTouchEnd?: TouchEventHandler
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function VirtualList(props: VirtualListProps): any
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { ClassValue, TouchEventHandler } from '@geastack/core'
|
|
2
|
+
|
|
3
|
+
// A windowing list backed by the native <virtual-list> element. The element is
|
|
4
|
+
// an ordinary overflow:scroll container that scrolls over a virtual content
|
|
5
|
+
// height of itemCount * itemHeight; this component only materializes a small
|
|
6
|
+
// fixed pool of `slotCount` real row nodes and recycles them as `scrollTop`
|
|
7
|
+
// changes. Each slot is absolutely positioned in *content* space (top =
|
|
8
|
+
// index * itemHeight) — the element's native scroll offset shifts it on screen,
|
|
9
|
+
// so slot positions stay put between recycles and the fast scroll path can
|
|
10
|
+
// blit instead of re-rendering. Row content, height, colours and fonts all come
|
|
11
|
+
// from `itemTemplate` + its CSS; the framework owns none of it.
|
|
12
|
+
|
|
13
|
+
export type VirtualListItemTemplate = (index: number, top: number) => any
|
|
14
|
+
|
|
15
|
+
export interface VirtualListProps {
|
|
16
|
+
itemCount: number
|
|
17
|
+
itemHeight: number
|
|
18
|
+
scrollTop: number
|
|
19
|
+
slotCount?: number
|
|
20
|
+
overscan?: number
|
|
21
|
+
id?: string
|
|
22
|
+
class?: ClassValue
|
|
23
|
+
itemClass?: ClassValue
|
|
24
|
+
itemTemplate: VirtualListItemTemplate
|
|
25
|
+
onTouchStart?: TouchEventHandler
|
|
26
|
+
onTouchMove?: TouchEventHandler
|
|
27
|
+
onTouchEnd?: TouchEventHandler
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SLOT_COUNT = 16
|
|
31
|
+
|
|
32
|
+
function vlWindowStart(scrollTop: number, itemHeight: number, overscan: number) {
|
|
33
|
+
let start = Math.floor(scrollTop / itemHeight) - overscan
|
|
34
|
+
if (start < 0) start = 0
|
|
35
|
+
return start
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Data index shown by slot `slotIndex` for the current scroll position. Within
|
|
39
|
+
// the visible window [start, start + SLOT_COUNT) each index maps to slot
|
|
40
|
+
// index % SLOT_COUNT, so advancing the window by one row recycles exactly one
|
|
41
|
+
// slot (its index jumps by SLOT_COUNT) and leaves the rest untouched.
|
|
42
|
+
function vlIndexForSlot(slotIndex: number, scrollTop: number, itemHeight: number, overscan: number) {
|
|
43
|
+
const start = vlWindowStart(scrollTop, itemHeight, overscan)
|
|
44
|
+
return start + (((slotIndex - start) % SLOT_COUNT) + SLOT_COUNT) % SLOT_COUNT
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function vlSlotTop(slotIndex: number, scrollTop: number, itemHeight: number, overscan: number) {
|
|
48
|
+
return vlIndexForSlot(slotIndex, scrollTop, itemHeight, overscan) * itemHeight
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function vlSlotVisible(slotIndex: number, scrollTop: number, itemHeight: number, overscan: number, itemCount: number) {
|
|
52
|
+
return vlIndexForSlot(slotIndex, scrollTop, itemHeight, overscan) < itemCount
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface VirtualListSlotProps {
|
|
56
|
+
slotIndex: number
|
|
57
|
+
scrollTop: number
|
|
58
|
+
itemHeight: number
|
|
59
|
+
overscan: number
|
|
60
|
+
itemCount: number
|
|
61
|
+
itemClass?: ClassValue
|
|
62
|
+
itemTemplate: VirtualListItemTemplate
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function VirtualListSlot({ slotIndex, scrollTop, itemHeight, overscan, itemCount, itemClass, itemTemplate }: VirtualListSlotProps) {
|
|
66
|
+
return (
|
|
67
|
+
<div
|
|
68
|
+
class={itemClass}
|
|
69
|
+
style={{
|
|
70
|
+
position: 'absolute',
|
|
71
|
+
left: 0,
|
|
72
|
+
top: vlSlotTop(slotIndex, scrollTop, itemHeight, overscan),
|
|
73
|
+
width: '100vw',
|
|
74
|
+
height: itemHeight,
|
|
75
|
+
display: vlSlotVisible(slotIndex, scrollTop, itemHeight, overscan, itemCount) ? 'flex' : 'none'
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
{itemTemplate(
|
|
79
|
+
vlIndexForSlot(slotIndex, scrollTop, itemHeight, overscan),
|
|
80
|
+
vlSlotTop(slotIndex, scrollTop, itemHeight, overscan)
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default function VirtualList({
|
|
87
|
+
itemCount,
|
|
88
|
+
itemHeight,
|
|
89
|
+
scrollTop,
|
|
90
|
+
overscan,
|
|
91
|
+
id,
|
|
92
|
+
class: cls,
|
|
93
|
+
itemClass,
|
|
94
|
+
itemTemplate,
|
|
95
|
+
onTouchStart,
|
|
96
|
+
onTouchMove,
|
|
97
|
+
onTouchEnd
|
|
98
|
+
}: VirtualListProps) {
|
|
99
|
+
const rowOverscan = overscan === undefined ? 2 : overscan
|
|
100
|
+
return (
|
|
101
|
+
<virtual-list
|
|
102
|
+
id={id}
|
|
103
|
+
class={cls}
|
|
104
|
+
item-count={itemCount}
|
|
105
|
+
onTouchStart={onTouchStart}
|
|
106
|
+
onTouchMove={onTouchMove}
|
|
107
|
+
onTouchEnd={onTouchEnd}
|
|
108
|
+
>
|
|
109
|
+
<VirtualListSlot slotIndex={0} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
110
|
+
<VirtualListSlot slotIndex={1} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
111
|
+
<VirtualListSlot slotIndex={2} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
112
|
+
<VirtualListSlot slotIndex={3} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
113
|
+
<VirtualListSlot slotIndex={4} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
114
|
+
<VirtualListSlot slotIndex={5} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
115
|
+
<VirtualListSlot slotIndex={6} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
116
|
+
<VirtualListSlot slotIndex={7} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
117
|
+
<VirtualListSlot slotIndex={8} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
118
|
+
<VirtualListSlot slotIndex={9} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
119
|
+
<VirtualListSlot slotIndex={10} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
120
|
+
<VirtualListSlot slotIndex={11} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
121
|
+
<VirtualListSlot slotIndex={12} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
122
|
+
<VirtualListSlot slotIndex={13} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
123
|
+
<VirtualListSlot slotIndex={14} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
124
|
+
<VirtualListSlot slotIndex={15} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
|
|
125
|
+
</virtual-list>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CameraView } from './CameraView'
|
|
2
|
+
export type { CameraViewProps } from './CameraView'
|
|
3
|
+
export type { CameraFacing, CameraFlashMode, CameraDevice, CameraOpenOptions, CameraCaptureOptions, CameraPhoto, CameraController } from '@geastack/core'
|
|
4
|
+
export { default as VirtualList } from './VirtualList'
|
|
5
|
+
export type { VirtualListProps, VirtualListItemTemplate } from './VirtualList'
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@geastack/elements",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Non-core GeaStack JSX elements and native element backends.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/geastack/core.git",
|
|
9
|
+
"directory": "packages/elements"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=20.19"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"types": "./components/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./components/index.d.ts",
|
|
19
|
+
"default": "./components/index.ts"
|
|
20
|
+
},
|
|
21
|
+
"./components": {
|
|
22
|
+
"types": "./components/index.d.ts",
|
|
23
|
+
"default": "./components/index.ts"
|
|
24
|
+
},
|
|
25
|
+
"./components/CameraView": {
|
|
26
|
+
"types": "./components/CameraView.d.ts",
|
|
27
|
+
"default": "./components/CameraView.tsx"
|
|
28
|
+
},
|
|
29
|
+
"./components/VirtualList": {
|
|
30
|
+
"types": "./components/VirtualList.d.ts",
|
|
31
|
+
"default": "./components/VirtualList.tsx"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"components",
|
|
37
|
+
"ui"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@geastack/core": "^0.1.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "camera_element.h"
|
|
3
|
+
|
|
4
|
+
#include "canvas.h"
|
|
5
|
+
#include "internal.h"
|
|
6
|
+
#include "tree_internal.h"
|
|
7
|
+
|
|
8
|
+
#include <cstdlib>
|
|
9
|
+
#include <cstring>
|
|
10
|
+
|
|
11
|
+
namespace gea::embedded::ui {
|
|
12
|
+
|
|
13
|
+
namespace {
|
|
14
|
+
|
|
15
|
+
// Process-wide camera preview provider. Null on targets without a camera
|
|
16
|
+
// backend, in which case a <camera> element renders nothing.
|
|
17
|
+
CameraSurfaceProvider *gCameraProvider = nullptr;
|
|
18
|
+
|
|
19
|
+
CameraPreviewFit parseFit(const char *fit)
|
|
20
|
+
{
|
|
21
|
+
if (fit) {
|
|
22
|
+
if (std::strcmp(fit, "contain") == 0) return CameraPreviewFit::Contain;
|
|
23
|
+
if (std::strcmp(fit, "fill") == 0) return CameraPreviewFit::Fill;
|
|
24
|
+
}
|
|
25
|
+
return CameraPreviewFit::Cover;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
bool parseBool(const char *value)
|
|
29
|
+
{
|
|
30
|
+
return value && (std::strcmp(value, "true") == 0 || std::strcmp(value, "1") == 0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
} // namespace
|
|
34
|
+
|
|
35
|
+
void CameraSurface::setProvider(CameraSurfaceProvider *provider)
|
|
36
|
+
{
|
|
37
|
+
gCameraProvider = provider;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
CameraSurfaceProvider *CameraSurface::provider()
|
|
41
|
+
{
|
|
42
|
+
return gCameraProvider;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
CameraElement CameraElement::create()
|
|
46
|
+
{
|
|
47
|
+
return CameraElement(Tree::instance().createCamera());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void CameraRenderer::positionNativeOverlay(const Node &node, CameraSurfaceProvider *provider)
|
|
51
|
+
{
|
|
52
|
+
if (!provider) return;
|
|
53
|
+
if (node.layout.width <= 0 || node.layout.height <= 0) return;
|
|
54
|
+
int x0 = node.layout.x;
|
|
55
|
+
int y0 = node.layout.y;
|
|
56
|
+
int x1 = node.layout.x + node.layout.width - 1;
|
|
57
|
+
int y1 = node.layout.y + node.layout.height - 1;
|
|
58
|
+
ViewRenderer::transformedBounds(node, false, &x0, &y0, &x1, &y1);
|
|
59
|
+
const int w = x1 - x0 + 1;
|
|
60
|
+
const int h = y1 - y0 + 1;
|
|
61
|
+
if (w <= 0 || h <= 0) return;
|
|
62
|
+
provider->positionPreviewLayer(x0, y0, w, h);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
void CameraRenderer::record(const Node &node)
|
|
66
|
+
{
|
|
67
|
+
CameraSurfaceProvider *provider = CameraSurface::provider();
|
|
68
|
+
if (!provider) return;
|
|
69
|
+
|
|
70
|
+
Tree &tree = Tree::instance();
|
|
71
|
+
const Node *nodes = tree.nodes();
|
|
72
|
+
const int id = static_cast<int>(&node - nodes);
|
|
73
|
+
|
|
74
|
+
// `facing`/`device` select the camera; `width`/`height` are capture
|
|
75
|
+
// resolution hints (distinct from the node's on-screen layout size).
|
|
76
|
+
const char *facing = tree.getAttribute(id, "facing");
|
|
77
|
+
const char *device = tree.getAttribute(id, "device");
|
|
78
|
+
const int preferredWidth = std::atoi(tree.getAttribute(id, "width"));
|
|
79
|
+
const int preferredHeight = std::atoi(tree.getAttribute(id, "height"));
|
|
80
|
+
if (!provider->ensureOpen(facing ? facing : "", device ? device : "", preferredWidth, preferredHeight)) return;
|
|
81
|
+
if (!provider->isStreaming()) return;
|
|
82
|
+
|
|
83
|
+
const int x = node.layout.x;
|
|
84
|
+
const int y = node.layout.y;
|
|
85
|
+
const int w = node.layout.width;
|
|
86
|
+
const int h = node.layout.height;
|
|
87
|
+
if (w <= 0 || h <= 0) return;
|
|
88
|
+
|
|
89
|
+
if (provider->previewMode() == CameraPreviewMode::NativeOverlay) {
|
|
90
|
+
// The platform owns the preview surface; keep it aligned to the node's
|
|
91
|
+
// visual CSS rect, including transforms inherited from ancestors.
|
|
92
|
+
positionNativeOverlay(node, provider);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Framebuffer mode: fill an owned RGB565 buffer sized to the node rect, then
|
|
97
|
+
// blit it like a canvas so the preview honours CSS clip / z-order.
|
|
98
|
+
gea::framework::graphics::Canvas *surface = tree.ensureCameraSurface(id, w, h);
|
|
99
|
+
if (!surface || !surface->pixels()) return;
|
|
100
|
+
|
|
101
|
+
const CameraPreviewFit fit = parseFit(tree.getAttribute(id, "fit"));
|
|
102
|
+
const bool mirror = parseBool(tree.getAttribute(id, "mirror"));
|
|
103
|
+
if (!provider->fillPreview(surface->pixels(), surface->width(), surface->height(), fit, mirror)) return;
|
|
104
|
+
|
|
105
|
+
DisplayCommand *cmd = DisplayList::instance().append();
|
|
106
|
+
if (!cmd) return;
|
|
107
|
+
cmd->type = DisplayCommandType::BlitImage;
|
|
108
|
+
cmd->bx = static_cast<int16_t>(x);
|
|
109
|
+
cmd->by = static_cast<int16_t>(y);
|
|
110
|
+
cmd->bw = static_cast<int16_t>(w);
|
|
111
|
+
cmd->bh = static_cast<int16_t>(h);
|
|
112
|
+
cmd->blit.pixels = surface->pixels();
|
|
113
|
+
cmd->blit.alpha = nullptr;
|
|
114
|
+
cmd->blit.sourceWidth = static_cast<int16_t>(surface->width());
|
|
115
|
+
cmd->blit.sourceHeight = static_cast<int16_t>(surface->height());
|
|
116
|
+
cmd->blit.dx = static_cast<int16_t>(x);
|
|
117
|
+
cmd->blit.dy = static_cast<int16_t>(y);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "node.h"
|
|
5
|
+
#include "pixel.h"
|
|
6
|
+
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
namespace gea::embedded::ui {
|
|
11
|
+
|
|
12
|
+
struct Node;
|
|
13
|
+
|
|
14
|
+
// How the platform composites a <camera> leaf's live preview.
|
|
15
|
+
enum class CameraPreviewMode : std::uint8_t {
|
|
16
|
+
// The runtime owns an RGB565 buffer that the backend fills each frame; the
|
|
17
|
+
// preview is blitted through the normal display list, so it obeys CSS clip
|
|
18
|
+
// / z-order / border-radius like a <canvas>. (esp32-p4, geaos)
|
|
19
|
+
Framebuffer = 0,
|
|
20
|
+
// The backend owns a native preview surface (e.g. an iOS
|
|
21
|
+
// AVCaptureVideoPreviewLayer) that the runtime positions over the node's
|
|
22
|
+
// computed rect. The preview floats above the gea framebuffer. (iOS)
|
|
23
|
+
NativeOverlay = 1,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// CSS `object-fit`-style scaling of the camera frame into the node rect.
|
|
27
|
+
enum class CameraPreviewFit : std::uint8_t {
|
|
28
|
+
Cover = 0, // fill the rect, cropping overflow (default)
|
|
29
|
+
Contain = 1, // fit inside the rect, letterboxing
|
|
30
|
+
Fill = 2, // stretch to the rect, ignoring aspect
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Board-independent seam between the <camera> leaf node and the platform
|
|
34
|
+
// camera backend. Targets with a camera register a provider during init
|
|
35
|
+
// (see gea::framework::camera::registerCameraSurface); camera-less targets
|
|
36
|
+
// leave it null and a <camera> element simply renders nothing.
|
|
37
|
+
class CameraSurfaceProvider {
|
|
38
|
+
public:
|
|
39
|
+
virtual ~CameraSurfaceProvider() = default;
|
|
40
|
+
|
|
41
|
+
// Ensure the single active camera is open for the requested parameters.
|
|
42
|
+
// Idempotent and cheap once streaming. `device` (a device id) overrides
|
|
43
|
+
// `facing` when non-empty. Returns true when a live stream is available.
|
|
44
|
+
virtual bool ensureOpen(const std::string &facing,
|
|
45
|
+
const std::string &device,
|
|
46
|
+
int preferredWidth,
|
|
47
|
+
int preferredHeight) = 0;
|
|
48
|
+
|
|
49
|
+
// True once frames are flowing.
|
|
50
|
+
virtual bool isStreaming() = 0;
|
|
51
|
+
|
|
52
|
+
virtual CameraPreviewMode previewMode() = 0;
|
|
53
|
+
|
|
54
|
+
// Framebuffer mode: scale + convert the latest frame into the caller's
|
|
55
|
+
// native-pixel buffer of size dstWidth x dstHeight (RGB565 on 16-bit targets,
|
|
56
|
+
// RGBA8888 on full-colour targets like iOS). Returns true if written.
|
|
57
|
+
virtual bool fillPreview(gea::framework::graphics::pixel::native_t *dst,
|
|
58
|
+
int dstWidth,
|
|
59
|
+
int dstHeight,
|
|
60
|
+
CameraPreviewFit fit,
|
|
61
|
+
bool mirror) = 0;
|
|
62
|
+
|
|
63
|
+
// NativeOverlay mode: position / hide the native preview surface. The rect
|
|
64
|
+
// is in framebuffer pixels (the node's computed layout box).
|
|
65
|
+
virtual void positionPreviewLayer(int x, int y, int width, int height) = 0;
|
|
66
|
+
virtual void hidePreviewLayer() = 0;
|
|
67
|
+
|
|
68
|
+
// NativeOverlay mode: present one fresh frame into the positioned rect. Called
|
|
69
|
+
// once per frame by the render tick (in place of marking the node dirty), so
|
|
70
|
+
// the platform can paint the preview directly — e.g. the ESP32-P4 backend
|
|
71
|
+
// PPA-scales the camera frame straight into the display framebuffer at the
|
|
72
|
+
// rect and flushes only that region, skipping the display-list blit/replay.
|
|
73
|
+
// Default no-op: targets whose preview floats above the gea framebuffer (iOS)
|
|
74
|
+
// need nothing here.
|
|
75
|
+
virtual void presentNativeOverlay() {}
|
|
76
|
+
|
|
77
|
+
// Release the active stream when the owning <camera> node unmounts.
|
|
78
|
+
virtual void release(int nodeId) = 0;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Process-wide registry for the camera preview seam. Null until a platform
|
|
82
|
+
// backend registers a provider.
|
|
83
|
+
class CameraSurface {
|
|
84
|
+
public:
|
|
85
|
+
static void setProvider(CameraSurfaceProvider *provider);
|
|
86
|
+
static CameraSurfaceProvider *provider();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// The <camera> element handle. The surface is the node itself (positioned by
|
|
90
|
+
// CSS); the imperative controls (capturePhoto / startRecording / setExposure /
|
|
91
|
+
// …) lower to the gea::host::Camera facade since there is one active camera at
|
|
92
|
+
// a time, so this handle only needs node creation.
|
|
93
|
+
class CameraElement : public NodeHandle {
|
|
94
|
+
public:
|
|
95
|
+
using NodeHandle::NodeHandle;
|
|
96
|
+
static CameraElement create();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// CameraRenderer (the per-frame preview presentation for a NodeType::Camera
|
|
100
|
+
// leaf) is declared in internal.h alongside CanvasRenderer.
|
|
101
|
+
|
|
102
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "internal.h"
|
|
3
|
+
|
|
4
|
+
#include "tree_state.h"
|
|
5
|
+
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <cerrno>
|
|
8
|
+
#include <cstdlib>
|
|
9
|
+
#include <cstring>
|
|
10
|
+
|
|
11
|
+
// A <virtual-list> is a generic overflow:scroll container that windows a small
|
|
12
|
+
// pool of real child "slot" nodes (the row template, supplied by the app) over
|
|
13
|
+
// a virtual content height of itemCount * rowHeight. It owns NO row content:
|
|
14
|
+
// labels, fonts, colours, padding and the row height itself all come from the
|
|
15
|
+
// child slots' own CSS, exactly like any other node. The C++ side only tracks
|
|
16
|
+
// the total item count and reports the virtual content height so the generic
|
|
17
|
+
// scroll/scrollbar/render machinery can drive it; the app positions and rebinds
|
|
18
|
+
// the recycled slots reactively from the element's scrollTop.
|
|
19
|
+
|
|
20
|
+
namespace gea::embedded::ui {
|
|
21
|
+
|
|
22
|
+
namespace {
|
|
23
|
+
|
|
24
|
+
int parseIntAttribute(const char *value, int fallback)
|
|
25
|
+
{
|
|
26
|
+
if (!value || !value[0]) return fallback;
|
|
27
|
+
char *end = nullptr;
|
|
28
|
+
errno = 0;
|
|
29
|
+
const long parsed = std::strtol(value, &end, 10);
|
|
30
|
+
if (errno != 0 || end == value) return fallback;
|
|
31
|
+
if (parsed < 0) return 0;
|
|
32
|
+
if (parsed > 0x3fffffffL) return 0x3fffffff;
|
|
33
|
+
return static_cast<int>(parsed);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bool sameName(const char *a, const char *b)
|
|
37
|
+
{
|
|
38
|
+
if (!a || !b) return false;
|
|
39
|
+
while (*a && *b) {
|
|
40
|
+
char ca = *a == '-' ? '_' : *a;
|
|
41
|
+
char cb = *b == '-' ? '_' : *b;
|
|
42
|
+
if (ca >= 'A' && ca <= 'Z') ca = static_cast<char>(ca - 'A' + 'a');
|
|
43
|
+
if (cb >= 'A' && cb <= 'Z') cb = static_cast<char>(cb - 'A' + 'a');
|
|
44
|
+
if (ca != cb) return false;
|
|
45
|
+
++a;
|
|
46
|
+
++b;
|
|
47
|
+
}
|
|
48
|
+
return *a == '\0' && *b == '\0';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
int clampScrollTop(const Node &n, int scrollTop)
|
|
52
|
+
{
|
|
53
|
+
int maxY = n.layout.scroll_content_height - n.layout.height;
|
|
54
|
+
if (maxY < 0) maxY = 0;
|
|
55
|
+
if (scrollTop < 0) scrollTop = 0;
|
|
56
|
+
if (scrollTop > maxY) scrollTop = maxY;
|
|
57
|
+
return scrollTop;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
bool canScrollY(int node, const Node &n)
|
|
61
|
+
{
|
|
62
|
+
if (n.type == NodeType::VirtualList) return VirtualListRenderer::scrollMaxY(node) > 0;
|
|
63
|
+
if (!isViewLikeNodeType(n.type) || !scrollsOverflowY(n.style)) return false;
|
|
64
|
+
return ViewRenderer::scrollMaxY(n) > 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
int nearestScrollableAncestorY(const TreeState &state, int node)
|
|
68
|
+
{
|
|
69
|
+
for (int current = state.nodes[node].parent; current >= 0; current = state.nodes[current].parent) {
|
|
70
|
+
if (canScrollY(current, state.nodes[current])) return current;
|
|
71
|
+
}
|
|
72
|
+
return -1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
bool targetContentBoundsY(const TreeState &state, int scroller, int target, int *top, int *bottom)
|
|
76
|
+
{
|
|
77
|
+
if (!top || !bottom) return false;
|
|
78
|
+
if (scroller < 0 || target < 0 || scroller >= state.nodeCount || target >= state.nodeCount) return false;
|
|
79
|
+
|
|
80
|
+
int y = 0;
|
|
81
|
+
for (int current = target; current >= 0 && current != scroller; current = state.nodes[current].parent) {
|
|
82
|
+
const Node &node = state.nodes[current];
|
|
83
|
+
if (!state.nodeActive[current] || node.style.display == kDisplayNone) return false;
|
|
84
|
+
y += node.layout.y;
|
|
85
|
+
|
|
86
|
+
const int parent = node.parent;
|
|
87
|
+
if (parent < 0 || parent >= state.nodeCount) return false;
|
|
88
|
+
if (parent != scroller && state.nodes[parent].style.overflow == 2 && scrollsOverflowY(state.nodes[parent].style)) {
|
|
89
|
+
y -= state.nodes[parent].layout.scroll_y;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (target != scroller) {
|
|
94
|
+
int current = target;
|
|
95
|
+
while (current >= 0 && current != scroller) current = state.nodes[current].parent;
|
|
96
|
+
if (current != scroller) return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
*top = y;
|
|
100
|
+
*bottom = y + state.nodes[target].layout.height;
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
bool scrollResolvedNodeIntoView(TreeState &state, int node)
|
|
105
|
+
{
|
|
106
|
+
const int scroller = nearestScrollableAncestorY(state, node);
|
|
107
|
+
if (scroller < 0) return false;
|
|
108
|
+
|
|
109
|
+
const Node &target = state.nodes[node];
|
|
110
|
+
const Node &container = state.nodes[scroller];
|
|
111
|
+
const int viewportTop = container.layout.scroll_y;
|
|
112
|
+
const int viewportBottom = viewportTop + container.layout.height;
|
|
113
|
+
const int targetTop = target.layout.y - container.layout.y + container.layout.scroll_y;
|
|
114
|
+
const int targetBottom = targetTop + target.layout.height;
|
|
115
|
+
|
|
116
|
+
int next = container.layout.scroll_y;
|
|
117
|
+
if (targetTop < viewportTop) {
|
|
118
|
+
next = targetTop;
|
|
119
|
+
} else if (targetBottom > viewportBottom) {
|
|
120
|
+
next = targetBottom - container.layout.height;
|
|
121
|
+
} else {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
Tree::instance().setScrollTop(scroller, next);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
} // namespace
|
|
129
|
+
|
|
130
|
+
void VirtualListRenderer::init(int node)
|
|
131
|
+
{
|
|
132
|
+
if (node < 0 || node >= kMaxNodes) return;
|
|
133
|
+
auto &state = treeState();
|
|
134
|
+
ensureRareData(node).virtualList.itemCount = 0;
|
|
135
|
+
// Behave like any overflow:scroll container so the generic scroll, clip and
|
|
136
|
+
// scrollbar paths drive the list. The app's CSS may also set this; forcing
|
|
137
|
+
// it here keeps a bare <virtual-list> scrollable.
|
|
138
|
+
state.nodes[node].style.overflow = 2;
|
|
139
|
+
state.nodes[node].style.overflow_x = 0;
|
|
140
|
+
state.nodes[node].style.overflow_y = 2;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void VirtualListRenderer::configureAttribute(int node, const char *name, const char *value)
|
|
144
|
+
{
|
|
145
|
+
auto &state = treeState();
|
|
146
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return;
|
|
147
|
+
auto &list = ensureRareData(node).virtualList;
|
|
148
|
+
|
|
149
|
+
if (sameName(name, "item-count") || sameName(name, "itemCount")) {
|
|
150
|
+
const int next = parseIntAttribute(value, list.itemCount);
|
|
151
|
+
if (next == list.itemCount) return;
|
|
152
|
+
list.itemCount = next;
|
|
153
|
+
Node &n = state.nodes[node];
|
|
154
|
+
n.render.dirty = 1;
|
|
155
|
+
n.render.layout_dirty = 1;
|
|
156
|
+
n.render.non_scroll_dirty = 1;
|
|
157
|
+
Tree::instance().markNodeDisplayCommandsDirty(node);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
int VirtualListRenderer::itemCount(int node)
|
|
162
|
+
{
|
|
163
|
+
const auto &state = treeState();
|
|
164
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
|
|
165
|
+
const NodeRareData *rd = rareDataFor(node);
|
|
166
|
+
return rd ? rd->virtualList.itemCount : 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
int VirtualListRenderer::virtualContentHeight(int node, int rowHeight)
|
|
170
|
+
{
|
|
171
|
+
auto &state = treeState();
|
|
172
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
|
|
173
|
+
// Cache the measured row height (the first slot child's rendered CSS layout
|
|
174
|
+
// height) so the app can read it back via the element's `rowHeight` property
|
|
175
|
+
// and position/window its recycled slots from the SAME value the native
|
|
176
|
+
// scroll geometry uses — one source of truth, instead of the app
|
|
177
|
+
// recomputing ITEM_HEIGHT and hand-syncing it to the CSS.
|
|
178
|
+
if (rowHeight > 0) ensureRareData(node).virtualList.rowHeight = static_cast<int32_t>(rowHeight);
|
|
179
|
+
const NodeRareData *rd = rareDataFor(node);
|
|
180
|
+
const int count = rd ? rd->virtualList.itemCount : 0;
|
|
181
|
+
if (count <= 0 || rowHeight <= 0) return 0;
|
|
182
|
+
const int64_t raw = static_cast<int64_t>(count) * static_cast<int64_t>(rowHeight);
|
|
183
|
+
return raw > 0x3fffffffLL ? 0x3fffffff : static_cast<int>(raw);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
int VirtualListRenderer::rowHeight(int node)
|
|
187
|
+
{
|
|
188
|
+
const auto &state = treeState();
|
|
189
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
|
|
190
|
+
const NodeRareData *rd = rareDataFor(node);
|
|
191
|
+
return rd ? rd->virtualList.rowHeight : 0;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
int VirtualListRenderer::scrollTop(int node)
|
|
195
|
+
{
|
|
196
|
+
const auto &state = treeState();
|
|
197
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
|
|
198
|
+
return state.nodes[node].layout.scroll_y;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
int VirtualListRenderer::previousScrollTop(int node)
|
|
202
|
+
{
|
|
203
|
+
const auto &state = treeState();
|
|
204
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
|
|
205
|
+
return state.nodes[node].layout.previous_scroll_y;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
int VirtualListRenderer::scrollMaxY(int node)
|
|
209
|
+
{
|
|
210
|
+
const auto &state = treeState();
|
|
211
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
|
|
212
|
+
const Node &n = state.nodes[node];
|
|
213
|
+
const int maxY = n.layout.scroll_content_height - n.layout.height;
|
|
214
|
+
return maxY > 0 ? maxY : 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
bool VirtualListRenderer::setScrollTop(int node, int scrollTop)
|
|
218
|
+
{
|
|
219
|
+
auto &state = treeState();
|
|
220
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return false;
|
|
221
|
+
Node &n = state.nodes[node];
|
|
222
|
+
const int clamped = clampScrollTop(n, scrollTop);
|
|
223
|
+
if (clamped == n.layout.scroll_y) return false;
|
|
224
|
+
n.layout.scroll_y = static_cast<int32_t>(clamped);
|
|
225
|
+
n.render.dirty = 1;
|
|
226
|
+
n.render.layout_dirty = 1;
|
|
227
|
+
Tree::instance().markScrollDirty(node);
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
void VirtualListRenderer::captureSnapshot(int node)
|
|
232
|
+
{
|
|
233
|
+
auto &state = treeState();
|
|
234
|
+
if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return;
|
|
235
|
+
Node &n = state.nodes[node];
|
|
236
|
+
n.layout.previous_scroll_y = n.layout.scroll_y;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
int Tree::scrollTop(int node) const
|
|
240
|
+
{
|
|
241
|
+
if (node < 0 || node >= nodeCount()) return 0;
|
|
242
|
+
return treeState().nodes[node].layout.scroll_y;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
int Tree::scrollLeft(int node) const
|
|
246
|
+
{
|
|
247
|
+
if (node < 0 || node >= nodeCount()) return 0;
|
|
248
|
+
return treeState().nodes[node].layout.scroll_x;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
void Tree::setScrollLeft(int node, int scrollLeft)
|
|
252
|
+
{
|
|
253
|
+
if (node < 0 || node >= nodeCount()) return;
|
|
254
|
+
Node &n = treeState().nodes[node];
|
|
255
|
+
if (!isViewLikeNodeType(n.type) || !scrollsOverflowX(n.style) || n.type == NodeType::VirtualList) return;
|
|
256
|
+
const int maxX = ViewRenderer::scrollMaxX(n);
|
|
257
|
+
if (scrollLeft < 0) scrollLeft = 0;
|
|
258
|
+
if (scrollLeft > maxX) scrollLeft = maxX;
|
|
259
|
+
if (scrollLeft == n.layout.scroll_x) return;
|
|
260
|
+
n.layout.scroll_x = static_cast<int32_t>(scrollLeft);
|
|
261
|
+
n.render.dirty = 1;
|
|
262
|
+
n.render.layout_dirty = 1;
|
|
263
|
+
n.render.non_scroll_dirty = 1;
|
|
264
|
+
markScrollDirty(node);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
void Tree::setScrollTop(int node, int scrollTop)
|
|
268
|
+
{
|
|
269
|
+
if (node < 0 || node >= nodeCount()) return;
|
|
270
|
+
Node &n = treeState().nodes[node];
|
|
271
|
+
if (!isViewLikeNodeType(n.type) || (n.type != NodeType::VirtualList && !scrollsOverflowY(n.style))) return;
|
|
272
|
+
const int maxY = ViewRenderer::scrollMaxY(n);
|
|
273
|
+
if (scrollTop < 0) scrollTop = 0;
|
|
274
|
+
if (scrollTop > maxY) scrollTop = maxY;
|
|
275
|
+
if (scrollTop == n.layout.scroll_y) return;
|
|
276
|
+
n.layout.scroll_y = static_cast<int32_t>(scrollTop);
|
|
277
|
+
n.render.dirty = 1;
|
|
278
|
+
n.render.layout_dirty = 1;
|
|
279
|
+
markScrollDirty(node);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
void Tree::scrollIntoView(int node)
|
|
283
|
+
{
|
|
284
|
+
auto &state = treeState();
|
|
285
|
+
if (node < 0 || node >= state.nodeCount || !state.nodeActive[node]) return;
|
|
286
|
+
state.pendingScrollIntoViewNode = node;
|
|
287
|
+
scrollResolvedNodeIntoView(state, node);
|
|
288
|
+
markDisplayListContentDirty();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
void Tree::applyPendingScrollIntoView()
|
|
292
|
+
{
|
|
293
|
+
auto &state = treeState();
|
|
294
|
+
const int node = state.pendingScrollIntoViewNode;
|
|
295
|
+
if (node < 0) return;
|
|
296
|
+
if (node >= state.nodeCount || !state.nodeActive[node]) {
|
|
297
|
+
state.pendingScrollIntoViewNode = -1;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const int scroller = nearestScrollableAncestorY(state, node);
|
|
301
|
+
if (scroller < 0) return;
|
|
302
|
+
|
|
303
|
+
const Node &container = state.nodes[scroller];
|
|
304
|
+
const int viewportTop = container.layout.scroll_y;
|
|
305
|
+
const int viewportBottom = viewportTop + container.layout.height;
|
|
306
|
+
int targetTop = 0;
|
|
307
|
+
int targetBottom = 0;
|
|
308
|
+
if (!targetContentBoundsY(state, scroller, node, &targetTop, &targetBottom)) {
|
|
309
|
+
state.pendingScrollIntoViewNode = -1;
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
int next = container.layout.scroll_y;
|
|
314
|
+
if (targetTop < viewportTop) {
|
|
315
|
+
next = targetTop;
|
|
316
|
+
} else if (targetBottom > viewportBottom) {
|
|
317
|
+
next = targetBottom - container.layout.height;
|
|
318
|
+
} else {
|
|
319
|
+
state.pendingScrollIntoViewNode = -1;
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
state.pendingScrollIntoViewNode = -1;
|
|
323
|
+
setScrollTop(scroller, next);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
} // namespace gea::embedded::ui
|