-
Notifications
You must be signed in to change notification settings - Fork 253
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
How do I colour buttons and where can I find the corresponding descriptions for button()
and Response
?
#307
Comments
Hi! You can construct a button with this API to be able to customise it: https://docs.rs/egui/latest/egui/widgets/struct.Button.html. For example: let button = egui::Button::new("Click me").fill(color);
if ui.add(button).clicked() {
// ...
} Btw, this is a question about |
Thank you for the quick reply. It worked straight away. The code now looks like this: use bevy::prelude::*;
use bevy_egui::{egui::{RichText,Color32,Button,Window,TopBottomPanel}, EguiContexts, EguiPlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.add_systems(Update, (ui_example_system, header_bar))
.run();
}
fn ui_example_system(mut contexts: EguiContexts) {
Window::new("Hello").show(contexts.ctx_mut(), |ui| {
ui.label("world");
});
}
fn header_bar(mut contexts: EguiContexts) {
TopBottomPanel::top("header_bar").show(contexts.ctx_mut(), |ui| {
// Create an array of button labels for easier management
ui.horizontal(|ui| {
[
("Button 1", Color32::GREEN,Color32::RED),
("Button 2", Color32::BLUE,Color32::GOLD),
("Button 3", Color32::RED,Color32::BLUE),
("Button 4", Color32::YELLOW,Color32::from_rgb(238,130,238)),
("Button 5", Color32::DARK_RED,Color32::DARK_BLUE),
]
.into_iter()
.for_each(|(label, button_color,label_color)| {
if ui
.add(
Button::new(RichText::new(label).color(label_color))
.fill(button_color),
)
.clicked()
{
// Handle button clicks here
println!("Clicked button: {}", label);
}
});
});
});
} It is not immediately obvious that the problem lies directly with egui if you cannot find the corresponding references in the documentation. |
There are very few structs, methods that All the ui methods, widgets, etc are provided by |
I've tried the following:
Which produced the followinge error:
Unfortunately, I can't find a description for the
button()
method used here, nor for theResponse
method used here in the associated documentation, or I don't know what to look for. Can anyone help me?The text was updated successfully, but these errors were encountered: