Upgrade to imgui/cimgui 1.45

This commit is contained in:
Joonas Javanainen 2015-12-23 14:35:45 +00:00
parent 9a53bfe019
commit a854953236
7 changed files with 43 additions and 34 deletions

View File

@ -5,8 +5,7 @@
![Hello world](hello_world.png)
```rust
ui.window()
.name(im_str!("Hello world"))
ui.window(im_str!("Hello world"))
.size((300.0, 100.0), ImGuiSetCond_FirstUseEver)
.build(|| {
ui.text(im_str!("Hello world!"));

View File

@ -23,8 +23,7 @@ fn main() {
}
fn hello_world<'a>(ui: &Ui<'a>) {
ui.window()
.name(im_str!("Hello world"))
ui.window(im_str!("Hello world"))
.size((300.0, 100.0), ImGuiSetCond_FirstUseEver)
.build(|| {
ui.text(im_str!("Hello world!"));

View File

@ -142,8 +142,7 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
show_example_app_manipulating_window_title(ui);
}
if state.show_app_about {
ui.window()
.name(im_str!("About ImGui"))
ui.window(im_str!("About ImGui"))
.always_auto_resize(true)
.opened(&mut state.show_app_about)
.build(|| {
@ -154,7 +153,7 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
})
}
ui.window().name(im_str!("ImGui Demo"))
ui.window(im_str!("ImGui Demo"))
.title_bar(!state.no_titlebar)
.show_borders(!state.no_border)
.resizable(!state.no_resize)
@ -338,8 +337,7 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
}
fn show_example_app_auto_resize<'a>(ui: &Ui<'a>, state: &mut AutoResizeState, opened: &mut bool) {
ui.window()
.name(im_str!("Example: Auto-resizing window"))
ui.window(im_str!("Example: Auto-resizing window"))
.opened(opened)
.always_auto_resize(true)
.build(|| {
@ -354,8 +352,7 @@ output your content because that would create a feedback loop."));
}
fn show_example_app_fixed_overlay<'a>(ui: &Ui<'a>, opened: &mut bool) {
ui.window()
.name(im_str!("Example: Fixed Overlay"))
ui.window(im_str!("Example: Fixed Overlay"))
.opened(opened)
.bg_alpha(0.3)
.title_bar(false)
@ -371,15 +368,13 @@ fn show_example_app_fixed_overlay<'a>(ui: &Ui<'a>, opened: &mut bool) {
}
fn show_example_app_manipulating_window_title<'a>(ui: &Ui<'a>) {
ui.window()
.name(im_str!("Same title as another window##1"))
ui.window(im_str!("Same title as another window##1"))
.position((100.0, 100.0), ImGuiSetCond_FirstUseEver)
.build(|| {
ui.text(im_str!("This is window 1.
My title is the same as window 2, but my identifier is unique."));
});
ui.window()
.name(im_str!("Same title as another window##2"))
ui.window(im_str!("Same title as another window##2"))
.position((100.0, 200.0), ImGuiSetCond_FirstUseEver)
.build(|| {
ui.text(im_str!("This is window 2.
@ -389,8 +384,7 @@ My title is the same as window 1, but my identifier is unique."));
let ch_idx = (ui.imgui().get_time() / 0.25) as usize & 3;
let num = ui.imgui().get_frame_count(); // The C++ version uses rand() here
let title = im_str!("Animated title {} {}###AnimatedTitle", chars[ch_idx], num);
ui.window()
.name(title)
ui.window(title)
.position((100.0, 300.0), ImGuiSetCond_FirstUseEver)
.build(|| {
ui.text(im_str!("This window has a changing title"));

View File

@ -162,6 +162,7 @@ bitflags!(
const ImGuiWindowFlags_NoSavedSettings = 1 << 8,
const ImGuiWindowFlags_NoInputs = 1 << 9,
const ImGuiWindowFlags_MenuBar = 1 << 10,
const ImGuiWindowFlags_HorizontalScrollbar = 1 << 11,
const ImGuiWindowFlags_ChildWindow = 1 << 20,
const ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 21,
@ -320,7 +321,7 @@ pub struct ImGuiStyle {
pub window_fill_alpha_default: c_float,
pub indent_spacing: c_float,
pub columns_min_spacing: c_float,
pub scrollbar_width: c_float,
pub scrollbar_size: c_float,
pub scrollbar_rounding: c_float,
pub grab_min_size: c_float,
pub grab_rounding: c_float,
@ -328,6 +329,7 @@ pub struct ImGuiStyle {
pub display_safe_area_padding: ImVec2,
pub anti_aliased_lines: bool,
pub anti_aliased_shapes: bool,
pub curve_tessellation_tol: c_float,
pub colors: [ImVec4; ImGuiCol_COUNT]
}
@ -348,6 +350,7 @@ pub struct ImGuiIO {
pub fonts: *mut ImFontAtlas,
pub font_global_scale: c_float,
pub font_allow_user_scaling: bool,
pub display_framebuffer_scale: ImVec2,
pub display_visible_min: ImVec2,
pub display_visible_max: ImVec2,
@ -372,6 +375,7 @@ pub struct ImGuiIO {
pub want_capture_mouse: bool,
pub want_capture_keyboard: bool,
pub want_text_input: bool,
pub framerate: c_float,
pub metrics_allocs: c_int,
pub metrics_render_vertices: c_int,
@ -520,7 +524,8 @@ pub struct ImDrawList {
clip_rect_stack: ImVector<ImVec4>,
texture_id_stack: ImVector<ImTextureID>,
path: ImVector<ImVec2>,
channel_current: c_int,
channels_current: c_int,
channels_count: c_int,
channels: ImVector<ImDrawChannel>
}
@ -625,8 +630,10 @@ extern "C" {
pub fn igEndChild();
pub fn igGetContentRegionMax(out: *mut ImVec2);
pub fn igGetContentRegionAvail(out: *mut ImVec2);
pub fn igGetContentRegionAvailWidth() -> c_float;
pub fn igGetWindowContentRegionMin(out: *mut ImVec2);
pub fn igGetWindowContentRegionMax(out: *mut ImVec2);
pub fn igGetWindowContentRegionWidth() -> c_float;
pub fn igGetWindowDrawList() -> *mut ImDrawList;
pub fn igGetWindowFont() -> *mut ImFont;
pub fn igGetWindowFontSize() -> c_float;
@ -634,11 +641,14 @@ extern "C" {
pub fn igGetWindowPos(out: *mut ImVec2);
pub fn igGetWindowSize(out: *mut ImVec2);
pub fn igGetWindowWidth() -> c_float;
pub fn igGetWindowHeight() -> c_float;
pub fn igIsWindowCollapsed() -> bool;
pub fn igSetNextWindowPos(pos: ImVec2, cond: ImGuiSetCond);
pub fn igSetNextWindowPosCenter(cond: ImGuiSetCond);
pub fn igSetNextWindowSize(size: ImVec2, cond: ImGuiSetCond);
pub fn igSetNextWindowContentSize(size: ImVec2);
pub fn igSetNextWindowContentWidth(width: c_float);
pub fn igSetNextWindowCollapsed(collapsed: bool, cond: ImGuiSetCond);
pub fn igSetNextWindowFocus();
pub fn igSetWindowPos(pos: ImVec2, cond: ImGuiSetCond);
@ -650,8 +660,11 @@ extern "C" {
pub fn igSetWindowCollapsed2(name: *const c_char, collapsed: bool, cond: ImGuiSetCond);
pub fn igSetWindowFocus2(name: *const c_char);
pub fn igGetScrollX() -> c_float;
pub fn igGetScrollY() -> c_float;
pub fn igGetScrollMaxX() -> c_float;
pub fn igGetScrollMaxY() -> c_float;
pub fn igSetScrollX(scroll_x: c_float);
pub fn igSetScrollY(scroll_y: c_float);
pub fn igSetScrollHere(center_y_ratio: c_float);
pub fn igSetScrollFromPosY(pos_y: c_float, center_y_ratio: c_float);
@ -689,7 +702,7 @@ extern "C" {
pub fn igBeginGroup();
pub fn igEndGroup();
pub fn igSeparator();
pub fn igSameLine(pos_x: c_float, spacing_w: c_float);
pub fn igSameLine(local_pos_x: c_float, spacing_w: c_float);
pub fn igSpacing();
pub fn igDummy(size: *const ImVec2);
pub fn igIndent();
@ -704,7 +717,7 @@ extern "C" {
pub fn igGetCursorPos(out: *mut ImVec2);
pub fn igGetCursorPosX() -> c_float;
pub fn igGetCursorPosY() -> c_float;
pub fn igSetCursorPos(pos: ImVec2);
pub fn igSetCursorPos(local_pos: ImVec2);
pub fn igSetCursorPosX(x: c_float);
pub fn igSetCursorPosY(y: c_float);
pub fn igGetCursorStartPos(out: *mut ImVec2);
@ -1020,6 +1033,7 @@ extern "C" {
pub fn igBeginChildFrame(id: ImGuiID, size: ImVec2) -> bool;
pub fn igEndChildFrame();
pub fn igColorConvertU32ToFloat4(out: *mut ImVec4, color: ImU32);
pub fn igColorConvertFloat4ToU32(color: ImVec4) -> ImU32;
pub fn igColorConvertRGBtoHSV(r: c_float, g: c_float, b: c_float,
out_h: *mut c_float, out_s: *mut c_float, out_v: *mut c_float);
@ -1035,9 +1049,10 @@ extern "C" {
pub fn igIsMouseReleased(button: c_int) -> bool;
pub fn igIsMouseHoveringWindow() -> bool;
pub fn igIsMouseHoveringAnyWindow() -> bool;
pub fn igIsMouseHoveringRect(rect_min: ImVec2, rect_max: ImVec2) -> bool;
pub fn igIsMouseHoveringRect(pos_min: ImVec2, pos_max: ImVec2) -> bool;
pub fn igIsMouseDragging(button: c_int, lock_threshold: c_float) -> bool;
pub fn igGetMousePos(out: *mut ImVec2);
pub fn igGetMousePosOnOpeningCurrentPopup(out: *mut ImVec2);
pub fn igGetMouseDragDelta(out: *mut ImVec2, button: c_int, lock_threshold: c_float);
pub fn igResetMouseDragDelta(button: c_int);
pub fn igGetMouseCursor() -> ImGuiMouseCursor;

@ -1 +1 @@
Subproject commit 5d061e7db70f85caa8fa2d6c96263ebe724eff88
Subproject commit 5fe328beaee5d3069886438d2f23872f72fd46b7

View File

@ -33,6 +33,7 @@ pub use imgui_sys::{
ImGuiWindowFlags_NoScrollbar, ImGuiWindowFlags_NoScrollWithMouse, ImGuiWindowFlags_NoCollapse,
ImGuiWindowFlags_AlwaysAutoResize, ImGuiWindowFlags_ShowBorders,
ImGuiWindowFlags_NoSavedSettings, ImGuiWindowFlags_NoInputs, ImGuiWindowFlags_MenuBar,
ImGuiWindowFlags_HorizontalScrollbar,
ImVec2, ImVec4,
ImGuiKey
};
@ -377,7 +378,7 @@ impl<'a> Ui<'a> {
// Window
impl<'ui> Ui<'ui> {
pub fn window<'p>(&self) -> Window<'ui, 'p> { Window::new() }
pub fn window<'p>(&self, name: ImStr<'p>) -> Window<'ui, 'p> { Window::new(name) }
}
// Layout
@ -497,7 +498,7 @@ struct RenderDrawListsState(*mut imgui_sys::ImDrawData);
unsafe impl Sync for RenderDrawListsState {}
static mut RENDER_DRAW_LISTS_STATE: RenderDrawListsState =
RenderDrawListsState(0 as *mut imgui_sys::ImDrawData);
RenderDrawListsState(0 as *mut imgui_sys::ImDrawData);
extern "C" fn render_draw_lists(data: *mut imgui_sys::ImDrawData) {
unsafe {

View File

@ -10,6 +10,7 @@ use super::{
ImGuiWindowFlags_NoScrollbar, ImGuiWindowFlags_NoScrollWithMouse, ImGuiWindowFlags_NoCollapse,
ImGuiWindowFlags_AlwaysAutoResize, ImGuiWindowFlags_ShowBorders,
ImGuiWindowFlags_NoSavedSettings, ImGuiWindowFlags_NoInputs, ImGuiWindowFlags_MenuBar,
ImGuiWindowFlags_HorizontalScrollbar,
ImStr, ImVec2
};
@ -27,13 +28,13 @@ pub struct Window<'ui, 'p> {
}
impl<'ui, 'p> Window<'ui, 'p> {
pub fn new() -> Window<'ui, 'p> {
pub fn new(name: ImStr<'p>) -> Window<'ui, 'p> {
Window {
pos: (0.0, 0.0),
pos_cond: ImGuiSetCond::empty(),
size: (0.0, 0.0),
size_cond: ImGuiSetCond::empty(),
name: unsafe { ImStr::from_bytes_unchecked(b"Debug\0") },
name: name,
opened: None,
bg_alpha: -1.0,
flags: ImGuiWindowFlags::empty(),
@ -57,13 +58,6 @@ impl<'ui, 'p> Window<'ui, 'p> {
}
}
#[inline]
pub fn name(self, name: ImStr<'p>) -> Self {
Window {
name: name,
.. self
}
}
#[inline]
pub fn opened(self, opened: &'p mut bool) -> Self {
Window {
opened: Some(opened),
@ -161,6 +155,13 @@ impl<'ui, 'p> Window<'ui, 'p> {
.. self
}
}
#[inline]
pub fn horizontal_scrollbar(self, value: bool) -> Self {
Window {
flags: self.flags.with(ImGuiWindowFlags_HorizontalScrollbar, value),
.. self
}
}
pub fn build<F: FnOnce()>(self, f: F) {
let render = unsafe {
if !self.pos_cond.is_empty() {