1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Improve the UI for changing the egui theme (#4257)

I added a new demo - a `Frame` editor:

![frame-editor](https://github.com/emilk/egui/assets/1148717/d0bec169-c211-45a3-9f53-5059fb8fc224)

This whole menu is now just a a bit nicer to use:
<img width="406" alt="Screenshot 2024-03-28 at 09 49 16"
src="https://github.com/emilk/egui/assets/1148717/32d12067-7cf0-4312-aa12-42909a5ed5ac">
This commit is contained in:
Emil Ernerfeldt
2024-03-28 10:09:28 +01:00
committed by GitHub
parent e183655aac
commit 3dba73e63e
23 changed files with 635 additions and 334 deletions

View File

@@ -29,6 +29,7 @@ impl Default for Demos {
Box::<super::drag_and_drop::DragAndDropDemo>::default(),
Box::<super::extra_viewport::ExtraViewport>::default(),
Box::<super::font_book::FontBook>::default(),
Box::<super::frame_demo::FrameDemo>::default(),
Box::<super::MiscDemoWindow>::default(),
Box::<super::multi_touch::MultiTouch>::default(),
Box::<super::painting::Painting>::default(),

View File

@@ -0,0 +1,73 @@
/// Shows off a table with dynamic layout
#[derive(PartialEq)]
pub struct FrameDemo {
frame: egui::Frame,
}
impl Default for FrameDemo {
fn default() -> Self {
Self {
frame: egui::Frame {
inner_margin: 12.0.into(),
outer_margin: 24.0.into(),
rounding: 14.0.into(),
shadow: egui::Shadow {
offset: [8.0, 12.0].into(),
blur: 16.0,
spread: 0.0,
color: egui::Color32::from_black_alpha(180),
},
fill: egui::Color32::from_rgba_unmultiplied(97, 0, 255, 128),
stroke: egui::Stroke::new(1.0, egui::Color32::GRAY),
},
}
}
}
impl super::Demo for FrameDemo {
fn name(&self) -> &'static str {
"▣ Frame"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
egui::Window::new(self.name())
.open(open)
.resizable(false)
.show(ctx, |ui| {
use super::View as _;
self.ui(ui);
});
}
}
impl super::View for FrameDemo {
fn ui(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.vertical(|ui| {
ui.add(&mut self.frame);
ui.add_space(8.0);
ui.set_max_width(ui.min_size().x);
ui.vertical_centered(|ui| egui::reset_button(ui, self, "Reset"));
});
ui.separator();
ui.vertical(|ui| {
// We want to paint a background around the outer margin of the demonstration frame, so we use another frame around it:
egui::Frame::default()
.stroke(ui.visuals().widgets.noninteractive.bg_stroke)
.rounding(ui.visuals().widgets.noninteractive.rounding)
.show(ui, |ui| {
self.frame.show(ui, |ui| {
ui.label(egui::RichText::new("Content").color(egui::Color32::WHITE));
});
});
});
});
ui.set_max_width(ui.min_size().x);
ui.separator();
ui.vertical_centered(|ui| ui.add(crate::egui_github_link_file!()));
}
}

View File

@@ -328,7 +328,7 @@ impl Default for ColorWidgets {
impl ColorWidgets {
fn ui(&mut self, ui: &mut Ui) {
egui::reset_button(ui, self);
egui::reset_button(ui, self, "Reset");
ui.label("egui lets you edit colors stored as either sRGBA or linear RGBA and with or without premultiplied alpha");

View File

@@ -13,6 +13,7 @@ pub mod demo_app_windows;
pub mod drag_and_drop;
pub mod extra_viewport;
pub mod font_book;
pub mod frame_demo;
pub mod highlighting;
pub mod layout_test;
pub mod misc_demo_window;

View File

@@ -43,13 +43,27 @@ impl Default for PaintBezier {
impl PaintBezier {
pub fn ui_control(&mut self, ui: &mut egui::Ui) {
ui.collapsing("Colors", |ui| {
ui.horizontal(|ui| {
ui.label("Fill color:");
ui.color_edit_button_srgba(&mut self.fill);
});
egui::stroke_ui(ui, &mut self.stroke, "Curve Stroke");
egui::stroke_ui(ui, &mut self.aux_stroke, "Auxiliary Stroke");
egui::stroke_ui(ui, &mut self.bounding_box_stroke, "Bounding Box Stroke");
Grid::new("colors")
.num_columns(2)
.spacing([12.0, 8.0])
.striped(true)
.show(ui, |ui| {
ui.label("Fill color");
ui.color_edit_button_srgba(&mut self.fill);
ui.end_row();
ui.label("Curve Stroke");
ui.add(&mut self.stroke);
ui.end_row();
ui.label("Auxiliary Stroke");
ui.add(&mut self.aux_stroke);
ui.end_row();
ui.label("Bounding Box Stroke");
ui.add(&mut self.bounding_box_stroke);
ui.end_row();
});
});
ui.collapsing("Global tessellation options", |ui| {

View File

@@ -20,7 +20,8 @@ impl Default for Painting {
impl Painting {
pub fn ui_control(&mut self, ui: &mut egui::Ui) -> egui::Response {
ui.horizontal(|ui| {
egui::stroke_ui(ui, &mut self.stroke, "Stroke");
ui.label("Stroke:");
ui.add(&mut self.stroke);
ui.separator();
if ui.button("Clear Painting").clicked() {
self.lines.clear();

View File

@@ -62,7 +62,7 @@ impl super::Demo for PlotDemo {
impl super::View for PlotDemo {
fn ui(&mut self, ui: &mut Ui) {
ui.horizontal(|ui| {
egui::reset_button(ui, self);
egui::reset_button(ui, self, "Reset");
ui.collapsing("Instructions", |ui| {
ui.label("Pan by dragging, or scroll (+ shift = horizontal).");
ui.label("Box zooming: Right click to zoom in and zoom out using a selection.");

View File

@@ -336,7 +336,7 @@ impl super::View for ScrollTo {
ui.separator();
ui.vertical_centered(|ui| {
egui::reset_button(ui, self);
egui::reset_button(ui, self, "Reset");
ui.add(crate::egui_github_link_file!());
});
}

View File

@@ -198,7 +198,7 @@ impl super::View for Sliders {
ui.add_space(8.0);
ui.vertical_centered(|ui| {
egui::reset_button(ui, self);
egui::reset_button(ui, self, "Reset");
ui.add(crate::egui_github_link_file!());
});
}

View File

@@ -8,7 +8,7 @@ pub struct StripDemo {}
impl super::Demo for StripDemo {
fn name(&self) -> &'static str {
"▣ Strip Demo"
"▣ Strip"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {

View File

@@ -40,7 +40,7 @@ impl Default for TableDemo {
impl super::Demo for TableDemo {
fn name(&self) -> &'static str {
"☰ Table Demo"
"☰ Table"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {

View File

@@ -131,7 +131,7 @@ impl super::Demo for ManualLayoutTest {
impl super::View for ManualLayoutTest {
fn ui(&mut self, ui: &mut egui::Ui) {
egui::reset_button(ui, self);
egui::reset_button(ui, self, "Reset");
let Self {
widget_offset,
@@ -298,7 +298,7 @@ impl super::View for TableTest {
});
ui.vertical_centered(|ui| {
egui::reset_button(ui, self);
egui::reset_button(ui, self, "Reset");
ui.add(crate::egui_github_link_file!());
});
}

View File

@@ -146,7 +146,7 @@ impl super::View for WindowOptions {
if ui.button("Disable for 2 seconds").clicked() {
self.disabled_time = ui.input(|i| i.time);
}
egui::reset_button(ui, self);
egui::reset_button(ui, self, "Reset");
ui.add(crate::egui_github_link_file!());
});
}

View File

@@ -48,7 +48,7 @@ impl EasyMarkEditor {
let _ = ui.button("Hotkeys").on_hover_ui(nested_hotkeys_ui);
ui.checkbox(&mut self.show_rendered, "Show rendered");
ui.checkbox(&mut self.highlight_editor, "Highlight editor");
egui::reset_button(ui, self);
egui::reset_button(ui, self, "Reset");
ui.end_row();
});
ui.separator();