From 1ef649900feeac08d52648a92f51af563a141b10 Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Sun, 18 Oct 2015 13:33:00 +0300 Subject: [PATCH] ImVec2/ImVec4 conversions --- imgui-sys/src/lib.rs | 25 +++++++++++++++++++++++++ src/window.rs | 14 ++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/imgui-sys/src/lib.rs b/imgui-sys/src/lib.rs index d192385..fd60577 100644 --- a/imgui-sys/src/lib.rs +++ b/imgui-sys/src/lib.rs @@ -13,6 +13,7 @@ use glium::vertex::{Attribute, AttributeType, Vertex, VertexFormat}; use libc::*; #[cfg(feature = "glium")] use std::borrow::Cow; +use std::convert::From; use std::mem; use std::slice; @@ -247,6 +248,18 @@ impl ImVec2 { } } +impl From<[f32; 2]> for ImVec2 { + fn from(array: [f32; 2]) -> ImVec2 { + ImVec2::new(array[0], array[1]) + } +} + +impl From<(f32, f32)> for ImVec2 { + fn from(tuple: (f32, f32)) -> ImVec2 { + ImVec2::new(tuple.0, tuple.1) + } +} + #[cfg(feature = "glium")] unsafe impl Attribute for ImVec2 { fn get_type() -> AttributeType { <(c_float, c_float) as Attribute>::get_type() } @@ -272,6 +285,18 @@ impl ImVec4 { } } +impl From<[f32; 4]> for ImVec4 { + fn from(array: [f32; 4]) -> ImVec4 { + ImVec4::new(array[0], array[1], array[2], array[3]) + } +} + +impl From<(f32, f32, f32, f32)> for ImVec4 { + fn from(tuple: (f32, f32, f32, f32)) -> ImVec4 { + ImVec4::new(tuple.0, tuple.1, tuple.2, tuple.3) + } +} + #[cfg(feature = "glium")] unsafe impl Attribute for ImVec4 { fn get_type() -> AttributeType { diff --git a/src/window.rs b/src/window.rs index 0811a82..55a838b 100644 --- a/src/window.rs +++ b/src/window.rs @@ -164,15 +164,17 @@ impl<'ui, 'p> Window<'ui, 'p> { pub fn build(self, f: F) { let render = unsafe { if !self.pos_cond.is_empty() { - imgui_sys::igSetNextWindowPos(ImVec2::new(self.pos.0, self.pos.1), self.pos_cond); + imgui_sys::igSetNextWindowPos(self.pos.into(), self.pos_cond); } if !self.size_cond.is_empty() { - imgui_sys::igSetNextWindowSize(ImVec2::new(self.size.0, self.size.1), self.size_cond); + imgui_sys::igSetNextWindowSize(self.size.into(), self.size_cond); } - imgui_sys::igBegin2(self.name.as_ptr(), - self.opened.map(|x| x as *mut bool).unwrap_or(ptr::null_mut()), - ImVec2::new(0.0, 0.0), self.bg_alpha, self.flags - ) + imgui_sys::igBegin2( + self.name.as_ptr(), + self.opened.map(|x| x as *mut bool).unwrap_or(ptr::null_mut()), + ImVec2::new(0.0, 0.0), + self.bg_alpha, + self.flags) }; if render { f();