Merge pull request #204 from sumeet/master

add builder method to specify window pivot
This commit is contained in:
Joonas Javanainen 2019-03-02 00:31:05 +02:00 committed by GitHub
commit da57859839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,12 +2,13 @@ use std::marker::PhantomData;
use std::ptr;
use sys;
use super::{ImGuiCond, ImGuiWindowFlags, ImStr, ImVec2, Ui};
use super::{ImGuiCond, ImGuiWindowFlags, ImStr, Ui};
#[must_use]
pub struct Window<'ui, 'p> {
pos: (f32, f32),
pos_cond: ImGuiCond,
pos_pivot: (f32, f32),
size: (f32, f32),
size_cond: ImGuiCond,
name: &'p ImStr,
@ -21,6 +22,7 @@ impl<'ui, 'p> Window<'ui, 'p> {
Window {
pos: (0.0, 0.0),
pos_cond: ImGuiCond::empty(),
pos_pivot: (0.0, 0.0),
size: (0.0, 0.0),
size_cond: ImGuiCond::empty(),
name,
@ -36,6 +38,11 @@ impl<'ui, 'p> Window<'ui, 'p> {
self
}
#[inline]
pub fn position_pivot(mut self, pivot: (f32, f32)) -> Self {
self.pos_pivot = pivot;
self
}
#[inline]
pub fn size(mut self, size: (f32, f32), cond: ImGuiCond) -> Self {
self.size = size;
self.size_cond = cond;
@ -138,7 +145,7 @@ impl<'ui, 'p> Window<'ui, 'p> {
pub fn build<F: FnOnce()>(self, f: F) {
let render = unsafe {
if !self.pos_cond.is_empty() {
sys::igSetNextWindowPos(self.pos.into(), self.pos_cond, ImVec2::zero());
sys::igSetNextWindowPos(self.pos.into(), self.pos_cond, self.pos_pivot.into());
}
if !self.size_cond.is_empty() {
sys::igSetNextWindowSize(self.size.into(), self.size_cond);