egui/crates/eframe/src/web
Jan Procházka 514ee0c433
Improve web text agent (#4561)
- Closes https://github.com/emilk/egui/issues/4060 - no longer aligned
to top
- Closes https://github.com/emilk/egui/issues/4479 - `canvas.style` is
not set anywhere anymore
- Closes https://github.com/emilk/egui/issues/2231 - same as #4060
- Closes https://github.com/emilk/egui/issues/3618 - there is now one
`<input>` per `eframe` app, and it's removed transitively by
`WebRunner::destroy -> AppRunner::drop -> TextAgent::drop`

This PR improves the text agent to make fewer assumptions about how
`egui` is embedded into the page:
- Text agent no longer sets the canvas position
- There is now a text agent for each instance of `WebRunner`
- The input element is now moved to the correct position, so the OS can
display the IME window in the correct place. Before it would typically
be outside of the viewport

The best way to test this is to build & server the web demo locally:
```
scripts/build_demo_web.sh && scripts/start_server.sh
```

Then open the EasyMark editor, and try using IME to input some emojis:
http://localhost:8888/#EasyMarkEditor

To open the emoji keyboard use:
- <kbd>win + .</kbd> on Windows
- <kbd>ctrl + cmd + space</kbd> on Mac

Tested on:
- [x] Windows
- [x] Linux
- [x] MacOS
- [x] Android
- [x] iOS

## Migration guide

The canvas no longer controls its own size/position on the page. This
means that those properties can now be controlled entirely via HTML and
CSS, and multiple separate `eframe` apps can coexist better on a single
page.

To match the old behavior, set the `canvas` width and height to 100% of
the `body` element:

```html
<html>
  <body>
    <canvas></canvas>
  </body>
</html>
```

```css
/* remove default margins and use full viewport */
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
}

canvas {
  /* match parent element size */
  width: 100%;
  height: 100%;
}
```

Note that there is no need to set `position: absolute`/`left: 50%;
transform: translateX(-50%)`/etc., and setting those properties may
poorly affect the sharpness of `egui`-rendered text.

Because `eframe` no longer updates the canvas style in any way, it also
means that on mobile, the canvas no longer collapses upwards to make
space for a mobile keyboard. This should be solved in other ways:
https://github.com/emilk/egui/issues/4572
2024-05-29 12:54:33 +02:00
..
app_runner.rs Improve web text agent (#4561) 2024-05-29 12:54:33 +02:00
backend.rs eframe: Correctly identify if browser tab has focus (#4280) 2024-03-30 16:22:16 +01:00
events.rs Improve web text agent (#4561) 2024-05-29 12:54:33 +02:00
input.rs Add web support for `zoom_factor` (#4260) 2024-03-29 11:55:49 +01:00
mod.rs Improve web text agent (#4561) 2024-05-29 12:54:33 +02:00
panic_handler.rs Improve documentation of `eframe`, especially for wasm32 (#3295) 2023-09-04 09:55:47 +02:00
screen_reader.rs Remove dependency on `tts` (#3651) 2023-11-28 10:46:18 +01:00
storage.rs Update to Rust 1.76 (#4411) 2024-04-25 15:51:01 +02:00
text_agent.rs Improve web text agent (#4561) 2024-05-29 12:54:33 +02:00
web_logger.rs Update wgpu to 0.19 (#3824) 2024-01-19 10:14:13 +01:00
web_painter.rs Fix crash on `request_animation_frame` when destroying web runner (#4169) 2024-03-14 10:26:34 +01:00
web_painter_glow.rs Fix crash on `request_animation_frame` when destroying web runner (#4169) 2024-03-14 10:26:34 +01:00
web_painter_wgpu.rs Fix crash on `request_animation_frame` when destroying web runner (#4169) 2024-03-14 10:26:34 +01:00
web_runner.rs Improve web text agent (#4561) 2024-05-29 12:54:33 +02:00