forked from emilk/egui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3556b72
commit d02906d
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use egui::{Frame, Label, RichText, Sense, UiBuilder, Widget}; | ||
|
||
/// Showcase [`egui::Ui::read_response`]. | ||
#[derive(PartialEq, Eq, Default)] | ||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] | ||
#[cfg_attr(feature = "serde", serde(default))] | ||
pub struct InteractiveContainerDemo { | ||
count: usize, | ||
} | ||
|
||
impl crate::Demo for InteractiveContainerDemo { | ||
fn name(&self) -> &'static str { | ||
"\u{20E3}TextEdit" | ||
} | ||
|
||
fn show(&mut self, ctx: &egui::Context, open: &mut bool) { | ||
egui::Window::new(self.name()) | ||
.open(open) | ||
.resizable(false) | ||
.show(ctx, |ui| { | ||
use crate::View as _; | ||
self.ui(ui); | ||
}); | ||
} | ||
} | ||
|
||
impl crate::View for InteractiveContainerDemo { | ||
fn ui(&mut self, ui: &mut egui::Ui) { | ||
ui.vertical_centered(|ui| { | ||
ui.add(crate::egui_github_link_file!()); | ||
}); | ||
|
||
ui.label("This demo showcases how to use Ui::read_response to create interactive container widgets that may contain other widgets."); | ||
|
||
let response = ui | ||
.scope_builder( | ||
UiBuilder::new() | ||
.id_salt("interactive_container") | ||
.sense(Sense::click()), | ||
|ui| { | ||
let response = ui.read_response(); | ||
let visuals = ui.style().interact(&response); | ||
let text_color = visuals.text_color(); | ||
|
||
Frame::canvas(ui.style()) | ||
.fill(visuals.bg_fill.gamma_multiply(0.3)) | ||
.stroke(visuals.bg_stroke) | ||
.inner_margin(ui.spacing().menu_margin) | ||
.show(ui, |ui| { | ||
ui.set_width(ui.available_width()); | ||
|
||
ui.add_space(32.0); | ||
ui.vertical_centered(|ui| { | ||
Label::new( | ||
RichText::new(format!("{}", self.count)) | ||
.color(text_color) | ||
.size(32.0), | ||
) | ||
.selectable(false) | ||
.ui(ui); | ||
}); | ||
ui.add_space(32.0); | ||
|
||
ui.horizontal(|ui| { | ||
if ui.button("Reset").clicked() { | ||
self.count = 0; | ||
} | ||
if ui.button("+ 100").clicked() { | ||
self.count += 100; | ||
} | ||
}); | ||
}); | ||
}, | ||
) | ||
.response; | ||
|
||
if response.clicked() { | ||
self.count += 1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters