mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-14 23:18:28 +00:00
Adapt to 1.65 changes
This commit is contained in:
parent
5372ba869f
commit
b4edc01574
@ -145,7 +145,7 @@ fn example_2(ui: &Ui) {
|
||||
im_str!("Red + ColorPreview::HalfAlpha"),
|
||||
(1.0, 0.0, 0.0, 0.5),
|
||||
).preview(ColorPreview::HalfAlpha)
|
||||
.build();
|
||||
.build();
|
||||
|
||||
ui.separator();
|
||||
ui.text_wrapped(im_str!(
|
||||
|
||||
@ -30,9 +30,17 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
|
||||
let font_size = (13.0 * hidpi_factor) as f32;
|
||||
|
||||
imgui.fonts().add_default_font_with_config(
|
||||
ImFontConfig::new()
|
||||
.oversample_h(1)
|
||||
.pixel_snap_h(true)
|
||||
.size_pixels(font_size),
|
||||
);
|
||||
|
||||
imgui.fonts().add_font_with_config(
|
||||
include_bytes!("../mplus-1p-regular.ttf"),
|
||||
ImFontConfig::new()
|
||||
.merge_mode(true)
|
||||
.oversample_h(1)
|
||||
.pixel_snap_h(true)
|
||||
.size_pixels(font_size)
|
||||
@ -40,14 +48,6 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
&FontGlyphRange::japanese(),
|
||||
);
|
||||
|
||||
imgui.fonts().add_default_font_with_config(
|
||||
ImFontConfig::new()
|
||||
.merge_mode(true)
|
||||
.oversample_h(1)
|
||||
.pixel_snap_h(true)
|
||||
.size_pixels(font_size),
|
||||
);
|
||||
|
||||
imgui.set_font_global_scale((1.0 / hidpi_factor) as f32);
|
||||
|
||||
let mut renderer = Renderer::init(&mut imgui, &display).expect("Failed to initialize renderer");
|
||||
@ -155,11 +155,12 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
ImGuiMouseCursor::None => unreachable!("mouse_cursor was None!"),
|
||||
ImGuiMouseCursor::Arrow => glutin::MouseCursor::Arrow,
|
||||
ImGuiMouseCursor::TextInput => glutin::MouseCursor::Text,
|
||||
ImGuiMouseCursor::Move => glutin::MouseCursor::Move,
|
||||
ImGuiMouseCursor::ResizeAll => glutin::MouseCursor::Move,
|
||||
ImGuiMouseCursor::ResizeNS => glutin::MouseCursor::NsResize,
|
||||
ImGuiMouseCursor::ResizeEW => glutin::MouseCursor::EwResize,
|
||||
ImGuiMouseCursor::ResizeNESW => glutin::MouseCursor::NeswResize,
|
||||
ImGuiMouseCursor::ResizeNWSE => glutin::MouseCursor::NwseResize,
|
||||
ImGuiMouseCursor::Hand => glutin::MouseCursor::Hand,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -199,11 +199,12 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
ImGuiMouseCursor::None => unreachable!("mouse_cursor was None!"),
|
||||
ImGuiMouseCursor::Arrow => glutin::MouseCursor::Arrow,
|
||||
ImGuiMouseCursor::TextInput => glutin::MouseCursor::Text,
|
||||
ImGuiMouseCursor::Move => glutin::MouseCursor::Move,
|
||||
ImGuiMouseCursor::ResizeAll => glutin::MouseCursor::Move,
|
||||
ImGuiMouseCursor::ResizeNS => glutin::MouseCursor::NsResize,
|
||||
ImGuiMouseCursor::ResizeEW => glutin::MouseCursor::EwResize,
|
||||
ImGuiMouseCursor::ResizeNESW => glutin::MouseCursor::NeswResize,
|
||||
ImGuiMouseCursor::ResizeNWSE => glutin::MouseCursor::NwseResize,
|
||||
ImGuiMouseCursor::Hand => glutin::MouseCursor::Hand,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -29,8 +29,7 @@ fn main() {
|
||||
canvas_pos,
|
||||
[canvas_pos.0 + RADIUS, canvas_pos.1 + RADIUS],
|
||||
RED,
|
||||
)
|
||||
.thickness(5.0)
|
||||
).thickness(5.0)
|
||||
.build();
|
||||
|
||||
channels.set_current(0);
|
||||
|
||||
@ -778,7 +778,7 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
|
||||
ui.checkbox(im_str!("Check"), &mut state.b);
|
||||
});
|
||||
ui.menu(im_str!("Colors")).build(|| {
|
||||
for &col in ImGuiCol::values() {
|
||||
for &col in ImGuiCol::VARIANTS.iter() {
|
||||
ui.menu_item(imgui::get_style_color_name(col)).build();
|
||||
}
|
||||
});
|
||||
@ -879,8 +879,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
|
||||
(x + state.sz * 0.5, y + state.sz * 0.5),
|
||||
state.sz * 0.5,
|
||||
state.col,
|
||||
)
|
||||
.num_segments(20)
|
||||
).num_segments(20)
|
||||
.thickness(thickness)
|
||||
.build();
|
||||
x += state.sz + spacing;
|
||||
@ -909,8 +908,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
|
||||
(x + state.sz, y + state.sz - 0.5),
|
||||
(x, y + state.sz - 0.5),
|
||||
state.col,
|
||||
)
|
||||
.thickness(thickness)
|
||||
).thickness(thickness)
|
||||
.build();
|
||||
x += state.sz + spacing;
|
||||
draw_list
|
||||
@ -935,8 +933,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
|
||||
(x + state.sz - state.sz * 1.3, y + state.sz - state.sz * 0.3),
|
||||
(x + state.sz, y + state.sz),
|
||||
state.col,
|
||||
)
|
||||
.thickness(thickness)
|
||||
).thickness(thickness)
|
||||
.build();
|
||||
y += state.sz + spacing;
|
||||
}
|
||||
@ -946,8 +943,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
|
||||
(x + state.sz * 0.5, y + state.sz * 0.5),
|
||||
state.sz * 0.5,
|
||||
state.col,
|
||||
)
|
||||
.num_segments(32)
|
||||
).num_segments(32)
|
||||
.filled(true)
|
||||
.build();
|
||||
x += state.sz + spacing;
|
||||
@ -976,8 +972,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
|
||||
(x + state.sz, y + state.sz - 0.5),
|
||||
(x, y + state.sz - 0.5),
|
||||
state.col,
|
||||
)
|
||||
.filled(true)
|
||||
).filled(true)
|
||||
.build();
|
||||
x += state.sz + spacing;
|
||||
const MULTICOLOR_RECT_CORNER_COLOR1: [f32; 3] = [0.0, 0.0, 0.0];
|
||||
@ -1046,8 +1041,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
|
||||
canvas_pos,
|
||||
(canvas_pos.0 + canvas_size.0, canvas_pos.1 + canvas_size.1),
|
||||
CANVAS_BORDER_COLOR,
|
||||
)
|
||||
.build();
|
||||
).build();
|
||||
|
||||
let mut adding_preview = false;
|
||||
ui.invisible_button(im_str!("canvas"), canvas_size);
|
||||
@ -1088,8 +1082,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
|
||||
(canvas_pos.0 + p1.0, canvas_pos.1 + p1.1),
|
||||
(canvas_pos.0 + p2.0, canvas_pos.1 + p2.1),
|
||||
LINE_COLOR,
|
||||
)
|
||||
.thickness(2.0)
|
||||
).thickness(2.0)
|
||||
.build();
|
||||
}
|
||||
},
|
||||
|
||||
@ -4,11 +4,11 @@ extern crate imgui;
|
||||
|
||||
use gfx::handle::{Buffer, RenderTargetView};
|
||||
use gfx::memory::Bind;
|
||||
use gfx::pso::{PipelineData, PipelineState};
|
||||
use gfx::texture::{FilterMethod, SamplerInfo, WrapMode};
|
||||
use gfx::traits::FactoryExt;
|
||||
use gfx::{CommandBuffer, Encoder, Factory, IntoIndexBuffer, Rect, Resources, Slice};
|
||||
use gfx::pso::{PipelineData, PipelineState};
|
||||
use imgui::{DrawList, FrameSize, ImDrawIdx, ImDrawVert, ImGui, Ui, Textures, ImTexture};
|
||||
use imgui::{DrawList, FrameSize, ImDrawIdx, ImDrawVert, ImGui, ImTexture, Textures, Ui};
|
||||
|
||||
pub type RendererResult<T> = Result<T, RendererError>;
|
||||
|
||||
@ -131,7 +131,10 @@ impl Shaders {
|
||||
}
|
||||
}
|
||||
|
||||
pub type Texture<R> = (gfx::handle::ShaderResourceView<R, [f32; 4]>, gfx::handle::Sampler<R>);
|
||||
pub type Texture<R> = (
|
||||
gfx::handle::ShaderResourceView<R, [f32; 4]>,
|
||||
gfx::handle::Sampler<R>,
|
||||
);
|
||||
|
||||
pub struct Renderer<R: Resources> {
|
||||
bundle: Bundle<R, pipe::Data<R>>,
|
||||
@ -254,7 +257,9 @@ impl<R: Resources> Renderer<R> {
|
||||
self.bundle.slice.start = 0;
|
||||
for cmd in draw_list.cmd_buffer {
|
||||
let texture_id = cmd.texture_id.into();
|
||||
let tex = self.textures.get(texture_id)
|
||||
let tex = self
|
||||
.textures
|
||||
.get(texture_id)
|
||||
.ok_or_else(|| RendererError::BadTexture(texture_id))?;
|
||||
|
||||
self.bundle.slice.end = self.bundle.slice.start + cmd.elem_count;
|
||||
|
||||
@ -8,7 +8,7 @@ use glium::program;
|
||||
use glium::texture;
|
||||
use glium::vertex;
|
||||
use glium::{DrawError, IndexBuffer, Program, Surface, Texture2d, VertexBuffer};
|
||||
use imgui::{DrawList, FrameSize, ImDrawIdx, ImDrawVert, ImGui, Ui, Textures, ImTexture};
|
||||
use imgui::{DrawList, FrameSize, ImDrawIdx, ImDrawVert, ImGui, ImTexture, Textures, Ui};
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
@ -137,7 +137,10 @@ impl Renderer {
|
||||
let mut idx_start = 0;
|
||||
for cmd in draw_list.cmd_buffer {
|
||||
let texture_id = cmd.texture_id.into();
|
||||
let texture = self.device_objects.textures.get(texture_id)
|
||||
let texture = self
|
||||
.device_objects
|
||||
.textures
|
||||
.get(texture_id)
|
||||
.ok_or_else(|| RendererError::BadTexture(texture_id))?;
|
||||
|
||||
let idx_end = idx_start + cmd.elem_count as usize;
|
||||
|
||||
@ -210,11 +210,12 @@ pub fn update_mouse_cursor(imgui: &ImGui, window: &Window) {
|
||||
ImGuiMouseCursor::None => unreachable!("mouse_cursor was None!"),
|
||||
ImGuiMouseCursor::Arrow => MouseCursor::Arrow,
|
||||
ImGuiMouseCursor::TextInput => MouseCursor::Text,
|
||||
ImGuiMouseCursor::Move => MouseCursor::Move,
|
||||
ImGuiMouseCursor::ResizeAll => MouseCursor::Move,
|
||||
ImGuiMouseCursor::ResizeNS => MouseCursor::NsResize,
|
||||
ImGuiMouseCursor::ResizeEW => MouseCursor::EwResize,
|
||||
ImGuiMouseCursor::ResizeNESW => MouseCursor::NeswResize,
|
||||
ImGuiMouseCursor::ResizeNWSE => MouseCursor::NwseResize,
|
||||
ImGuiMouseCursor::Hand => MouseCursor::Hand,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,23 +111,23 @@ pub struct ImDrawVert {
|
||||
/// Runtime data for a single font within a parent ImFontAtlas
|
||||
#[repr(C)]
|
||||
pub struct ImFont {
|
||||
font_size: c_float,
|
||||
scale: c_float,
|
||||
display_offset: ImVec2,
|
||||
glyphs: ImVector<ImFontGlyph>,
|
||||
index_advance_x: ImVector<c_float>,
|
||||
index_lookup: ImVector<c_ushort>,
|
||||
fallback_glyph: *const ImFontGlyph,
|
||||
fallback_advance_x: c_float,
|
||||
fallback_char: ImWchar,
|
||||
pub font_size: c_float,
|
||||
pub scale: c_float,
|
||||
pub display_offset: ImVec2,
|
||||
pub glyphs: ImVector<ImFontGlyph>,
|
||||
pub index_advance_x: ImVector<c_float>,
|
||||
pub index_lookup: ImVector<c_ushort>,
|
||||
pub fallback_glyph: *const ImFontGlyph,
|
||||
pub fallback_advance_x: c_float,
|
||||
pub fallback_char: ImWchar,
|
||||
|
||||
config_data_count: c_short,
|
||||
config_data: *mut ImFontConfig,
|
||||
container_font_atlas: *mut ImFontAtlas,
|
||||
ascent: c_float,
|
||||
descent: c_float,
|
||||
dirty_lookup_tables: bool,
|
||||
metrics_total_surface: c_int,
|
||||
pub config_data_count: c_short,
|
||||
pub config_data: *mut ImFontConfig,
|
||||
pub container_font_atlas: *mut ImFontAtlas,
|
||||
pub ascent: c_float,
|
||||
pub descent: c_float,
|
||||
pub dirty_lookup_tables: bool,
|
||||
pub metrics_total_surface: c_int,
|
||||
}
|
||||
|
||||
/// Runtime data for multiple fonts, bake multiple fonts into a single texture, TTF/OTF font loader
|
||||
@ -139,16 +139,16 @@ pub struct ImFontAtlas {
|
||||
pub tex_desired_width: c_int,
|
||||
pub tex_glyph_padding: c_int,
|
||||
|
||||
tex_pixels_alpha8: *mut c_uchar,
|
||||
tex_pixels_rgba32: *mut c_uint,
|
||||
tex_width: c_int,
|
||||
tex_height: c_int,
|
||||
tex_uv_scale: ImVec2,
|
||||
tex_uv_white_pixel: ImVec2,
|
||||
fonts: ImVector<*mut ImFont>,
|
||||
custom_rects: ImVector<CustomRect>,
|
||||
config_data: ImVector<ImFontConfig>,
|
||||
custom_rect_ids: [c_int; 1],
|
||||
pub tex_pixels_alpha8: *mut c_uchar,
|
||||
pub tex_pixels_rgba32: *mut c_uint,
|
||||
pub tex_width: c_int,
|
||||
pub tex_height: c_int,
|
||||
pub tex_uv_scale: ImVec2,
|
||||
pub tex_uv_white_pixel: ImVec2,
|
||||
pub fonts: ImVector<*mut ImFont>,
|
||||
pub custom_rects: ImVector<CustomRect>,
|
||||
pub config_data: ImVector<ImFontConfig>,
|
||||
pub custom_rect_ids: [c_int; 1],
|
||||
}
|
||||
|
||||
/// Configuration data when adding a font or merging fonts
|
||||
|
||||
39
src/fonts.rs
39
src/fonts.rs
@ -6,7 +6,8 @@ use sys;
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
|
||||
enum FontGlyphRangeData {
|
||||
Chinese,
|
||||
ChineseSimplifiedCommon,
|
||||
ChineseFull,
|
||||
Cyrillic,
|
||||
Default,
|
||||
Japanese,
|
||||
@ -24,9 +25,13 @@ impl FontGlyphRange {
|
||||
FontGlyphRange(FontGlyphRangeData::Default)
|
||||
}
|
||||
|
||||
/// A set of glyph ranges appropriate for use with simplified common Chinese text.
|
||||
pub fn chinese_simplified_common() -> FontGlyphRange {
|
||||
FontGlyphRange(FontGlyphRangeData::ChineseSimplifiedCommon)
|
||||
}
|
||||
/// A set of glyph ranges appropriate for use with Chinese text.
|
||||
pub fn chinese() -> FontGlyphRange {
|
||||
FontGlyphRange(FontGlyphRangeData::Chinese)
|
||||
pub fn chinese_full() -> FontGlyphRange {
|
||||
FontGlyphRange(FontGlyphRangeData::ChineseFull)
|
||||
}
|
||||
/// A set of glyph ranges appropriate for use with Cyrillic text.
|
||||
pub fn cyrillic() -> FontGlyphRange {
|
||||
@ -122,7 +127,10 @@ impl FontGlyphRange {
|
||||
|
||||
unsafe fn to_ptr(&self, atlas: *mut sys::ImFontAtlas) -> *const sys::ImWchar {
|
||||
match &self.0 {
|
||||
&FontGlyphRangeData::Chinese => sys::ImFontAtlas_GetGlyphRangesChinese(atlas),
|
||||
&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),
|
||||
@ -258,25 +266,27 @@ impl<'a> ImFont<'a> {
|
||||
}
|
||||
|
||||
pub fn font_size(&self) -> f32 {
|
||||
unsafe { sys::ImFont_GetFontSize(self.font) }
|
||||
unsafe { (*self.font).font_size }
|
||||
}
|
||||
pub fn set_font_size(&mut self, size: f32) -> ImFont {
|
||||
unsafe { sys::ImFont_SetFontSize(self.font, size) }
|
||||
unsafe {
|
||||
(*self.font).font_size = size;
|
||||
}
|
||||
self.chain()
|
||||
}
|
||||
|
||||
pub fn scale(&self) -> f32 {
|
||||
unsafe { sys::ImFont_GetScale(self.font) }
|
||||
unsafe { (*self.font).scale }
|
||||
}
|
||||
pub fn set_scale(&mut self, size: f32) -> ImFont {
|
||||
unsafe { sys::ImFont_SetScale(self.font, size) }
|
||||
unsafe {
|
||||
(*self.font).scale = size;
|
||||
}
|
||||
self.chain()
|
||||
}
|
||||
|
||||
pub fn display_offset(&self) -> (f32, f32) {
|
||||
let mut display_offset = unsafe { mem::uninitialized() };
|
||||
unsafe { sys::ImFont_GetDisplayOffset(self.font, &mut display_offset) }
|
||||
display_offset.into()
|
||||
unsafe { (*self.font).display_offset.into() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,7 +360,7 @@ impl<'a> ImFontAtlas<'a> {
|
||||
|
||||
/// The number of fonts currently registered in the atlas.
|
||||
pub fn font_count(&self) -> usize {
|
||||
unsafe { sys::ImFontAtlas_Fonts_size(self.atlas) as usize }
|
||||
unsafe { (*self.atlas).fonts.size as usize }
|
||||
}
|
||||
|
||||
/// Gets a font from the atlas.
|
||||
@ -360,8 +370,9 @@ impl<'a> ImFontAtlas<'a> {
|
||||
///
|
||||
/// Panics if the index is out of range.
|
||||
pub fn index_font(&mut self, index: usize) -> ImFont {
|
||||
assert!(index < self.font_count(), "Font index is out of range.");
|
||||
unsafe { ImFont::from_ptr(sys::ImFontAtlas_Fonts_index(self.atlas, index as c_int)) }
|
||||
let fonts = unsafe { (*self.atlas).fonts.as_slice() };
|
||||
assert!(index < fonts.len(), "Font index is out of range.");
|
||||
unsafe { ImFont::from_ptr(fonts[index]) }
|
||||
}
|
||||
|
||||
/// Clears all fonts associated with this texture atlas.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use super::{ImVec2, ImVec4, Ui};
|
||||
use std::marker::PhantomData;
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::os::raw::c_void;
|
||||
use sys;
|
||||
|
||||
|
||||
20
src/input.rs
20
src/input.rs
@ -126,16 +126,6 @@ macro_rules! impl_step_params {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_precision_params {
|
||||
($InputType:ident) => {
|
||||
#[inline]
|
||||
pub fn decimal_precision(mut self, value: i32) -> Self {
|
||||
self.decimal_precision = value;
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub struct InputText<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
@ -257,7 +247,6 @@ pub struct InputFloat<'ui, 'p> {
|
||||
value: &'p mut f32,
|
||||
step: f32,
|
||||
step_fast: f32,
|
||||
decimal_precision: i32,
|
||||
flags: ImGuiInputTextFlags,
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
@ -269,7 +258,6 @@ impl<'ui, 'p> InputFloat<'ui, 'p> {
|
||||
value,
|
||||
step: 0.0,
|
||||
step_fast: 0.0,
|
||||
decimal_precision: -1,
|
||||
flags: ImGuiInputTextFlags::empty(),
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
@ -282,14 +270,13 @@ impl<'ui, 'p> InputFloat<'ui, 'p> {
|
||||
self.value as *mut f32,
|
||||
self.step,
|
||||
self.step_fast,
|
||||
self.decimal_precision,
|
||||
b"%.3f\0".as_ptr() as *const _,
|
||||
self.flags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl_step_params!(InputFloat, f32);
|
||||
impl_precision_params!(InputFloat);
|
||||
impl_text_flags!(InputFloat);
|
||||
}
|
||||
|
||||
@ -299,7 +286,6 @@ macro_rules! impl_input_floatn {
|
||||
pub struct $InputFloatN<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; $N],
|
||||
decimal_precision: i32,
|
||||
flags: ImGuiInputTextFlags,
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
@ -309,7 +295,6 @@ macro_rules! impl_input_floatn {
|
||||
$InputFloatN {
|
||||
label,
|
||||
value,
|
||||
decimal_precision: -1,
|
||||
flags: ImGuiInputTextFlags::empty(),
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
@ -320,13 +305,12 @@ macro_rules! impl_input_floatn {
|
||||
sys::$igInputFloatN(
|
||||
self.label.as_ptr(),
|
||||
self.value.as_mut_ptr(),
|
||||
self.decimal_precision,
|
||||
b"%.3f\0".as_ptr() as *const _,
|
||||
self.flags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl_precision_params!($InputFloatN);
|
||||
impl_text_flags!($InputFloatN);
|
||||
}
|
||||
};
|
||||
|
||||
109
src/lib.rs
109
src/lib.rs
@ -130,6 +130,9 @@ impl FrameSize {
|
||||
|
||||
impl ImGui {
|
||||
pub fn init() -> ImGui {
|
||||
unsafe {
|
||||
sys::igCreateContext(ptr::null_mut());
|
||||
}
|
||||
ImGui {
|
||||
ini_filename: None,
|
||||
log_filename: None,
|
||||
@ -384,7 +387,7 @@ impl ImGui {
|
||||
let mut buf = [0; 5];
|
||||
character.encode_utf8(&mut buf);
|
||||
unsafe {
|
||||
sys::ImGuiIO_AddInputCharactersUTF8(buf.as_ptr() as *const _);
|
||||
sys::ImGuiIO_AddInputCharactersUTF8(self.io_mut(), buf.as_ptr() as *const _);
|
||||
}
|
||||
}
|
||||
pub fn get_time(&self) -> f32 {
|
||||
@ -425,7 +428,7 @@ impl Drop for ImGui {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
CURRENT_UI = None;
|
||||
sys::igShutdown();
|
||||
sys::igDestroyContext(ptr::null_mut());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -529,10 +532,6 @@ impl<'ui> Ui<'ui> {
|
||||
let io = self.imgui.io();
|
||||
io.framerate
|
||||
}
|
||||
pub fn metrics_allocs(&self) -> i32 {
|
||||
let io = self.imgui.io();
|
||||
io.metrics_allocs
|
||||
}
|
||||
pub fn metrics_render_vertices(&self) -> i32 {
|
||||
let io = self.imgui.io();
|
||||
io.metrics_render_vertices
|
||||
@ -606,19 +605,13 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
/// Get current window's size in pixels
|
||||
pub fn get_window_size(&self) -> (f32, f32) {
|
||||
let mut out = ImVec2::new(0.0, 0.0);
|
||||
unsafe {
|
||||
sys::igGetWindowSize(&mut out as *mut ImVec2);
|
||||
}
|
||||
(out.x, out.y)
|
||||
let size = unsafe { sys::igGetWindowSize() };
|
||||
size.into()
|
||||
}
|
||||
/// Get current window's position in pixels
|
||||
pub fn get_window_pos(&self) -> (f32, f32) {
|
||||
let mut out = ImVec2::new(0.0, 0.0);
|
||||
unsafe {
|
||||
sys::igGetWindowPos(&mut out);
|
||||
}
|
||||
(out.x, out.y)
|
||||
let size = unsafe { sys::igGetWindowPos() };
|
||||
size.into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -694,8 +687,7 @@ impl<'ui> Ui<'ui> {
|
||||
/// Fill a space of `size` in pixels with nothing on the current window.
|
||||
/// Can be used to move the cursor on the window.
|
||||
pub fn dummy<S: Into<ImVec2>>(&self, size: S) {
|
||||
let size = size.into();
|
||||
unsafe { sys::igDummy(&size) }
|
||||
unsafe { sys::igDummy(size.into()) }
|
||||
}
|
||||
|
||||
/// Get cursor position on the screen, in screen coordinates.
|
||||
@ -704,11 +696,8 @@ impl<'ui> Ui<'ui> {
|
||||
/// This is especially useful for drawing, as the drawing API uses
|
||||
/// screen coordiantes.
|
||||
pub fn get_cursor_screen_pos(&self) -> (f32, f32) {
|
||||
let mut out = ImVec2::new(0.0, 0.0);
|
||||
unsafe {
|
||||
sys::igGetCursorScreenPos(&mut out);
|
||||
}
|
||||
(out.x, out.y)
|
||||
let size = unsafe { sys::igGetCursorScreenPos() };
|
||||
size.into()
|
||||
}
|
||||
|
||||
/// Set cursor position on the screen, in screen coordinates.
|
||||
@ -719,11 +708,8 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
/// Get cursor position on the screen, in window coordinates.
|
||||
pub fn get_cursor_pos(&self) -> (f32, f32) {
|
||||
let mut out = ImVec2::new(0.0, 0.0);
|
||||
unsafe {
|
||||
sys::igGetCursorPos(&mut out);
|
||||
}
|
||||
(out.x, out.y)
|
||||
let size = unsafe { sys::igGetCursorPos() };
|
||||
size.into()
|
||||
}
|
||||
|
||||
/// Set cursor position on the screen, in window coordinates.
|
||||
@ -735,11 +721,8 @@ impl<'ui> Ui<'ui> {
|
||||
/// Get available space left between the cursor and the edges of the current
|
||||
/// window.
|
||||
pub fn get_content_region_avail(&self) -> (f32, f32) {
|
||||
let mut out = ImVec2::new(0.0, 0.0);
|
||||
unsafe {
|
||||
sys::igGetContentRegionAvail(&mut out);
|
||||
}
|
||||
(out.x, out.y)
|
||||
let size = unsafe { sys::igGetContentRegionAvail() };
|
||||
size.into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -787,7 +770,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);
|
||||
sys::igPushIDStrRange(start, end);
|
||||
sys::igPushIDRange(start, end);
|
||||
}
|
||||
ImId::Ptr(p) => {
|
||||
sys::igPushIDPtr(p as *const c_void);
|
||||
@ -1206,7 +1189,7 @@ impl<'ui> Ui<'ui> {
|
||||
where
|
||||
F: FnOnce(),
|
||||
{
|
||||
let render = unsafe { sys::igBeginPopup(str_id.as_ptr()) };
|
||||
let render = unsafe { sys::igBeginPopup(str_id.as_ptr(), ImGuiWindowFlags::empty()) };
|
||||
if render {
|
||||
f();
|
||||
unsafe { sys::igEndPopup() };
|
||||
@ -1272,7 +1255,7 @@ impl<'ui> Ui<'ui> {
|
||||
) -> bool {
|
||||
let items_inner: Vec<*const c_char> = items.into_iter().map(|item| item.as_ptr()).collect();
|
||||
unsafe {
|
||||
sys::igListBox(
|
||||
sys::igListBoxStr_arr(
|
||||
label.as_ptr(),
|
||||
current_item,
|
||||
items_inner.as_ptr() as *mut *const c_char,
|
||||
@ -1299,7 +1282,7 @@ impl<'ui> Ui<'ui> {
|
||||
/// ui.radio_button(im_str!("Item 3"), &mut selected_radio_value, 3);
|
||||
/// ```
|
||||
pub fn radio_button<'p>(&self, label: &'p ImStr, value: &'p mut i32, wanted: i32) -> bool {
|
||||
unsafe { sys::igRadioButton(label.as_ptr(), value, wanted) }
|
||||
unsafe { sys::igRadioButtonIntPtr(label.as_ptr(), value, wanted) }
|
||||
}
|
||||
|
||||
/// Creates a radio button that shows as selected if the given value is true.
|
||||
@ -1362,17 +1345,14 @@ impl<'ui> Ui<'ui> {
|
||||
hide_text_after_double_hash: bool,
|
||||
wrap_width: f32,
|
||||
) -> ImVec2 {
|
||||
let mut buffer = ImVec2::new(0.0, 0.0);
|
||||
unsafe {
|
||||
sys::igCalcTextSize(
|
||||
&mut buffer as *mut ImVec2,
|
||||
text.as_ptr(),
|
||||
std::ptr::null(),
|
||||
hide_text_after_double_hash,
|
||||
wrap_width,
|
||||
);
|
||||
)
|
||||
}
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
@ -1383,11 +1363,8 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
/// Get previously drawn item's size
|
||||
pub fn get_item_rect_size(&self) -> (f32, f32) {
|
||||
let mut out = ImVec2::new(0.0, 0.0);
|
||||
unsafe {
|
||||
sys::igGetItemRectSize(&mut out);
|
||||
}
|
||||
(out.x, out.y)
|
||||
let size = unsafe { sys::igGetItemRectSize() };
|
||||
size.into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1483,26 +1460,30 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
#[inline]
|
||||
fn push_style_var(&self, style_var: StyleVar) {
|
||||
use sys::{igPushStyleVar, igPushStyleVarVec};
|
||||
use sys::{igPushStyleVarFloat, igPushStyleVarVec2};
|
||||
use StyleVar::*;
|
||||
match style_var {
|
||||
Alpha(v) => unsafe { igPushStyleVar(ImGuiStyleVar::Alpha, v) },
|
||||
WindowPadding(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::WindowPadding, v) },
|
||||
WindowRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::WindowRounding, v) },
|
||||
WindowBorderSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::WindowBorderSize, v) },
|
||||
WindowMinSize(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::WindowMinSize, v) },
|
||||
ChildRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::ChildRounding, v) },
|
||||
ChildBorderSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::ChildBorderSize, v) },
|
||||
PopupRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::PopupRounding, v) },
|
||||
PopupBorderSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::PopupBorderSize, v) },
|
||||
FramePadding(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::FramePadding, v) },
|
||||
FrameRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::FrameRounding, v) },
|
||||
FrameBorderSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::FrameBorderSize, v) },
|
||||
ItemSpacing(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ItemSpacing, v) },
|
||||
ItemInnerSpacing(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ItemInnerSpacing, v) },
|
||||
IndentSpacing(v) => unsafe { igPushStyleVar(ImGuiStyleVar::IndentSpacing, v) },
|
||||
GrabMinSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::GrabMinSize, v) },
|
||||
ButtonTextAlign(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ButtonTextAlign, v) },
|
||||
Alpha(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::Alpha, v) },
|
||||
WindowPadding(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::WindowPadding, v) },
|
||||
WindowRounding(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::WindowRounding, v) },
|
||||
WindowBorderSize(v) => unsafe {
|
||||
igPushStyleVarFloat(ImGuiStyleVar::WindowBorderSize, v)
|
||||
},
|
||||
WindowMinSize(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::WindowMinSize, v) },
|
||||
ChildRounding(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::ChildRounding, v) },
|
||||
ChildBorderSize(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::ChildBorderSize, v) },
|
||||
PopupRounding(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::PopupRounding, v) },
|
||||
PopupBorderSize(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::PopupBorderSize, v) },
|
||||
FramePadding(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::FramePadding, v) },
|
||||
FrameRounding(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::FrameRounding, v) },
|
||||
FrameBorderSize(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::FrameBorderSize, v) },
|
||||
ItemSpacing(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::ItemSpacing, v) },
|
||||
ItemInnerSpacing(v) => unsafe {
|
||||
igPushStyleVarVec2(ImGuiStyleVar::ItemInnerSpacing, v)
|
||||
},
|
||||
IndentSpacing(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::IndentSpacing, v) },
|
||||
GrabMinSize(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::GrabMinSize, v) },
|
||||
ButtonTextAlign(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::ButtonTextAlign, v) },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,6 +75,6 @@ impl<'ui, 'p> MenuItem<'ui, 'p> {
|
||||
.map(|x| x as *mut bool)
|
||||
.unwrap_or(ptr::null_mut());
|
||||
let enabled = self.enabled;
|
||||
unsafe { sys::igMenuItemPtr(label, shortcut, selected, enabled) }
|
||||
unsafe { sys::igMenuItemBoolPtr(label, shortcut, selected, enabled) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ impl<'ui, 'p> PlotHistogram<'ui, 'p> {
|
||||
|
||||
pub fn build(self) {
|
||||
unsafe {
|
||||
sys::igPlotHistogram(
|
||||
sys::igPlotHistogramFloatPtr(
|
||||
self.label.as_ptr(),
|
||||
self.values.as_ptr() as *const c_float,
|
||||
self.values.len() as i32,
|
||||
|
||||
@ -51,7 +51,7 @@ impl<'ui, 'p> ProgressBar<'ui, 'p> {
|
||||
unsafe {
|
||||
sys::igProgressBar(
|
||||
self.fraction,
|
||||
&self.size,
|
||||
self.size,
|
||||
self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()),
|
||||
);
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ impl<'ui, 'p> TreeNode<'ui, 'p> {
|
||||
if !self.opened_cond.is_empty() {
|
||||
sys::igSetNextTreeNodeOpen(self.opened, self.opened_cond);
|
||||
}
|
||||
sys::igTreeNodeExStr(
|
||||
sys::igTreeNodeExStrStr(
|
||||
self.id.as_ptr(),
|
||||
self.flags,
|
||||
super::fmt_ptr(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user