1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

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

@@ -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)
})