mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 13:38:35 +00:00
added id back to child window
This commit is contained in:
parent
f0782f4ea2
commit
203780c884
@ -340,7 +340,7 @@ impl Ui {
|
||||
/// This, like many objects in the library, uses the builder
|
||||
/// pattern to set optional arguments (like window size, flags,
|
||||
/// etc). Once all desired options are set, you must call either
|
||||
/// [`Window::build`] or [`Window::begin`] must be called to
|
||||
/// [`Window::build`] or [`Window::begin`] to
|
||||
/// actually create the window.
|
||||
///
|
||||
/// # Examples
|
||||
@ -355,28 +355,44 @@ impl Ui {
|
||||
/// ui.text("An example");
|
||||
/// });
|
||||
/// ```
|
||||
///
|
||||
/// Same as [`Ui::window`] but using the "token based" `.begin()` approach.
|
||||
///
|
||||
/// ```no_run
|
||||
/// # let mut ctx = imgui::Context::create();
|
||||
/// # let ui = ctx.frame();
|
||||
/// if let Some(wt) = ui
|
||||
/// .window("Example Window")
|
||||
/// .size([100.0, 50.0], imgui::Condition::FirstUseEver)
|
||||
/// .begin()
|
||||
/// {
|
||||
/// ui.text("Window is visible");
|
||||
/// // Window ends where where wt is dropped,
|
||||
/// // or you could call
|
||||
/// // if you want to let it drop on its own, name it `_wt`.
|
||||
/// // never name it `_`, as this will drop it *immediately*.
|
||||
/// wt.unwrap().end();
|
||||
/// }
|
||||
/// ```
|
||||
pub fn window<Label: AsRef<str>>(&self, name: Label) -> Window<'_, '_, Label> {
|
||||
Window::new(self, name)
|
||||
}
|
||||
|
||||
/// Same as [`Ui::window`] but using the "token based" `.begin()` approach.
|
||||
/// Begins constructing a child window with the given name.
|
||||
///
|
||||
/// ```
|
||||
/// fn example(ui: &imgui::Ui) {
|
||||
/// let wt = ui.window("Example Window")
|
||||
/// .size([100.0, 50.0], imgui::Condition::FirstUseEver)
|
||||
/// .begin();
|
||||
/// if wt.is_some() {
|
||||
/// ui.text("Window is visible");
|
||||
/// }
|
||||
/// // Window ends where where wt is dropped,
|
||||
/// // or you could call
|
||||
/// wt.unwrap().end()
|
||||
/// }
|
||||
/// ```
|
||||
pub fn child_window<Label: AsRef<str>>(&self, name: Label) -> ChildWindow<'_, Label> {
|
||||
/// Use child windows to begin into a self-contained independent scrolling/clipping
|
||||
/// regions within a host window. Child windows can embed their own child.
|
||||
pub fn child_window<Label: AsRef<str>>(&self, name: Label) -> ChildWindow<'_> {
|
||||
ChildWindow::new(self, name)
|
||||
}
|
||||
|
||||
/// Begins constructing a child window with the given name.
|
||||
///
|
||||
/// Use child windows to begin into a self-contained independent scrolling/clipping
|
||||
/// regions within a host window. Child windows can embed their own child.
|
||||
pub fn child_window_id(&self, id: Id<'_>) -> ChildWindow<'_> {
|
||||
ChildWindow::new_id(self, id)
|
||||
}
|
||||
}
|
||||
|
||||
// Widgets: Input
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
use std::f32;
|
||||
|
||||
use crate::math::MintVec2;
|
||||
use crate::sys;
|
||||
use crate::window::WindowFlags;
|
||||
use crate::Ui;
|
||||
use crate::{sys, Id};
|
||||
|
||||
/// Builder for a child window
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[must_use]
|
||||
pub struct ChildWindow<'ui, Label> {
|
||||
pub struct ChildWindow<'ui> {
|
||||
ui: &'ui Ui,
|
||||
name: Label,
|
||||
id: u32,
|
||||
flags: WindowFlags,
|
||||
size: [f32; 2],
|
||||
content_size: [f32; 2],
|
||||
@ -19,13 +19,20 @@ pub struct ChildWindow<'ui, Label> {
|
||||
border: bool,
|
||||
}
|
||||
|
||||
impl<'ui, Label: AsRef<str>> ChildWindow<'ui, Label> {
|
||||
/// Creates a new child window builder with the given ID
|
||||
impl<'ui> ChildWindow<'ui> {
|
||||
/// Creates a new child window builder with the str.
|
||||
#[doc(alias = "BeginChildID")]
|
||||
pub fn new(ui: &'ui Ui, name: Label) -> ChildWindow<'ui, Label> {
|
||||
ChildWindow {
|
||||
pub fn new(ui: &'ui Ui, name: impl AsRef<str>) -> Self {
|
||||
let id = Id::Str(name.as_ref());
|
||||
Self::new_id(ui, id)
|
||||
}
|
||||
|
||||
/// Creates a new child window builder with the given imgui id.
|
||||
#[doc(alias = "BeginChildID")]
|
||||
pub fn new_id(ui: &'ui Ui, id: Id<'_>) -> Self {
|
||||
Self {
|
||||
ui,
|
||||
name,
|
||||
id: id.as_imgui_id(),
|
||||
flags: WindowFlags::empty(),
|
||||
size: [0.0, 0.0],
|
||||
content_size: [0.0, 0.0],
|
||||
@ -34,6 +41,7 @@ impl<'ui, Label: AsRef<str>> ChildWindow<'ui, Label> {
|
||||
border: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace current window flags with the given value
|
||||
#[inline]
|
||||
pub fn flags(mut self, flags: WindowFlags) -> Self {
|
||||
@ -258,8 +266,8 @@ impl<'ui, Label: AsRef<str>> ChildWindow<'ui, Label> {
|
||||
unsafe { sys::igSetNextWindowBgAlpha(self.bg_alpha) };
|
||||
}
|
||||
let should_render = unsafe {
|
||||
sys::igBeginChild_Str(
|
||||
self.ui.scratch_txt(self.name),
|
||||
sys::igBeginChild_ID(
|
||||
self.id,
|
||||
self.size.into(),
|
||||
self.border,
|
||||
self.flags.bits() as i32,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user