2021-03-13 11:38:03 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct CursorTest {}
|
|
|
|
|
|
|
|
impl super::Demo for CursorTest {
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
"Cursor Test"
|
|
|
|
}
|
|
|
|
|
2022-01-10 22:13:10 +00:00
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
2021-03-13 11:38:03 +00:00
|
|
|
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
2021-10-07 19:39:04 +00:00
|
|
|
use super::View as _;
|
2021-03-13 11:38:03 +00:00
|
|
|
self.ui(ui);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::View for CursorTest {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
|
|
|
ui.vertical_centered_justified(|ui| {
|
2021-03-31 21:12:42 +00:00
|
|
|
ui.heading("Hover to switch cursor icon:");
|
2021-03-13 11:38:03 +00:00
|
|
|
for &cursor_icon in &egui::CursorIcon::ALL {
|
|
|
|
let _ = ui
|
|
|
|
.button(format!("{:?}", cursor_icon))
|
|
|
|
.on_hover_cursor(cursor_icon);
|
|
|
|
}
|
2021-03-31 21:12:42 +00:00
|
|
|
ui.add(crate::__egui_github_link_file!());
|
2021-03-13 11:38:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2020-11-03 21:00:56 +00:00
|
|
|
#[derive(Default)]
|
2021-01-27 19:14:53 +00:00
|
|
|
pub struct IdTest {}
|
2020-11-03 21:00:56 +00:00
|
|
|
|
2021-01-27 19:14:53 +00:00
|
|
|
impl super::Demo for IdTest {
|
2021-02-20 08:18:23 +00:00
|
|
|
fn name(&self) -> &'static str {
|
2021-02-06 15:54:38 +00:00
|
|
|
"ID Test"
|
2020-11-03 21:00:56 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 22:13:10 +00:00
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
2020-12-29 12:40:11 +00:00
|
|
|
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
2021-10-07 19:39:04 +00:00
|
|
|
use super::View as _;
|
2020-11-03 21:00:56 +00:00
|
|
|
self.ui(ui);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:14:53 +00:00
|
|
|
impl super::View for IdTest {
|
2020-12-29 12:40:11 +00:00
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
2020-11-03 21:00:56 +00:00
|
|
|
ui.heading("Name collision example");
|
|
|
|
|
|
|
|
ui.label("\
|
|
|
|
Widgets that store state require unique and persisting identifiers so we can track their state between frames.\n\
|
|
|
|
For instance, collapsable headers needs to store wether or not they are open. \
|
|
|
|
Their Id:s are derived from their names. \
|
|
|
|
If you fail to give them unique names then clicking one will open both. \
|
|
|
|
To help you debug this, an error message is printed on screen:");
|
|
|
|
|
|
|
|
ui.collapsing("Collapsing header", |ui| {
|
|
|
|
ui.label("Contents of first foldable ui");
|
|
|
|
});
|
|
|
|
ui.collapsing("Collapsing header", |ui| {
|
|
|
|
ui.label("Contents of second foldable ui");
|
|
|
|
});
|
|
|
|
|
|
|
|
ui.label("\
|
|
|
|
Any widget that can be interacted with also need a unique Id. \
|
|
|
|
For most widgets the Id is generated by a running counter. \
|
|
|
|
As long as elements are not added or removed, the Id stays the same. \
|
|
|
|
This is fine, because during interaction (i.e. while dragging a slider), \
|
|
|
|
the number of widgets previously in the same window is most likely not changing \
|
|
|
|
(and if it is, the window will have a new layout, and the slider will endup somewhere else, and so aborthing the interaction probably makes sense).");
|
|
|
|
|
|
|
|
ui.label("So these buttons have automatic Id:s, and therefore there is no name clash:");
|
|
|
|
let _ = ui.button("Button");
|
|
|
|
let _ = ui.button("Button");
|
|
|
|
|
2021-01-11 22:50:50 +00:00
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
ui.add(crate::__egui_github_link_file!());
|
|
|
|
});
|
2020-11-03 21:00:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-06 15:54:38 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-02-07 12:48:55 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
|
|
enum WidgetType {
|
|
|
|
Label,
|
|
|
|
Button,
|
|
|
|
TextEdit,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
pub struct ManualLayoutTest {
|
|
|
|
widget_offset: egui::Vec2,
|
|
|
|
widget_size: egui::Vec2,
|
|
|
|
widget_type: WidgetType,
|
|
|
|
text_edit_contents: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ManualLayoutTest {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
widget_offset: egui::Vec2::splat(150.0),
|
|
|
|
widget_size: egui::Vec2::new(200.0, 100.0),
|
|
|
|
widget_type: WidgetType::Button,
|
|
|
|
text_edit_contents: crate::LOREM_IPSUM.to_owned(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::Demo for ManualLayoutTest {
|
2021-02-20 08:18:23 +00:00
|
|
|
fn name(&self) -> &'static str {
|
2021-02-07 12:48:55 +00:00
|
|
|
"Manual Layout Test"
|
|
|
|
}
|
|
|
|
|
2022-01-10 22:13:10 +00:00
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
2021-08-26 16:54:38 +00:00
|
|
|
egui::Window::new(self.name())
|
|
|
|
.resizable(false)
|
|
|
|
.open(open)
|
|
|
|
.show(ctx, |ui| {
|
2021-10-07 19:39:04 +00:00
|
|
|
use super::View as _;
|
2021-08-26 16:54:38 +00:00
|
|
|
self.ui(ui);
|
|
|
|
});
|
2021-02-07 12:48:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::View for ManualLayoutTest {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
2021-03-07 18:32:27 +00:00
|
|
|
egui::reset_button(ui, self);
|
2021-03-07 18:51:07 +00:00
|
|
|
|
2021-02-07 12:48:55 +00:00
|
|
|
let Self {
|
|
|
|
widget_offset,
|
|
|
|
widget_size,
|
|
|
|
widget_type,
|
|
|
|
text_edit_contents,
|
|
|
|
} = self;
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.label("Test widget:");
|
|
|
|
ui.radio_value(widget_type, WidgetType::Button, "Button");
|
|
|
|
ui.radio_value(widget_type, WidgetType::Label, "Label");
|
|
|
|
ui.radio_value(widget_type, WidgetType::TextEdit, "TextEdit");
|
|
|
|
});
|
2021-03-07 18:32:27 +00:00
|
|
|
egui::Grid::new("pos_size").show(ui, |ui| {
|
2021-02-07 12:48:55 +00:00
|
|
|
ui.label("Widget position:");
|
2021-03-27 15:07:18 +00:00
|
|
|
ui.add(egui::Slider::new(&mut widget_offset.x, 0.0..=400.0));
|
|
|
|
ui.add(egui::Slider::new(&mut widget_offset.y, 0.0..=400.0));
|
2021-02-07 12:48:55 +00:00
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.label("Widget size:");
|
2021-03-27 15:07:18 +00:00
|
|
|
ui.add(egui::Slider::new(&mut widget_size.x, 0.0..=400.0));
|
|
|
|
ui.add(egui::Slider::new(&mut widget_size.y, 0.0..=400.0));
|
2021-02-07 12:48:55 +00:00
|
|
|
ui.end_row();
|
|
|
|
});
|
2021-03-07 18:51:07 +00:00
|
|
|
|
2021-03-07 18:32:27 +00:00
|
|
|
let widget_rect =
|
|
|
|
egui::Rect::from_min_size(ui.min_rect().min + *widget_offset, *widget_size);
|
2021-02-07 12:48:55 +00:00
|
|
|
|
2021-03-07 18:51:07 +00:00
|
|
|
ui.add(crate::__egui_github_link_file!());
|
|
|
|
|
2021-02-07 12:48:55 +00:00
|
|
|
// Showing how to place a widget anywhere in the `Ui`:
|
|
|
|
match *widget_type {
|
|
|
|
WidgetType::Button => {
|
2021-03-07 18:32:27 +00:00
|
|
|
ui.put(widget_rect, egui::Button::new("Example button"));
|
2021-02-07 12:48:55 +00:00
|
|
|
}
|
|
|
|
WidgetType::Label => {
|
2021-03-07 18:32:27 +00:00
|
|
|
ui.put(widget_rect, egui::Label::new("Example label"));
|
2021-02-07 12:48:55 +00:00
|
|
|
}
|
|
|
|
WidgetType::TextEdit => {
|
2021-03-07 18:32:27 +00:00
|
|
|
ui.put(widget_rect, egui::TextEdit::multiline(text_edit_contents));
|
2021-02-07 12:48:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-03-07 18:51:07 +00:00
|
|
|
#[derive(PartialEq)]
|
2021-02-06 15:54:38 +00:00
|
|
|
pub struct TableTest {
|
|
|
|
num_cols: usize,
|
|
|
|
num_rows: usize,
|
|
|
|
min_col_width: f32,
|
|
|
|
max_col_width: f32,
|
2021-07-02 07:25:53 +00:00
|
|
|
text_length: usize,
|
2021-02-06 15:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TableTest {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
num_cols: 4,
|
|
|
|
num_rows: 4,
|
|
|
|
min_col_width: 10.0,
|
|
|
|
max_col_width: 200.0,
|
2021-07-02 07:25:53 +00:00
|
|
|
text_length: 10,
|
2021-02-06 15:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::Demo for TableTest {
|
2021-02-20 08:18:23 +00:00
|
|
|
fn name(&self) -> &'static str {
|
2021-02-06 15:54:38 +00:00
|
|
|
"Table Test"
|
|
|
|
}
|
|
|
|
|
2022-01-10 22:13:10 +00:00
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
2021-02-06 15:54:38 +00:00
|
|
|
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
2021-10-07 19:39:04 +00:00
|
|
|
use super::View as _;
|
2021-02-06 15:54:38 +00:00
|
|
|
self.ui(ui);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::View for TableTest {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
|
|
|
ui.add(
|
2021-03-27 15:07:18 +00:00
|
|
|
egui::Slider::new(&mut self.min_col_width, 0.0..=400.0).text("Minimum column width"),
|
2021-02-06 15:54:38 +00:00
|
|
|
);
|
|
|
|
ui.add(
|
2021-03-27 15:07:18 +00:00
|
|
|
egui::Slider::new(&mut self.max_col_width, 0.0..=400.0).text("Maximum column width"),
|
2021-02-06 15:54:38 +00:00
|
|
|
);
|
2021-03-27 15:07:18 +00:00
|
|
|
ui.add(egui::Slider::new(&mut self.num_cols, 0..=5).text("Columns"));
|
|
|
|
ui.add(egui::Slider::new(&mut self.num_rows, 0..=20).text("Rows"));
|
2021-02-06 15:54:38 +00:00
|
|
|
|
|
|
|
ui.separator();
|
|
|
|
|
|
|
|
let words = [
|
|
|
|
"random", "words", "in", "a", "random", "order", "that", "just", "keeps", "going",
|
|
|
|
"with", "some", "more",
|
|
|
|
];
|
|
|
|
|
|
|
|
egui::Grid::new("my_grid")
|
|
|
|
.striped(true)
|
|
|
|
.min_col_width(self.min_col_width)
|
|
|
|
.max_col_width(self.max_col_width)
|
|
|
|
.show(ui, |ui| {
|
|
|
|
for row in 0..self.num_rows {
|
|
|
|
for col in 0..self.num_cols {
|
|
|
|
if col == 0 {
|
|
|
|
ui.label(format!("row {}", row));
|
|
|
|
} else {
|
|
|
|
let word_idx = row * 3 + col * 5;
|
|
|
|
let word_count = (row * 5 + col * 75) % 13;
|
|
|
|
let mut string = String::new();
|
|
|
|
for word in words.iter().cycle().skip(word_idx).take(word_count) {
|
|
|
|
string += word;
|
|
|
|
string += " ";
|
|
|
|
}
|
|
|
|
ui.label(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui.end_row();
|
|
|
|
}
|
|
|
|
});
|
2021-03-07 18:51:07 +00:00
|
|
|
|
2021-07-02 07:25:53 +00:00
|
|
|
ui.separator();
|
|
|
|
ui.add(egui::Slider::new(&mut self.text_length, 1..=40).text("Text length"));
|
|
|
|
egui::Grid::new("parent grid").striped(true).show(ui, |ui| {
|
|
|
|
ui.vertical(|ui| {
|
|
|
|
ui.label("Vertical nest1");
|
|
|
|
ui.label("Vertical nest2");
|
|
|
|
});
|
|
|
|
ui.label("First row, second column");
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.label("Horizontal nest1");
|
|
|
|
ui.label("Horizontal nest2");
|
|
|
|
});
|
|
|
|
ui.label("Second row, second column");
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.scope(|ui| {
|
|
|
|
ui.label("Scope nest 1");
|
|
|
|
ui.label("Scope nest 2");
|
|
|
|
});
|
|
|
|
ui.label("Third row, second column");
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
egui::Grid::new("nested grid").show(ui, |ui| {
|
|
|
|
ui.label("Grid nest11");
|
|
|
|
ui.label("Grid nest12");
|
|
|
|
ui.end_row();
|
|
|
|
ui.label("Grid nest21");
|
|
|
|
ui.label("Grid nest22");
|
|
|
|
ui.end_row();
|
|
|
|
});
|
|
|
|
ui.label("Fourth row, second column");
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
let mut dyn_text = String::from("O");
|
|
|
|
dyn_text.extend(std::iter::repeat('h').take(self.text_length));
|
|
|
|
ui.label(dyn_text);
|
|
|
|
ui.label("Fifth row, second column");
|
|
|
|
ui.end_row();
|
|
|
|
});
|
|
|
|
|
2021-03-07 18:51:07 +00:00
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
egui::reset_button(ui, self);
|
|
|
|
ui.add(crate::__egui_github_link_file!());
|
|
|
|
});
|
2021-02-06 15:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-09-29 06:45:13 +00:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
2021-02-06 15:54:38 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct InputTest {
|
|
|
|
info: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::Demo for InputTest {
|
2021-02-20 08:18:23 +00:00
|
|
|
fn name(&self) -> &'static str {
|
2021-02-06 15:54:38 +00:00
|
|
|
"Input Test"
|
|
|
|
}
|
|
|
|
|
2022-01-10 22:13:10 +00:00
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
2021-02-06 15:54:38 +00:00
|
|
|
egui::Window::new(self.name())
|
|
|
|
.open(open)
|
|
|
|
.resizable(false)
|
|
|
|
.show(ctx, |ui| {
|
2021-10-07 19:39:04 +00:00
|
|
|
use super::View as _;
|
2021-02-06 15:54:38 +00:00
|
|
|
self.ui(ui);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::View for InputTest {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
2021-03-07 18:51:07 +00:00
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
ui.add(crate::__egui_github_link_file!());
|
|
|
|
});
|
|
|
|
|
2021-02-06 15:54:38 +00:00
|
|
|
let response = ui.add(
|
|
|
|
egui::Button::new("Click, double-click or drag me with any mouse button")
|
|
|
|
.sense(egui::Sense::click_and_drag()),
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut new_info = String::new();
|
|
|
|
for &button in &[
|
|
|
|
egui::PointerButton::Primary,
|
|
|
|
egui::PointerButton::Secondary,
|
|
|
|
egui::PointerButton::Middle,
|
|
|
|
] {
|
|
|
|
if response.clicked_by(button) {
|
2021-03-31 21:12:42 +00:00
|
|
|
new_info += &format!("Clicked by {:?} button\n", button);
|
2021-02-06 15:54:38 +00:00
|
|
|
}
|
|
|
|
if response.double_clicked_by(button) {
|
2021-03-31 21:12:42 +00:00
|
|
|
new_info += &format!("Double-clicked by {:?} button\n", button);
|
2021-02-06 15:54:38 +00:00
|
|
|
}
|
2021-03-06 09:48:39 +00:00
|
|
|
if response.dragged_by(button) {
|
|
|
|
new_info += &format!(
|
2021-03-31 21:12:42 +00:00
|
|
|
"Dragged by {:?} button, delta: {:?}\n",
|
2021-03-06 09:48:39 +00:00
|
|
|
button,
|
|
|
|
response.drag_delta()
|
|
|
|
);
|
2021-02-06 15:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if !new_info.is_empty() {
|
|
|
|
self.info = new_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.label(&self.info);
|
|
|
|
}
|
|
|
|
}
|
2021-02-07 13:46:53 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-05-02 19:56:59 +00:00
|
|
|
pub struct WindowResizeTest {
|
|
|
|
text: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for WindowResizeTest {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-09-07 18:37:50 +00:00
|
|
|
text: crate::LOREM_IPSUM_LONG.to_owned(),
|
2021-05-02 19:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-07 13:46:53 +00:00
|
|
|
|
|
|
|
impl super::Demo for WindowResizeTest {
|
2021-02-20 08:18:23 +00:00
|
|
|
fn name(&self) -> &'static str {
|
2021-02-07 13:46:53 +00:00
|
|
|
"↔ Window Resize"
|
|
|
|
}
|
|
|
|
|
2022-01-10 22:13:10 +00:00
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
2021-02-07 13:46:53 +00:00
|
|
|
use egui::*;
|
|
|
|
|
2021-03-07 19:15:42 +00:00
|
|
|
Window::new("↔ auto-sized")
|
2021-02-07 13:46:53 +00:00
|
|
|
.open(open)
|
2021-03-07 19:15:42 +00:00
|
|
|
.auto_sized()
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
ui.label("This window will auto-size based on its contents.");
|
|
|
|
ui.heading("Resize this area:");
|
|
|
|
Resize::default().show(ui, |ui| {
|
2021-09-07 18:37:50 +00:00
|
|
|
lorem_ipsum(ui, crate::LOREM_IPSUM);
|
2021-03-07 19:15:42 +00:00
|
|
|
});
|
|
|
|
ui.heading("Resize the above area!");
|
|
|
|
});
|
|
|
|
|
|
|
|
Window::new("↔ resizable + scroll")
|
|
|
|
.open(open)
|
2021-08-28 11:18:21 +00:00
|
|
|
.vscroll(true)
|
2021-02-07 13:46:53 +00:00
|
|
|
.resizable(true)
|
2021-03-07 19:15:42 +00:00
|
|
|
.default_height(300.0)
|
2021-02-07 13:46:53 +00:00
|
|
|
.show(ctx, |ui| {
|
2021-03-07 19:15:42 +00:00
|
|
|
ui.label(
|
2021-09-07 18:37:50 +00:00
|
|
|
"This window is resizable and has a scroll area. You can shrink it to any size.",
|
2021-03-07 19:15:42 +00:00
|
|
|
);
|
|
|
|
ui.separator();
|
2021-09-07 18:37:50 +00:00
|
|
|
lorem_ipsum(ui, crate::LOREM_IPSUM_LONG);
|
2021-02-07 13:46:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Window::new("↔ resizable + embedded scroll")
|
|
|
|
.open(open)
|
2021-08-28 11:18:21 +00:00
|
|
|
.vscroll(false)
|
2021-02-07 13:46:53 +00:00
|
|
|
.resizable(true)
|
|
|
|
.default_height(300.0)
|
|
|
|
.show(ctx, |ui| {
|
2021-03-07 19:15:42 +00:00
|
|
|
ui.label("This window is resizable but has no built-in scroll area.");
|
|
|
|
ui.label("However, we have a sub-region with a scroll bar:");
|
|
|
|
ui.separator();
|
2021-08-28 11:18:21 +00:00
|
|
|
ScrollArea::vertical().show(ui, |ui| {
|
2021-09-07 18:37:50 +00:00
|
|
|
let lorem_ipsum_extra_long =
|
|
|
|
format!("{}\n\n{}", crate::LOREM_IPSUM_LONG, crate::LOREM_IPSUM_LONG);
|
|
|
|
lorem_ipsum(ui, &lorem_ipsum_extra_long);
|
2021-02-07 13:46:53 +00:00
|
|
|
});
|
|
|
|
// ui.heading("Some additional text here, that should also be visible"); // this works, but messes with the resizing a bit
|
|
|
|
});
|
|
|
|
|
2021-03-07 19:15:42 +00:00
|
|
|
Window::new("↔ resizable without scroll")
|
2021-02-07 13:46:53 +00:00
|
|
|
.open(open)
|
2021-08-28 11:18:21 +00:00
|
|
|
.vscroll(false)
|
2021-02-07 13:46:53 +00:00
|
|
|
.resizable(true)
|
|
|
|
.show(ctx, |ui| {
|
2021-03-07 19:15:42 +00:00
|
|
|
ui.label("This window is resizable but has no scroll area. This means it can only be resized to a size where all the contents is visible.");
|
|
|
|
ui.label("egui will not clip the contents of a window, nor add whitespace to it.");
|
|
|
|
ui.separator();
|
2021-09-07 18:37:50 +00:00
|
|
|
lorem_ipsum(ui, crate::LOREM_IPSUM);
|
2021-02-07 13:46:53 +00:00
|
|
|
});
|
2021-05-02 19:56:59 +00:00
|
|
|
|
|
|
|
Window::new("↔ resizable with TextEdit")
|
|
|
|
.open(open)
|
2021-08-28 11:18:21 +00:00
|
|
|
.vscroll(false)
|
2021-05-02 19:56:59 +00:00
|
|
|
.resizable(true)
|
2021-08-27 17:59:31 +00:00
|
|
|
.default_height(300.0)
|
2021-05-02 19:56:59 +00:00
|
|
|
.show(ctx, |ui| {
|
|
|
|
ui.label("Shows how you can fill an area with a widget.");
|
|
|
|
ui.add_sized(ui.available_size(), TextEdit::multiline(&mut self.text));
|
|
|
|
});
|
2021-08-27 17:59:31 +00:00
|
|
|
|
|
|
|
Window::new("↔ freely resized")
|
|
|
|
.open(open)
|
2021-08-28 11:18:21 +00:00
|
|
|
.vscroll(false)
|
2021-08-27 17:59:31 +00:00
|
|
|
.resizable(true)
|
|
|
|
.default_size([250.0, 150.0])
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
ui.label("This window has empty space that fills up the available space, preventing auto-shrink.");
|
|
|
|
ui.allocate_space(ui.available_size());
|
|
|
|
});
|
2021-02-07 13:46:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-07 18:37:50 +00:00
|
|
|
|
|
|
|
fn lorem_ipsum(ui: &mut egui::Ui, text: &str) {
|
|
|
|
ui.with_layout(
|
|
|
|
egui::Layout::top_down(egui::Align::LEFT).with_cross_justify(true),
|
|
|
|
|ui| {
|
2021-11-01 20:30:10 +00:00
|
|
|
ui.label(egui::RichText::new(text).weak());
|
2021-09-07 18:37:50 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|