mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 21:48:36 +00:00
ImVec2/ImVec4 conversions
This commit is contained in:
parent
4d378606f1
commit
1ef649900f
@ -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 {
|
||||
|
||||
@ -164,15 +164,17 @@ impl<'ui, 'p> Window<'ui, 'p> {
|
||||
pub fn build<F: FnOnce()>(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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user