Created
January 1, 2018 00:47
-
-
Save bitshifter/e84418b910622587cd21dfbbea728fa6 to your computer and use it in GitHub Desktop.
Test case for issue 96, replicating cgmath AsMut ambiguity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/imgui-examples/examples/test_window_impl.rs b/imgui-examples/examples/test_window_impl.rs | |
index c9cc5c8..e5ec03a 100644 | |
--- a/imgui-examples/examples/test_window_impl.rs | |
+++ b/imgui-examples/examples/test_window_impl.rs | |
@@ -4,9 +4,34 @@ extern crate imgui; | |
extern crate imgui_glium_renderer; | |
use imgui::*; | |
+use std::mem; | |
mod support; | |
+struct Vector3 { | |
+ x: f32, y: f32, z: f32, | |
+} | |
+ | |
+impl From<[f32; 3]> for Vector3 { | |
+ fn from(v: [f32; 3]) -> Self { | |
+ Self { | |
+ x: v[0], y: v[1], z: v[2] | |
+ } | |
+ } | |
+} | |
+ | |
+impl AsMut<[f32; 3]> for Vector3 { | |
+ fn as_mut(&mut self) -> &mut [f32; 3] { | |
+ unsafe { mem::transmute(self) } | |
+ } | |
+} | |
+ | |
+impl AsMut<(f32, f32, f32)> for Vector3 { | |
+ fn as_mut(&mut self) -> &mut (f32, f32, f32) { | |
+ unsafe { mem::transmute(self) } | |
+ } | |
+} | |
+ | |
struct State { | |
show_app_main_menu_bar: bool, | |
show_app_console: bool, | |
@@ -40,7 +65,7 @@ struct State { | |
vec3f: [f32; 3], | |
vec2i: [i32; 2], | |
vec3i: [i32; 3], | |
- col1: [f32; 3], | |
+ col1: Vector3, | |
col2: [f32; 4], | |
selected_fish: Option<usize>, | |
auto_resize_state: AutoResizeState, | |
@@ -88,7 +113,7 @@ impl Default for State { | |
vec3f: [0.10, 0.20, 0.30], | |
vec2i: [10, 20], | |
vec3i: [10, 20, 30], | |
- col1: [1.0, 0.0, 0.2], | |
+ col1: Vector3::from([1.0, 0.0, 0.2]), | |
col2: [0.4, 0.7, 0.0, 0.5], | |
selected_fish: None, | |
auto_resize_state: Default::default(), | |
@@ -430,7 +455,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { | |
.build(); | |
ui.input_float3(im_str!("input float3"), &mut state.vec3f) | |
.build(); | |
- ui.color_edit(im_str!("color 1"), &mut state.col1).build(); | |
+ ui.color_edit(im_str!("color 1"), state.col1.as_mut()).build(); | |
ui.color_edit(im_str!("color 2"), &mut state.col2).build(); | |
ui.tree_node(im_str!("Multi-component Widgets")).build(|| { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment