mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
moved window building to boxed closure
This commit is contained in:
@ -79,7 +79,7 @@ fn handle_main_events_cleared(
|
||||
let mut exit = true;
|
||||
while let Some(state_result) = states.last_mut().map(|last| {
|
||||
let events = global_state.window.fetch_events();
|
||||
global_state.window.begin_imgui_frame();
|
||||
global_state.window.imgui_begin_frame();
|
||||
last.tick(global_state, events)
|
||||
}) {
|
||||
// Implement state transfer logic.
|
||||
@ -143,7 +143,7 @@ fn handle_main_events_cleared(
|
||||
global_state.window.renderer_mut().clear();
|
||||
|
||||
last.render(global_state.window.renderer_mut(), &global_state.settings);
|
||||
global_state.window.render_imgui();
|
||||
global_state.window.imgui_render();
|
||||
|
||||
global_state.window.renderer_mut().flush();
|
||||
global_state
|
||||
|
@ -29,6 +29,7 @@ use specs::{Join, WorldExt};
|
||||
use std::{cell::RefCell, rc::Rc, time::Duration};
|
||||
use tracing::{error, info};
|
||||
use vek::*;
|
||||
use imgui::{Condition, im_str, Window};
|
||||
|
||||
/// The action to perform after a tick
|
||||
enum TickAction {
|
||||
@ -185,20 +186,21 @@ impl PlayState for SessionState {
|
||||
&global_state.settings.language.selected_language,
|
||||
));
|
||||
|
||||
let ui = global_state.window.imgui.frame();
|
||||
Window::new(window_title)
|
||||
.size([300.0, 100.0], Condition::FirstUseEver)
|
||||
.build(ui, || {
|
||||
ui.text(im_str!("Hello world!"));
|
||||
ui.text(im_str!("こんにちは世界!"));
|
||||
ui.text(im_str!("This...is...imgui-rs!"));
|
||||
ui.separator();
|
||||
let mouse_pos = ui.io().mouse_pos;
|
||||
ui.text(format!(
|
||||
"Mouse Position: ({:.1},{:.1})",
|
||||
mouse_pos[0], mouse_pos[1]
|
||||
));
|
||||
});
|
||||
global_state.window.imgui_run_ui = Box::new(|ui| {
|
||||
Window::new(im_str!("Veloren ImgUi Test"))
|
||||
.size([300.0, 100.0], Condition::FirstUseEver)
|
||||
.build( ui, || {
|
||||
ui.text(im_str!("Hello world!"));
|
||||
ui.text(im_str!("こんにちは世界!"));
|
||||
ui.text(im_str!("This...is...imgui-rs!"));
|
||||
ui.separator();
|
||||
let mouse_pos = ui.io().mouse_pos;
|
||||
ui.text(format!(
|
||||
"Mouse Position: ({:.1},{:.1})",
|
||||
mouse_pos[0], mouse_pos[1]
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: can this be a method on the session or are there borrowcheck issues?
|
||||
|
||||
|
@ -13,7 +13,7 @@ use std::fmt;
|
||||
use tracing::{error, info, warn};
|
||||
use vek::*;
|
||||
use imgui_winit_support::{WinitPlatform, HiDpiMode};
|
||||
use imgui::{Condition, ConfigFlags, Context, FontSource, FontConfig, FontGlyphRanges, im_str};
|
||||
use imgui::{ConfigFlags, Context, FontSource, FontConfig, FontGlyphRanges};
|
||||
|
||||
/// Represents a key that the game recognises after input mapping.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
|
||||
@ -493,8 +493,9 @@ pub struct Window {
|
||||
// Used for screenshots & fullscreen toggle to deduplicate/postpone to after event handler
|
||||
take_screenshot: bool,
|
||||
toggle_fullscreen: bool,
|
||||
pub imgui: Context,
|
||||
imgui_platform: WinitPlatform
|
||||
imgui: Context,
|
||||
imgui_platform: WinitPlatform,
|
||||
pub imgui_run_ui: Box<dyn FnMut(&mut imgui::Ui)>
|
||||
}
|
||||
|
||||
impl Window {
|
||||
@ -628,7 +629,8 @@ impl Window {
|
||||
take_screenshot: false,
|
||||
toggle_fullscreen: false,
|
||||
imgui,
|
||||
imgui_platform
|
||||
imgui_platform,
|
||||
imgui_run_ui: Box::new(|_|{})
|
||||
};
|
||||
|
||||
this.fullscreen(settings.graphics.fullscreen);
|
||||
@ -646,18 +648,19 @@ impl Window {
|
||||
|
||||
pub fn renderer_mut(&mut self) -> &mut Renderer { &mut self.renderer }
|
||||
|
||||
pub fn begin_imgui_frame(&mut self) {
|
||||
pub fn imgui_begin_frame(&mut self) {
|
||||
self.imgui_platform
|
||||
.prepare_frame(self.imgui.io_mut(), self.window.window())
|
||||
.expect("Failed to start frame");
|
||||
self.imgui.io_mut().config_flags |= ConfigFlags::NO_MOUSE_CURSOR_CHANGE;
|
||||
}
|
||||
|
||||
pub fn render_imgui(&mut self) {
|
||||
let ui = self.imgui.frame();
|
||||
pub fn imgui_render(&mut self) {
|
||||
let mut ui = self.imgui.frame();
|
||||
self.imgui_platform.prepare_render(&ui, &self.window.window());
|
||||
(self.imgui_run_ui)(&mut ui);
|
||||
let draw_data = ui.render();
|
||||
self.renderer.render_imgui(&draw_data);
|
||||
self.renderer.render_imgui(draw_data);
|
||||
}
|
||||
|
||||
pub fn resolve_deduplicated_events(&mut self, settings: &mut Settings) {
|
||||
|
Reference in New Issue
Block a user