Skip to content

Button styling #4518

Answered by YgorSouza
breard-r asked this question in Q&A
May 21, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

The problem is that the button does the interaction first, and then draws itself depending on the response, and you don't have access to that until you have already rendered it. I think one workaround is to do the LayoutJob twice, first with invisible text just to get the size of the button right, and then again with the correct color according to the button response:

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.style_mut().visuals.widgets.hovered.fg_stroke.color = egui::Color32::BLUE;
            let ICON_SIZE = 30.0;
            let TEXT_SIZE = 12.0;

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@breard-r
Comment options

Answer selected by breard-r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants