mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
@@ -439,7 +439,7 @@ pub struct WebOptions {
|
||||
/// Unused by webgl context as of writing.
|
||||
pub depth_buffer: u8,
|
||||
|
||||
/// Which version of WebGl context to select
|
||||
/// Which version of WebGL context to select
|
||||
///
|
||||
/// Default: [`WebGlContextOption::BestFirst`].
|
||||
#[cfg(feature = "glow")]
|
||||
|
||||
@@ -14,7 +14,7 @@ impl EventLoopGuard {
|
||||
cell.get().is_none(),
|
||||
"Attempted to set a new event loop while one is already set"
|
||||
);
|
||||
cell.set(Some(event_loop as *const ActiveEventLoop));
|
||||
cell.set(Some(std::ptr::from_ref::<ActiveEventLoop>(event_loop)));
|
||||
});
|
||||
Self
|
||||
}
|
||||
|
||||
@@ -1,42 +1,14 @@
|
||||
use raw_window_handle::{
|
||||
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
|
||||
RawWindowHandle, WebDisplayHandle, WebWindowHandle, WindowHandle,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
use wasm_bindgen::JsValue;
|
||||
use web_sys::HtmlCanvasElement;
|
||||
|
||||
use crate::WebOptions;
|
||||
use egui_wgpu::{RenderState, SurfaceErrorAction, WgpuSetup};
|
||||
|
||||
use crate::WebOptions;
|
||||
|
||||
use super::web_painter::WebPainter;
|
||||
|
||||
struct EguiWebWindow(u32);
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl HasWindowHandle for EguiWebWindow {
|
||||
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
|
||||
// SAFETY: there is no lifetime here.
|
||||
unsafe {
|
||||
Ok(WindowHandle::borrow_raw(RawWindowHandle::Web(
|
||||
WebWindowHandle::new(self.0),
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl HasDisplayHandle for EguiWebWindow {
|
||||
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
|
||||
// SAFETY: there is no lifetime here.
|
||||
unsafe {
|
||||
Ok(DisplayHandle::borrow_raw(RawDisplayHandle::Web(
|
||||
WebDisplayHandle::new(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct WebPainterWgpu {
|
||||
canvas: HtmlCanvasElement,
|
||||
surface: wgpu::Surface<'static>,
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct WebRunner {
|
||||
/// Have we ever panicked?
|
||||
panic_handler: PanicHandler,
|
||||
|
||||
/// If we ever panic during running, this RefCell is poisoned.
|
||||
/// If we ever panic during running, this `RefCell` is poisoned.
|
||||
/// So before we use it, we need to check [`Self::panic_handler`].
|
||||
runner: Rc<RefCell<Option<AppRunner>>>,
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ pub struct ScreenDescriptor {
|
||||
/// Size of the window in physical pixels.
|
||||
pub size_in_pixels: [u32; 2],
|
||||
|
||||
/// HiDPI scale factor (pixels per point).
|
||||
/// High-DPI scale factor (pixels per point).
|
||||
pub pixels_per_point: f32,
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ pub struct State {
|
||||
scroll_start_offset_from_top_left: [Option<f32>; 2],
|
||||
|
||||
/// Is the scroll sticky. This is true while scroll handle is in the end position
|
||||
/// and remains that way until the user moves the scroll_handle. Once unstuck (false)
|
||||
/// and remains that way until the user moves the `scroll_handle`. Once unstuck (false)
|
||||
/// it remains false until the scroll touches the end position, which reenables stickiness.
|
||||
scroll_stuck_to_end: Vec2b,
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ pub enum Key {
|
||||
// `]`
|
||||
CloseBracket,
|
||||
|
||||
/// \`, also known as "backquote" or "grave"
|
||||
/// Also known as "backquote" or "grave"
|
||||
Backtick,
|
||||
|
||||
/// `-`
|
||||
|
||||
@@ -889,9 +889,9 @@ impl Default for PointerState {
|
||||
press_start_time: None,
|
||||
has_moved_too_much_for_a_click: false,
|
||||
started_decidedly_dragging: false,
|
||||
last_click_time: std::f64::NEG_INFINITY,
|
||||
last_last_click_time: std::f64::NEG_INFINITY,
|
||||
last_move_time: std::f64::NEG_INFINITY,
|
||||
last_click_time: f64::NEG_INFINITY,
|
||||
last_last_click_time: f64::NEG_INFINITY,
|
||||
last_move_time: f64::NEG_INFINITY,
|
||||
pointer_events: vec![],
|
||||
input_options: Default::default(),
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
emath::{pos2, vec2, Align2, NumExt, Pos2, Rect, Vec2},
|
||||
Align,
|
||||
};
|
||||
use std::f32::INFINITY;
|
||||
const INFINITY: f32 = f32::INFINITY;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! Try the live web demo: <https://www.egui.rs/#demo>. Read more about egui at <https://github.com/emilk/egui>.
|
||||
//!
|
||||
//! `egui` is in heavy development, with each new version having breaking changes.
|
||||
//! You need to have rust 1.77.0 or later to use `egui`.
|
||||
//! You need to have rust 1.79.0 or later to use `egui`.
|
||||
//!
|
||||
//! To quickly get started with egui, you can take a look at [`eframe_template`](https://github.com/emilk/eframe_template)
|
||||
//! which uses [`eframe`](https://docs.rs/eframe).
|
||||
|
||||
@@ -736,7 +736,7 @@ impl Focus {
|
||||
|
||||
let current_rect = self.focus_widgets_cache.get(¤t_focused.id)?;
|
||||
|
||||
let mut best_score = std::f32::INFINITY;
|
||||
let mut best_score = f32::INFINITY;
|
||||
let mut best_id = None;
|
||||
|
||||
for (candidate_id, candidate_rect) in &self.focus_widgets_cache {
|
||||
|
||||
@@ -288,7 +288,7 @@ pub struct Style {
|
||||
/// If true and scrolling is enabled for only one direction, allow horizontal scrolling without pressing shift
|
||||
pub always_scroll_the_only_direction: bool,
|
||||
|
||||
/// The animation that should be used when scrolling a [`crate::ScrollArea`] using e.g. [Ui::scroll_to_rect].
|
||||
/// The animation that should be used when scrolling a [`crate::ScrollArea`] using e.g. [`Ui::scroll_to_rect`].
|
||||
pub scroll_animation: ScrollAnimation,
|
||||
}
|
||||
|
||||
|
||||
@@ -1030,7 +1030,7 @@ impl<'a> Widget for Slider<'a> {
|
||||
// Logarithmic sliders are allowed to include zero and infinity,
|
||||
// even though mathematically it doesn't make sense.
|
||||
|
||||
use std::f64::INFINITY;
|
||||
const INFINITY: f64 = f64::INFINITY;
|
||||
|
||||
/// When the user asks for an infinitely large range (e.g. logarithmic from zero),
|
||||
/// give a scale that this many orders of magnitude in size.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use egui::{style::HandleShape, Slider, SliderClamping, SliderOrientation, Ui};
|
||||
use std::f64::INFINITY;
|
||||
|
||||
/// Showcase sliders
|
||||
#[derive(PartialEq)]
|
||||
@@ -77,7 +76,7 @@ impl crate::View for Sliders {
|
||||
let (type_min, type_max) = if *integer {
|
||||
((i32::MIN as f64), (i32::MAX as f64))
|
||||
} else if *logarithmic {
|
||||
(-INFINITY, INFINITY)
|
||||
(-f64::INFINITY, f64::INFINITY)
|
||||
} else {
|
||||
(-1e5, 1e5) // linear sliders make little sense with huge numbers
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ pub enum Item<'a> {
|
||||
// TODO(emilk): add Style here so empty heading still uses up the right amount of space.
|
||||
Newline,
|
||||
|
||||
///
|
||||
/// Text
|
||||
Text(Style, &'a str),
|
||||
|
||||
/// title, url
|
||||
|
||||
@@ -18,8 +18,8 @@ macro_rules! impl_numeric_float {
|
||||
($t: ident) => {
|
||||
impl Numeric for $t {
|
||||
const INTEGRAL: bool = false;
|
||||
const MIN: Self = std::$t::MIN;
|
||||
const MAX: Self = std::$t::MAX;
|
||||
const MIN: Self = $t::MIN;
|
||||
const MAX: Self = $t::MAX;
|
||||
|
||||
#[inline(always)]
|
||||
fn to_f64(self) -> f64 {
|
||||
@@ -44,8 +44,8 @@ macro_rules! impl_numeric_integer {
|
||||
($t: ident) => {
|
||||
impl Numeric for $t {
|
||||
const INTEGRAL: bool = true;
|
||||
const MIN: Self = std::$t::MIN;
|
||||
const MAX: Self = std::$t::MAX;
|
||||
const MIN: Self = $t::MIN;
|
||||
const MAX: Self = $t::MAX;
|
||||
|
||||
#[inline(always)]
|
||||
fn to_f64(self) -> f64 {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::f32::INFINITY;
|
||||
use std::fmt;
|
||||
|
||||
use crate::{lerp, pos2, vec2, Div, Mul, Pos2, Rangef, Rot2, Vec2};
|
||||
@@ -33,8 +32,8 @@ pub struct Rect {
|
||||
impl Rect {
|
||||
/// Infinite rectangle that contains every point.
|
||||
pub const EVERYTHING: Self = Self {
|
||||
min: pos2(-INFINITY, -INFINITY),
|
||||
max: pos2(INFINITY, INFINITY),
|
||||
min: pos2(-f32::INFINITY, -f32::INFINITY),
|
||||
max: pos2(f32::INFINITY, f32::INFINITY),
|
||||
};
|
||||
|
||||
/// The inverse of [`Self::EVERYTHING`]: stretches from positive infinity to negative infinity.
|
||||
@@ -53,8 +52,8 @@ impl Rect {
|
||||
/// assert_eq!(rect, Rect::from_min_max(pos2(0.0, 1.0), pos2(2.0, 3.0)))
|
||||
/// ```
|
||||
pub const NOTHING: Self = Self {
|
||||
min: pos2(INFINITY, INFINITY),
|
||||
max: pos2(-INFINITY, -INFINITY),
|
||||
min: pos2(f32::INFINITY, f32::INFINITY),
|
||||
max: pos2(-f32::INFINITY, -f32::INFINITY),
|
||||
};
|
||||
|
||||
/// An invalid [`Rect`] filled with [`f32::NAN`].
|
||||
|
||||
@@ -138,7 +138,9 @@ fn test_aim() {
|
||||
assert_eq!(best_in_range_f64(99.999, 100.000), 100.0);
|
||||
assert_eq!(best_in_range_f64(10.001, 100.001), 100.0);
|
||||
|
||||
use std::f64::{INFINITY, NAN, NEG_INFINITY};
|
||||
const NAN: f64 = f64::NAN;
|
||||
const INFINITY: f64 = f64::INFINITY;
|
||||
const NEG_INFINITY: f64 = f64::NEG_INFINITY;
|
||||
assert!(best_in_range_f64(NAN, NAN).is_nan());
|
||||
assert_eq!(best_in_range_f64(NAN, 1.2), 1.2);
|
||||
assert_eq!(best_in_range_f64(NAN, INFINITY), INFINITY);
|
||||
|
||||
@@ -75,7 +75,7 @@ mod mutex_impl {
|
||||
// Detect if we are recursively taking out a lock on this mutex.
|
||||
|
||||
// use a pointer to the inner data as an id for this lock
|
||||
let ptr = (&self.0 as *const parking_lot::Mutex<_>).cast::<()>();
|
||||
let ptr = std::ptr::from_ref::<parking_lot::Mutex<_>>(&self.0).cast::<()>();
|
||||
|
||||
// Store it in thread local storage while we have a lock guard taken out
|
||||
HELD_LOCKS_TLS.with(|held_locks| {
|
||||
|
||||
@@ -623,10 +623,10 @@ pub struct Glyph {
|
||||
/// The row/line height of this font.
|
||||
pub font_height: f32,
|
||||
|
||||
/// The ascent of the sub-font within the font ("FontImpl").
|
||||
/// The ascent of the sub-font within the font (`FontImpl`).
|
||||
pub font_impl_ascent: f32,
|
||||
|
||||
/// The row/line height of the sub-font within the font ("FontImpl").
|
||||
/// The row/line height of the sub-font within the font (`FontImpl`).
|
||||
pub font_impl_height: f32,
|
||||
|
||||
/// Position and size of the glyph in the font texture, in texels.
|
||||
|
||||
Reference in New Issue
Block a user