Merge pull request #53 from Gekkio/feature/imgui-1.50

Upgrade cimgui and imgui to 1.50
This commit is contained in:
Joonas Javanainen 2017-06-17 19:22:19 +03:00 committed by GitHub
commit bfd9419ae8
4 changed files with 130 additions and 43 deletions

View File

@ -12,6 +12,7 @@
- ImStr is now "a dear imgui -compatible string slice". This change
significantly affects how strings are handled.
- Upgrade to imgui/cimgui 1.50
### Fixed

View File

@ -6,6 +6,7 @@ fn main() {
.file("third-party/cimgui/cimgui/cimgui.cpp")
.file("third-party/cimgui/cimgui/fontAtlas.cpp")
.file("third-party/cimgui/cimgui/drawList.cpp")
.file("third-party/cimgui/cimgui/listClipper.cpp")
.file("third-party/cimgui/imgui/imgui.cpp")
.file("third-party/cimgui/imgui/imgui_demo.cpp")
.file("third-party/cimgui/imgui/imgui_draw.cpp")

View File

@ -24,6 +24,7 @@ mod glium_support;
/// ImGui context (opaque)
pub enum ImGuiContext { }
/// 32-bit unsigned integer (typically used to store packed colors)
pub type ImU32 = c_uint;
/// Character for keyboard input/display
@ -100,7 +101,9 @@ pub enum ImGuiStyleVar {
ItemInnerSpacing,
IndentSpacing,
GrabMinSize,
ButtonTextAlign,
}
pub const ImGuiStyleVar_COUNT: usize = 12;
/// A key identifier (ImGui-side enum)
#[repr(C)]
@ -128,19 +131,6 @@ pub enum ImGuiKey {
}
pub const ImGuiKey_COUNT: usize = 19;
bitflags!(
/// Alignment
#[repr(C)]
pub flags ImGuiAlign: c_int {
const ImGuiAlign_Left = 1 << 0,
const ImGuiAlign_Center = 1 << 1,
const ImGuiAlign_Right = 1 << 2,
const ImGuiAlign_Top = 1 << 3,
const ImGuiAlign_VCenter = 1 << 4,
const ImGuiAlign_Default = ImGuiAlign_Left.bits | ImGuiAlign_Top.bits
}
);
/// Color edit mode
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -156,6 +146,7 @@ pub enum ImGuiColorEditMode {
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ImGuiMouseCursor {
None = -1,
Arrow,
TextInput,
Move,
@ -164,7 +155,6 @@ pub enum ImGuiMouseCursor {
ResizeNESW,
ResizeNWSE,
}
pub const ImGuiMouseCursor_COUNT: usize = 7;
bitflags!(
@ -365,8 +355,8 @@ pub struct ImGuiStyle {
pub window_min_size: ImVec2,
/// Radius of window corners rounding. Set to 0.0f to have rectangular windows
pub window_rounding: c_float,
/// Alignment for title bar text
pub window_title_align: ImGuiAlign,
/// Alignment for title bar text. Defaults to (0.0f, 0.5f) for left-aligned, vertically centered
pub window_title_align: ImVec2,
/// Radius of child window corners rounding. Set to 0.0f to have rectangular child windows
pub child_window_rounding: c_float,
/// Padding within a framed rectangle (used by most widgets)
@ -379,7 +369,7 @@ pub struct ImGuiStyle {
/// Horizontal and vertical spacing between within elements of a composed
/// widget (e.g. a slider and its label)
pub item_inner_spacing: ImVec2,
/// Expand reactive bounding box for touch-based system where touch position is not accurat
/// Expand reactive bounding box for touch-based system where touch position is not accurate
/// enough. Unfortunately we don't sort widgets so priority on overlap will always be given
/// to the first widget. So don't grow this too much!
pub touch_extra_padding: ImVec2,
@ -396,6 +386,9 @@ pub struct ImGuiStyle {
pub grab_min_size: c_float,
/// Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
pub grab_rounding: c_float,
/// Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f)
/// for horizontally + vertically centered
pub button_text_align: ImVec2,
/// Window positions are clamped to be visible within the display area by at least this
/// amount. Only covers regular windows.
pub display_window_padding: ImVec2,
@ -432,18 +425,17 @@ pub struct ImGuiIO {
pub fonts: *mut ImFontAtlas,
pub font_global_scale: c_float,
pub font_allow_user_scaling: bool,
pub font_default: *mut ImFont,
pub display_framebuffer_scale: ImVec2,
pub display_visible_min: ImVec2,
pub display_visible_max: ImVec2,
pub word_movement_uses_alt_key: bool,
pub shortcuts_use_super_key: bool,
pub double_click_selects_word: bool,
pub multi_select_uses_super_key: bool,
pub osx_behaviors: bool,
pub render_draw_lists_fn: Option<extern "C" fn(data: *mut ImDrawData)>,
pub get_clipboard_text_fn: Option<extern "C" fn() -> *const c_char>,
pub set_clipboard_text_fn: Option<extern "C" fn(text: *const c_char)>,
pub get_clipboard_text_fn: Option<extern "C" fn(user_data: *mut c_void) -> *const c_char>,
pub set_clipboard_text_fn: Option<extern "C" fn(user_data: *mut c_void, text: *const c_char)>,
pub clipboard_user_data: *mut c_void,
pub mem_alloc_fn: Option<extern "C" fn(sz: usize) -> *mut c_void>,
pub mem_free_fn: Option<extern "C" fn(ptr: *mut c_void)>,
pub ime_set_input_screen_pos_fn: Option<extern "C" fn(x: c_int, y: c_int)>,
@ -470,8 +462,8 @@ pub struct ImGuiIO {
pub metrics_render_indices: c_int,
pub metrics_active_windows: c_int,
pub mouse_pos_prev: ImVec2,
pub mouse_delta: ImVec2,
pub mouse_pos_prev: ImVec2,
pub mouse_clicked: [bool; 5],
pub mouse_clicked_pos: [ImVec2; 5],
pub mouse_clicked_time: [c_float; 5],
@ -558,8 +550,9 @@ pub struct ImColor {
pub value: ImVec4,
}
/// Helper to manually clip large list of items
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug)]
pub struct ImGuiListClipper {
pub start_pos_y: c_float,
pub items_height: c_float,
@ -569,6 +562,19 @@ pub struct ImGuiListClipper {
pub display_end: c_int,
}
impl Default for ImGuiListClipper {
fn default() -> ImGuiListClipper {
ImGuiListClipper {
start_pos_y: 0.0,
items_height: -1.0,
items_count: -1,
step_no: 0,
display_start: 0,
display_end: 0,
}
}
}
pub type ImDrawCallback = Option<extern "C" fn(parent_list: *const ImDrawList,
cmd: *const ImDrawCmd)>;
@ -649,9 +655,9 @@ pub struct ImFontConfig {
pub oversample_v: c_int,
pub pixel_snap_h: bool,
pub glyph_extra_spacing: ImVec2,
pub glyph_offset: ImVec2,
pub glyph_ranges: *const ImWchar,
pub merge_mode: bool,
pub merge_glyph_center_v: bool,
name: [c_char; 32],
dst_font: *mut ImFont,
@ -905,7 +911,7 @@ extern "C" {
pub fn igRadioButton(label: *const c_char, v: *mut c_int, v_button: c_int) -> bool;
pub fn igCombo(label: *const c_char,
current_item: *mut c_int,
items: *mut *const c_char,
items: *const *const c_char,
items_count: c_int,
height_in_items: c_int)
-> bool;
@ -1234,7 +1240,7 @@ extern "C" {
-> bool;
pub fn igListBox(label: *const c_char,
current_item: *mut c_int,
items: *mut *const c_char,
items: *const *const c_char,
items_count: c_int,
height_in_items: c_int)
-> bool;
@ -1263,7 +1269,7 @@ extern "C" {
pub fn igValueUInt(prefix: *const c_char, v: c_uint);
pub fn igValueFloat(prefix: *const c_char, v: c_float, float_format: *const c_char);
pub fn igValueColor(prefix: *const c_char, v: ImVec4);
pub fn igValueColor2(prefix: *const c_char, v: c_uint);
pub fn igValueColor2(prefix: *const c_char, v: ImU32);
}
// Tooltip
@ -1348,7 +1354,8 @@ extern "C" {
pub fn igIsRootWindowFocused() -> bool;
pub fn igIsRootWindowOrAnyChildFocused() -> bool;
pub fn igIsRootWindowOrAnyChildHovered() -> bool;
pub fn igIsRectVisible(pos: ImVec2) -> bool;
pub fn igIsRectVisible(item_size: ImVec2) -> bool;
pub fn igIsRectVisible2(rect_min: *const ImVec2, rect_max: *const ImVec2) -> bool;
pub fn igIsPosHoveringAnyWindow(pos: ImVec2) -> bool;
pub fn igGetTime() -> c_float;
pub fn igGetFrameCount() -> c_int;
@ -1385,10 +1392,10 @@ extern "C" {
out_g: *mut c_float,
out_b: *mut c_float);
pub fn igGetKeyIndex(key: ImGuiKey) -> c_int;
pub fn igIsKeyDown(key_index: c_int) -> bool;
pub fn igIsKeyPressed(key_index: c_int, repeat: bool) -> bool;
pub fn igIsKeyReleased(key_index: c_int) -> bool;
pub fn igGetKeyIndex(imgui_key: ImGuiKey) -> c_int;
pub fn igIsKeyDown(user_key_index: c_int) -> bool;
pub fn igIsKeyPressed(user_key_index: c_int, repeat: bool) -> bool;
pub fn igIsKeyReleased(user_key_index: c_int) -> bool;
pub fn igIsMouseDown(button: c_int) -> bool;
pub fn igIsMouseClicked(button: c_int, repeat: bool) -> bool;
pub fn igIsMouseDoubleClicked(button: c_int) -> bool;
@ -1441,7 +1448,7 @@ extern "C" {
out_width: *mut c_int,
out_height: *mut c_int,
out_bytes_per_pixel: *mut c_int);
pub fn ImFontAtlas_SetTexID(atlas: *mut ImFontAtlas, tex: *mut c_void);
pub fn ImFontAtlas_SetTexID(atlas: *mut ImFontAtlas, tex: ImTextureID);
pub fn ImFontAtlas_AddFont(atlas: *mut ImFontAtlas,
font_cfg: *const ImFontConfig)
-> *mut ImFont;
@ -1476,6 +1483,12 @@ extern "C" {
glyph_ranges: *const ImWchar) -> *mut ImFont;
pub fn ImFontAtlas_ClearTexData(atlas: *mut ImFontAtlas);
pub fn ImFontAtlas_Clear(atlas: *mut ImFontAtlas);
pub fn ImFontAtlas_GetGlyphRangesDefault(atlas: *mut ImFontAtlas) -> *const ImWchar;
pub fn ImFontAtlas_GetGlyphRangesKorean(atlas: *mut ImFontAtlas) -> *const ImWchar;
pub fn ImFontAtlas_GetGlyphRangesJapanese(atlas: *mut ImFontAtlas) -> *const ImWchar;
pub fn ImFontAtlas_GetGlyphRangesChinese(atlas: *mut ImFontAtlas) -> *const ImWchar;
pub fn ImFontAtlas_GetGlyphRangesCyrillic(atlas: *mut ImFontAtlas) -> *const ImWchar;
pub fn ImFontAtlas_GetGlyphRangesThai(atlas: *mut ImFontAtlas) -> *const ImWchar;
pub fn ImGuiIO_AddInputCharacter(c: c_ushort);
pub fn ImGuiIO_AddInputCharactersUTF8(utf8_chars: *const c_char);
@ -1485,6 +1498,7 @@ extern "C" {
// ImDrawData
extern "C" {
pub fn ImDrawData_DeIndexAllBuffers(drawData: *mut ImDrawData);
pub fn ImDrawData_ScaleClipRects(drawData: *mut ImDrawData, sc: ImVec2);
}
// ImDrawList
@ -1517,14 +1531,14 @@ extern "C" {
b: ImVec2,
col: ImU32,
rounding: c_float,
rounding_corners: c_int,
rounding_corners_flags: c_int,
thickness: c_float);
pub fn ImDrawList_AddRectFilled(list: *mut ImDrawList,
a: ImVec2,
b: ImVec2,
col: ImU32,
rounding: c_float,
rounding_corners: c_int);
rounding_corners_flags: c_int);
pub fn ImDrawList_AddRectFilledMultiColor(list: *mut ImDrawList,
a: ImVec2,
b: ImVec2,
@ -1584,9 +1598,20 @@ extern "C" {
user_texture_id: ImTextureID,
a: ImVec2,
b: ImVec2,
uv0: ImVec2,
uv1: ImVec2,
uv_a: ImVec2,
uv_b: ImVec2,
col: ImU32);
pub fn ImDrawList_AddImageQuad(list: *mut ImDrawList,
user_texture_id: ImTextureID,
a: ImVec2,
b: ImVec2,
c: ImVec2,
d: ImVec2,
uv_a: ImVec2,
uv_b: ImVec2,
uv_c: ImVec2,
uv_d: ImVec2,
col: ImU32);
pub fn ImDrawList_AddPolyLine(list: *mut ImDrawList,
points: *const ImVec2,
num_points: c_int,
@ -1611,7 +1636,7 @@ extern "C" {
pub fn ImDrawList_PathClear(list: *mut ImDrawList);
pub fn ImDrawList_PathLineTo(list: *mut ImDrawList, pos: ImVec2);
pub fn ImDrawList_PathLineToMergeDuplicate(list: *mut ImDrawList, pos: ImVec2);
pub fn ImDrawList_PathFill(list: *mut ImDrawList, col: ImU32);
pub fn ImDrawList_PathFillConvex(list: *mut ImDrawList, col: ImU32);
pub fn ImDrawList_PathStroke(list: *mut ImDrawList,
col: ImU32,
closed: bool,
@ -1636,7 +1661,7 @@ extern "C" {
rect_min: ImVec2,
rect_max: ImVec2,
rounding: c_float,
rounding_corners: c_int);
rounding_corners_flags: c_int);
pub fn ImDrawList_ChannelsSplit(list: *mut ImDrawList, channels_count: c_int);
pub fn ImDrawList_ChannelsMerge(list: *mut ImDrawList);
@ -1672,6 +1697,65 @@ extern "C" {
pub fn ImDrawList_UpdateTextureID(list: *mut ImDrawList);
}
// ImGuiListClipper
extern "C" {
pub fn ImGuiListClipper_Begin(clipper: *mut ImGuiListClipper,
count: c_int, items_height: c_float);
pub fn ImGuiListClipper_End(clipper: *mut ImGuiListClipper);
pub fn ImGuiListClipper_Step(clipper: *mut ImGuiListClipper) -> bool;
pub fn ImGuiListClipper_GetDisplayStart(clipper: *mut ImGuiListClipper) -> c_int;
pub fn ImGuiListClipper_GetDisplayEnd(clipper: *mut ImGuiListClipper) -> c_int;
}
// ImGuiTextFilter
extern "C" {
pub fn ImGuiTextFilter_Init(filter: *mut ImGuiTextFilter, default_filter: *const c_char);
pub fn ImGuiTextFilter_Clear(filter: *mut ImGuiTextFilter);
pub fn ImGuiTextFilter_Draw(filter: *mut ImGuiTextFilter,
label: *const c_char, width: c_float) -> bool;
pub fn ImGuiTextFilter_PassFilter(filter: *mut ImGuiTextFilter,
text: *const c_char, text_end: *const c_char) -> bool;
pub fn ImGuiTextFilter_IsActive(filter: *mut ImGuiTextFilter) -> bool;
pub fn ImGuiTextFilter_Build(filter: *mut ImGuiTextFilter);
}
// ImGuiTextEditCallbackData
extern "C" {
pub fn ImGuiTextEditCallbackData_DeleteChars(data: *mut ImGuiTextEditCallbackData,
pos: c_int, bytes_count: c_int);
pub fn ImGuiTextEditCallbackData_InsertChars(data: *mut ImGuiTextEditCallbackData,
pos: c_int,
text: *const c_char, text_end: *const c_char);
pub fn ImGuiTextEditCallbackData_HasSelection(data: *mut ImGuiTextEditCallbackData) -> bool;
}
// ImGuiStorage
extern "C" {
pub fn ImGuiStorage_Init(store: *mut ImGuiStorage);
pub fn ImGuiStorage_Clear(store: *mut ImGuiStorage);
pub fn ImGuiStorage_GetInt(store: *mut ImGuiStorage, key: ImGuiID,
default_val: c_int) -> c_int;
pub fn ImGuiStorage_SetInt(store: *mut ImGuiStorage, key: ImGuiID, val: c_int);
pub fn ImGuiStorage_GetBool(store: *mut ImGuiStorage, key: ImGuiID,
default_val: bool) -> bool;
pub fn ImGuiStorage_SetBool(store: *mut ImGuiStorage, key: ImGuiID, val: bool);
pub fn ImGuiStorage_GetFloat(store: *mut ImGuiStorage, key: ImGuiID,
default_val: c_float) -> c_float;
pub fn ImGuiStorage_SetFloat(store: *mut ImGuiStorage, key: ImGuiID, val: c_float);
pub fn ImGuiStorage_GetVoidPtr(store: *mut ImGuiStorage, key: ImGuiID);
pub fn ImGuiStorage_SetVoidPtr(store: *mut ImGuiStorage, key: ImGuiID, val: *mut c_void);
pub fn ImGuiStorage_GetIntRef(store: *mut ImGuiStorage, key: ImGuiID,
default_val: c_int) -> *mut c_int;
pub fn ImGuiStorage_GetBoolRef(store: *mut ImGuiStorage, key: ImGuiID,
default_val: bool) -> *mut bool;
pub fn ImGuiStorage_GetFloatRef(store: *mut ImGuiStorage, key: ImGuiID,
default_val: c_float) -> *mut c_float;
pub fn ImGuiStorage_GetVoidPtrRef(store: *mut ImGuiStorage, key: ImGuiID,
default_val: *mut c_void) -> *mut *mut c_void;
pub fn ImGuiStorage_SetAllInt(store: *mut ImGuiStorage, val: c_int);
}
// Although this test is sensitive to ImGui updates, it's useful to reveal potential
// alignment errors
#[test]
@ -1681,7 +1765,7 @@ fn test_default_style() {
assert_eq!(style.window_padding, ImVec2::new(8.0, 8.0));
assert_eq!(style.window_min_size, ImVec2::new(32.0, 32.0));
assert_eq!(style.window_rounding, 9.0);
assert_eq!(style.window_title_align, ImGuiAlign_Left);
assert_eq!(style.window_title_align, ImVec2::new(0.0, 0.5));
assert_eq!(style.child_window_rounding, 0.0);
assert_eq!(style.frame_padding, ImVec2::new(4.0, 3.0));
assert_eq!(style.frame_rounding, 0.0);
@ -1694,6 +1778,7 @@ fn test_default_style() {
assert_eq!(style.scrollbar_rounding, 9.0);
assert_eq!(style.grab_min_size, 10.0);
assert_eq!(style.grab_rounding, 0.0);
assert_eq!(style.button_text_align, ImVec2::new(0.5, 0.5));
assert_eq!(style.display_window_padding, ImVec2::new(22.0, 22.0));
assert_eq!(style.display_safe_area_padding, ImVec2::new(4.0, 4.0));
assert_eq!(style.anti_aliased_lines, true);

@ -1 +1 @@
Subproject commit fb044c4b6a25a5f8ce6409d6ecfc8702828b6e65
Subproject commit dbbac62a8479a0fbdb2d833c3d34cf810660505e