mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 12:50:04 -04:00
The three methods for showing a `Panel` are now: * `panel.show`: always show the panel. * `panel.show_collapsible`: show or hide the panel, with a slide animation in between. * `Panel::show_switched`: animate between two different panels: a thin/collapsed one and a thick/expanded one.
74 lines
2.5 KiB
Rust
74 lines
2.5 KiB
Rust
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
#![expect(rustdoc::missing_crate_level_docs)] // it's an example
|
|
|
|
use eframe::egui;
|
|
use egui::{FontFamily, FontId, RichText, TextStyle};
|
|
use std::collections::BTreeMap;
|
|
|
|
fn main() -> eframe::Result {
|
|
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
|
let options = eframe::NativeOptions::default();
|
|
|
|
eframe::run_native(
|
|
"egui example: global font style",
|
|
options,
|
|
Box::new(|cc| Ok(Box::new(MyApp::new(cc)))),
|
|
)
|
|
}
|
|
|
|
#[inline]
|
|
fn heading2() -> TextStyle {
|
|
TextStyle::Name("Heading2".into())
|
|
}
|
|
|
|
#[inline]
|
|
fn heading3() -> TextStyle {
|
|
TextStyle::Name("ContextHeading".into())
|
|
}
|
|
|
|
fn configure_text_styles(ctx: &egui::Context) {
|
|
use FontFamily::{Monospace, Proportional};
|
|
|
|
let text_styles: BTreeMap<TextStyle, FontId> = [
|
|
(TextStyle::Heading, FontId::new(25.0, Proportional)),
|
|
(heading2(), FontId::new(22.0, Proportional)),
|
|
(heading3(), FontId::new(19.0, Proportional)),
|
|
(TextStyle::Body, FontId::new(16.0, Proportional)),
|
|
(TextStyle::Monospace, FontId::new(12.0, Monospace)),
|
|
(TextStyle::Button, FontId::new(12.0, Proportional)),
|
|
(TextStyle::Small, FontId::new(8.0, Proportional)),
|
|
]
|
|
.into();
|
|
ctx.all_styles_mut(move |style| style.text_styles = text_styles.clone());
|
|
}
|
|
|
|
fn content(ui: &mut egui::Ui) {
|
|
ui.heading("Top Heading");
|
|
ui.add_space(5.);
|
|
ui.label(LOREM_IPSUM);
|
|
ui.add_space(15.);
|
|
ui.label(RichText::new("Sub Heading").text_style(heading2()).strong());
|
|
ui.monospace(LOREM_IPSUM);
|
|
ui.add_space(15.);
|
|
ui.label(RichText::new("Context").text_style(heading3()).strong());
|
|
ui.add_space(5.);
|
|
ui.label(LOREM_IPSUM);
|
|
}
|
|
|
|
struct MyApp;
|
|
|
|
impl MyApp {
|
|
fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
|
configure_text_styles(&cc.egui_ctx);
|
|
Self
|
|
}
|
|
}
|
|
|
|
impl eframe::App for MyApp {
|
|
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
|
egui::CentralPanel::default().show(ui, content);
|
|
}
|
|
}
|
|
|
|
pub const LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|