Add Ui::with_visual_transform - #5055
Merged
Merged
Conversation
…ut creating a new layer
lucasmerlin
force-pushed
the
add-ui-with-transform
branch
from
September 1, 2024 20:45
0d30ec7 to
467f7ab
Compare
emilk
reviewed
Sep 2, 2024
lucasmerlin
force-pushed
the
add-ui-with-transform
branch
from
September 2, 2024 13:21
f52296f to
a42ecba
Compare
hacknus
pushed a commit
to hacknus/egui
that referenced
this pull request
Oct 30, 2024
* [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) }); }); }) } ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows you to transform widgets without having to put them on a new layer.
Example usage:
Bildschirmaufnahme.2024-09-01.um.22.32.42.mov