mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Add ability to highlight any widget (#2632)
* Add ability to highlight any widget * Add line to changelog * Demote the demo to a test
This commit is contained in:
@@ -90,6 +90,7 @@ impl Default for Tests {
|
||||
fn default() -> Self {
|
||||
Self::from_demos(vec![
|
||||
Box::new(super::tests::CursorTest::default()),
|
||||
Box::new(super::highlighting::Highlighting::default()),
|
||||
Box::new(super::tests::IdTest::default()),
|
||||
Box::new(super::tests::InputTest::default()),
|
||||
Box::new(super::layout_test::LayoutTest::default()),
|
||||
|
||||
37
crates/egui_demo_lib/src/demo/highlighting.rs
Normal file
37
crates/egui_demo_lib/src/demo/highlighting.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub struct Highlighting {}
|
||||
|
||||
impl super::Demo for Highlighting {
|
||||
fn name(&self) -> &'static str {
|
||||
"Highlighting"
|
||||
}
|
||||
|
||||
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
||||
egui::Window::new(self.name())
|
||||
.default_width(320.0)
|
||||
.open(open)
|
||||
.show(ctx, |ui| {
|
||||
use super::View as _;
|
||||
self.ui(ui);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl super::View for Highlighting {
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
ui.label("This demo demonstrates highlighting a widget.");
|
||||
ui.add_space(4.0);
|
||||
let label_response = ui.label("Hover me to highlight the button!");
|
||||
ui.add_space(4.0);
|
||||
let mut button_response = ui.button("Hover the button to highlight the label!");
|
||||
|
||||
if label_response.hovered() {
|
||||
button_response = button_response.highlight();
|
||||
}
|
||||
if button_response.hovered() {
|
||||
label_response.highlight();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ pub mod dancing_strings;
|
||||
pub mod demo_app_windows;
|
||||
pub mod drag_and_drop;
|
||||
pub mod font_book;
|
||||
pub mod highlighting;
|
||||
pub mod layout_test;
|
||||
pub mod misc_demo_window;
|
||||
pub mod multi_touch;
|
||||
|
||||
Reference in New Issue
Block a user