Commit 2d4e140
authored
UI per text section picking (#22047)
# Objective
Allow picking text per section.
Fixes #17477
## Solution
In `ui_picking` whenever a node with text components is below a pointer,
don't add the `Text` node's entity to the `hit_nodes` list. Instead,
iterate the list of text section bounding rects in its `TextLayoutInfo`
component to find which text section the pointer is over, and add that
section's entity id to the `hit_nodes` list.
* Add optional text components to `NodeQuery`.
* New helper function, `pick_ui_text`. Finds if a text section is
hovered and returns its id.
* Add the entities of text sections to `hit_nodes` when hovered.
* Add the target camera entity to `hit_nodes`, instead of querying for
it a second time.
* When a picked node is a text node and `require_markers` is enabled,
check if the hit section entity has a `Pickable` component, instead of
the text node.
#
This design might need to be changed later to allow for text selection
and copying. But there doesn't seem any need to overcomplicate things
for now by considering it.
## Testing
I added observers to the `TextBackgroundColors` example's text entities.
The observers turn a text section's text color to white when the pointer
hovers them.
```
cargo run --example text_background_colors
```1 parent c7b752a commit 2d4e140
File tree
4 files changed
+93
-24
lines changed- crates/bevy_ui/src
- examples/ui
- release-content
- migration-guides
- release-notes
4 files changed
+93
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| 113 | + | |
111 | 114 | | |
112 | 115 | | |
113 | 116 | | |
| |||
143 | 146 | | |
144 | 147 | | |
145 | 148 | | |
146 | | - | |
| 149 | + | |
147 | 150 | | |
148 | 151 | | |
149 | 152 | | |
| |||
175 | 178 | | |
176 | 179 | | |
177 | 180 | | |
178 | | - | |
| 181 | + | |
| 182 | + | |
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
| |||
188 | 192 | | |
189 | 193 | | |
190 | 194 | | |
191 | | - | |
192 | | - | |
| 195 | + | |
| 196 | + | |
193 | 197 | | |
194 | 198 | | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
198 | 202 | | |
199 | 203 | | |
200 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
201 | 227 | | |
202 | 228 | | |
203 | 229 | | |
| |||
210 | 236 | | |
211 | 237 | | |
212 | 238 | | |
| 239 | + | |
213 | 240 | | |
214 | 241 | | |
215 | 242 | | |
| |||
224 | 251 | | |
225 | 252 | | |
226 | 253 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 254 | + | |
234 | 255 | | |
235 | | - | |
236 | | - | |
| 256 | + | |
| 257 | + | |
237 | 258 | | |
238 | 259 | | |
239 | | - | |
| 260 | + | |
240 | 261 | | |
241 | 262 | | |
242 | 263 | | |
| |||
258 | 279 | | |
259 | 280 | | |
260 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
61 | 76 | | |
62 | 77 | | |
63 | 78 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments