mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
Experiment with calculating an Ui's "intrinsic size" by remembering the widget's size
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{Align, Button, Layout, Popup, TextWrapMode, Widget};
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -15,19 +16,46 @@ fn main() -> eframe::Result {
|
||||
let mut name = "Arthur".to_owned();
|
||||
let mut age = 42;
|
||||
|
||||
let mut checked = true;
|
||||
|
||||
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.add(egui::Slider::new(&mut age, 0..=120).text("age"));
|
||||
if ui.button("Increment").clicked() {
|
||||
age += 1;
|
||||
}
|
||||
ui.label(format!("Hello '{name}', age {age}"));
|
||||
// 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;
|
||||
// }
|
||||
// ui.label(format!("Hello '{name}', age {age}"));
|
||||
|
||||
let response = ui.button("Hiiii");
|
||||
|
||||
let text = if checked {
|
||||
"short"
|
||||
} else {
|
||||
"Very long text for this item that should be wrapped"
|
||||
};
|
||||
Popup::from_response(&response)
|
||||
.layout(Layout::top_down_justified(Align::Min))
|
||||
.show(|ui| {
|
||||
// ui.checkbox(&mut checked, text);
|
||||
|
||||
ui.button("Hiiii");
|
||||
|
||||
if Button::new(text)
|
||||
.wrap_mode(TextWrapMode::Extend)
|
||||
.ui(ui)
|
||||
.clicked()
|
||||
{
|
||||
checked = !checked;
|
||||
}
|
||||
|
||||
ui.button("Some other button");
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user