Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: images with background color now respects rounding #4029

Merged
merged 2 commits into from
Feb 18, 2024
Merged

Fix: images with background color now respects rounding #4029

merged 2 commits into from
Feb 18, 2024

Conversation

vincent-sparks
Copy link
Contributor

Code:

use egui::{TextureHandle, Image, Vec2, Layout, Direction};

struct App {
    texture: TextureHandle,
}

const ROW_HEIGHT: f32 = 200.0;

impl App {
    fn new(ctx: &eframe::CreationContext) -> Self {
        Self {
            texture: ctx.egui_ctx.load_texture("sample", egui::ColorImage::example(), egui::TextureOptions::default()),
        }
    }
}

impl eframe::App for App {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().frame(egui::Frame::dark_canvas(&ctx.style())).show(ctx, |ui| {
            ui.with_layout(Layout::centered_and_justified(Direction::TopDown), |ui|{
                ui.add(Image::new(&self.texture)
                       .bg_fill(egui::Color32::WHITE)
                       .rounding(30.0)
                      );
            });
        });
    }
}

fn main() -> eframe::Result<()> {
    eframe::run_native("egui test", eframe::NativeOptions{
        viewport: egui::ViewportBuilder::default().with_inner_size((256.,200.)),
        ..Default::default()
    }, Box::new(|cc| Box::new(App::new(cc))))
}

Before:
before

After:
after

(please see the comment in the diff -- definitely not sure if it's up to code standards. you might want to change/remove that comment as well as the Mesh codepath if it was not, in fact, done for performance reasons)

crates/egui/src/widgets/image.rs Outdated Show resolved Hide resolved
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
@emilk emilk added bug Something is broken egui labels Feb 18, 2024
@emilk emilk changed the title Fixed images with background color not respecting rounding Fix: images with background color now respects rounding Feb 18, 2024
@emilk emilk merged commit 68b3ef7 into emilk:master Feb 18, 2024
20 of 21 checks passed
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
Co-authored-by: Vincent Sparks <vincent@spacestation.blue>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken egui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants