emilk / emilk/egui

Rotation of egui layers

Open
#4,130 0 comments 6 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

Since #3906 has added TSTransform which allows for scaling and zooming egui layers (awesome!), could we upgrade this transform to also allow for layer rotation?

**Is your feature request related to a problem? Please describe.**
In my collaborative painting app users should be able to rotate the canvas they are working on. Due to the collaborative nature I'd also like to show ui on the canvas.

**Describe the solution you'd like**
Context::set_transform_layer should accept a Transform that also has a rotation component.

**Describe alternatives you've considered**
- Write a tiny custom ui framework to render the canvas ui for my app
- The hack using a secound egui context outlined here: #1811

**Additional context**

I tried to [make a quick proof of concept ](https://github.com/lucasmerlin/egui/tree/transform-rotation)to see how much effort this would be using glam for the transform matrix and I've got some promising results:

https://github.com/emilk/egui/assets/8009393/c7769025-57de-4f9f-aa56-fe44272f9f19

I guess using glam or some other crate is probably not possible and egui would need to either add Rotation to it's Transform struct or add it's own Matrix implementation?
If this is something that could be added to egui I would be interested in making a PR and working on this.

The biggest challenges seem to be:
- Handling PaintCallback (I don't think those could be rotated?)
- Handling ClipRects

Related to #2054 (individual widget rotation)

Edit: Looking a bit more into how ClipRects are handled, it seems like for rotation to work properly with e.g. ScrollAreas we would need support for rotated clip rects. In egui_wgpu, ClipRects are implemented with set_scissor_rect, which wouldn't support rotation, so I'm not sure if there is a good way to do this.

Contributor guide

Open the contributing guide

Research direction

Start at Context::set_transform_layer and the TSTransform added in #3906, then trace how PaintCallback and ClipRects are handled, especially egui_wgpu's set_scissor_rect path. Compare the proof of concept's glam-based transform with egui's existing transform types. Done means layers, canvas UI, callbacks, and clipping behave correctly under rotation, including in scroll areas.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.