1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

apply style to label

This commit is contained in:
Adrien Zianne
2025-10-15 17:44:29 +02:00
parent ad4b0de2b3
commit f66b5b599b
4 changed files with 92 additions and 29 deletions

View File

@@ -1,7 +1,9 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
use eframe::egui::{self, Button};
use std::process::exit;
use eframe::egui::{self, Color32, FontId, Label, RichText, Sense, Stroke, style::WidgetVisuals};
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
@@ -17,24 +19,51 @@ fn main() -> eframe::Result {
eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("My egui Application");
ui.horizontal(|ui| {
let name_label = ui.label("Your name: ");
ui.text_edit_singleline(&mut name)
.labelled_by(name_label.id);
ui.ctx().style_mut(|s| {
s.visuals.widgets.inactive = WidgetVisuals {
fg_stroke: Stroke::new(1.0, Color32::LIGHT_GRAY),
..s.visuals.widgets.inactive
};
s.visuals.widgets.active = WidgetVisuals {
fg_stroke: Stroke::new(1.0, Color32::BLUE),
..s.visuals.widgets.inactive
};
s.visuals.widgets.hovered = WidgetVisuals {
fg_stroke: Stroke::new(1.0, Color32::YELLOW),
..s.visuals.widgets.inactive
};
s.visuals.widgets.noninteractive = WidgetVisuals {
fg_stroke: Stroke::new(1.0, Color32::RED),
..s.visuals.widgets.inactive
};
});
ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
if ui.button("Increment").clicked() {
age += 1;
}
// ui.heading("My egui Application");
// ui.horizontal(|ui| {
// let name_label = ui.label("Your name: ");
// ui.text_edit_singleline(&mut name)
// .labelled_by(name_label.id);
// });
// ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
// if ui.button("Increment").clicked() {
// age += 1;
// }
// Button test
ui.add(Button::new("no frame").frame(false));
ui.add(Button::new("small").small());
ui.add_enabled(false, Button::new("disabled"));
ui.add(Button::new("no frame inactive").frame_when_inactive(false));
// ui.add(Button::new("no frame").frame(false));
// ui.add(Button::new("small").small());
// ui.add_enabled(false, Button::new("disabled"));
// ui.add(Button::new("no frame inactive").frame_when_inactive(false));
ui.label(format!("Hello '{name}', age {age}"));
ui.label("Normal text");
// Should not be affected by WidgetStyle
ui.label(
RichText::new("Unaffected by style")
.font(FontId::monospace(15.0))
.color(Color32::KHAKI),
);
ui.add(Label::new("test").sense(Sense::click()))
});
})
}