Skip to content

Commit

Permalink
Remove the "+" icon from the "Add SV/Container" modal and close on cl…
Browse files Browse the repository at this point in the history
…ick (#4927)

### What

This PR introduces two minor tweaks to the "Add Space View or Container"
modal:
- remove the big "+" button
- close the modal on click

<img width="690" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/5b5e0e63-534b-45ec-a8ab-663abb3d6e9f">


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/4927/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/4927/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/4927/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4927)
- [Docs
preview](https://rerun.io/preview/46b823d22815129b69a2506ab91389d7b994200c/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/46b823d22815129b69a2506ab91389d7b994200c/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
abey79 authored Jan 30, 2024
1 parent d67ac4a commit c2688ad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 45 deletions.
Binary file removed crates/re_ui/data/icons/add_big.png
Binary file not shown.
1 change: 0 additions & 1 deletion crates/re_ui/src/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub const INVISIBLE: Icon = Icon::new("invisible", include_bytes!("../data/icons

pub const ADD: Icon = Icon::new("add", include_bytes!("../data/icons/add.png"));

pub const ADD_BIG: Icon = Icon::new("add_big", include_bytes!("../data/icons/add_big.png"));
pub const REMOVE: Icon = Icon::new("remove", include_bytes!("../data/icons/remove.png"));

pub const RESET: Icon = Icon::new("reset", include_bytes!("../data/icons/reset.png"));
Expand Down
76 changes: 32 additions & 44 deletions crates/re_viewer/src/ui/add_space_view_or_container_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl AddSpaceViewOrContainerModal {
.min_width(500.0)
.full_span_content(true)
},
|_, ui, _| modal_ui(ui, ctx, viewport, self.target_container),
|_, ui, keep_open| modal_ui(ui, ctx, viewport, self.target_container, keep_open),
);
}
}
Expand All @@ -39,6 +39,7 @@ fn modal_ui(
ctx: &ViewerContext<'_>,
viewport: &Viewport<'_, '_>,
target_container: Option<ContainerId>,
keep_open: &mut bool,
) {
let container_data = [
(
Expand Down Expand Up @@ -67,6 +68,7 @@ fn modal_ui(
if row_ui(ui, icon_for_container_kind(&kind), title, subtitle).clicked() {
viewport.blueprint.add_container(kind, target_container);
viewport.blueprint.mark_user_interaction(ctx);
*keep_open = false;
}
}

Expand Down Expand Up @@ -96,6 +98,7 @@ fn modal_ui(
.blueprint
.add_space_views(std::iter::once(space_view), ctx, target_container);
viewport.blueprint.mark_user_interaction(ctx);
*keep_open = false;
}
}
}
Expand All @@ -110,9 +113,9 @@ fn modal_ui(
/// ┌───────────────────────────────────────────────────┐──▲
/// │ │ │ row_space/2
/// │ ╔══════╦══════════════════════════════════╗────│──▼▲
/// │ ║ ║ ┌───┐ ║ │ │
/// │ ║ Icon ║ Title and Subtitles │ + │ ║ │ │ row_height
/// │ ║ ║ └───┘ ║ │ │
/// │ ║ ║ ║ │ │
/// │ ║ Icon ║ Title and Subtitles ║ │ │ row_height
/// │ ║ ║ ║ │ │
/// │ ╚══════╩══════════════════════════════════╝────│──▲▼
/// │ │ │ row_space/2
/// └───────────────────────────────────────────────────┘──▼
Expand Down Expand Up @@ -163,50 +166,35 @@ fn row_ui(ui: &mut egui::Ui, icon: &re_ui::Icon, title: &str, subtitle: &str) ->
ui.add(egui::Label::new(subtitle).wrap(false));
});

ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let right_coord = ui.cursor().max.x;
let right_coord = ui.cursor().max.x;

// interact with the entire row
let interact_rect = egui::Rect::from_min_max(
top_left_corner,
egui::pos2(right_coord, top_left_corner.y + row_height + row_space),
);
// interact with the entire row
let interact_rect = egui::Rect::from_min_max(
top_left_corner,
egui::pos2(right_coord, top_left_corner.y + row_height + row_space),
);

let response =
ui.interact(interact_rect, title.to_owned().into(), egui::Sense::click());

if response.hovered() {
let clip_rect = ui.clip_rect();

let response =
ui.interact(interact_rect, title.to_owned().into(), egui::Sense::click());
let tint = if response.hovered() {
ui.visuals().widgets.active.fg_stroke.color
} else {
ui.visuals().widgets.inactive.fg_stroke.color
};

ui.add(
re_ui::icons::ADD_BIG
.as_image()
.fit_to_exact_size(egui::vec2(24.0, 24.0))
.tint(tint),
let bg_rect = interact_rect
.with_min_x(clip_rect.min.x)
.with_max_x(clip_rect.max.x);

ui.painter().set(
background_frame,
egui::Shape::rect_filled(
bg_rect,
0.0,
ui.visuals().widgets.hovered.weak_bg_fill,
),
);
}

if response.hovered() {
let clip_rect = ui.clip_rect();

let bg_rect = interact_rect
.with_min_x(clip_rect.min.x)
.with_max_x(clip_rect.max.x);

ui.painter().set(
background_frame,
egui::Shape::rect_filled(
bg_rect,
0.0,
ui.visuals().widgets.hovered.weak_bg_fill,
),
);
}

response
})
.inner
response
})
.inner;

Expand Down

0 comments on commit c2688ad

Please sign in to comment.