From f3a243adcf20c0de1b26cfc10aa57fd6f8cbc8e5 Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Fri, 17 Feb 2017 22:15:46 +0200 Subject: [PATCH] Move glium support to a separate file --- imgui-sys/src/glium_support.rs | 34 +++++++++++++++++++++++++++++++++ imgui-sys/src/lib.rs | 35 +++------------------------------- 2 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 imgui-sys/src/glium_support.rs diff --git a/imgui-sys/src/glium_support.rs b/imgui-sys/src/glium_support.rs new file mode 100644 index 0000000..492266c --- /dev/null +++ b/imgui-sys/src/glium_support.rs @@ -0,0 +1,34 @@ +use glium::vertex::{Attribute, AttributeType, Vertex, VertexFormat}; +use std::borrow::Cow; +use std::mem; +use std::os::raw::{c_float}; + +use super::{ImDrawVert, ImVec2, ImVec4}; + +#[cfg(feature = "glium")] +unsafe impl Attribute for ImVec2 { + fn get_type() -> AttributeType { <(c_float, c_float) as Attribute>::get_type() } +} + +#[cfg(feature = "glium")] +unsafe impl Attribute for ImVec4 { + fn get_type() -> AttributeType { + <(c_float, c_float, c_float, c_float) as Attribute>::get_type() + } +} + +#[cfg(feature = "glium")] +impl Vertex for ImDrawVert { + fn build_bindings() -> VertexFormat { + unsafe { + let dummy: &ImDrawVert = mem::transmute(0usize); + Cow::Owned(vec![("pos".into(), + mem::transmute(&dummy.pos), + ::get_type()), + ("uv".into(), + mem::transmute(&dummy.uv), + ::get_type()), + ("col".into(), mem::transmute(&dummy.col), AttributeType::U8U8U8U8)]) + } + } +} diff --git a/imgui-sys/src/lib.rs b/imgui-sys/src/lib.rs index d01fc91..da7db45 100644 --- a/imgui-sys/src/lib.rs +++ b/imgui-sys/src/lib.rs @@ -7,15 +7,14 @@ extern crate bitflags; #[macro_use] extern crate glium; -#[cfg(feature = "glium")] -use glium::vertex::{Attribute, AttributeType, Vertex, VertexFormat}; -#[cfg(feature = "glium")] -use std::borrow::Cow; use std::convert::From; use std::mem; use std::os::raw::{c_char, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void}; use std::slice; +#[cfg(feature = "glium")] +mod glium_support; + /// ImGui context (opaque) pub enum ImGuiContext { } @@ -304,11 +303,6 @@ impl Into<(f32, f32)> for ImVec2 { fn into(self) -> (f32, f32) { (self.x, self.y) } } -#[cfg(feature = "glium")] -unsafe impl Attribute for ImVec2 { - fn get_type() -> AttributeType { <(c_float, c_float) as Attribute>::get_type() } -} - /// A tuple of 4 floating-point values #[repr(C)] #[derive(Copy, Clone, Debug, Default, PartialEq)] @@ -354,13 +348,6 @@ impl Into<(f32, f32, f32, f32)> for ImVec4 { fn into(self) -> (f32, f32, f32, f32) { (self.x, self.y, self.z, self.w) } } -#[cfg(feature = "glium")] -unsafe impl Attribute for ImVec4 { - fn get_type() -> AttributeType { - <(c_float, c_float, c_float, c_float) as Attribute>::get_type() - } -} - /// Runtime data for styling/colors #[repr(C)] pub struct ImGuiStyle { @@ -601,22 +588,6 @@ pub struct ImDrawVert { pub col: ImU32, } -#[cfg(feature = "glium")] -impl Vertex for ImDrawVert { - fn build_bindings() -> VertexFormat { - unsafe { - let dummy: &ImDrawVert = mem::transmute(0usize); - Cow::Owned(vec![("pos".into(), - mem::transmute(&dummy.pos), - ::get_type()), - ("uv".into(), - mem::transmute(&dummy.uv), - ::get_type()), - ("col".into(), mem::transmute(&dummy.col), AttributeType::U8U8U8U8)]) - } - } -} - /// Temporary storage for outputting drawing commands out of order #[repr(C)] pub struct ImDrawChannel {