2021-01-17 13:48:59 +00:00
|
|
|
//! Demo-code for showing how egui is used.
|
2021-01-01 16:11:05 +00:00
|
|
|
//!
|
|
|
|
//! The demo-code is also used in benchmarks and tests.
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
mod app;
|
New text layout (#682)
This PR introduces a completely rewritten text layout engine which is simpler and more powerful. It allows mixing different text styles (heading, body, etc) and formats (color, underlining, strikethrough, …) in the same layout pass, and baked into the same `Galley`.
This opens up the door to having a syntax-highlighed code editor, or a WYSIWYG markdown editor.
One major change is the color is now baked in at layout time. However, many widgets changes text color on hovered. But we need to do the text layout before we know if it is hovered. Therefor the painter has an option to override the text color of a galley.
## Performance
Text layout alone is about 20% slower, but a lot of that is because more tessellation is done upfront. Text tessellation is now a lot faster, but text layout + tessellation still lands at a net loss of 5-10% in performance. There are however a few tricks to speed it up (like using `smallvec`) which I am saving for later. Text layout is also cached, meaning that in most cases (when all text isn't changing each frame) text tessellation is actually more important (and that's more than 2x faster!).
Sadly, the actual text cache lookup is significantly slower (300ns -> 600ns). That's because the `TextLayoutJob` is a lot bigger (it has more options, like underlining, fonts etc), so it is slower to hash and compare. I have an idea how to speed this up, but I need to do some other work before I can implement that.
All in all, the performance impact on `demo_with_tesselate__realistic` is about 5-6% in the red. Not great; not terrible. The benefits are worth it, but I also think with some work I can get that down significantly, hopefully down to the old levels.
2021-09-03 16:18:00 +00:00
|
|
|
pub mod code_editor;
|
2021-10-20 10:34:27 +00:00
|
|
|
pub mod code_example;
|
2021-10-26 17:55:42 +00:00
|
|
|
pub mod context_menu;
|
2021-01-25 19:43:41 +00:00
|
|
|
pub mod dancing_strings;
|
2021-05-09 08:53:35 +00:00
|
|
|
pub mod demo_app_windows;
|
2021-01-25 19:43:41 +00:00
|
|
|
pub mod drag_and_drop;
|
|
|
|
pub mod font_book;
|
2021-12-17 17:39:15 +00:00
|
|
|
pub mod grid_demo;
|
2021-01-25 19:52:47 +00:00
|
|
|
pub mod layout_test;
|
2021-05-09 08:53:35 +00:00
|
|
|
pub mod misc_demo_window;
|
2021-05-09 08:09:05 +00:00
|
|
|
pub mod multi_touch;
|
2022-01-31 19:26:31 +00:00
|
|
|
pub mod paint_bezier;
|
2021-01-25 19:43:41 +00:00
|
|
|
pub mod painting;
|
2021-04-18 08:13:08 +00:00
|
|
|
pub mod password;
|
2021-02-14 20:39:04 +00:00
|
|
|
pub mod plot_demo;
|
2021-01-25 19:43:41 +00:00
|
|
|
pub mod scrolling;
|
2021-01-25 19:14:39 +00:00
|
|
|
pub mod sliders;
|
2021-12-17 15:11:34 +00:00
|
|
|
pub mod table_demo;
|
2021-01-25 19:43:41 +00:00
|
|
|
pub mod tests;
|
2022-01-06 10:32:00 +00:00
|
|
|
pub mod text_edit;
|
2021-01-01 16:11:05 +00:00
|
|
|
pub mod toggle_switch;
|
2021-01-25 19:43:41 +00:00
|
|
|
pub mod widget_gallery;
|
|
|
|
pub mod window_options;
|
2021-08-16 19:32:44 +00:00
|
|
|
pub mod window_with_panels;
|
2021-01-01 16:11:05 +00:00
|
|
|
|
2021-05-09 08:53:35 +00:00
|
|
|
pub use {
|
|
|
|
app::DemoApp, demo_app_windows::DemoWindows, misc_demo_window::MiscDemoWindow,
|
|
|
|
widget_gallery::WidgetGallery,
|
|
|
|
};
|
2021-01-01 16:11:05 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/// Something to view in the demo windows
|
|
|
|
pub trait View {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Something to view
|
|
|
|
pub trait Demo {
|
2021-02-20 08:18:23 +00:00
|
|
|
/// `&'static` so we can also use it as a key to store open/close state.
|
|
|
|
fn name(&self) -> &'static str;
|
2021-01-01 16:11:05 +00:00
|
|
|
|
|
|
|
/// Show windows, etc
|
2022-01-10 22:13:10 +00:00
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool);
|
2021-01-01 16:11:05 +00:00
|
|
|
}
|