mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
More cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[cfg_attr(feature = "serde", serde(default))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub struct CodeEditor {
|
pub struct CodeEditor {
|
||||||
@@ -36,7 +37,7 @@ impl super::Demo for CodeEditor {
|
|||||||
|
|
||||||
impl super::View for CodeEditor {
|
impl super::View for CodeEditor {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
let CodeEditor { language, code } = self;
|
let Self { language, code } = self;
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.set_height(0.0);
|
ui.set_height(0.0);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ impl super::Demo for DancingStrings {
|
|||||||
.open(open)
|
.open(open)
|
||||||
.default_size(vec2(512.0, 256.0))
|
.default_size(vec2(512.0, 256.0))
|
||||||
.vscroll(false)
|
.vscroll(false)
|
||||||
.show(ctx, |ui| Self::default().ui(ui));
|
.show(ctx, |ui| self.ui(ui));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
use egui::{Context, Modifiers, ScrollArea, Ui};
|
use egui::{Context, Modifiers, ScrollArea, Ui};
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::sync::RwLock;
|
|
||||||
|
|
||||||
use super::About;
|
use super::About;
|
||||||
use super::Demo;
|
use super::Demo;
|
||||||
@@ -14,7 +12,7 @@ use crate::is_mobile;
|
|||||||
#[cfg_attr(feature = "serde", serde(default))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
struct Demos {
|
struct Demos {
|
||||||
#[cfg_attr(feature = "serde", serde(skip))]
|
#[cfg_attr(feature = "serde", serde(skip))]
|
||||||
demos: Vec<Box<dyn Demo + Sync + Send>>,
|
demos: Vec<Box<dyn Demo>>,
|
||||||
|
|
||||||
open: BTreeSet<String>,
|
open: BTreeSet<String>,
|
||||||
}
|
}
|
||||||
@@ -47,7 +45,7 @@ impl Default for Demos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Demos {
|
impl Demos {
|
||||||
pub fn from_demos(demos: Vec<Box<dyn Demo + Sync + Send>>) -> Self {
|
pub fn from_demos(demos: Vec<Box<dyn Demo>>) -> Self {
|
||||||
let mut open = BTreeSet::new();
|
let mut open = BTreeSet::new();
|
||||||
open.insert(
|
open.insert(
|
||||||
super::widget_gallery::WidgetGallery::default()
|
super::widget_gallery::WidgetGallery::default()
|
||||||
@@ -151,20 +149,14 @@ fn set_open(open: &mut BTreeSet<String>, key: &'static str, is_open: bool) {
|
|||||||
|
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[cfg_attr(feature = "serde", serde(default))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub struct DemoWindowsData {
|
pub struct DemoWindows {
|
||||||
about_is_open: bool,
|
about_is_open: bool,
|
||||||
about: About,
|
about: About,
|
||||||
demos: Demos,
|
demos: Demos,
|
||||||
tests: Tests,
|
tests: Tests,
|
||||||
}
|
}
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
|
||||||
#[cfg_attr(feature = "serde", serde(default))]
|
|
||||||
#[derive(Clone, Default)]
|
|
||||||
pub struct DemoWindows {
|
|
||||||
data: Arc<RwLock<DemoWindowsData>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for DemoWindowsData {
|
impl Default for DemoWindows {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
about_is_open: true,
|
about_is_open: true,
|
||||||
@@ -186,36 +178,32 @@ impl DemoWindows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mobile_ui(&mut self, ctx: &Context) {
|
fn mobile_ui(&mut self, ctx: &Context) {
|
||||||
let mut about_is_open = self.data.read().unwrap().about_is_open;
|
if self.about_is_open {
|
||||||
if about_is_open {
|
|
||||||
let screen_size = ctx.input(|i| i.screen_rect.size());
|
let screen_size = ctx.input(|i| i.screen_rect.size());
|
||||||
let default_width = (screen_size.x - 20.0).min(400.0);
|
let default_width = (screen_size.x - 20.0).min(400.0);
|
||||||
|
|
||||||
let close = Arc::new(RwLock::new(false));
|
let mut close = false;
|
||||||
let close_ = close.clone();
|
egui::Window::new(self.about.name())
|
||||||
let clone = self.clone();
|
|
||||||
egui::Window::new(self.data.read().unwrap().about.name())
|
|
||||||
.anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0])
|
.anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0])
|
||||||
.default_width(default_width)
|
.default_width(default_width)
|
||||||
.default_height(ctx.available_rect().height() - 46.0)
|
.default_height(ctx.available_rect().height() - 46.0)
|
||||||
.vscroll(true)
|
.vscroll(true)
|
||||||
.open(&mut about_is_open)
|
.open(&mut self.about_is_open)
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
.collapsible(false)
|
.collapsible(false)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
let close = close.clone();
|
self.about.ui(ui);
|
||||||
clone.data.write().unwrap().about.ui(ui);
|
|
||||||
ui.add_space(12.0);
|
ui.add_space(12.0);
|
||||||
ui.vertical_centered_justified(|ui| {
|
ui.vertical_centered_justified(|ui| {
|
||||||
if ui
|
if ui
|
||||||
.button(egui::RichText::new("Continue to the demo!").size(20.0))
|
.button(egui::RichText::new("Continue to the demo!").size(20.0))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
*close.write().unwrap() = true;
|
close = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
self.data.write().unwrap().about_is_open &= !*close_.read().unwrap();
|
self.about_is_open &= !close;
|
||||||
} else {
|
} else {
|
||||||
self.mobile_top_bar(ctx);
|
self.mobile_top_bar(ctx);
|
||||||
self.show_windows(ctx);
|
self.show_windows(ctx);
|
||||||
@@ -288,22 +276,20 @@ impl DemoWindows {
|
|||||||
|
|
||||||
/// Show the open windows.
|
/// Show the open windows.
|
||||||
fn show_windows(&mut self, ctx: &Context) {
|
fn show_windows(&mut self, ctx: &Context) {
|
||||||
let data = &mut *self.data.write().unwrap();
|
self.about.show(ctx, &mut self.about_is_open);
|
||||||
data.about.show(ctx, &mut data.about_is_open);
|
self.demos.windows(ctx);
|
||||||
data.demos.windows(ctx);
|
self.tests.windows(ctx);
|
||||||
data.tests.windows(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn demo_list_ui(&mut self, ui: &mut egui::Ui) {
|
fn demo_list_ui(&mut self, ui: &mut egui::Ui) {
|
||||||
ScrollArea::vertical().show(ui, |ui| {
|
ScrollArea::vertical().show(ui, |ui| {
|
||||||
ui.with_layout(egui::Layout::top_down_justified(egui::Align::LEFT), |ui| {
|
ui.with_layout(egui::Layout::top_down_justified(egui::Align::LEFT), |ui| {
|
||||||
let data = &mut *self.data.write().unwrap();
|
ui.toggle_value(&mut self.about_is_open, self.about.name());
|
||||||
ui.toggle_value(&mut data.about_is_open, data.about.name());
|
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
data.demos.checkboxes(ui);
|
self.demos.checkboxes(ui);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
data.tests.checkboxes(ui);
|
self.tests.checkboxes(ui);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
if ui.button("Organize windows").clicked() {
|
if ui.button("Organize windows").clicked() {
|
||||||
|
|||||||
@@ -120,9 +120,8 @@ impl super::View for DragAndDropDemo {
|
|||||||
let id_source = "my_drag_and_drop_demo";
|
let id_source = "my_drag_and_drop_demo";
|
||||||
let mut source_col_row = None;
|
let mut source_col_row = None;
|
||||||
let mut drop_col = None;
|
let mut drop_col = None;
|
||||||
let columns = &mut self.columns;
|
ui.columns(self.columns.len(), |uis| {
|
||||||
ui.columns(columns.len(), |uis| {
|
for (col_idx, column) in self.columns.clone().into_iter().enumerate() {
|
||||||
for (col_idx, column) in columns.clone().into_iter().enumerate() {
|
|
||||||
let ui = &mut uis[col_idx];
|
let ui = &mut uis[col_idx];
|
||||||
let can_accept_what_is_being_dragged = true; // We accept anything being dragged (for now) ¯\_(ツ)_/¯
|
let can_accept_what_is_being_dragged = true; // We accept anything being dragged (for now) ¯\_(ツ)_/¯
|
||||||
let response = drop_target(ui, can_accept_what_is_being_dragged, |ui| {
|
let response = drop_target(ui, can_accept_what_is_being_dragged, |ui| {
|
||||||
@@ -133,7 +132,7 @@ impl super::View for DragAndDropDemo {
|
|||||||
let response = ui.add(Label::new(item).sense(Sense::click()));
|
let response = ui.add(Label::new(item).sense(Sense::click()));
|
||||||
response.context_menu(|ui| {
|
response.context_menu(|ui| {
|
||||||
if ui.button("Remove").clicked() {
|
if ui.button("Remove").clicked() {
|
||||||
columns[col_idx].remove(row_idx);
|
self.columns[col_idx].remove(row_idx);
|
||||||
ui.close_menu();
|
ui.close_menu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -148,7 +147,7 @@ impl super::View for DragAndDropDemo {
|
|||||||
|
|
||||||
let response = response.context_menu(|ui| {
|
let response = response.context_menu(|ui| {
|
||||||
if ui.button("New Item").clicked() {
|
if ui.button("New Item").clicked() {
|
||||||
columns[col_idx].push("New Item".to_owned());
|
self.columns[col_idx].push("New Item".to_owned());
|
||||||
ui.close_menu();
|
ui.close_menu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -164,8 +163,8 @@ impl super::View for DragAndDropDemo {
|
|||||||
if let Some(drop_col) = drop_col {
|
if let Some(drop_col) = drop_col {
|
||||||
if ui.input(|i| i.pointer.any_released()) {
|
if ui.input(|i| i.pointer.any_released()) {
|
||||||
// do the drop:
|
// do the drop:
|
||||||
let item = columns[source_col].remove(source_row);
|
let item = self.columns[source_col].remove(source_row);
|
||||||
columns[drop_col].push(item);
|
self.columns[drop_col].push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
pub struct FontBook {
|
pub struct FontBook {
|
||||||
filter: String,
|
filter: String,
|
||||||
font_id: egui::FontId,
|
font_id: egui::FontId,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ impl super::Demo for Highlighting {
|
|||||||
.open(open)
|
.open(open)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
use super::View as _;
|
use super::View as _;
|
||||||
Self::default().ui(ui);
|
self.ui(ui);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ impl Default for Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
#[derive(Default, PartialEq)]
|
|
||||||
|
#[derive(PartialEq, Default)]
|
||||||
pub struct PlotDemo {
|
pub struct PlotDemo {
|
||||||
line_demo: LineDemo,
|
line_demo: LineDemo,
|
||||||
marker_demo: MarkerDemo,
|
marker_demo: MarkerDemo,
|
||||||
|
|||||||
@@ -55,141 +55,137 @@ impl super::Demo for Sliders {
|
|||||||
|
|
||||||
impl super::View for Sliders {
|
impl super::View for Sliders {
|
||||||
fn ui(&mut self, ui: &mut Ui) {
|
fn ui(&mut self, ui: &mut Ui) {
|
||||||
{
|
let Self {
|
||||||
let Sliders {
|
min,
|
||||||
min,
|
max,
|
||||||
max,
|
logarithmic,
|
||||||
logarithmic,
|
clamp_to_range,
|
||||||
clamp_to_range,
|
smart_aim,
|
||||||
smart_aim,
|
step,
|
||||||
step,
|
use_steps,
|
||||||
use_steps,
|
integer,
|
||||||
integer,
|
vertical,
|
||||||
vertical,
|
value,
|
||||||
value,
|
trailing_fill,
|
||||||
trailing_fill,
|
} = self;
|
||||||
} = self;
|
|
||||||
|
|
||||||
ui.label("You can click a slider value to edit it with the keyboard.");
|
ui.label("You can click a slider value to edit it with the keyboard.");
|
||||||
|
|
||||||
let (type_min, type_max) = if *integer {
|
let (type_min, type_max) = if *integer {
|
||||||
((i32::MIN as f64), (i32::MAX as f64))
|
((i32::MIN as f64), (i32::MAX as f64))
|
||||||
} else if *logarithmic {
|
} else if *logarithmic {
|
||||||
(-INFINITY, INFINITY)
|
(-INFINITY, INFINITY)
|
||||||
} else {
|
} else {
|
||||||
(-1e5, 1e5) // linear sliders make little sense with huge numbers
|
(-1e5, 1e5) // linear sliders make little sense with huge numbers
|
||||||
};
|
};
|
||||||
|
|
||||||
*min = min.clamp(type_min, type_max);
|
*min = min.clamp(type_min, type_max);
|
||||||
*max = max.clamp(type_min, type_max);
|
*max = max.clamp(type_min, type_max);
|
||||||
|
|
||||||
let orientation = if *vertical {
|
let orientation = if *vertical {
|
||||||
SliderOrientation::Vertical
|
SliderOrientation::Vertical
|
||||||
} else {
|
} else {
|
||||||
SliderOrientation::Horizontal
|
SliderOrientation::Horizontal
|
||||||
};
|
};
|
||||||
|
|
||||||
let istep = if *use_steps { *step } else { 0.0 };
|
let istep = if *use_steps { *step } else { 0.0 };
|
||||||
if *integer {
|
if *integer {
|
||||||
let mut value_i32 = *value as i32;
|
let mut value_i32 = *value as i32;
|
||||||
ui.add(
|
|
||||||
Slider::new(&mut value_i32, (*min as i32)..=(*max as i32))
|
|
||||||
.logarithmic(*logarithmic)
|
|
||||||
.clamp_to_range(*clamp_to_range)
|
|
||||||
.smart_aim(*smart_aim)
|
|
||||||
.orientation(orientation)
|
|
||||||
.text("i32 demo slider")
|
|
||||||
.step_by(istep)
|
|
||||||
.trailing_fill(*trailing_fill),
|
|
||||||
);
|
|
||||||
*value = value_i32 as f64;
|
|
||||||
} else {
|
|
||||||
ui.add(
|
|
||||||
Slider::new(value, (*min)..=(*max))
|
|
||||||
.logarithmic(*logarithmic)
|
|
||||||
.clamp_to_range(*clamp_to_range)
|
|
||||||
.smart_aim(*smart_aim)
|
|
||||||
.orientation(orientation)
|
|
||||||
.text("f64 demo slider")
|
|
||||||
.step_by(istep)
|
|
||||||
.trailing_fill(*trailing_fill),
|
|
||||||
);
|
|
||||||
|
|
||||||
ui.label(
|
|
||||||
"Sliders will intelligently pick how many decimals to show. \
|
|
||||||
You can always see the full precision value by hovering the value.",
|
|
||||||
);
|
|
||||||
|
|
||||||
if ui.button("Assign PI").clicked() {
|
|
||||||
self.value = std::f64::consts::PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.separator();
|
|
||||||
|
|
||||||
ui.label("Slider range:");
|
|
||||||
ui.add(
|
ui.add(
|
||||||
Slider::new(min, type_min..=type_max)
|
Slider::new(&mut value_i32, (*min as i32)..=(*max as i32))
|
||||||
.logarithmic(true)
|
.logarithmic(*logarithmic)
|
||||||
|
.clamp_to_range(*clamp_to_range)
|
||||||
.smart_aim(*smart_aim)
|
.smart_aim(*smart_aim)
|
||||||
.text("left")
|
.orientation(orientation)
|
||||||
|
.text("i32 demo slider")
|
||||||
|
.step_by(istep)
|
||||||
.trailing_fill(*trailing_fill),
|
.trailing_fill(*trailing_fill),
|
||||||
);
|
);
|
||||||
|
*value = value_i32 as f64;
|
||||||
|
} else {
|
||||||
ui.add(
|
ui.add(
|
||||||
Slider::new(max, type_min..=type_max)
|
Slider::new(value, (*min)..=(*max))
|
||||||
.logarithmic(true)
|
.logarithmic(*logarithmic)
|
||||||
|
.clamp_to_range(*clamp_to_range)
|
||||||
.smart_aim(*smart_aim)
|
.smart_aim(*smart_aim)
|
||||||
.text("right")
|
.orientation(orientation)
|
||||||
|
.text("f64 demo slider")
|
||||||
|
.step_by(istep)
|
||||||
.trailing_fill(*trailing_fill),
|
.trailing_fill(*trailing_fill),
|
||||||
);
|
);
|
||||||
|
|
||||||
ui.separator();
|
|
||||||
|
|
||||||
ui.checkbox(trailing_fill, "Toggle trailing color");
|
|
||||||
ui.label("When enabled, trailing color will be painted up until the circle.");
|
|
||||||
|
|
||||||
ui.separator();
|
|
||||||
|
|
||||||
ui.checkbox(use_steps, "Use steps");
|
|
||||||
ui.label("When enabled, the minimal value change would be restricted to a given step.");
|
|
||||||
if *use_steps {
|
|
||||||
ui.add(egui::DragValue::new(step).speed(1.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.separator();
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.label("Slider type:");
|
|
||||||
ui.radio_value(integer, true, "i32");
|
|
||||||
ui.radio_value(integer, false, "f64");
|
|
||||||
})
|
|
||||||
.response
|
|
||||||
.on_hover_text("All numeric types (f32, usize, …) are supported.");
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.label("Slider orientation:");
|
|
||||||
ui.radio_value(vertical, false, "Horizontal");
|
|
||||||
ui.radio_value(vertical, true, "Vertical");
|
|
||||||
});
|
|
||||||
ui.add_space(8.0);
|
|
||||||
|
|
||||||
ui.checkbox(logarithmic, "Logarithmic");
|
|
||||||
ui.label("Logarithmic sliders are great for when you want to span a huge range, i.e. from zero to a million.");
|
|
||||||
ui.label("Logarithmic sliders can include infinity and zero.");
|
|
||||||
ui.add_space(8.0);
|
|
||||||
|
|
||||||
ui.checkbox(clamp_to_range, "Clamp to range");
|
|
||||||
ui.label(
|
ui.label(
|
||||||
"If true, the slider will clamp incoming and outgoing values to the given range.",
|
"Sliders will intelligently pick how many decimals to show. \
|
||||||
|
You can always see the full precision value by hovering the value.",
|
||||||
);
|
);
|
||||||
ui.label("If false, the slider can shows values outside its range, and you can manually enter values outside the range.");
|
|
||||||
ui.add_space(8.0);
|
|
||||||
|
|
||||||
ui.checkbox(smart_aim, "Smart Aim");
|
if ui.button("Assign PI").clicked() {
|
||||||
ui.label("Smart Aim will guide you towards round values when you drag the slider so you you are more likely to hit 250 than 247.23");
|
self.value = std::f64::consts::PI;
|
||||||
ui.add_space(8.0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
ui.label("Slider range:");
|
||||||
|
ui.add(
|
||||||
|
Slider::new(min, type_min..=type_max)
|
||||||
|
.logarithmic(true)
|
||||||
|
.smart_aim(*smart_aim)
|
||||||
|
.text("left")
|
||||||
|
.trailing_fill(*trailing_fill),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
Slider::new(max, type_min..=type_max)
|
||||||
|
.logarithmic(true)
|
||||||
|
.smart_aim(*smart_aim)
|
||||||
|
.text("right")
|
||||||
|
.trailing_fill(*trailing_fill),
|
||||||
|
);
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
ui.checkbox(trailing_fill, "Toggle trailing color");
|
||||||
|
ui.label("When enabled, trailing color will be painted up until the circle.");
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
ui.checkbox(use_steps, "Use steps");
|
||||||
|
ui.label("When enabled, the minimal value change would be restricted to a given step.");
|
||||||
|
if *use_steps {
|
||||||
|
ui.add(egui::DragValue::new(step).speed(1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("Slider type:");
|
||||||
|
ui.radio_value(integer, true, "i32");
|
||||||
|
ui.radio_value(integer, false, "f64");
|
||||||
|
})
|
||||||
|
.response
|
||||||
|
.on_hover_text("All numeric types (f32, usize, …) are supported.");
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("Slider orientation:");
|
||||||
|
ui.radio_value(vertical, false, "Horizontal");
|
||||||
|
ui.radio_value(vertical, true, "Vertical");
|
||||||
|
});
|
||||||
|
ui.add_space(8.0);
|
||||||
|
|
||||||
|
ui.checkbox(logarithmic, "Logarithmic");
|
||||||
|
ui.label("Logarithmic sliders are great for when you want to span a huge range, i.e. from zero to a million.");
|
||||||
|
ui.label("Logarithmic sliders can include infinity and zero.");
|
||||||
|
ui.add_space(8.0);
|
||||||
|
|
||||||
|
ui.checkbox(clamp_to_range, "Clamp to range");
|
||||||
|
ui.label("If true, the slider will clamp incoming and outgoing values to the given range.");
|
||||||
|
ui.label("If false, the slider can shows values outside its range, and you can manually enter values outside the range.");
|
||||||
|
ui.add_space(8.0);
|
||||||
|
|
||||||
|
ui.checkbox(smart_aim, "Smart Aim");
|
||||||
|
ui.label("Smart Aim will guide you towards round values when you drag the slider so you you are more likely to hit 250 than 247.23");
|
||||||
|
ui.add_space(8.0);
|
||||||
|
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
egui::reset_button(ui, self);
|
egui::reset_button(ui, self);
|
||||||
ui.add(crate::egui_github_link_file!());
|
ui.add(crate::egui_github_link_file!());
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ impl super::Demo for StripDemo {
|
|||||||
.default_width(400.0)
|
.default_width(400.0)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
use super::View as _;
|
use super::View as _;
|
||||||
Self::default().ui(ui);
|
self.ui(ui);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,54 +51,52 @@ const NUM_MANUAL_ROWS: usize = 20;
|
|||||||
|
|
||||||
impl super::View for TableDemo {
|
impl super::View for TableDemo {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
{
|
ui.vertical(|ui| {
|
||||||
ui.vertical(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.checkbox(&mut self.striped, "Striped");
|
||||||
ui.checkbox(&mut self.striped, "Striped");
|
ui.checkbox(&mut self.resizable, "Resizable columns");
|
||||||
ui.checkbox(&mut self.resizable, "Resizable columns");
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.label("Table type:");
|
|
||||||
ui.radio_value(&mut self.demo, DemoType::Manual, "Few, manual rows");
|
|
||||||
ui.radio_value(
|
|
||||||
&mut self.demo,
|
|
||||||
DemoType::ManyHomogeneous,
|
|
||||||
"Thousands of rows of same height",
|
|
||||||
);
|
|
||||||
ui.radio_value(
|
|
||||||
&mut self.demo,
|
|
||||||
DemoType::ManyHeterogenous,
|
|
||||||
"Thousands of rows of differing heights",
|
|
||||||
);
|
|
||||||
|
|
||||||
if self.demo != DemoType::Manual {
|
|
||||||
ui.add(
|
|
||||||
egui::Slider::new(&mut self.num_rows, 0..=100_000)
|
|
||||||
.logarithmic(true)
|
|
||||||
.text("Num rows"),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let max_rows = if self.demo == DemoType::Manual {
|
|
||||||
NUM_MANUAL_ROWS
|
|
||||||
} else {
|
|
||||||
self.num_rows
|
|
||||||
};
|
|
||||||
|
|
||||||
let slider_response = ui.add(
|
|
||||||
egui::Slider::new(&mut self.scroll_to_row_slider, 0..=max_rows)
|
|
||||||
.logarithmic(true)
|
|
||||||
.text("Row to scroll to"),
|
|
||||||
);
|
|
||||||
if slider_response.changed() {
|
|
||||||
self.scroll_to_row = Some(self.scroll_to_row_slider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.label("Table type:");
|
||||||
}
|
ui.radio_value(&mut self.demo, DemoType::Manual, "Few, manual rows");
|
||||||
|
ui.radio_value(
|
||||||
|
&mut self.demo,
|
||||||
|
DemoType::ManyHomogeneous,
|
||||||
|
"Thousands of rows of same height",
|
||||||
|
);
|
||||||
|
ui.radio_value(
|
||||||
|
&mut self.demo,
|
||||||
|
DemoType::ManyHeterogenous,
|
||||||
|
"Thousands of rows of differing heights",
|
||||||
|
);
|
||||||
|
|
||||||
|
if self.demo != DemoType::Manual {
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut self.num_rows, 0..=100_000)
|
||||||
|
.logarithmic(true)
|
||||||
|
.text("Num rows"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let max_rows = if self.demo == DemoType::Manual {
|
||||||
|
NUM_MANUAL_ROWS
|
||||||
|
} else {
|
||||||
|
self.num_rows
|
||||||
|
};
|
||||||
|
|
||||||
|
let slider_response = ui.add(
|
||||||
|
egui::Slider::new(&mut self.scroll_to_row_slider, 0..=max_rows)
|
||||||
|
.logarithmic(true)
|
||||||
|
.text("Row to scroll to"),
|
||||||
|
);
|
||||||
|
if slider_response.changed() {
|
||||||
|
self.scroll_to_row = Some(self.scroll_to_row_slider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
// Leave room for the source code link after the table demo:
|
// Leave room for the source code link after the table demo:
|
||||||
use egui_extras::{Size, StripBuilder};
|
use egui_extras::{Size, StripBuilder};
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CursorTest {}
|
pub struct CursorTest {}
|
||||||
|
|
||||||
@@ -11,7 +9,7 @@ impl super::Demo for CursorTest {
|
|||||||
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
||||||
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
||||||
use super::View as _;
|
use super::View as _;
|
||||||
Self::default().ui(ui);
|
self.ui(ui);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,7 +41,7 @@ impl super::Demo for IdTest {
|
|||||||
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
||||||
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
||||||
use super::View as _;
|
use super::View as _;
|
||||||
Self::default().ui(ui);
|
self.ui(ui);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,6 +178,7 @@ impl super::View for ManualLayoutTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct TableTest {
|
pub struct TableTest {
|
||||||
num_cols: usize,
|
num_cols: usize,
|
||||||
@@ -216,91 +215,87 @@ impl super::Demo for TableTest {
|
|||||||
|
|
||||||
impl super::View for TableTest {
|
impl super::View for TableTest {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
{
|
ui.add(
|
||||||
ui.add(
|
egui::Slider::new(&mut self.min_col_width, 0.0..=400.0).text("Minimum column width"),
|
||||||
egui::Slider::new(&mut self.min_col_width, 0.0..=400.0)
|
);
|
||||||
.text("Minimum column width"),
|
ui.add(
|
||||||
);
|
egui::Slider::new(&mut self.max_col_width, 0.0..=400.0).text("Maximum column width"),
|
||||||
ui.add(
|
);
|
||||||
egui::Slider::new(&mut self.max_col_width, 0.0..=400.0)
|
ui.add(egui::Slider::new(&mut self.num_cols, 0..=5).text("Columns"));
|
||||||
.text("Maximum column width"),
|
ui.add(egui::Slider::new(&mut self.num_rows, 0..=20).text("Rows"));
|
||||||
);
|
|
||||||
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"));
|
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
let words = [
|
let words = [
|
||||||
"random", "words", "in", "a", "random", "order", "that", "just", "keeps", "going",
|
"random", "words", "in", "a", "random", "order", "that", "just", "keeps", "going",
|
||||||
"with", "some", "more",
|
"with", "some", "more",
|
||||||
];
|
];
|
||||||
|
|
||||||
egui::Grid::new("my_grid")
|
egui::Grid::new("my_grid")
|
||||||
.striped(true)
|
.striped(true)
|
||||||
.min_col_width(self.min_col_width)
|
.min_col_width(self.min_col_width)
|
||||||
.max_col_width(self.max_col_width)
|
.max_col_width(self.max_col_width)
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
for row in 0..self.num_rows {
|
for row in 0..self.num_rows {
|
||||||
for col in 0..self.num_cols {
|
for col in 0..self.num_cols {
|
||||||
if col == 0 {
|
if col == 0 {
|
||||||
ui.label(format!("row {}", row));
|
ui.label(format!("row {}", row));
|
||||||
} else {
|
} else {
|
||||||
let word_idx = row * 3 + col * 5;
|
let word_idx = row * 3 + col * 5;
|
||||||
let word_count = (row * 5 + col * 75) % 13;
|
let word_count = (row * 5 + col * 75) % 13;
|
||||||
let mut string = String::new();
|
let mut string = String::new();
|
||||||
for word in words.iter().cycle().skip(word_idx).take(word_count) {
|
for word in words.iter().cycle().skip(word_idx).take(word_count) {
|
||||||
string += word;
|
string += word;
|
||||||
string += " ";
|
string += " ";
|
||||||
}
|
|
||||||
ui.label(string);
|
|
||||||
}
|
}
|
||||||
|
ui.label(string);
|
||||||
}
|
}
|
||||||
ui.end_row();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
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.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");
|
ui.separator();
|
||||||
dyn_text.extend(std::iter::repeat('h').take(self.text_length));
|
ui.add(egui::Slider::new(&mut self.text_length, 1..=40).text("Text length"));
|
||||||
ui.label(dyn_text);
|
egui::Grid::new("parent grid").striped(true).show(ui, |ui| {
|
||||||
ui.label("Fifth row, second column");
|
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.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();
|
||||||
|
});
|
||||||
|
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
egui::reset_button(ui, self);
|
egui::reset_button(ui, self);
|
||||||
@@ -383,15 +378,14 @@ impl super::View for InputTest {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct WindowResizeTest {
|
pub struct WindowResizeTest {
|
||||||
text: Arc<RwLock<String>>,
|
text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WindowResizeTest {
|
impl Default for WindowResizeTest {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: Arc::new(RwLock::new(crate::LOREM_IPSUM_LONG.to_owned())),
|
text: crate::LOREM_IPSUM_LONG.to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,8 +451,6 @@ impl super::Demo for WindowResizeTest {
|
|||||||
lorem_ipsum(ui, crate::LOREM_IPSUM);
|
lorem_ipsum(ui, crate::LOREM_IPSUM);
|
||||||
});
|
});
|
||||||
|
|
||||||
let clone = self.clone();
|
|
||||||
|
|
||||||
Window::new("↔ resizable with TextEdit")
|
Window::new("↔ resizable with TextEdit")
|
||||||
.open(open)
|
.open(open)
|
||||||
.vscroll(false)
|
.vscroll(false)
|
||||||
@@ -466,8 +458,7 @@ impl super::Demo for WindowResizeTest {
|
|||||||
.default_height(300.0)
|
.default_height(300.0)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.label("Shows how you can fill an area with a widget.");
|
ui.label("Shows how you can fill an area with a widget.");
|
||||||
let mut text = clone.text.write().unwrap();
|
ui.add_sized(ui.available_size(), TextEdit::multiline(&mut self.text));
|
||||||
ui.add_sized(ui.available_size(), TextEdit::multiline(&mut *text));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Window::new("↔ freely resized")
|
Window::new("↔ freely resized")
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ impl super::View for WidgetGallery {
|
|||||||
|
|
||||||
impl WidgetGallery {
|
impl WidgetGallery {
|
||||||
fn gallery_grid_contents(&mut self, ui: &mut egui::Ui) {
|
fn gallery_grid_contents(&mut self, ui: &mut egui::Ui) {
|
||||||
let WidgetGallery {
|
let Self {
|
||||||
enabled: _,
|
enabled: _,
|
||||||
visible: _,
|
visible: _,
|
||||||
boolean,
|
boolean,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ impl super::Demo for WindowOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
||||||
let WindowOptions {
|
let Self {
|
||||||
title,
|
title,
|
||||||
title_bar,
|
title_bar,
|
||||||
closable,
|
closable,
|
||||||
@@ -75,7 +75,7 @@ impl super::Demo for WindowOptions {
|
|||||||
|
|
||||||
impl super::View for WindowOptions {
|
impl super::View for WindowOptions {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
let WindowOptions {
|
let Self {
|
||||||
title,
|
title,
|
||||||
title_bar,
|
title_bar,
|
||||||
closable,
|
closable,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ impl super::Demo for WindowWithPanels {
|
|||||||
.default_height(400.0)
|
.default_height(400.0)
|
||||||
.vscroll(false)
|
.vscroll(false)
|
||||||
.open(open);
|
.open(open);
|
||||||
window.show(ctx, |ui| Self {}.ui(ui));
|
window.show(ctx, |ui| self.ui(ui));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user