egui/crates
lucasmerlin 89b6055f9c
Add `Ui::with_visual_transform` (#5055)
* [X] I have followed the instructions in the PR template

This allows you to transform widgets without having to put them on a new
layer.
Example usage: 


https://github.com/user-attachments/assets/6b547782-f15e-42ce-835f-e8febe8d2d65

```rust
use eframe::egui;
use eframe::egui::{Button, Frame, InnerResponse, Label, Pos2, RichText, UiBuilder, Widget};
use eframe::emath::TSTransform;
use eframe::NativeOptions;
use egui::{CentralPanel, Sense, WidgetInfo};

pub fn main() -> eframe::Result {
    eframe::run_simple_native("focus test", NativeOptions::default(), |ctx, _frame| {
        CentralPanel::default().show(ctx, |ui| {
            let response = ui.ctx().read_response(ui.next_auto_id());

            let pressed = response
                .as_ref()
                .is_some_and(|r| r.is_pointer_button_down_on());

            let hovered = response.as_ref().is_some_and(|r| r.hovered());

            let target_scale = match (pressed, hovered) {
                (true, _) => 0.94,
                (_, true) => 1.06,
                _ => 1.0,
            };

            let scale = ui
                .ctx()
                .animate_value_with_time(ui.id().with("Down"), target_scale, 0.1);

            let mut center = response
                .as_ref()
                .map(|r| r.rect.center())
                .unwrap_or_else(|| Pos2::new(0.0, 0.0));
            if center.any_nan() {
                center = Pos2::new(0.0, 0.0);
            }

            let transform = TSTransform::from_translation(center.to_vec2())
                * TSTransform::from_scaling(scale)
                * TSTransform::from_translation(-center.to_vec2());

            ui.with_visual_transform(transform, |ui| {
                Button::new(RichText::new("Yaaaay").size(20.0))
                    .sense(Sense::click())
                    .ui(ui)
            });
        });
    })
}

```
2024-09-10 11:04:13 +02:00
..
ecolor Use precomputed lookup table in Color32::from_rgba_unmultiplied (#5088) 2024-09-10 09:50:56 +02:00
eframe Update `glow` to 0.14 (#4952) 2024-09-09 14:02:06 +02:00
egui Add `Ui::with_visual_transform` (#5055) 2024-09-10 11:04:13 +02:00
egui-wgpu Remove reference to egui::Color32. (#5011) 2024-09-09 14:34:13 +02:00
egui-winit Enable rustdoc `generate-link-to-definition` feature on docs.rs (#5030) 2024-08-30 11:22:29 +02:00
egui_demo_app Rename `id_source` to `id_salt` (#5025) 2024-09-02 09:29:01 +02:00
egui_demo_lib Add `egui::Sides` for adding UI on left and right sides (#5036) 2024-09-02 10:47:20 +02:00
egui_extras Add `ui.shrink_clip_rect` (#5068) 2024-09-04 17:01:41 +02:00
egui_glow Update `glow` to 0.14 (#4952) 2024-09-09 14:02:06 +02:00
egui_plot Move `egui_plot` to its own repo (#4828) 2024-07-15 18:45:19 +02:00
egui_web Fix typos (#2866) 2023-04-18 15:52:45 +02:00
emath Enable rustdoc `generate-link-to-definition` feature on docs.rs (#5030) 2024-08-30 11:22:29 +02:00
epaint Use precomputed lookup table in Color32::from_rgba_unmultiplied (#5088) 2024-09-10 09:50:56 +02:00
epaint_default_fonts Enable rustdoc `generate-link-to-definition` feature on docs.rs (#5030) 2024-08-30 11:22:29 +02:00