mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-14 06:58:35 +00:00
Merge pull request #468 from AngelOfSol/feature/build-return
Modifies build functions to allow returning data from the build closures. Thanks @AngelOfSol !
This commit is contained in:
commit
80ae0bd7ed
@ -2,6 +2,9 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- BREAKING: Modifies `build` style methods to allow the provide closure to return a value. The build call will then return Some(value) if the closure is called, and None if it isn't.
|
||||
- The most likely breaking changes users will see is that they will need to add semicolons after calling `build`, because these function no longer return `()`.
|
||||
|
||||
- BREAKING: Created `with_x` variants for most functions which previously took multiple parameters where some had default arguments in the C++. This makes calling most functions simpler and more similar to the C++.
|
||||
- The most likely breaking changes users will see is `button` and `same_line` now take one fewer parameter -- if you were calling `button` with `[0.0, 0.0]`, simply delete that -- otherwise, call `button_with_size`. Similarly, for `same_line`, if you were passing in `0.0.` simply delete that parameter. Otherwise, call `same_line_with_pos`.
|
||||
|
||||
|
||||
@ -828,7 +828,7 @@ CTRL+click on individual component to input value.\n",
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn show_example_app_main_menu_bar<'a>(ui: &Ui<'a>, state: &mut State) {
|
||||
@ -942,7 +942,7 @@ output your content because that would create a feedback loop.",
|
||||
for i in 0..state.lines {
|
||||
ui.text(format!("{:2$}This is line {}", "", i, i as usize * 4));
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) {
|
||||
|
||||
@ -125,11 +125,10 @@ impl<'p> PopupModal<'p> {
|
||||
}
|
||||
|
||||
/// Consume and draw the PopupModal.
|
||||
/// Returns the result of the closure, if it is called.
|
||||
#[doc(alias = "BeginPopupModal")]
|
||||
pub fn build<F: FnOnce()>(self, ui: &Ui<'_>, f: F) {
|
||||
if let Some(_popup) = self.begin_popup(ui) {
|
||||
f();
|
||||
}
|
||||
pub fn build<T, F: FnOnce() -> T>(self, ui: &Ui<'_>, f: F) -> Option<T> {
|
||||
self.begin_popup(ui).map(|_popup| f())
|
||||
}
|
||||
|
||||
/// Consume and draw the PopupModal.
|
||||
|
||||
@ -155,12 +155,11 @@ impl<'a> ComboBox<'a> {
|
||||
}
|
||||
}
|
||||
/// Creates a combo box and runs a closure to construct the popup contents.
|
||||
/// Returns the result of the closure, if it is called.
|
||||
///
|
||||
/// Note: the closure is not called if the combo box is not open.
|
||||
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
|
||||
if let Some(_combo) = self.begin(ui) {
|
||||
f();
|
||||
}
|
||||
pub fn build<T, F: FnOnce() -> T>(self, ui: &Ui, f: F) -> Option<T> {
|
||||
self.begin(ui).map(|_combo| f())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -49,12 +49,11 @@ impl<'a> ListBox<'a> {
|
||||
}
|
||||
}
|
||||
/// Creates a list box and runs a closure to construct the list contents.
|
||||
/// Returns the result of the closure, if it is called.
|
||||
///
|
||||
/// Note: the closure is not called if the list box is not open.
|
||||
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
|
||||
if let Some(_list) = self.begin(ui) {
|
||||
f();
|
||||
}
|
||||
pub fn build<T, F: FnOnce() -> T>(self, ui: &Ui<'_>, f: F) -> Option<T> {
|
||||
self.begin(ui).map(|_list| f())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -103,12 +103,11 @@ impl<'a> TabBar<'a> {
|
||||
}
|
||||
|
||||
/// Creates a tab bar and runs a closure to construct the contents.
|
||||
/// Returns the result of the closure, if it is called.
|
||||
///
|
||||
/// Note: the closure is not called if no tabbar content is visible
|
||||
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
|
||||
if let Some(_tab) = self.begin(ui) {
|
||||
f();
|
||||
}
|
||||
pub fn build<T, F: FnOnce() -> T>(self, ui: &Ui<'_>, f: F) -> Option<T> {
|
||||
self.begin(ui).map(|_tab| f())
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,12 +174,11 @@ impl<'a> TabItem<'a> {
|
||||
}
|
||||
|
||||
/// Creates a tab item and runs a closure to construct the contents.
|
||||
/// Returns the result of the closure, if it is called.
|
||||
///
|
||||
/// Note: the closure is not called if the tab item is not selected
|
||||
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
|
||||
if let Some(_tab) = self.begin(ui) {
|
||||
f();
|
||||
}
|
||||
pub fn build<T, F: FnOnce() -> T>(self, ui: &Ui<'_>, f: F) -> Option<T> {
|
||||
self.begin(ui).map(|_tab| f())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -264,12 +264,11 @@ impl<'a> TreeNode<'a> {
|
||||
}
|
||||
}
|
||||
/// Creates a tree node and runs a closure to construct the contents.
|
||||
/// Returns the result of the closure, if it is called.
|
||||
///
|
||||
/// Note: the closure is not called if the tree node is not open.
|
||||
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
|
||||
if let Some(_node) = self.push(ui) {
|
||||
f();
|
||||
}
|
||||
pub fn build<T, F: FnOnce() -> T>(self, ui: &Ui<'_>, f: F) -> Option<T> {
|
||||
self.push(ui).map(|_node| f())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -277,13 +277,12 @@ impl<'a> ChildWindow<'a> {
|
||||
}
|
||||
}
|
||||
/// Creates a child window and runs a closure to construct the contents.
|
||||
/// Returns the result of the closure, if it is called.
|
||||
///
|
||||
/// Note: the closure is not called if no window content is visible (e.g. window is collapsed
|
||||
/// or fully clipped).
|
||||
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
|
||||
if let Some(_window) = self.begin(ui) {
|
||||
f();
|
||||
}
|
||||
pub fn build<T, F: FnOnce() -> T>(self, ui: &Ui<'_>, f: F) -> Option<T> {
|
||||
self.begin(ui).map(|_window| f())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -541,13 +541,12 @@ impl<'a> Window<'a> {
|
||||
}
|
||||
}
|
||||
/// Creates a window and runs a closure to construct the contents.
|
||||
/// Returns the result of the closure, if it is called.
|
||||
///
|
||||
/// Note: the closure is not called if no window content is visible (e.g. window is collapsed
|
||||
/// or fully clipped).
|
||||
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
|
||||
if let Some(_window) = self.begin(ui) {
|
||||
f();
|
||||
}
|
||||
pub fn build<T, F: FnOnce() -> T>(self, ui: &Ui<'_>, f: F) -> Option<T> {
|
||||
self.begin(ui).map(|_window| f())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user