1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Merge branch 'master' of https://github.com/emilk/egui into multiples_viewports

This commit is contained in:
Konkitoman
2023-08-15 02:17:12 +03:00
159 changed files with 2536 additions and 1163 deletions

View File

@@ -139,7 +139,7 @@ fn ui_url(ui: &mut egui::Ui, frame: &mut eframe::Frame, url: &mut String) -> boo
if ui.button("Random image").clicked() {
let seed = ui.input(|i| i.time);
let side = 640;
*url = format!("https://picsum.photos/seed/{}/{}", seed, side);
*url = format!("https://picsum.photos/seed/{seed}/{side}");
trigger_fetch = true;
}
});

View File

@@ -239,8 +239,7 @@ impl BackendPanel {
if ui
.add_enabled(enabled, egui::Button::new("Reset"))
.on_hover_text(format!(
"Reset scale to native value ({:.1})",
native_pixels_per_point
"Reset scale to native value ({native_pixels_per_point:.1})"
))
.clicked()
{
@@ -454,8 +453,8 @@ impl EguiWindows {
egui::ScrollArea::vertical()
.stick_to_bottom(true)
.show(ui, |ui| {
for event in &*tmp_output_event_history.read().unwrap() {
ui.label(format!("{:?}", event));
for event in output_event_history.read() {
ui.label(format!("{event:?}"));
}
});
});

View File

@@ -161,6 +161,15 @@ impl Default for Anchor {
// ----------------------------------------------------------------------------
#[derive(Clone, Copy, Debug)]
#[must_use]
enum Command {
Nothing,
ResetEverything,
}
// ----------------------------------------------------------------------------
/// The state that we persist (serialize).
#[derive(Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
@@ -286,18 +295,19 @@ impl eframe::App for WrapApp {
frame.set_fullscreen(!frame.info().window_info.fullscreen);
}
let mut cmd = Command::Nothing;
egui::TopBottomPanel::top("wrap_app_top_bar").show(ctx, |ui| {
egui::trace!(ui);
ui.horizontal_wrapped(|ui| {
ui.visuals_mut().button_frame = false;
self.bar_contents(ui, frame);
self.bar_contents(ui, frame, &mut cmd);
});
});
self.state.backend_panel.update(ctx, frame);
if !is_mobile(ctx) {
self.backend_panel(ctx, frame);
cmd = self.backend_panel(ctx, frame);
}
self.show_selected_app(ctx, frame, render);
@@ -310,6 +320,8 @@ impl eframe::App for WrapApp {
if !frame.is_web() {
egui::gui_zoom::zoom_with_keyboard_shortcuts(ctx, frame.info().native_pixels_per_point);
}
self.run_cmd(ctx, cmd);
}
#[cfg(feature = "glow")]
@@ -326,12 +338,14 @@ impl eframe::App for WrapApp {
}
impl WrapApp {
fn backend_panel(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
fn backend_panel(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) -> Command {
// The backend-panel can be toggled on/off.
// We show a little animation when the user switches it.
let is_open =
self.state.backend_panel.open || ctx.memory(|mem| mem.everything_is_visible());
let mut cmd = Command::Nothing;
egui::SidePanel::left("backend_panel")
.resizable(false)
.show_animated(ctx, is_open, |ui| {
@@ -340,11 +354,28 @@ impl WrapApp {
});
ui.separator();
self.backend_panel_contents(ui, frame);
self.backend_panel_contents(ui, frame, &mut cmd);
});
cmd
}
fn backend_panel_contents(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
fn run_cmd(&mut self, ctx: &egui::Context, cmd: Command) {
match cmd {
Command::Nothing => {}
Command::ResetEverything => {
self.state = Default::default();
ctx.memory_mut(|mem| *mem = Default::default());
}
}
}
fn backend_panel_contents(
&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
cmd: &mut Command,
) {
self.state.backend_panel.ui(ui, frame);
ui.separator();
@@ -360,8 +391,7 @@ impl WrapApp {
}
if ui.button("Reset everything").clicked() {
self.state = Default::default();
ui.ctx().memory_mut(|mem| *mem = Default::default());
*cmd = Command::ResetEverything;
ui.close_menu();
}
});
@@ -381,7 +411,7 @@ impl WrapApp {
}
}
fn bar_contents(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
fn bar_contents(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cmd: &mut Command) {
egui::widgets::global_dark_light_mode_switch(ui);
ui.separator();
@@ -389,7 +419,7 @@ impl WrapApp {
if is_mobile(ui.ctx()) {
ui.menu_button("💻 Backend", |ui| {
ui.set_style(ui.ctx().style()); // ignore the "menu" style set by `menu_button`.
self.backend_panel_contents(ui, frame);
self.backend_panel_contents(ui, frame, cmd);
});
} else {
ui.toggle_value(&mut self.state.backend_panel.open, "💻 Backend");
@@ -405,7 +435,7 @@ impl WrapApp {
{
selected_anchor = anchor;
if frame.is_web() {
ui.output_mut(|o| o.open_url(format!("#{}", anchor)));
ui.output_mut(|o| o.open_url(format!("#{anchor}")));
}
}
}