Rename ui.wrap
to ui.scope
This commit is contained in:
parent
9dc092b778
commit
a8c3deaf08
7 changed files with 41 additions and 20 deletions
|
@ -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.
|
* 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())`.
|
* Make labels interactive with `Label::sense(Sense::click())`.
|
||||||
* Add `Response::request_focus` and `Response::surrender_focus`.
|
* 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).
|
* [Pan and zoom plots](https://github.com/emilk/egui/pull/317).
|
||||||
* [Add plot legends](https://github.com/emilk/egui/pull/349)
|
* [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).
|
* [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.
|
* Add `Response::on_disabled_hover_text` to show tooltip for disabled widgets.
|
||||||
* Zoom input: ctrl-scroll and (on `egui_web`) trackpad-pinch gesture.
|
* Zoom input: ctrl-scroll and (on `egui_web`) trackpad-pinch gesture.
|
||||||
* Support for raw [multi touch](https://github.com/emilk/egui/pull/306) events,
|
* 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,
|
enabling zoom, rotate, and more. Works with `egui_web` on mobile devices,
|
||||||
and should work with `egui_glium` for certain touch devices/screens.
|
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 🔧
|
### Changed 🔧
|
||||||
* Make `Memory::has_focus` public (again).
|
* Make `Memory::has_focus` public (again).
|
||||||
* `Plot` must now be given a name that is unique within its scope.
|
* `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.
|
* Tab only selects labels if the `screen_reader` option is turned on.
|
||||||
|
* Rename `ui.wrap` to `ui.scope`.
|
||||||
|
|
||||||
### Fixed 🐛
|
### Fixed 🐛
|
||||||
* Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288).
|
* Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288).
|
||||||
|
|
|
@ -67,7 +67,7 @@ impl State {
|
||||||
if openness <= 0.0 {
|
if openness <= 0.0 {
|
||||||
None
|
None
|
||||||
} else if openness < 1.0 {
|
} 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() {
|
let max_height = if self.open && self.open_height.is_none() {
|
||||||
// First frame of expansion.
|
// First frame of expansion.
|
||||||
// We don't know full height yet, but we will next frame.
|
// We don't know full height yet, but we will next frame.
|
||||||
|
@ -93,7 +93,7 @@ impl State {
|
||||||
ret
|
ret
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
let ret_response = ui.wrap(add_contents);
|
let ret_response = ui.scope(add_contents);
|
||||||
let full_size = ret_response.response.rect.size();
|
let full_size = ret_response.response.rect.size();
|
||||||
self.open_height = Some(full_size.y);
|
self.open_height = Some(full_size.y);
|
||||||
Some(ret_response)
|
Some(ret_response)
|
||||||
|
|
|
@ -229,11 +229,16 @@
|
||||||
//! ui.set_min_height(200.0);
|
//! ui.set_min_height(200.0);
|
||||||
//! });
|
//! });
|
||||||
//!
|
//!
|
||||||
//! // Change test color on subsequent widgets:
|
//! // A `scope` creates a temporary [`Ui`] in which you can change settings:
|
||||||
//! ui.visuals_mut().override_text_color = Some(egui::Color32::RED);
|
//! 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:
|
//! // Turn off text wrapping on subsequent widgets:
|
||||||
//! ui.style_mut().wrap = Some(false);
|
//! 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
|
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
|
||||||
|
|
|
@ -1195,8 +1195,18 @@ impl Ui {
|
||||||
crate::Frame::group(self.style()).show(self, add_contents)
|
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.
|
/// Create a scoped child ui.
|
||||||
pub fn wrap<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
|
///
|
||||||
|
/// 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 child_rect = self.available_rect_before_wrap();
|
||||||
let mut child_ui = self.child_ui(child_rect, *self.layout());
|
let mut child_ui = self.child_ui(child_rect, *self.layout());
|
||||||
let ret = add_contents(&mut child_ui);
|
let ret = add_contents(&mut child_ui);
|
||||||
|
@ -1204,13 +1214,18 @@ impl Ui {
|
||||||
InnerResponse::new(ret, response)
|
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.
|
/// Redirect shapes to another paint layer.
|
||||||
pub fn with_layer_id<R>(
|
pub fn with_layer_id<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
layer_id: LayerId,
|
layer_id: LayerId,
|
||||||
add_contents: impl FnOnce(&mut Self) -> R,
|
add_contents: impl FnOnce(&mut Self) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.wrap(|ui| {
|
self.scope(|ui| {
|
||||||
ui.painter.set_layer_id(layer_id);
|
ui.painter.set_layer_id(layer_id);
|
||||||
add_contents(ui)
|
add_contents(ui)
|
||||||
})
|
})
|
||||||
|
@ -1324,7 +1339,7 @@ impl Ui {
|
||||||
text_style: TextStyle,
|
text_style: TextStyle,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.wrap(|ui| {
|
self.scope(|ui| {
|
||||||
let row_height = ui.fonts().row_height(text_style);
|
let row_height = ui.fonts().row_height(text_style);
|
||||||
let space_width = ui.fonts().glyph_width(text_style, ' ');
|
let space_width = ui.fonts().glyph_width(text_style, ' ');
|
||||||
let spacing = ui.spacing_mut();
|
let spacing = ui.spacing_mut();
|
||||||
|
@ -1368,7 +1383,7 @@ impl Ui {
|
||||||
text_style: TextStyle,
|
text_style: TextStyle,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.wrap(|ui| {
|
self.scope(|ui| {
|
||||||
let row_height = ui.fonts().row_height(text_style);
|
let row_height = ui.fonts().row_height(text_style);
|
||||||
let space_width = ui.fonts().glyph_width(text_style, ' ');
|
let space_width = ui.fonts().glyph_width(text_style, ' ');
|
||||||
let spacing = ui.spacing_mut();
|
let spacing = ui.spacing_mut();
|
||||||
|
|
|
@ -180,7 +180,7 @@ impl Widget for Button {
|
||||||
self.enabled_ui(ui)
|
self.enabled_ui(ui)
|
||||||
} else {
|
} else {
|
||||||
// We need get a temporary disabled `Ui` to get that grayed out look:
|
// We need get a temporary disabled `Ui` to get that grayed out look:
|
||||||
ui.wrap(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.set_enabled(false);
|
ui.set_enabled(false);
|
||||||
self.enabled_ui(ui)
|
self.enabled_ui(ui)
|
||||||
})
|
})
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl ColorTest {
|
||||||
|
|
||||||
ui.heading("sRGB color test");
|
ui.heading("sRGB color test");
|
||||||
ui.label("Use a color picker to ensure this color is (255, 165, 0) / #ffa500");
|
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
|
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
|
||||||
let g = Gradient::one_color(Color32::from_rgb(255, 165, 0));
|
let g = Gradient::one_color(Color32::from_rgb(255, 165, 0));
|
||||||
self.vertex_gradient(ui, "orange rgb(255, 165, 0) - vertex", WHITE, &g);
|
self.vertex_gradient(ui, "orange rgb(255, 165, 0) - vertex", WHITE, &g);
|
||||||
|
@ -86,7 +86,7 @@ impl ColorTest {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
ui.label("Test that vertex color times texture color is done in linear space:");
|
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
|
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
|
||||||
|
|
||||||
let tex_color = Rgba::from_rgb(1.0, 0.25, 0.25);
|
let tex_color = Rgba::from_rgb(1.0, 0.25, 0.25);
|
||||||
|
@ -185,7 +185,7 @@ impl ColorTest {
|
||||||
show_color(ui, right, color_size);
|
show_color(ui, right, color_size);
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.wrap(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
|
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
|
||||||
if is_opaque {
|
if is_opaque {
|
||||||
let g = Gradient::ground_truth_linear_gradient(left, right);
|
let g = Gradient::ground_truth_linear_gradient(left, right);
|
||||||
|
|
|
@ -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);
|
let is_being_dragged = ui.memory().is_being_dragged(id);
|
||||||
|
|
||||||
if !is_being_dragged {
|
if !is_being_dragged {
|
||||||
let response = ui.wrap(body).response;
|
let response = ui.scope(body).response;
|
||||||
|
|
||||||
// Check for drags:
|
// Check for drags:
|
||||||
let response = ui.interact(response.rect, id, Sense::drag());
|
let response = ui.interact(response.rect, id, Sense::drag());
|
||||||
|
|
Loading…
Reference in a new issue