[glium-example] Pass GlContext and Textures to Ui loop

This commit is contained in:
Malik Olivier Boussejra 2018-11-23 17:02:05 +09:00
parent ecffa09e84
commit ea8121b539
6 changed files with 19 additions and 7 deletions

View File

@ -32,7 +32,7 @@ impl Default for State {
fn main() {
let mut state = State::default();
support::run("color_button.rs".to_owned(), CLEAR_COLOR, |ui| {
support::run("color_button.rs".to_owned(), CLEAR_COLOR, |ui, _, _| {
example_selector(&mut state, ui);
match state.example {
1 => example_1(&mut state, ui),

View File

@ -11,7 +11,9 @@ mod support;
const CLEAR_COLOR: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
fn main() {
support::run("hello_world.rs".to_owned(), CLEAR_COLOR, hello_world);
support::run("hello_world.rs".to_owned(), CLEAR_COLOR, |ui, _, _| {
hello_world(ui)
});
}
fn hello_world<'a>(ui: &Ui<'a>) -> bool {

View File

@ -1,8 +1,18 @@
use glium::{
backend::{Context, Facade},
Texture2d,
};
use imgui::{FontGlyphRange, ImFontConfig, ImGui, Ui};
use imgui_glutin_support;
use std::rc::Rc;
use std::time::Instant;
pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_ui: F) {
pub type Textures = imgui::Textures<Texture2d>;
pub fn run<F>(title: String, clear_color: [f32; 4], mut run_ui: F)
where
F: FnMut(&Ui, &Rc<Context>, &mut Textures) -> bool,
{
use glium::glutin;
use glium::{Display, Surface};
use imgui_glium_renderer::Renderer;
@ -80,7 +90,7 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
let frame_size = imgui_glutin_support::get_frame_size(&window, hidpi_factor).unwrap();
let ui = imgui.frame(frame_size, delta_s);
if !run_ui(&ui) {
if !run_ui(&ui, display.get_context(), renderer.textures()) {
break;
}

View File

@ -13,7 +13,7 @@ fn main() {
support::run(
"test_drawing_channels_split".to_owned(),
CLEAR_COLOR,
|ui| {
|ui, _, _| {
let draw_list = ui.get_window_draw_list();
// Will draw channel 0 first, then channel 1, whatever the order of
// the calls in the code.

View File

@ -8,7 +8,7 @@ mod support;
const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.0];
fn main() {
support::run("test_window.rs".to_owned(), CLEAR_COLOR, |ui| {
support::run("test_window.rs".to_owned(), CLEAR_COLOR, |ui, _, _| {
let mut open = true;
ui.show_demo_window(&mut open);
open

View File

@ -193,7 +193,7 @@ const CLEAR_COLOR: [f32; 4] = [114.0 / 255.0, 144.0 / 255.0, 154.0 / 255.0, 1.0]
fn main() {
let mut state = State::default();
support::run("test_window.rs".to_owned(), CLEAR_COLOR, |ui| {
support::run("test_window.rs".to_owned(), CLEAR_COLOR, |ui, _, _| {
let mut open = true;
show_test_window(ui, &mut state, &mut open);
open