Rename ui.wrap to ui.scope

This commit is contained in:
Emil Ernerfeldt 2021-05-09 13:17:32 +02:00
parent 9dc092b778
commit a8c3deaf08
7 changed files with 41 additions and 20 deletions

View file

@ -11,21 +11,22 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
* Add anchors to windows and areas so you can put a window in e.g. the top right corner.
* Make labels interactive with `Label::sense(Sense::click())`.
* Add `Response::request_focus` and `Response::surrender_focus`.
* Add `TextEdit::code_editor` (VERY basic)
* Add `TextEdit::code_editor` (VERY basic).
* [Pan and zoom plots](https://github.com/emilk/egui/pull/317).
* [Add plot legends](https://github.com/emilk/egui/pull/349)
* [Users can now store custom state in `egui::Memory`.](https://github.com/emilk/egui/pull/257).
* [Add plot legends](https://github.com/emilk/egui/pull/349).
* [Users can now store custom state in `egui::Memory`](https://github.com/emilk/egui/pull/257).
* Add `Response::on_disabled_hover_text` to show tooltip for disabled widgets.
* Zoom input: ctrl-scroll and (on `egui_web`) trackpad-pinch gesture.
* Support for raw [multi touch](https://github.com/emilk/egui/pull/306) events,
enabling zoom, rotate, and more. Works with `egui_web` on mobile devices,
and should work with `egui_glium` for certain touch devices/screens.
* Add (optional) compatability with [mint](https://docs.rs/mint)
* Add (optional) compatability with [mint](https://docs.rs/mint).
### Changed 🔧
* Make `Memory::has_focus` public (again).
* `Plot` must now be given a name that is unique within its scope.
* Tab only selects labels if the `screen_reader` option is turned on.
* Rename `ui.wrap` to `ui.scope`.
### Fixed 🐛
* Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288).

View file

@ -67,7 +67,7 @@ impl State {
if openness <= 0.0 {
None
} else if openness < 1.0 {
Some(ui.wrap(|child_ui| {
Some(ui.scope(|child_ui| {
let max_height = if self.open && self.open_height.is_none() {
// First frame of expansion.
// We don't know full height yet, but we will next frame.
@ -93,7 +93,7 @@ impl State {
ret
}))
} else {
let ret_response = ui.wrap(add_contents);
let ret_response = ui.scope(add_contents);
let full_size = ret_response.response.rect.size();
self.open_height = Some(full_size.y);
Some(ret_response)

View file

@ -229,11 +229,16 @@
//! ui.set_min_height(200.0);
//! });
//!
//! // Change test color on subsequent widgets:
//! ui.visuals_mut().override_text_color = Some(egui::Color32::RED);
//! // A `scope` creates a temporary [`Ui`] in which you can change settings:
//! ui.scope(|ui|{
//! // Change test color on subsequent widgets:
//! ui.visuals_mut().override_text_color = Some(egui::Color32::RED);
//!
//! // Turn off text wrapping on subsequent widgets:
//! ui.style_mut().wrap = Some(false);
//! // Turn off text wrapping on subsequent widgets:
//! ui.style_mut().wrap = Some(false);
//!
//! ui.label("This text will be red, and won't wrap to a new line");
//! }); // the temporary settings are reverted here
//! ```
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds

View file

@ -1195,8 +1195,18 @@ impl Ui {
crate::Frame::group(self.style()).show(self, add_contents)
}
/// Create a child ui. You can use this to temporarily change the Style of a sub-region, for instance.
pub fn wrap<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
/// Create a scoped child ui.
///
/// You can use this to temporarily change the [`Style`] of a sub-region, for instance:
///
/// ```
/// # let ui = &mut egui::Ui::__test();
/// ui.scope(|ui|{
/// ui.spacing_mut().slider_width = 200.0; // Temporary change
/// // …
/// });
/// ```
pub fn scope<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
let child_rect = self.available_rect_before_wrap();
let mut child_ui = self.child_ui(child_rect, *self.layout());
let ret = add_contents(&mut child_ui);
@ -1204,13 +1214,18 @@ impl Ui {
InnerResponse::new(ret, response)
}
#[deprecated = "Renamed scope()"]
pub fn wrap<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
self.scope(add_contents)
}
/// Redirect shapes to another paint layer.
pub fn with_layer_id<R>(
&mut self,
layer_id: LayerId,
add_contents: impl FnOnce(&mut Self) -> R,
) -> InnerResponse<R> {
self.wrap(|ui| {
self.scope(|ui| {
ui.painter.set_layer_id(layer_id);
add_contents(ui)
})
@ -1324,7 +1339,7 @@ impl Ui {
text_style: TextStyle,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
self.wrap(|ui| {
self.scope(|ui| {
let row_height = ui.fonts().row_height(text_style);
let space_width = ui.fonts().glyph_width(text_style, ' ');
let spacing = ui.spacing_mut();
@ -1368,7 +1383,7 @@ impl Ui {
text_style: TextStyle,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
self.wrap(|ui| {
self.scope(|ui| {
let row_height = ui.fonts().row_height(text_style);
let space_width = ui.fonts().glyph_width(text_style, ' ');
let spacing = ui.spacing_mut();

View file

@ -180,7 +180,7 @@ impl Widget for Button {
self.enabled_ui(ui)
} else {
// We need get a temporary disabled `Ui` to get that grayed out look:
ui.wrap(|ui| {
ui.scope(|ui| {
ui.set_enabled(false);
self.enabled_ui(ui)
})

View file

@ -70,7 +70,7 @@ impl ColorTest {
ui.heading("sRGB color test");
ui.label("Use a color picker to ensure this color is (255, 165, 0) / #ffa500");
ui.wrap(|ui| {
ui.scope(|ui| {
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
let g = Gradient::one_color(Color32::from_rgb(255, 165, 0));
self.vertex_gradient(ui, "orange rgb(255, 165, 0) - vertex", WHITE, &g);
@ -86,7 +86,7 @@ impl ColorTest {
ui.separator();
ui.label("Test that vertex color times texture color is done in linear space:");
ui.wrap(|ui| {
ui.scope(|ui| {
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
let tex_color = Rgba::from_rgb(1.0, 0.25, 0.25);
@ -185,7 +185,7 @@ impl ColorTest {
show_color(ui, right, color_size);
});
ui.wrap(|ui| {
ui.scope(|ui| {
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
if is_opaque {
let g = Gradient::ground_truth_linear_gradient(left, right);

View file

@ -4,7 +4,7 @@ pub fn drag_source(ui: &mut Ui, id: Id, body: impl FnOnce(&mut Ui)) {
let is_being_dragged = ui.memory().is_being_dragged(id);
if !is_being_dragged {
let response = ui.wrap(body).response;
let response = ui.scope(body).response;
// Check for drags:
let response = ui.interact(response.rect, id, Sense::drag());