Commit ddfafab
Windows as Entities (#5589)
# Objective
Fix #4530
- Make it easier to open/close/modify windows by setting them up as `Entity`s with a `Window` component.
- Make multiple windows very simple to set up. (just add a `Window` component to an entity and it should open)
## Solution
- Move all properties of window descriptor to ~components~ a component.
- Replace `WindowId` with `Entity`.
- ~Use change detection for components to update backend rather than events/commands. (The `CursorMoved`/`WindowResized`/... events are kept for user convenience.~
Check each field individually to see what we need to update, events are still kept for user convenience.
---
## Changelog
- `WindowDescriptor` renamed to `Window`.
- Width/height consolidated into a `WindowResolution` component.
- Requesting maximization/minimization is done on the [`Window::state`] field.
- `WindowId` is now `Entity`.
## Migration Guide
- Replace `WindowDescriptor` with `Window`.
- Change `width` and `height` fields in a `WindowResolution`, either by doing
```rust
WindowResolution::new(width, height) // Explicitly
// or using From<_> for tuples for convenience
(1920., 1080.).into()
```
- Replace any `WindowCommand` code to just modify the `Window`'s fields directly and creating/closing windows is now by spawning/despawning an entity with a `Window` component like so:
```rust
let window = commands.spawn(Window { ... }).id(); // open window
commands.entity(window).despawn(); // close window
```
## Unresolved
- ~How do we tell when a window is minimized by a user?~
~Currently using the `Resize(0, 0)` as an indicator of minimization.~
No longer attempting to tell given how finnicky this was across platforms, now the user can only request that a window be maximized/minimized.
## Future work
- Move `exit_on_close` functionality out from windowing and into app(?)
- #5621
- #7099
- #7098
Co-authored-by: Carter Anderson <[email protected]>1 parent f0c5049 commit ddfafab
File tree
47 files changed
+1912
-1864
lines changed- crates
- bevy_render/src
- camera
- view
- bevy_text/src
- bevy_ui/src
- flex
- render
- widget
- bevy_window/src
- bevy_winit/src
- examples
- 3d
- app
- ecs
- games
- input
- ios/src
- shader
- stress_tests
- tools/scene_viewer
- ui
- window
- tests/window
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
47 files changed
+1912
-1864
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
| |||
325 | 329 | | |
326 | 330 | | |
327 | 331 | | |
328 | | - | |
| 332 | + | |
329 | 333 | | |
330 | 334 | | |
331 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
332 | 347 | | |
333 | 348 | | |
334 | 349 | | |
| |||
340 | 355 | | |
341 | 356 | | |
342 | 357 | | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
343 | 370 | | |
344 | 371 | | |
345 | 372 | | |
346 | 373 | | |
347 | 374 | | |
348 | 375 | | |
349 | | - | |
350 | | - | |
| 376 | + | |
| 377 | + | |
351 | 378 | | |
352 | | - | |
| 379 | + | |
353 | 380 | | |
354 | 381 | | |
355 | 382 | | |
| |||
362 | 389 | | |
363 | 390 | | |
364 | 391 | | |
365 | | - | |
366 | | - | |
| 392 | + | |
| 393 | + | |
367 | 394 | | |
368 | | - | |
| 395 | + | |
369 | 396 | | |
370 | 397 | | |
371 | 398 | | |
372 | 399 | | |
373 | 400 | | |
374 | | - | |
| 401 | + | |
375 | 402 | | |
376 | | - | |
| 403 | + | |
377 | 404 | | |
378 | 405 | | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
388 | 418 | | |
389 | 419 | | |
390 | | - | |
| 420 | + | |
391 | 421 | | |
392 | 422 | | |
393 | | - | |
| 423 | + | |
394 | 424 | | |
395 | | - | |
| 425 | + | |
396 | 426 | | |
| 427 | + | |
397 | 428 | | |
398 | 429 | | |
399 | 430 | | |
400 | | - | |
| 431 | + | |
401 | 432 | | |
402 | 433 | | |
403 | 434 | | |
404 | | - | |
405 | | - | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
406 | 441 | | |
407 | 442 | | |
408 | 443 | | |
| |||
431 | 466 | | |
432 | 467 | | |
433 | 468 | | |
434 | | - | |
| 469 | + | |
| 470 | + | |
435 | 471 | | |
436 | 472 | | |
437 | 473 | | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
| 474 | + | |
448 | 475 | | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
457 | 479 | | |
458 | 480 | | |
459 | 481 | | |
| |||
472 | 494 | | |
473 | 495 | | |
474 | 496 | | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
487 | 509 | | |
488 | 510 | | |
489 | 511 | | |
490 | 512 | | |
491 | 513 | | |
492 | 514 | | |
493 | 515 | | |
494 | | - | |
| 516 | + | |
495 | 517 | | |
496 | 518 | | |
497 | 519 | | |
| |||
510 | 532 | | |
511 | 533 | | |
512 | 534 | | |
| 535 | + | |
513 | 536 | | |
| 537 | + | |
514 | 538 | | |
515 | 539 | | |
516 | 540 | | |
| |||
525 | 549 | | |
526 | 550 | | |
527 | 551 | | |
528 | | - | |
| 552 | + | |
529 | 553 | | |
530 | 554 | | |
531 | 555 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
141 | 146 | | |
142 | | - | |
143 | 147 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
| 288 | + | |
289 | 289 | | |
290 | | - | |
291 | | - | |
| 290 | + | |
| 291 | + | |
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| |||
0 commit comments