Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update egui via a [patch] #2969

Merged
merged 7 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 164 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ tokio = { version = "1.24", default-features = false }
unindent = "0.1"
vec1 = "1.8"
web-time = "0.2.0"
wgpu = { version = "0.16.1" }
wgpu-core = { version = "0.16.1" }
wgpu = { version = "0.17.0" }
wgpu-core = { version = "0.17.0" }


[profile.dev]
Expand Down Expand Up @@ -150,5 +150,15 @@ debug = true
# As a last resport, patch with a commit to our own repository.
# ALWAYS document what PR the commit hash is part of, or when it was merged into the upstream trunk.

# Temporary patch until next egui release
ecolor = { git = "https://github.com/emilk/egui", commit = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
eframe = { git = "https://github.com/emilk/egui", commit = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
egui-wgpu = { git = "https://github.com/emilk/egui", commit = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
egui-winit = { git = "https://github.com/emilk/egui", commit = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
egui = { git = "https://github.com/emilk/egui", commit = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
egui_extras = { git = "https://github.com/emilk/egui", commit = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
emath = { git = "https://github.com/emilk/egui", commit = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
epaint = { git = "https://github.com/emilk/egui", commit = "98087029e020a1b2d78a4eb840d0a8505340ecad" }

# Temporary patch until next egui_tiles release
egui_tiles = { git = "https://github.com/rerun-io/egui_tiles", commit = "f835c4df1cc260a58122a8d37c7c3738902b9643" }
4 changes: 2 additions & 2 deletions crates/re_renderer/src/error_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ macro_rules! try_downcast {
wgpu_core::binding_model::CreatePipelineLayoutError,
wgpu_core::binding_model::GetBindGroupLayoutError,
wgpu_core::binding_model::PushConstantUploadError,
wgpu_core::device::CreateDeviceError,
wgpu_core::device::resource::CreateDeviceError,
wgpu_core::device::DeviceError,
wgpu_core::device::RenderPassCompatibilityError,
wgpu_core::pipeline::ColorStateError,
Expand Down Expand Up @@ -129,7 +129,7 @@ impl_trait![
wgpu_core::binding_model::CreatePipelineLayoutError,
wgpu_core::binding_model::GetBindGroupLayoutError,
wgpu_core::binding_model::PushConstantUploadError,
wgpu_core::device::CreateDeviceError,
wgpu_core::device::resource::CreateDeviceError,
wgpu_core::device::DeviceError,
wgpu_core::device::RenderPassCompatibilityError,
wgpu_core::pipeline::ColorStateError,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl SpaceViewClass for TimeSeriesSpaceView {
response,
transform,
} = plot.show(ui, |plot_ui| {
if plot_ui.plot_secondary_clicked() {
if plot_ui.response().secondary_clicked() {
let timeline = ctx.rec_cfg.time_ctrl.timeline();
ctx.rec_cfg.time_ctrl.set_timeline_and_time(
*timeline,
Expand Down
19 changes: 12 additions & 7 deletions crates/re_time_panel/src/data_density_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use std::ops::RangeInclusive;

use egui::emath::Rangef;
use egui::{epaint::Vertex, lerp, pos2, remap, Color32, NumExt as _, Rect, Shape};

use re_data_store::TimeHistogram;
Expand Down Expand Up @@ -87,9 +88,9 @@ struct DensityGraph {
}

impl DensityGraph {
pub fn new(x_range: RangeInclusive<f32>) -> Self {
let min_x = *x_range.start() - MARGIN_X;
let max_x = *x_range.end() + MARGIN_X;
pub fn new(x_range: Rangef) -> Self {
let min_x = x_range.min - MARGIN_X;
let max_x = x_range.max + MARGIN_X;
let n = ((max_x - min_x) * DENSITIES_PER_UI_PIXEL).ceil() as usize;
Self {
buckets: vec![0.0; n],
Expand Down Expand Up @@ -187,15 +188,19 @@ impl DensityGraph {

pub fn paint(
&self,
data_dentity_graph_painter: &mut DataDensityGraphPainter,
y_range: RangeInclusive<f32>,
data_density_graph_painter: &mut DataDensityGraphPainter,
y_range: Rangef,
painter: &egui::Painter,
full_color: Color32,
hovered_x_range: RangeInclusive<f32>,
) {
re_tracing::profile_function!();

let (min_y, max_y) = (*y_range.start(), *y_range.end());
let Rangef {
min: min_y,
max: max_y,
} = y_range;

let center_y = (min_y + max_y) / 2.0;
let max_radius = (max_y - min_y) / 2.0;

Expand Down Expand Up @@ -235,7 +240,7 @@ impl DensityGraph {

let x = self.x_from_bucket_index(i);

let normalized_density = data_dentity_graph_painter.normalize_density(density);
let normalized_density = data_density_graph_painter.normalize_density(density);

let (inner_radius, inner_color) = if normalized_density == 0.0 {
(0.0, Color32::TRANSPARENT)
Expand Down
49 changes: 26 additions & 23 deletions crates/re_time_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ mod time_control_ui;
mod time_ranges_ui;
mod time_selection_ui;

use std::ops::RangeInclusive;

use egui::emath::Rangef;
use egui::{pos2, Color32, CursorIcon, NumExt, PointerButton, Rect, Shape, Vec2};

use re_data_store::{EntityTree, InstancePath, TimeHistogram};
Expand Down Expand Up @@ -205,21 +204,24 @@ impl TimePanel {
.at_most(ui.max_rect().right() - 100.0);

// Where the time will be shown.
let time_bg_x_range = time_x_left..=ui.max_rect().right();
let time_bg_x_range = Rangef::new(time_x_left, ui.max_rect().right());
let time_fg_x_range = {
// Painting to the right of the scroll bar (if any) looks bad:
let right = ui.max_rect().right() - ui.spacing_mut().scroll_bar_outer_margin;
debug_assert!(time_x_left < right);
time_x_left..=right
Rangef::new(time_x_left, right)
};

let side_margin = 26.0; // chosen so that the scroll bar looks approximately centered in the default gap
self.time_ranges_ui = initialize_time_ranges_ui(
ctx,
(*time_fg_x_range.start() + side_margin)..=(*time_fg_x_range.end() - side_margin),
Rangef::new(
time_fg_x_range.min + side_margin,
time_fg_x_range.max - side_margin,
),
ctx.rec_cfg.time_ctrl.time_view(),
);
let full_y_range = ui.min_rect().bottom()..=ui.max_rect().bottom();
let full_y_range = Rangef::new(ui.min_rect().bottom(), ui.max_rect().bottom());

let timeline_rect = {
let top = ui.min_rect().bottom();
Expand All @@ -239,18 +241,17 @@ impl TimePanel {
);

let bottom = ui.min_rect().bottom();
Rect::from_x_y_ranges(time_fg_x_range.clone(), top..=bottom)
Rect::from_x_y_ranges(time_fg_x_range, top..=bottom)
};

let streams_rect = Rect::from_x_y_ranges(
time_fg_x_range.clone(),
time_fg_x_range,
timeline_rect.bottom()..=ui.max_rect().bottom(),
);

// includes the timeline and streams areas.
let time_bg_area_rect = Rect::from_x_y_ranges(time_bg_x_range, full_y_range.clone());
let time_fg_area_rect =
Rect::from_x_y_ranges(time_fg_x_range.clone(), full_y_range.clone());
let time_bg_area_rect = Rect::from_x_y_ranges(time_bg_x_range, full_y_range);
let time_fg_area_rect = Rect::from_x_y_ranges(time_fg_x_range, full_y_range);
let time_bg_area_painter = ui.painter().with_clip_rect(time_bg_area_rect);
let time_area_painter = ui.painter().with_clip_rect(time_fg_area_rect);

Expand All @@ -272,7 +273,7 @@ impl TimePanel {
ctx.re_ui,
ui,
&time_bg_area_painter,
full_y_range.clone(),
full_y_range,
);
time_selection_ui::loop_selection_ui(
ctx.store_db,
Expand Down Expand Up @@ -310,9 +311,9 @@ impl TimePanel {
// This looks great but only if there are still time markers.
// When they move to the right (or have a cut) one expects the shadow to go all the way up.
// But that's quite complicated so let's have the shadow all the way
let shadow_y_start = *full_y_range.start();
let shadow_y_start = full_y_range.min;

let shadow_y_end = *full_y_range.end();
let shadow_y_end = full_y_range.max;
let rect = egui::Rect::from_x_y_ranges(
time_x_left..=(time_x_left + shadow_width),
shadow_y_start..=shadow_y_end,
Expand Down Expand Up @@ -721,7 +722,7 @@ fn current_time_ui(ctx: &ViewerContext<'_>, ui: &mut egui::Ui) {

fn initialize_time_ranges_ui(
ctx: &mut ViewerContext<'_>,
time_x_range: RangeInclusive<f32>,
time_x_range: Rangef,
mut time_view: Option<TimeView>,
) -> TimeRangesUi {
re_tracing::profile_function!();
Expand Down Expand Up @@ -762,10 +763,10 @@ fn initialize_time_ranges_ui(
}

/// Find a nice view of everything.
fn view_everything(x_range: &RangeInclusive<f32>, timeline_axis: &TimelineAxis) -> TimeView {
fn view_everything(x_range: &Rangef, timeline_axis: &TimelineAxis) -> TimeView {
let gap_width = time_ranges_ui::gap_width(x_range, &timeline_axis.ranges) as f32;
let num_gaps = timeline_axis.ranges.len().saturating_sub(1);
let width = *x_range.end() - *x_range.start();
let width = x_range.span();
let width_sans_gaps = width - num_gaps as f32 * gap_width;

let factor = if width_sans_gaps > 0.0 {
Expand All @@ -789,7 +790,7 @@ fn paint_time_ranges_gaps(
re_ui: &re_ui::ReUi,
ui: &mut egui::Ui,
painter: &egui::Painter,
y_range: RangeInclusive<f32>,
y_range: Rangef,
) {
re_tracing::profile_function!();

Expand Down Expand Up @@ -818,8 +819,10 @@ fn paint_time_ranges_gaps(

use itertools::Itertools as _;

let top = *y_range.start();
let bottom = *y_range.end();
let Rangef {
min: top,
max: bottom,
} = y_range;

let fill_color = ui.visuals().widgets.noninteractive.bg_fill;
let stroke = ui.visuals().widgets.noninteractive.bg_stroke;
Expand Down Expand Up @@ -896,7 +899,7 @@ fn paint_time_ranges_gaps(
0.0,
fill_color,
);
painter.vline(gap_edge, y_range.clone(), stroke);
painter.vline(gap_edge, y_range, stroke);
}
}

Expand Down Expand Up @@ -1005,7 +1008,7 @@ fn time_marker_ui(
// show current time as a line:
if let Some(time) = time_ctrl.time() {
if let Some(x) = time_ranges_ui.x_from_time_f32(time) {
if timeline_rect.x_range().contains(&x) {
if timeline_rect.x_range().contains(x) {
let line_rect =
Rect::from_x_y_ranges(x..=x, timeline_rect.top()..=ui.max_rect().bottom())
.expand(interact_radius);
Expand Down Expand Up @@ -1036,7 +1039,7 @@ fn time_marker_ui(
re_ui.paint_time_cursor(
time_area_painter,
x,
timeline_rect.top()..=ui.max_rect().bottom(),
Rangef::new(timeline_rect.top(), ui.max_rect().bottom()),
stroke,
);
}
Expand Down
20 changes: 8 additions & 12 deletions crates/re_time_panel/src/time_ranges_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::ops::RangeInclusive;

use egui::emath::Rangef;
use egui::{lerp, remap, NumExt};
use itertools::Itertools as _;

Expand All @@ -23,15 +24,14 @@ const MAX_GAP: f64 = 40.0;
const GAP_EXPANSION_FRACTION: f64 = 1.0 / 4.0;

/// Sze of the gap between time segments.
pub fn gap_width(x_range: &RangeInclusive<f32>, segments: &[TimeRange]) -> f64 {
pub fn gap_width(x_range: &Rangef, segments: &[TimeRange]) -> f64 {
let num_gaps = segments.len().saturating_sub(1);
if num_gaps == 0 {
// gap width doesn't matter when there are no gaps
MAX_GAP
} else {
// shrink gaps if there are a lot of them
let width = *x_range.end() - *x_range.start();
(width as f64 / (num_gaps as f64)).at_most(MAX_GAP)
(x_range.span() as f64 / (num_gaps as f64)).at_most(MAX_GAP)
}
}

Expand Down Expand Up @@ -93,14 +93,10 @@ impl Default for TimeRangesUi {
}

impl TimeRangesUi {
pub fn new(
x_range: RangeInclusive<f32>,
time_view: TimeView,
time_ranges: &[TimeRange],
) -> Self {
pub fn new(x_range: Rangef, time_view: TimeView, time_ranges: &[TimeRange]) -> Self {
re_tracing::profile_function!();

debug_assert!(x_range.start() < x_range.end());
debug_assert!(x_range.min < x_range.max);

// <------- time_view ------>
// <-------- x_range ------->
Expand All @@ -109,7 +105,7 @@ impl TimeRangesUi {
// ^ gap

let gap_width_in_ui = gap_width(&x_range, time_ranges);
let x_range = (*x_range.start() as f64)..=(*x_range.end() as f64);
let x_range = (x_range.min as f64)..=(x_range.max as f64);
let width_in_ui = *x_range.end() - *x_range.start();
let points_per_time = width_in_ui / time_view.time_spanned;
let points_per_time = if points_per_time > 0.0 && points_per_time.is_finite() {
Expand Down Expand Up @@ -384,7 +380,7 @@ impl TimeRangesUi {
#[test]
fn test_time_ranges_ui() {
let time_range_ui = TimeRangesUi::new(
100.0..=1000.0,
Rangef::new(100.0, 1000.0),
TimeView {
min: TimeReal::from(0.5),
time_spanned: 14.2,
Expand Down Expand Up @@ -426,7 +422,7 @@ fn test_time_ranges_ui() {
#[test]
fn test_time_ranges_ui_2() {
let time_range_ui = TimeRangesUi::new(
0.0..=500.0,
Rangef::new(0.0, 500.0),
TimeView {
min: TimeReal::from(0),
time_spanned: 50.0,
Expand Down
12 changes: 7 additions & 5 deletions crates/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ pub struct TopBarStyle {

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

use std::{ops::RangeInclusive, sync::Arc};
use std::sync::Arc;

use parking_lot::Mutex;

use crate::list_item::ListItem;
use egui::emath::Rot2;
use egui::emath::{Rangef, Rot2};
use egui::{pos2, Align2, Color32, Mesh, NumExt, Rect, Shape, Vec2};

#[derive(Clone)]
Expand Down Expand Up @@ -816,11 +816,13 @@ impl ReUi {
&self,
painter: &egui::Painter,
x: f32,
y: RangeInclusive<f32>,
y: Rangef,
stroke: egui::Stroke,
) {
let y_min = *y.start();
let y_max = *y.end();
let Rangef {
min: y_min,
max: y_max,
} = y;

let stroke = egui::Stroke {
width: 1.5 * stroke.width,
Expand Down