Skip to content

Commit

Permalink
Merge branch 'emilk:master' into patch22
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Jun 26, 2024
2 parents 13b3478 + 93d458b commit 67ec63e
Show file tree
Hide file tree
Showing 31 changed files with 73 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR.
* Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Expand Down
10 changes: 5 additions & 5 deletions crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub mod icon_data;
/// ``` no_run
/// use eframe::egui;
///
/// fn main() -> eframe::Result<()> {
/// fn main() -> eframe::Result {
/// let native_options = eframe::NativeOptions::default();
/// eframe::run_native("MyApp", native_options, Box::new(|cc| Ok(Box::new(MyEguiApp::new(cc)))))
/// }
Expand Down Expand Up @@ -233,7 +233,7 @@ pub fn run_native(
app_name: &str,
mut native_options: NativeOptions,
app_creator: AppCreator,
) -> Result<()> {
) -> Result {
#[cfg(not(feature = "__screenshot"))]
assert!(
std::env::var("EFRAME_SCREENSHOT_TO").is_err(),
Expand Down Expand Up @@ -278,7 +278,7 @@ pub fn run_native(
///
/// # Example
/// ``` no_run
/// fn main() -> eframe::Result<()> {
/// fn main() -> eframe::Result {
/// // Our application state:
/// let mut name = "Arthur".to_owned();
/// let mut age = 42;
Expand Down Expand Up @@ -310,7 +310,7 @@ pub fn run_simple_native(
app_name: &str,
native_options: NativeOptions,
update_fun: impl FnMut(&egui::Context, &mut Frame) + 'static,
) -> Result<()> {
) -> Result {
struct SimpleApp<U> {
update_fun: U,
}
Expand Down Expand Up @@ -445,7 +445,7 @@ impl std::fmt::Display for Error {
}

/// Short for `Result<T, eframe::Error>`.
pub type Result<T, E = Error> = std::result::Result<T, E>;
pub type Result<T = (), E = Error> = std::result::Result<T, E>;

// ---------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ impl GlutinWindowContext {
&mut self,
viewport_id: ViewportId,
event_loop: &EventLoopWindowTarget<UserEvent>,
) -> Result<()> {
) -> Result {
crate::profile_function!();

let Some(viewport) = self.viewports.get_mut(&viewport_id) else {
Expand Down Expand Up @@ -1218,7 +1218,7 @@ impl GlutinWindowContext {
}

/// only applies for android. but we basically drop surface + window and make context not current
fn on_suspend(&mut self) -> Result<()> {
fn on_suspend(&mut self) -> Result {
log::debug!("received suspend event. dropping window and surface");
for viewport in self.viewports.values_mut() {
viewport.gl_surface = None;
Expand Down
11 changes: 4 additions & 7 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ fn with_event_loop<R>(
}

#[cfg(not(target_os = "ios"))]
fn run_and_return(
event_loop: &mut EventLoop<UserEvent>,
mut winit_app: impl WinitApp,
) -> Result<()> {
fn run_and_return(event_loop: &mut EventLoop<UserEvent>, mut winit_app: impl WinitApp) -> Result {
use winit::{event_loop::ControlFlow, platform::run_on_demand::EventLoopExtRunOnDemand};

log::trace!("Entering the winit event loop (run_on_demand)…");
Expand Down Expand Up @@ -228,7 +225,7 @@ fn run_and_return(
fn run_and_exit(
event_loop: EventLoop<UserEvent>,
mut winit_app: impl WinitApp + 'static,
) -> Result<()> {
) -> Result {
use winit::event_loop::ControlFlow;
log::trace!("Entering the winit event loop (run)…");

Expand Down Expand Up @@ -391,7 +388,7 @@ pub fn run_glow(
app_name: &str,
mut native_options: epi::NativeOptions,
app_creator: epi::AppCreator,
) -> Result<()> {
) -> Result {
#![allow(clippy::needless_return_with_question_mark)] // False positive

use super::glow_integration::GlowWinitApp;
Expand All @@ -416,7 +413,7 @@ pub fn run_wgpu(
app_name: &str,
mut native_options: epi::NativeOptions,
app_creator: epi::AppCreator,
) -> Result<()> {
) -> Result {
#![allow(clippy::needless_return_with_question_mark)] // False positive

use super::wgpu_integration::WgpuWinitApp;
Expand Down
8 changes: 7 additions & 1 deletion crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,16 @@ pub fn popup_above_or_below_widget<R>(
add_contents: impl FnOnce(&mut Ui) -> R,
) -> Option<R> {
if parent_ui.memory(|mem| mem.is_popup_open(popup_id)) {
let (pos, pivot) = match above_or_below {
let (mut pos, pivot) = match above_or_below {
AboveOrBelow::Above => (widget_response.rect.left_top(), Align2::LEFT_BOTTOM),
AboveOrBelow::Below => (widget_response.rect.left_bottom(), Align2::LEFT_TOP),
};
if let Some(transform) = parent_ui
.ctx()
.memory(|m| m.layer_transforms.get(&parent_ui.layer_id()).copied())
{
pos = transform * pos;
}

let frame = Frame::popup(parent_ui.style());
let frame_margin = frame.total_margin();
Expand Down
7 changes: 7 additions & 0 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ impl MenuRoot {
}
}

if let Some(transform) = button
.ctx
.memory(|m| m.layer_transforms.get(&button.layer_id).copied())
{
pos = transform * pos;
}

return MenuResponse::Create(pos, id);
} else if button
.ctx
Expand Down
9 changes: 8 additions & 1 deletion crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,14 @@ impl Response {
///
/// This can be used to give attention to a widget during a tutorial.
pub fn show_tooltip_ui(&self, add_contents: impl FnOnce(&mut Ui)) {
crate::containers::show_tooltip_for(&self.ctx, self.id, &self.rect, add_contents);
let mut rect = self.rect;
if let Some(transform) = self
.ctx
.memory(|m| m.layer_transforms.get(&self.layer_id).copied())
{
rect = transform * rect;
}
crate::containers::show_tooltip_for(&self.ctx, self.id, &rect, add_contents);
}

/// Always show this tooltip, even if disabled and the user isn't hovering it.
Expand Down
17 changes: 15 additions & 2 deletions crates/egui/src/widgets/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,21 @@ impl Label {
}
(pos, galley, response)
} else {
layout_job.wrap =
text::TextWrapping::from_wrap_mode_and_width(wrap_mode, available_width);
// Apply wrap_mode, but don't overwrite anything important
// the user may have set manually on the layout_job:
match wrap_mode {
TextWrapMode::Extend => {
layout_job.wrap.max_width = f32::INFINITY;
}
TextWrapMode::Wrap => {
layout_job.wrap.max_width = available_width;
}
TextWrapMode::Truncate => {
layout_job.wrap.max_width = available_width;
layout_job.wrap.max_rows = 1;
layout_job.wrap.break_anywhere = true;
}
}

if ui.is_grid() {
// TODO(emilk): remove special Grid hacks like these
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_demo_app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(clippy::never_loop)] // False positive

// When compiling natively:
fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
for arg in std::env::args().skip(1) {
match arg.as_str() {
"--profile" => {
Expand Down
4 changes: 2 additions & 2 deletions crates/emath/src/rot2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use super::Vec2;
// `vec2(c,s)` represents where the X axis will end up after rotation.
//
/// Represents a rotation in the 2D plane.
//
///
/// A rotation of 𝞃/4 = 90° rotates the X axis to the Y axis.
//
///
/// Normally a [`Rot2`] is normalized (unit-length).
/// If not, it will also scale vectors.
#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion examples/confirm_exit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_3d_glow/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use eframe::{egui, egui_glow, glow};
use egui::mutex::Mutex;
use std::sync::Arc;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([350.0, 380.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_font/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_font_style/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use eframe::egui;
use egui::{FontFamily, FontId, RichText, TextStyle};

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions::default();

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_keypad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use eframe::egui;
mod keypad;
use keypad::Keypad;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 480.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_plot_manipulation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use eframe::egui::{self, DragValue, Event, Vec2};
use egui_plot::{Legend, Line, PlotPoints};

fn main() -> Result<(), eframe::Error> {
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(
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_window_frame/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use eframe::egui::{self, ViewportCommand};

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
Expand Down
2 changes: 1 addition & 1 deletion examples/file_dialog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world_par/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::thread::JoinHandle;

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([1024.0, 768.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world_simple/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).

let options = eframe::NativeOptions {
Expand Down
2 changes: 1 addition & 1 deletion examples/images/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 800.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/keyboard_events/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use eframe::egui;
use egui::*;

fn main() -> Result<(), eframe::Error> {
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(
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple_viewports/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::{

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/puffin_profiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::{

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
start_puffin_server(); // NOTE: you may only want to call this if the users specifies some flag or clicks a button!

Expand Down
2 changes: 1 addition & 1 deletion examples/save_plot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use eframe::egui;
use egui_plot::{Legend, Line, Plot, PlotPoints};

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).

let options = eframe::NativeOptions {
Expand Down
2 changes: 1 addition & 1 deletion examples/screenshot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;

use eframe::egui::{self, ColorImage};

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
renderer: eframe::Renderer::Wgpu,
Expand Down
2 changes: 1 addition & 1 deletion examples/serial_windows/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).

if cfg!(target_os = "macos") {
Expand Down
2 changes: 1 addition & 1 deletion examples/user_attention/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use egui::{Button, CentralPanel, Context, UserAttentionType};

use std::time::{Duration, SystemTime};

fn main() -> eframe::Result<()> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let native_options = NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([400., 200.]),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_size_pass/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use eframe::egui;

fn main() -> eframe::Result<()> {
fn main() -> eframe::Result {
env_logger::init(); // Use `RUST_LOG=debug` to see logs.

let options = eframe::NativeOptions::default();
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ui_stack/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use eframe::egui;
use eframe::egui::{Rangef, Shape, UiKind};
use egui_extras::Column;

fn main() -> Result<(), eframe::Error> {
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
Expand Down

0 comments on commit 67ec63e

Please sign in to comment.