From 2312f4121a93c232a7f44668b7f0d56a11d87525 Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Fri, 30 Mar 2018 09:06:50 +0900 Subject: [PATCH] test_drawing_channels_split: Add an example for channels_split As channels_split may be difficult to understand, this commit adds a simple example of its usage. --- .../examples/test_drawing_channels_split.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 imgui-examples/examples/test_drawing_channels_split.rs diff --git a/imgui-examples/examples/test_drawing_channels_split.rs b/imgui-examples/examples/test_drawing_channels_split.rs new file mode 100644 index 0000000..38954cd --- /dev/null +++ b/imgui-examples/examples/test_drawing_channels_split.rs @@ -0,0 +1,44 @@ +extern crate glium; +extern crate imgui; +extern crate imgui_glium_renderer; + +mod support; + +const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.0]; +const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0]; +const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0]; + +fn main() { + support::run("test_drawing_channels_split".to_owned(), CLEAR_COLOR, |ui| { + ui.with_window_draw_list(|draw_list| { + // Will draw channel 0 first, then channel 1, whatever the order of + // the calls in the code. + // + // Here, we draw a red line on channel 1 then a white circle on + // channel 0. As a result, the red line will always appear on top of + // the white circle. + draw_list.channels_split(2, |draw_list| { + const RADIUS: f32 = 100.0; + let canvas_pos = ui.get_cursor_screen_pos(); + draw_list.channels_set_current(1); + draw_list + .add_line( + canvas_pos, + [canvas_pos.0 + RADIUS, canvas_pos.1 + RADIUS], + RED, + ) + .thickness(5.0) + .build(); + + draw_list.channels_set_current(0); + let center = (canvas_pos.0 + RADIUS, canvas_pos.1 + RADIUS); + draw_list + .add_circle(center, RADIUS, WHITE) + .thickness(10.0) + .num_segments(50) + .build(); + }); + }); + true + }); +}