mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 15:13:12 -04:00
Fix labels, propagate preferred size in scrollareas and add more examples from the issue
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{Align, Button, Layout, Popup, TextWrapMode, Widget};
|
||||
use eframe::egui::containers::menu::{MenuButton, MenuConfig};
|
||||
use eframe::egui::{Align, Button, Layout, Popup, PopupCloseBehavior, TextWrapMode, Widget};
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -18,52 +19,89 @@ fn main() -> eframe::Result {
|
||||
|
||||
let mut checked = true;
|
||||
|
||||
let mut flag = false;
|
||||
let mut row_count = 5;
|
||||
|
||||
eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
|
||||
ctx.options_mut(|o| o.max_passes = 1.try_into().unwrap());
|
||||
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}"));
|
||||
// std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
// 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");
|
||||
//
|
||||
// ui.horizontal(|ui| {
|
||||
// ui.vertical(|ui| {
|
||||
// if Button::new(text)
|
||||
// // .wrap_mode(TextWrapMode::Extend)
|
||||
// .ui(ui)
|
||||
// .clicked()
|
||||
// {
|
||||
// checked = !checked;
|
||||
// }
|
||||
// ui.button("Button1");
|
||||
// });
|
||||
//
|
||||
// ui.button("Button2")
|
||||
// });
|
||||
//
|
||||
// ui.button("Some other button");
|
||||
// });
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
let response = ui.button("Hiiii");
|
||||
// Antoines example
|
||||
|
||||
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.label(format!("Showing {} rows", row_count));
|
||||
// if MenuButton::new("BTN")
|
||||
// .config(MenuConfig::new().close_behavior(PopupCloseBehavior::CloseOnClickOutside))
|
||||
// .ui(ui, |ui| {
|
||||
// ui.radio_value(&mut flag, false, "False");
|
||||
// ui.radio_value(&mut flag, true, "True");
|
||||
//
|
||||
// if flag {
|
||||
// egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
// for _ in 0..row_count {
|
||||
// ui.add_space(30.0);
|
||||
// ui.label("Veeeeeeeeeeeery long text.");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
// .0
|
||||
// .clicked()
|
||||
// {
|
||||
// if row_count % 2 == 1 {
|
||||
// row_count -= 3;
|
||||
// } else {
|
||||
// row_count += 5;
|
||||
// }
|
||||
// }
|
||||
|
||||
ui.button("Hiiii");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
if Button::new(text)
|
||||
// .wrap_mode(TextWrapMode::Extend)
|
||||
.ui(ui)
|
||||
.clicked()
|
||||
{
|
||||
checked = !checked;
|
||||
MenuButton::new("Menu")
|
||||
.config(MenuConfig::new().close_behavior(PopupCloseBehavior::CloseOnClickOutside))
|
||||
.ui(ui, |ui| {
|
||||
if ui.button("Close menu").clicked() {
|
||||
ui.close_menu();
|
||||
}
|
||||
ui.collapsing("Collapsing", |ui| {
|
||||
egui::ScrollArea::both().show(ui, |ui| {
|
||||
for _ in 0..10 {
|
||||
ui.label(
|
||||
"This is a long text label containing \
|
||||
a lot of words and spans many lines",
|
||||
);
|
||||
}
|
||||
ui.button("Button1");
|
||||
});
|
||||
|
||||
ui.button("Button2")
|
||||
});
|
||||
|
||||
ui.button("Some other button");
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user