Use more 2018 edition idioms

This commit is contained in:
Joonas Javanainen 2018-12-31 12:16:28 +02:00
parent 0d878e1ecb
commit 91a961e06a
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
20 changed files with 35 additions and 116 deletions

View File

@ -1,11 +1,3 @@
extern crate gfx;
extern crate gfx_window_glutin;
extern crate glutin;
#[macro_use]
extern crate imgui;
extern crate imgui_gfx_renderer;
extern crate imgui_winit_support;
use imgui::*;
mod support_gfx;

View File

@ -18,7 +18,7 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
.with_dimensions(glutin::dpi::LogicalSize::new(1024f64, 768f64));
let (window, mut device, mut factory, mut main_color, mut main_depth) =
gfx_window_glutin::init::<ColorFormat, DepthFormat>(window, context, &events_loop)
.expect("Failed to initalize graphics");
.expect("Failed to initalize graphics");
let mut encoder: gfx::Encoder<_, _> = factory.create_command_buffer().into();
let shaders = {
let version = device.get_info().shading_language;

View File

@ -1,7 +1,3 @@
#[macro_use]
extern crate gfx;
extern crate imgui;
use gfx::handle::{Buffer, RenderTargetView};
use gfx::memory::Bind;
use gfx::pso::{PipelineData, PipelineState};
@ -52,9 +48,9 @@ macro_rules! extended_defines {
#[allow(missing_docs)]
mod $module {
#[allow(unused_imports)]
use super::*;
use crate::*;
#[allow(unused_imports)]
use super::gfx;
use gfx::gfx_pipeline_inner;
gfx_pipeline_inner!{ $(
$field: $ty,
)*}

View File

@ -1,9 +1,3 @@
extern crate glium;
#[macro_use]
extern crate imgui;
extern crate imgui_glium_renderer;
extern crate imgui_winit_support;
use imgui::*;
mod support;

View File

@ -1,9 +1,3 @@
extern crate glium;
extern crate image;
extern crate imgui;
extern crate imgui_glium_renderer;
extern crate imgui_winit_support;
use std::borrow::Cow;
use std::error::Error;
use std::io::Cursor;

View File

@ -1,9 +1,3 @@
extern crate glium;
#[macro_use]
extern crate imgui;
extern crate imgui_glium_renderer;
extern crate imgui_winit_support;
use imgui::*;
mod support;

View File

@ -1,8 +1,3 @@
extern crate glium;
extern crate imgui;
extern crate imgui_glium_renderer;
extern crate imgui_winit_support;
mod support;
const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.0];

View File

@ -1,8 +1,3 @@
extern crate glium;
extern crate imgui;
extern crate imgui_glium_renderer;
extern crate imgui_winit_support;
mod support;
const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.0];

View File

@ -1,9 +1,3 @@
extern crate glium;
#[macro_use]
extern crate imgui;
extern crate imgui_glium_renderer;
extern crate imgui_winit_support;
use imgui::*;
mod support;

View File

@ -1,13 +1,9 @@
#[macro_use]
extern crate glium;
extern crate imgui;
use glium::backend::{Context, Facade};
use glium::index::{self, PrimitiveType};
use glium::program;
use glium::texture;
use glium::vertex;
use glium::{DrawError, IndexBuffer, Program, Surface, Texture2d, VertexBuffer};
use glium::{uniform, DrawError, IndexBuffer, Program, Surface, Texture2d, VertexBuffer};
use imgui::{DrawList, FrameSize, ImGui, ImTexture, Textures, Ui};
use std::borrow::Cow;
use std::fmt;

View File

@ -1,5 +1,3 @@
extern crate cc;
fn main() {
cc::Build::new()
.cpp(true)

View File

@ -1,3 +1,4 @@
use bitflags::bitflags;
use std::os::raw::c_int;
bitflags!(

View File

@ -1,9 +1,10 @@
use gfx::format::{Format, Formatted, U8Norm};
use gfx::gfx_format;
use gfx::pso::buffer::{ElemOffset, Element, Structure};
use gfx::traits::Pod;
use std::mem;
use super::{ImDrawVert, ImVec2};
use crate::{ImDrawVert, ImVec2};
unsafe impl Pod for ImDrawVert {}

View File

@ -3,23 +3,20 @@ use std::borrow::Cow;
use std::mem;
use std::os::raw::c_float;
use super::{ImDrawVert, ImVec2, ImVec4};
use crate::{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 {

View File

@ -1,17 +1,5 @@
#![allow(non_upper_case_globals)]
#[macro_use]
extern crate bitflags;
extern crate libc;
#[cfg(feature = "gfx")]
#[macro_use]
extern crate gfx;
#[cfg(feature = "glium")]
extern crate glium;
use libc::size_t;
use std::convert::From;
use std::os::raw::{c_char, c_double, c_float, c_int, c_uint, c_ushort, c_void};

View File

@ -1,12 +1,12 @@
use std::os::raw::{c_char, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void};
use std::slice;
use super::enums::{ImGuiCol, ImGuiKey, ImGuiMouseCursor, ImGuiNavInput};
use super::flags::{
use crate::enums::{ImGuiCol, ImGuiKey, ImGuiMouseCursor, ImGuiNavInput};
use crate::flags::{
ImDrawCornerFlags, ImDrawListFlags, ImFontAtlasFlags, ImGuiBackendFlags, ImGuiConfigFlags,
ImGuiInputTextFlags,
};
use super::{ImDrawCallback, ImDrawIdx, ImGuiID, ImTextureID, ImU32, ImVec2, ImVec4, ImWchar};
use crate::{ImDrawCallback, ImDrawIdx, ImGuiID, ImTextureID, ImU32, ImVec2, ImVec4, ImWchar};
/// Font atlas glyph range builder
#[repr(C)]

View File

@ -5,8 +5,6 @@
//! In your initialization code call `configure_keys`:
//!
//! ```rust,no_run
//! # extern crate imgui;
//! # extern crate imgui_winit_support;
//! use imgui::ImGui;
//!
//! # fn main() {
@ -19,9 +17,6 @@
//! you need to do is pass each event to `imgui_winit_support` as well:
//!
//! ```rust,no_run
//! # extern crate imgui;
//! # extern crate imgui_winit_support;
//! # extern crate winit;
//! # use imgui::ImGui;
//! # use winit::EventsLoop;
//! # fn main() {
@ -50,9 +45,6 @@
//! For example, you might want to customize mouse wheel line scrolling amount:
//!
//! ```rust,no_run
//! # extern crate imgui;
//! # extern crate imgui_winit_support;
//! # extern crate winit;
//! # use imgui::ImGui;
//! # use winit::{EventsLoop, Event, WindowEvent, MouseScrollDelta, TouchPhase};
//! # fn main() {
@ -89,9 +81,6 @@
//! # }
//! ```
extern crate imgui;
extern crate winit;
use imgui::{FrameSize, ImGui, ImGuiKey, ImGuiMouseCursor};
use winit::{
ElementState, Event, KeyboardInput, ModifiersState, MouseButton, MouseCursor, MouseScrollDelta,
@ -184,11 +173,8 @@ pub fn handle_event(
window_hidpi_factor: f64,
app_hidpi_factor: f64,
) {
match event {
&Event::WindowEvent { ref event, .. } => {
handle_window_event(imgui, event, window_hidpi_factor, app_hidpi_factor)
}
_ => (),
if let Event::WindowEvent { ref event, .. } = event {
handle_window_event(imgui, event, window_hidpi_factor, app_hidpi_factor)
}
}
@ -201,9 +187,9 @@ pub fn handle_window_event(
) {
use self::WindowEvent::*;
match event {
&KeyboardInput { input, .. } => handle_keyboard_input(imgui, input),
&ReceivedCharacter(ch) => imgui.add_input_character(ch),
&CursorMoved {
KeyboardInput { input, .. } => handle_keyboard_input(imgui, *input),
ReceivedCharacter(ch) => imgui.add_input_character(*ch),
CursorMoved {
position,
modifiers,
..
@ -212,25 +198,25 @@ pub fn handle_window_event(
.to_physical(window_hidpi_factor)
.to_logical(app_hidpi_factor);
imgui.set_mouse_pos(position.x as f32, position.y as f32);
handle_modifiers(imgui, modifiers);
handle_modifiers(imgui, *modifiers);
}
&MouseWheel {
MouseWheel {
delta,
modifiers,
phase: TouchPhase::Moved,
..
} => {
handle_mouse_scroll_delta(imgui, delta, window_hidpi_factor, app_hidpi_factor);
handle_modifiers(imgui, modifiers);
handle_mouse_scroll_delta(imgui, *delta, window_hidpi_factor, app_hidpi_factor);
handle_modifiers(imgui, *modifiers);
}
&MouseInput {
MouseInput {
state,
button,
modifiers,
..
} => {
handle_mouse_button_state(imgui, button, state);
handle_modifiers(imgui, modifiers);
handle_mouse_button_state(imgui, *button, *state);
handle_modifiers(imgui, *modifiers);
}
_ => (),
}

View File

@ -127,18 +127,18 @@ impl FontGlyphRange {
}
unsafe fn to_ptr(&self, atlas: *mut sys::ImFontAtlas) -> *const sys::ImWchar {
match &self.0 {
&FontGlyphRangeData::ChineseFull => sys::ImFontAtlas_GetGlyphRangesChineseFull(atlas),
&FontGlyphRangeData::ChineseSimplifiedCommon => {
match self.0 {
FontGlyphRangeData::ChineseFull => sys::ImFontAtlas_GetGlyphRangesChineseFull(atlas),
FontGlyphRangeData::ChineseSimplifiedCommon => {
sys::ImFontAtlas_GetGlyphRangesChineseSimplifiedCommon(atlas)
}
&FontGlyphRangeData::Cyrillic => sys::ImFontAtlas_GetGlyphRangesCyrillic(atlas),
&FontGlyphRangeData::Default => sys::ImFontAtlas_GetGlyphRangesDefault(atlas),
&FontGlyphRangeData::Japanese => sys::ImFontAtlas_GetGlyphRangesJapanese(atlas),
&FontGlyphRangeData::Korean => sys::ImFontAtlas_GetGlyphRangesKorean(atlas),
&FontGlyphRangeData::Thai => sys::ImFontAtlas_GetGlyphRangesThai(atlas),
FontGlyphRangeData::Cyrillic => sys::ImFontAtlas_GetGlyphRangesCyrillic(atlas),
FontGlyphRangeData::Default => sys::ImFontAtlas_GetGlyphRangesDefault(atlas),
FontGlyphRangeData::Japanese => sys::ImFontAtlas_GetGlyphRangesJapanese(atlas),
FontGlyphRangeData::Korean => sys::ImFontAtlas_GetGlyphRangesKorean(atlas),
FontGlyphRangeData::Thai => sys::ImFontAtlas_GetGlyphRangesThai(atlas),
&FontGlyphRangeData::Custom(ptr) => ptr,
FontGlyphRangeData::Custom(ptr) => ptr,
}
}
}

View File

@ -110,6 +110,7 @@ impl<'ui> Image<'ui> {
}
/// Generic texture mapping for use by renderers.
#[derive(Debug, Default)]
pub struct Textures<T> {
textures: HashMap<usize, T>,
next: usize,

View File

@ -784,7 +784,7 @@ impl<'ui> Ui<'ui> {
}
ImId::Str(s) => {
let start = s.as_ptr() as *const c_char;
let end = start.offset(s.len() as isize);
let end = start.add(s.len());
sys::igPushIDRange(start, end);
}
ImId::Ptr(p) => {
@ -820,7 +820,7 @@ impl<'ui> Ui<'ui> {
let s = text.as_ref();
unsafe {
let start = s.as_ptr();
let end = start.offset(s.len() as isize);
let end = start.add(s.len());
sys::igTextUnformatted(start as *const c_char, end as *const c_char);
}
}
@ -1137,7 +1137,6 @@ impl<'ui> Ui<'ui> {
/// # Examples
///
/// ```
/// # #[macro_use] extern crate imgui;
/// # use imgui::*;
/// fn user_interface(ui: &Ui) {
/// ui.text("Hover over me");
@ -1162,7 +1161,6 @@ impl<'ui> Ui<'ui> {
/// # Examples
///
/// ```
/// # #[macro_use] extern crate imgui;
/// # use imgui::*;
/// fn user_interface(ui: &Ui) {
/// ui.text("Hover over me");
@ -1597,7 +1595,6 @@ impl<'ui> Ui<'ui> {
/// # Examples
///
/// ```
/// # #[macro_use] extern crate imgui;
/// # use imgui::*;
/// fn user_interface(ui: &Ui) {
/// ui.text("Hover over me");