Merge branch 'master' into drawimage

This commit is contained in:
dbr/Ben 2021-03-09 10:27:23 +11:00 committed by GitHub
commit 965dd87892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 3162 additions and 2296 deletions

View File

@ -130,6 +130,7 @@ jobs:
${{ runner.os }}-target-test-${{ matrix.rust }}-${{ hashFiles('**/Cargo.toml') }}
${{ runner.os }}-target-test-${{ matrix.rust }}-
- run: cargo test --workspace --all-targets
- run: cargo test --workspace --doc
# - run: cargo test --manifest-path imgui-gfx-examples/Cargo.toml --no-default-features --features directx
# if: runner.os == 'Windows'
- run: cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-19

View File

@ -2,9 +2,11 @@
## [Unreleased]
- Removed legacy `ImGuiDragDropFlags` from `legacy.rs`, which were accidentally not cleared when they were remade in `drag_drop.rs` in v0.7.0.
- BREAKING: Created `with_x` variants for most functions which previously took multiple parameters where some had default arguments in the C++. This makes calling most functions simpler and more similar to the C++.
- The most likely breaking changes users will see is `button` and `same_line` now take one fewer parameter -- if you were calling `button` with `[0.0, 0.0]`, simply delete that -- otherwise, call `button_with_size`. Similarly, for `same_line`, if you were passing in `0.0.` simply delete that parameter. Otherwise, call `same_line_with_pos`.
- The remaining flags in `imgui::legacy` have been updated to be consistent with other flags in the project.
- BREAKING: Removed `imgui::legacy` which contained the old style of flags. The remaining flags in `imgui::legacy` have been updated to be consistent with other flags in the project.
- `imgui::legacy::ImGuiDragDropFlags` were accidentally not cleared when they were remade in `drag_drop.rs` in v0.7.0.
- `imgui::legacy::ImGuiInputTextFlags` is now `imgui::input_widgets::InputTextFlags`
- `imgui::legacy::ImGuiTreeNodeFlags` is now `imgui::widget::tree::TreeNodeFlags`
- `imgui::legacy::ImDrawListFlags` is now `imgui::draw_list::DrawListFlags`
@ -13,6 +15,13 @@
- The methods are `add_image`, `add_image_quad`, and `add_image_rounded`. The `imgui-examples/examples/custom_textures.rs` has been updated to show their usage.
- Additionally the `imgui::draw_list` module is now public, which contains the various draw list objects. While the `add_*` methods are preferred, `imgui::draw_list::Circle::new(&draw_list_mut, ...).build()` is equivalent
- BREAKING: Most tokens through the repository (eg. `WindowToken`, `TabBarToken`, `FontStackToken`, etc) now allow for permissive dropping -- i.e, you don't need to actually call the `.end()` method on them anymore. In exchange, these tokens have taken on a lifetime, which allows them to be safe. This could make some patterns impossible. Please file an issue if this causes a problem.
- `end()` no longer takes `Ui`. This is a breaking change, but hopefully should be trivial (and perhaps nice) for users to fix. Simply delete the argument, or add a `_` before the token's binding name and allow it to be dropped on its own.
- BREAKING: `PopupModal`'s `new` was reworked so that it didn't take `Ui` until `build` was called. This is a breaking change if you were invoking it directly. Simply move your `ui` call to `build` or `begin`.
- Upgrade to [Dear ImGui v1.81](https://github.com/ocornut/imgui/releases/tag/v1.81)
- BREAKING: `imgui::ListBox::calculate_size(items_count: ..., height_in_items: ...)` has been removed as the function backing it has been marked as obsolete. The recommended approach is to calculate the size yourself and use `.size(...)` (or use the default auto-calculated size)
## [0.7.0] - 2021-02-04

89
docs/upgrading-imgui.md Normal file
View File

@ -0,0 +1,89 @@
# Updating to new imgui versions
This document covers how to upgrade imgui-rs to a new version of the upstream C++ library.
The process is much the same to build imgui-rs for a tagged release (as shown) as it is for any arbitrary revision (such as one on a different branch)
## Step by step
1. Ensure the submodules are populated (`git submodule init` and `git submodule update --recursive`)
2. Check out the desired version of the `imgui-sys/third-party/imgui/` submodule
$ pwd
.../imgui-sys/third-party/imgui
$ git checkout v1.81
Previous HEAD position was 58075c44 Version 1.80
HEAD is now at 4df57136 Version 1.81
3. Ensure `luajit` is installed, as this is required by cimgui's generator.
$ luajit --help
4. Check out the `cimgui` project somewhere, as we use use the generator within this
$ git clone --recursive https://github.com/cimgui/cimgui.git /tmp/cimgui
5. Ensure the `imgui` submodule within `cimgui` is pointing to the same revision as in `imgui-rs`
$ cd /tmp/cimgui/imgui
$ git checkout v1.81
HEAD is now at 4df57136 Version 1.81
6. Back in `imgui-rs/imgui-sys/third-party/` - run the `update-cimgui-output.sh` helper script to execute cimgui's generator
$ pwd
.../imgui-sys/third-party
$ ./update-cimgui-output.sh /tmp/cimgui/
[...]
copyfile ./output/cimgui.h ../cimgui.h
copyfile ./output/cimgui.cpp ../cimgui.cpp
all done!!
This updates various files in the imgui-sys folder like `cimgui.cpp`, `definitions.json` and so on
With this step, we now have new C bindings to the desired verison of Dear ImGui.
7. Back in the root of the imgui-rs repo, run `cargo xtask bindgen`
$ cargo xtask bindgen
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/xtask bindgen`
Executing bindgen [output = .../imgui-rs/imgui-sys/src/bindings.rs]
Success [output = .../imgui-rs/imgui-sys/src/bindings.rs]
Executing bindgen [output = .../imgui-rs/imgui-sys/src/wasm_bindings.rs]
Success [output = .../imgui-rs/imgui-sys/src/wasm_bindings.rs]
This requires bindgen to be installed (`cargo install bindgen` should do it)
This step generates `imgui-sys/src/bindings.rs` which is used by `imgui/src/*`
8. Run `cargo build` and fix any errors from upstream.
9. Run the tests with `cargo test`.
10. Try running one of the examples
cargo run --example test_window_impl
## Common sources of problems
### Function changes
Check the upstream imgui release notes for the new versions, as they detail any breaking changes.
If functions have been renamed, the required changes to the bindings are usually simple.
If functions have been removed, the changes are usually also simple but the implications may require some thought. Note by default `cimgui` generator will exclude any obsolete API.
If new function overloads are added - for example `imgui::Thing()` existed but `imgui::Thing(float)` was added - `bindings.rs` will previously have contained only `igThing`, but will now contain `igThingNil()` and `igThingFloat(...)`
### Memory layout changes
It is common for upstream to add/remove/reorder fields, so the bindings will compile but the memory layout will not match - which will (hopefully) result in the bindings causing a segfault. These are not tagged as breaking changes in the release notes.
The `*_memory_layout` tests when running `cargo test` should catch these (if they are created for every relevant struct!)
The fix for this is usually to compare the struct in (read-only) `imgui-sys/src/bindings.rs` compared to the relevant struct in `imgui/src/...` - the ordering and data-types must match, but the names do not (structs in `imgui/src/...` should use conventional Rust naming/casing)

View File

@ -10,7 +10,7 @@ fn draw_text_centered(
text: &ImStr,
color: [f32; 3],
) {
let text_size = ui.calc_text_size(text, false, 0.0);
let text_size = ui.calc_text_size(text);
let cx = (rect[2] - text_size[0]) / 2.0;
let cy = (rect[3] - text_size[1]) / 2.0;
draw_list.add_text([rect[0] + cx, rect[1] + cy], color, text);
@ -54,7 +54,7 @@ fn main() {
.size([300.0, 110.0], Condition::FirstUseEver)
.scroll_bar(false)
.build(ui, || {
ui.button(im_str!("random button"), [0.0, 0.0]);
ui.button(im_str!("random button"));
let draw_list = ui.get_window_draw_list();
let o = ui.cursor_screen_pos();
let ws = ui.content_region_avail();

View File

@ -27,9 +27,9 @@ fn main() {
ui.text("Hello, I'm Roboto Regular!");
let _dokdo = ui.push_font(dokdo);
ui.text("Hello, I'm Dokdo Regular!");
_dokdo.pop(&ui);
_dokdo.pop();
ui.text("Hello, I'm Roboto Regular again!");
_roboto.pop(&ui);
_roboto.pop();
ui.text("Hello, I'm the default font again!");
});
});

View File

@ -336,11 +336,11 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
ui.push_item_width(-140.0);
ui.text(format!("dear imgui says hello. ({})", imgui::dear_imgui_version()));
if let Some(menu_bar) = ui.begin_menu_bar() {
if let Some(menu) = ui.begin_menu(im_str!("Menu"), true) {
if let Some(menu) = ui.begin_menu(im_str!("Menu")) {
show_example_menu_file(ui, &mut state.file_menu);
menu.end(ui);
menu.end();
}
if let Some(menu) = ui.begin_menu(im_str!("Examples"), true) {
if let Some(menu) = ui.begin_menu(im_str!("Examples")) {
MenuItem::new(im_str!("Main menu bar"))
.build_with_ref(ui, &mut state.show_app_main_menu_bar);
MenuItem::new(im_str!("Console"))
@ -363,18 +363,18 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
.build_with_ref(ui, &mut state.show_app_manipulating_window_title);
MenuItem::new(im_str!("Custom rendering"))
.build_with_ref(ui, &mut state.show_app_custom_rendering);
menu.end(ui);
menu.end();
}
if let Some(menu) = ui.begin_menu(im_str!("Help"), true) {
if let Some(menu) = ui.begin_menu(im_str!("Help")) {
MenuItem::new(im_str!("Metrics"))
.build_with_ref(ui, &mut state.show_app_metrics);
MenuItem::new(im_str!("Style Editor"))
.build_with_ref(ui, &mut state.show_app_style_editor);
MenuItem::new(im_str!("About ImGui"))
.build_with_ref(ui, &mut state.show_app_about);
menu.end(ui);
menu.end();
}
menu_bar.end(ui);
menu_bar.end();
}
ui.spacing();
if CollapsingHeader::new(im_str!("Help")).build(&ui) {
@ -388,14 +388,14 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
if CollapsingHeader::new(im_str!("Window options")).build(&ui) {
ui.checkbox(im_str!("No titlebar"), &mut state.no_titlebar);
ui.same_line(150.0);
ui.same_line_with_pos(150.0);
ui.checkbox(im_str!("No scrollbar"), &mut state.no_scrollbar);
ui.same_line(300.0);
ui.same_line_with_pos(300.0);
ui.checkbox(im_str!("No menu"), &mut state.no_menu);
ui.checkbox(im_str!("No move"), &mut state.no_move);
ui.same_line(150.0);
ui.same_line_with_pos(150.0);
ui.checkbox(im_str!("No resize"), &mut state.no_resize);
ui.same_line(300.0);
ui.same_line_with_pos(300.0);
ui.checkbox(im_str!("No collapse"), &mut state.no_collapse);
ui.checkbox(im_str!("No close"), &mut state.no_close);
@ -408,7 +408,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
for i in 0..5 {
TreeNode::new(&im_str!("Child {}", i)).build(&ui, || {
ui.text(im_str!("blah blah"));
ui.same_line(0.0);
ui.same_line();
if ui.small_button(im_str!("print")) {
println!("Child {} pressed", i);
}
@ -473,9 +473,9 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
});
ui.radio_button(im_str!("radio a"), &mut state.radio_button, 0);
ui.same_line(0.0);
ui.same_line();
ui.radio_button(im_str!("radio b"), &mut state.radio_button, 1);
ui.same_line(0.0);
ui.same_line();
ui.radio_button(im_str!("radio c"), &mut state.radio_button, 2);
ui.separator();
@ -515,7 +515,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
im_str!("Tilefish"),
];
ListBox::new(im_str!("selectables list")).calculate_size(8, 4).build(ui, || {
ListBox::new(im_str!("selectables list")).build(ui, || {
for (index, name) in names.iter().enumerate() {
let selected = matches!(state.selected_fish2, Some(i) if i == index );
if Selectable::new(name).selected(selected).build(ui) {
@ -568,7 +568,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
TreeNode::new(im_str!("Color/Picker Widgets")).build(&ui, || {
let s = &mut state.color_edit;
ui.checkbox(im_str!("With HDR"), &mut s.hdr);
ui.same_line(0.0);
ui.same_line();
show_help_marker(
ui,
"Currently all this does is to lift the 0..1 \
@ -581,7 +581,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
&mut s.alpha_half_preview,
);
ui.checkbox(im_str!("With Options Menu"), &mut s.options_menu);
ui.same_line(0.0);
ui.same_line();
show_help_marker(
ui,
"Right-click on the individual color widget to \
@ -599,7 +599,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
};
ui.text(im_str!("Color widget:"));
ui.same_line(0.0);
ui.same_line();
show_help_marker(
ui,
"Click on the colored square to open a color picker.
@ -623,7 +623,7 @@ CTRL+click on individual component to input value.\n",
.build(ui);
ui.text(im_str!("Color button with Picker:"));
ui.same_line(0.0);
ui.same_line();
show_help_marker(
ui,
"With the inputs(false) function you can hide all \
@ -642,10 +642,10 @@ CTRL+click on individual component to input value.\n",
ui.checkbox(im_str!("With Alpha Bar"), &mut s.alpha_bar);
ui.checkbox(im_str!("With Side Preview"), &mut s.side_preview);
if s.side_preview {
ui.same_line(0.0);
ui.same_line();
ui.checkbox(im_str!("With Ref Color"), &mut s.ref_color);
if s.ref_color {
ui.same_line(0.0);
ui.same_line();
ColorEdit::new(im_str!("##RefColor"), &mut s.ref_color_v)
.flags(misc_flags)
.inputs(false)
@ -703,13 +703,13 @@ CTRL+click on individual component to input value.\n",
}
let style = ui.push_style_var(StyleVar::FramePadding([0.0, 0.0]));
ui.checkbox(im_str!("Artichoke"), &mut s.artichoke_tab);
ui.same_line(0.0);
ui.same_line();
ui.checkbox(im_str!("Beetroot"), &mut s.beetroot_tab);
ui.same_line(0.0);
ui.same_line();
ui.checkbox(im_str!("Celery"), &mut s.celery_tab);
ui.same_line(0.0);
ui.same_line();
ui.checkbox(im_str!("Daikon"), &mut s.daikon_tab);
style.pop(ui);
style.pop();
let flags = {
let mut f = TabBarFlags::empty();
@ -757,7 +757,7 @@ CTRL+click on individual component to input value.\n",
if ui.small_button(im_str!("Select..")) {
ui.open_popup(im_str!("select"));
}
ui.same_line(0.0);
ui.same_line();
ui.text(match state.selected_fish {
Some(index) => names[index],
None => im_str!("<None>"),
@ -779,29 +779,29 @@ CTRL+click on individual component to input value.\n",
them by clicking outside the window."
));
if ui.button(im_str!("Delete.."), [0.0, 0.0]) {
if ui.button(im_str!("Delete..")) {
ui.open_popup(im_str!("Delete?"));
}
ui.popup_modal(im_str!("Delete?")).always_auto_resize(true).build(|| {
PopupModal::new(im_str!("Delete?")).always_auto_resize(true).build(ui, || {
ui.text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n");
ui.separator();
let style = ui.push_style_var(StyleVar::FramePadding([0.0, 0.0]));
ui.checkbox(im_str!("Don't ask me next time"), &mut state.dont_ask_me_next_time);
if ui.button(im_str!("OK"), [120.0, 0.0]) {
if ui.button_with_size(im_str!("OK"), [120.0, 0.0]) {
ui.close_current_popup();
}
ui.same_line(0.0);
if ui.button(im_str!("Cancel"), [120.0, 0.0]) {
ui.same_line();
if ui.button_with_size(im_str!("Cancel"), [120.0, 0.0]) {
ui.close_current_popup();
}
style.pop(ui);
style.pop();
});
if ui.button(im_str!("Stacked modals.."), [0.0, 0.0]) {
if ui.button(im_str!("Stacked modals..")) {
ui.open_popup(im_str!("Stacked 1"));
}
ui.popup_modal(im_str!("Stacked 1")).build(|| {
PopupModal::new(im_str!("Stacked 1")).build(ui, || {
ui.text(
"Hello from Stacked The First\n\
Using style[StyleColor::ModalWindowDarkening] for darkening."
@ -812,17 +812,17 @@ CTRL+click on individual component to input value.\n",
ColorEdit::new(im_str!("color"), &mut state.stacked_modals_color).build(ui);
if ui.button(im_str!("Add another modal.."), [0.0, 0.0]) {
if ui.button(im_str!("Add another modal..")) {
ui.open_popup(im_str!("Stacked 2")) ;
}
ui.popup_modal(im_str!("Stacked 2")).build(|| {
PopupModal::new(im_str!("Stacked 2")).build(ui, || {
ui.text("Hello from Stacked The Second");
if ui.button(im_str!("Close"), [0.0, 0.0]) {
if ui.button(im_str!("Close")) {
ui.close_current_popup();
}
});
if ui.button(im_str!("Close"), [0.0, 0.0]) {
if ui.button(im_str!("Close")) {
ui.close_current_popup();
}
});
@ -833,11 +833,11 @@ CTRL+click on individual component to input value.\n",
fn show_example_app_main_menu_bar<'a>(ui: &Ui<'a>, state: &mut State) {
if let Some(menu_bar) = ui.begin_main_menu_bar() {
if let Some(menu) = ui.begin_menu(im_str!("File"), true) {
if let Some(menu) = ui.begin_menu(im_str!("File")) {
show_example_menu_file(ui, &mut state.file_menu);
menu.end(ui);
menu.end();
}
if let Some(menu) = ui.begin_menu(im_str!("Edit"), true) {
if let Some(menu) = ui.begin_menu(im_str!("Edit")) {
MenuItem::new(im_str!("Undo"))
.shortcut(im_str!("CTRL+Z"))
.build(ui);
@ -855,9 +855,9 @@ fn show_example_app_main_menu_bar<'a>(ui: &Ui<'a>, state: &mut State) {
MenuItem::new(im_str!("Paste"))
.shortcut(im_str!("CTRL+V"))
.build(ui);
menu.end(ui);
menu.end();
}
menu_bar.end(ui);
menu_bar.end();
}
}
@ -869,27 +869,27 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
MenuItem::new(im_str!("Open"))
.shortcut(im_str!("Ctrl+O"))
.build(ui);
if let Some(menu) = ui.begin_menu(im_str!("Open Recent"), true) {
if let Some(menu) = ui.begin_menu(im_str!("Open Recent")) {
MenuItem::new(im_str!("fish_hat.c")).build(ui);
MenuItem::new(im_str!("fish_hat.inl")).build(ui);
MenuItem::new(im_str!("fish_hat.h")).build(ui);
if let Some(menu) = ui.begin_menu(im_str!("More.."), true) {
if let Some(menu) = ui.begin_menu(im_str!("More..")) {
MenuItem::new(im_str!("Hello")).build(ui);
MenuItem::new(im_str!("Sailor")).build(ui);
if let Some(menu) = ui.begin_menu(im_str!("Recurse.."), true) {
if let Some(menu) = ui.begin_menu(im_str!("Recurse..")) {
show_example_menu_file(ui, state);
menu.end(ui);
menu.end();
}
menu.end(ui);
menu.end();
}
menu.end(ui);
menu.end();
}
MenuItem::new(im_str!("Save"))
.shortcut(im_str!("Ctrl+S"))
.build(ui);
MenuItem::new(im_str!("Save As..")).build(ui);
ui.separator();
if let Some(menu) = ui.begin_menu(im_str!("Options"), true) {
if let Some(menu) = ui.begin_menu(im_str!("Options")) {
MenuItem::new(im_str!("Enabled")).build_with_ref(ui, &mut state.enabled);
ChildWindow::new("child")
.size([0.0, 60.0])
@ -909,15 +909,17 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
let items = [im_str!("Yes"), im_str!("No"), im_str!("Maybe")];
ComboBox::new(im_str!("Combo")).build_simple_string(ui, &mut state.n, &items);
ui.checkbox(im_str!("Check"), &mut state.b);
menu.end(ui);
menu.end();
}
if let Some(menu) = ui.begin_menu(im_str!("Colors"), true) {
if let Some(menu) = ui.begin_menu(im_str!("Colors")) {
for &col in StyleColor::VARIANTS.iter() {
MenuItem::new(&im_str!("{:?}", col)).build(ui);
}
menu.end(ui);
menu.end();
}
assert!(ui.begin_menu(im_str!("Disabled"), false).is_none());
assert!(ui
.begin_menu_with_enabled(im_str!("Disabled"), false)
.is_none());
MenuItem::new(im_str!("Checked")).selected(true).build(ui);
MenuItem::new(im_str!("Quit"))
.shortcut(im_str!("Alt+F4"))
@ -966,7 +968,7 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) {
mouse_pos[0], mouse_pos[1]
));
});
style.pop(ui);
style.pop();
}
fn show_example_app_manipulating_window_title(ui: &Ui) {
@ -1132,12 +1134,12 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
ui.separator();
ui.text(im_str!("Canvas example"));
if ui.button(im_str!("Clear"), [0.0, 0.0]) {
if ui.button(im_str!("Clear")) {
state.points.clear();
}
if state.points.len() >= 2 {
ui.same_line(0.0);
if ui.button(im_str!("Undo"), [0.0, 0.0]) {
ui.same_line();
if ui.button(im_str!("Undo")) {
state.points.pop();
state.points.pop();
}
@ -1272,11 +1274,11 @@ fn show_app_log(ui: &Ui, app_log: &mut Vec<String>) {
app_log.push(text);
}
}
if ui.button(im_str!("Clear"), [0.0, 0.0]) {
if ui.button(im_str!("Clear")) {
app_log.clear();
}
ui.same_line(0.0);
if ui.button(im_str!("Copy"), [0.0, 0.0]) {
ui.same_line();
if ui.button(im_str!("Copy")) {
ui.set_clipboard_text(&ImString::from(app_log.join("\n")));
}
ui.separator();

10
imgui-sys/README.markdown Normal file
View File

@ -0,0 +1,10 @@
# imgui-sys: Low level bindings
This crate contains the raw FFI bindings to the Dear ImGui C++
library, by using the [cimgui](https://github.com/cimgui/cimgui) (a C
API wrapper project for Dear ImGui), then creating Rust bindings using
[bindgen](https://github.com/rust-lang/rust-bindgen).
These low level, mostly `unsafe` bindings are then used by `imgui-rs`
which wraps them in a nice to use, mostly safe API. Therefore most
users should not need to interact with this crate directly.

View File

@ -90,6 +90,11 @@ pub struct ImGuiContext {
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ImFontBuilderIO {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ImDrawListSharedData {
_unused: [u8; 0],
}
@ -125,6 +130,7 @@ pub type ImGuiTableFlags = cty::c_int;
pub type ImGuiTableColumnFlags = cty::c_int;
pub type ImGuiTableRowFlags = cty::c_int;
pub type ImGuiTreeNodeFlags = cty::c_int;
pub type ImGuiViewportFlags = cty::c_int;
pub type ImGuiWindowFlags = cty::c_int;
pub type ImTextureID = *mut cty::c_void;
pub type ImGuiID = cty::c_uint;
@ -1293,10 +1299,10 @@ impl Default for ImDrawList {
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct ImDrawData {
pub Valid: bool,
pub CmdLists: *mut *mut ImDrawList,
pub CmdListsCount: cty::c_int,
pub TotalIdxCount: cty::c_int,
pub TotalVtxCount: cty::c_int,
pub CmdLists: *mut *mut ImDrawList,
pub DisplayPos: ImVec2,
pub DisplaySize: ImVec2,
pub FramebufferScale: ImVec2,
@ -1323,7 +1329,7 @@ pub struct ImFontConfig {
pub GlyphMinAdvanceX: f32,
pub GlyphMaxAdvanceX: f32,
pub MergeMode: bool,
pub RasterizerFlags: cty::c_uint,
pub FontBuilderFlags: cty::c_uint,
pub RasterizerMultiply: f32,
pub EllipsisChar: ImWchar,
pub Name: [cty::c_char; 40usize],
@ -1336,7 +1342,7 @@ impl Default for ImFontConfig {
}
impl ::core::fmt::Debug for ImFontConfig {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write ! (f , "ImFontConfig {{ FontData: {:?}, FontDataSize: {:?}, FontDataOwnedByAtlas: {:?}, FontNo: {:?}, SizePixels: {:?}, OversampleH: {:?}, OversampleV: {:?}, PixelSnapH: {:?}, GlyphExtraSpacing: {:?}, GlyphOffset: {:?}, GlyphRanges: {:?}, GlyphMinAdvanceX: {:?}, GlyphMaxAdvanceX: {:?}, MergeMode: {:?}, RasterizerFlags: {:?}, RasterizerMultiply: {:?}, EllipsisChar: {:?}, Name: [...], DstFont: {:?} }}" , self . FontData , self . FontDataSize , self . FontDataOwnedByAtlas , self . FontNo , self . SizePixels , self . OversampleH , self . OversampleV , self . PixelSnapH , self . GlyphExtraSpacing , self . GlyphOffset , self . GlyphRanges , self . GlyphMinAdvanceX , self . GlyphMaxAdvanceX , self . MergeMode , self . RasterizerFlags , self . RasterizerMultiply , self . EllipsisChar , self . DstFont)
write ! (f , "ImFontConfig {{ FontData: {:?}, FontDataSize: {:?}, FontDataOwnedByAtlas: {:?}, FontNo: {:?}, SizePixels: {:?}, OversampleH: {:?}, OversampleV: {:?}, PixelSnapH: {:?}, GlyphExtraSpacing: {:?}, GlyphOffset: {:?}, GlyphRanges: {:?}, GlyphMinAdvanceX: {:?}, GlyphMaxAdvanceX: {:?}, MergeMode: {:?}, FontBuilderFlags: {:?}, RasterizerMultiply: {:?}, EllipsisChar: {:?}, Name: [...], DstFont: {:?} }}" , self . FontData , self . FontDataSize , self . FontDataOwnedByAtlas , self . FontNo , self . SizePixels , self . OversampleH , self . OversampleV , self . PixelSnapH , self . GlyphExtraSpacing , self . GlyphOffset , self . GlyphRanges , self . GlyphMinAdvanceX , self . GlyphMaxAdvanceX , self . MergeMode , self . FontBuilderFlags , self . RasterizerMultiply , self . EllipsisChar , self . DstFont)
}
}
#[repr(C)]
@ -1355,42 +1361,58 @@ pub struct ImFontGlyph {
}
impl ImFontGlyph {
#[inline]
pub fn Codepoint(&self) -> cty::c_uint {
unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) }
pub fn Colored(&self) -> cty::c_uint {
unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) }
}
#[inline]
pub fn set_Codepoint(&mut self, val: cty::c_uint) {
pub fn set_Colored(&mut self, val: cty::c_uint) {
unsafe {
let val: u32 = ::core::mem::transmute(val);
self._bitfield_1.set(0usize, 31u8, val as u64)
self._bitfield_1.set(0usize, 1u8, val as u64)
}
}
#[inline]
pub fn Visible(&self) -> cty::c_uint {
unsafe { ::core::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u32) }
unsafe { ::core::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) }
}
#[inline]
pub fn set_Visible(&mut self, val: cty::c_uint) {
unsafe {
let val: u32 = ::core::mem::transmute(val);
self._bitfield_1.set(31usize, 1u8, val as u64)
self._bitfield_1.set(1usize, 1u8, val as u64)
}
}
#[inline]
pub fn Codepoint(&self) -> cty::c_uint {
unsafe { ::core::mem::transmute(self._bitfield_1.get(2usize, 30u8) as u32) }
}
#[inline]
pub fn set_Codepoint(&mut self, val: cty::c_uint) {
unsafe {
let val: u32 = ::core::mem::transmute(val);
self._bitfield_1.set(2usize, 30u8, val as u64)
}
}
#[inline]
pub fn new_bitfield_1(
Codepoint: cty::c_uint,
Colored: cty::c_uint,
Visible: cty::c_uint,
Codepoint: cty::c_uint,
) -> __BindgenBitfieldUnit<[u8; 4usize], u32> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize], u32> =
Default::default();
__bindgen_bitfield_unit.set(0usize, 31u8, {
let Codepoint: u32 = unsafe { ::core::mem::transmute(Codepoint) };
Codepoint as u64
__bindgen_bitfield_unit.set(0usize, 1u8, {
let Colored: u32 = unsafe { ::core::mem::transmute(Colored) };
Colored as u64
});
__bindgen_bitfield_unit.set(31usize, 1u8, {
__bindgen_bitfield_unit.set(1usize, 1u8, {
let Visible: u32 = unsafe { ::core::mem::transmute(Visible) };
Visible as u64
});
__bindgen_bitfield_unit.set(2usize, 30u8, {
let Codepoint: u32 = unsafe { ::core::mem::transmute(Codepoint) };
Codepoint as u64
});
__bindgen_bitfield_unit
}
}
@ -1444,6 +1466,8 @@ pub struct ImFontAtlas {
pub CustomRects: ImVector_ImFontAtlasCustomRect,
pub ConfigData: ImVector_ImFontConfig,
pub TexUvLines: [ImVec4; 64usize],
pub FontBuilderIO: *const ImFontBuilderIO,
pub FontBuilderFlags: cty::c_uint,
pub PackIdMouseCursors: cty::c_int,
pub PackIdLines: cty::c_int,
}
@ -1454,7 +1478,7 @@ impl Default for ImFontAtlas {
}
impl ::core::fmt::Debug for ImFontAtlas {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write ! (f , "ImFontAtlas {{ Locked: {:?}, Flags: {:?}, TexID: {:?}, TexDesiredWidth: {:?}, TexGlyphPadding: {:?}, TexPixelsAlpha8: {:?}, TexPixelsRGBA32: {:?}, TexWidth: {:?}, TexHeight: {:?}, TexUvScale: {:?}, TexUvWhitePixel: {:?}, Fonts: {:?}, CustomRects: {:?}, ConfigData: {:?}, TexUvLines: [...], PackIdMouseCursors: {:?}, PackIdLines: {:?} }}" , self . Locked , self . Flags , self . TexID , self . TexDesiredWidth , self . TexGlyphPadding , self . TexPixelsAlpha8 , self . TexPixelsRGBA32 , self . TexWidth , self . TexHeight , self . TexUvScale , self . TexUvWhitePixel , self . Fonts , self . CustomRects , self . ConfigData , self . PackIdMouseCursors , self . PackIdLines)
write ! (f , "ImFontAtlas {{ Locked: {:?}, Flags: {:?}, TexID: {:?}, TexDesiredWidth: {:?}, TexGlyphPadding: {:?}, TexPixelsAlpha8: {:?}, TexPixelsRGBA32: {:?}, TexWidth: {:?}, TexHeight: {:?}, TexUvScale: {:?}, TexUvWhitePixel: {:?}, Fonts: {:?}, CustomRects: {:?}, ConfigData: {:?}, TexUvLines: [...], FontBuilderIO: {:?}, FontBuilderFlags: {:?}, PackIdMouseCursors: {:?}, PackIdLines: {:?} }}" , self . Locked , self . Flags , self . TexID , self . TexDesiredWidth , self . TexGlyphPadding , self . TexPixelsAlpha8 , self . TexPixelsRGBA32 , self . TexWidth , self . TexHeight , self . TexUvScale , self . TexUvWhitePixel , self . Fonts , self . CustomRects , self . ConfigData , self . FontBuilderIO , self . FontBuilderFlags , self . PackIdMouseCursors , self . PackIdLines)
}
}
#[repr(C)]
@ -1483,6 +1507,20 @@ impl Default for ImFont {
unsafe { ::core::mem::zeroed() }
}
}
pub const ImGuiViewportFlags_None: ImGuiViewportFlags_ = 0;
pub const ImGuiViewportFlags_IsPlatformWindow: ImGuiViewportFlags_ = 1;
pub const ImGuiViewportFlags_IsPlatformMonitor: ImGuiViewportFlags_ = 2;
pub const ImGuiViewportFlags_OwnedByApp: ImGuiViewportFlags_ = 4;
pub type ImGuiViewportFlags_ = cty::c_uint;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct ImGuiViewport {
pub Flags: ImGuiViewportFlags,
pub Pos: ImVec2,
pub Size: ImVec2,
pub WorkPos: ImVec2,
pub WorkSize: ImVec2,
}
extern "C" {
pub fn ImVec2_ImVec2Nil() -> *mut ImVec2;
}
@ -2542,6 +2580,12 @@ extern "C" {
size: ImVec2,
) -> bool;
}
extern "C" {
pub fn igBeginListBox(label: *const cty::c_char, size: ImVec2) -> bool;
}
extern "C" {
pub fn igEndListBox();
}
extern "C" {
pub fn igListBoxStr_arr(
label: *const cty::c_char,
@ -2567,19 +2611,6 @@ extern "C" {
height_in_items: cty::c_int,
) -> bool;
}
extern "C" {
pub fn igListBoxHeaderVec2(label: *const cty::c_char, size: ImVec2) -> bool;
}
extern "C" {
pub fn igListBoxHeaderInt(
label: *const cty::c_char,
items_count: cty::c_int,
height_in_items: cty::c_int,
) -> bool;
}
extern "C" {
pub fn igListBoxFooter();
}
extern "C" {
pub fn igPlotLinesFloatPtr(
label: *const cty::c_char,
@ -2950,6 +2981,9 @@ extern "C" {
extern "C" {
pub fn igSetItemAllowOverlap();
}
extern "C" {
pub fn igGetMainViewport() -> *mut ImGuiViewport;
}
extern "C" {
pub fn igIsRectVisibleNil(size: ImVec2) -> bool;
}
@ -4228,6 +4262,18 @@ extern "C" {
c_last: cty::c_uint,
) -> bool;
}
extern "C" {
pub fn ImGuiViewport_ImGuiViewport() -> *mut ImGuiViewport;
}
extern "C" {
pub fn ImGuiViewport_destroy(self_: *mut ImGuiViewport);
}
extern "C" {
pub fn ImGuiViewport_GetCenter(pOut: *mut ImVec2, self_: *mut ImGuiViewport);
}
extern "C" {
pub fn ImGuiViewport_GetWorkCenter(pOut: *mut ImVec2, self_: *mut ImGuiViewport);
}
extern "C" {
pub fn igLogText(fmt: *const cty::c_char, ...);
}

View File

@ -90,6 +90,11 @@ pub struct ImGuiContext {
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ImFontBuilderIO {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ImDrawListSharedData {
_unused: [u8; 0],
}
@ -125,6 +130,7 @@ pub type ImGuiTableFlags = cty::c_int;
pub type ImGuiTableColumnFlags = cty::c_int;
pub type ImGuiTableRowFlags = cty::c_int;
pub type ImGuiTreeNodeFlags = cty::c_int;
pub type ImGuiViewportFlags = cty::c_int;
pub type ImGuiWindowFlags = cty::c_int;
pub type ImTextureID = *mut cty::c_void;
pub type ImGuiID = cty::c_uint;
@ -1293,10 +1299,10 @@ impl Default for ImDrawList {
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct ImDrawData {
pub Valid: bool,
pub CmdLists: *mut *mut ImDrawList,
pub CmdListsCount: cty::c_int,
pub TotalIdxCount: cty::c_int,
pub TotalVtxCount: cty::c_int,
pub CmdLists: *mut *mut ImDrawList,
pub DisplayPos: ImVec2,
pub DisplaySize: ImVec2,
pub FramebufferScale: ImVec2,
@ -1323,7 +1329,7 @@ pub struct ImFontConfig {
pub GlyphMinAdvanceX: f32,
pub GlyphMaxAdvanceX: f32,
pub MergeMode: bool,
pub RasterizerFlags: cty::c_uint,
pub FontBuilderFlags: cty::c_uint,
pub RasterizerMultiply: f32,
pub EllipsisChar: ImWchar,
pub Name: [cty::c_char; 40usize],
@ -1336,7 +1342,7 @@ impl Default for ImFontConfig {
}
impl ::core::fmt::Debug for ImFontConfig {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write ! (f , "ImFontConfig {{ FontData: {:?}, FontDataSize: {:?}, FontDataOwnedByAtlas: {:?}, FontNo: {:?}, SizePixels: {:?}, OversampleH: {:?}, OversampleV: {:?}, PixelSnapH: {:?}, GlyphExtraSpacing: {:?}, GlyphOffset: {:?}, GlyphRanges: {:?}, GlyphMinAdvanceX: {:?}, GlyphMaxAdvanceX: {:?}, MergeMode: {:?}, RasterizerFlags: {:?}, RasterizerMultiply: {:?}, EllipsisChar: {:?}, Name: [...], DstFont: {:?} }}" , self . FontData , self . FontDataSize , self . FontDataOwnedByAtlas , self . FontNo , self . SizePixels , self . OversampleH , self . OversampleV , self . PixelSnapH , self . GlyphExtraSpacing , self . GlyphOffset , self . GlyphRanges , self . GlyphMinAdvanceX , self . GlyphMaxAdvanceX , self . MergeMode , self . RasterizerFlags , self . RasterizerMultiply , self . EllipsisChar , self . DstFont)
write ! (f , "ImFontConfig {{ FontData: {:?}, FontDataSize: {:?}, FontDataOwnedByAtlas: {:?}, FontNo: {:?}, SizePixels: {:?}, OversampleH: {:?}, OversampleV: {:?}, PixelSnapH: {:?}, GlyphExtraSpacing: {:?}, GlyphOffset: {:?}, GlyphRanges: {:?}, GlyphMinAdvanceX: {:?}, GlyphMaxAdvanceX: {:?}, MergeMode: {:?}, FontBuilderFlags: {:?}, RasterizerMultiply: {:?}, EllipsisChar: {:?}, Name: [...], DstFont: {:?} }}" , self . FontData , self . FontDataSize , self . FontDataOwnedByAtlas , self . FontNo , self . SizePixels , self . OversampleH , self . OversampleV , self . PixelSnapH , self . GlyphExtraSpacing , self . GlyphOffset , self . GlyphRanges , self . GlyphMinAdvanceX , self . GlyphMaxAdvanceX , self . MergeMode , self . FontBuilderFlags , self . RasterizerMultiply , self . EllipsisChar , self . DstFont)
}
}
#[repr(C)]
@ -1355,42 +1361,58 @@ pub struct ImFontGlyph {
}
impl ImFontGlyph {
#[inline]
pub fn Codepoint(&self) -> cty::c_uint {
unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) }
pub fn Colored(&self) -> cty::c_uint {
unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) }
}
#[inline]
pub fn set_Codepoint(&mut self, val: cty::c_uint) {
pub fn set_Colored(&mut self, val: cty::c_uint) {
unsafe {
let val: u32 = ::core::mem::transmute(val);
self._bitfield_1.set(0usize, 31u8, val as u64)
self._bitfield_1.set(0usize, 1u8, val as u64)
}
}
#[inline]
pub fn Visible(&self) -> cty::c_uint {
unsafe { ::core::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u32) }
unsafe { ::core::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) }
}
#[inline]
pub fn set_Visible(&mut self, val: cty::c_uint) {
unsafe {
let val: u32 = ::core::mem::transmute(val);
self._bitfield_1.set(31usize, 1u8, val as u64)
self._bitfield_1.set(1usize, 1u8, val as u64)
}
}
#[inline]
pub fn Codepoint(&self) -> cty::c_uint {
unsafe { ::core::mem::transmute(self._bitfield_1.get(2usize, 30u8) as u32) }
}
#[inline]
pub fn set_Codepoint(&mut self, val: cty::c_uint) {
unsafe {
let val: u32 = ::core::mem::transmute(val);
self._bitfield_1.set(2usize, 30u8, val as u64)
}
}
#[inline]
pub fn new_bitfield_1(
Codepoint: cty::c_uint,
Colored: cty::c_uint,
Visible: cty::c_uint,
Codepoint: cty::c_uint,
) -> __BindgenBitfieldUnit<[u8; 4usize], u32> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize], u32> =
Default::default();
__bindgen_bitfield_unit.set(0usize, 31u8, {
let Codepoint: u32 = unsafe { ::core::mem::transmute(Codepoint) };
Codepoint as u64
__bindgen_bitfield_unit.set(0usize, 1u8, {
let Colored: u32 = unsafe { ::core::mem::transmute(Colored) };
Colored as u64
});
__bindgen_bitfield_unit.set(31usize, 1u8, {
__bindgen_bitfield_unit.set(1usize, 1u8, {
let Visible: u32 = unsafe { ::core::mem::transmute(Visible) };
Visible as u64
});
__bindgen_bitfield_unit.set(2usize, 30u8, {
let Codepoint: u32 = unsafe { ::core::mem::transmute(Codepoint) };
Codepoint as u64
});
__bindgen_bitfield_unit
}
}
@ -1444,6 +1466,8 @@ pub struct ImFontAtlas {
pub CustomRects: ImVector_ImFontAtlasCustomRect,
pub ConfigData: ImVector_ImFontConfig,
pub TexUvLines: [ImVec4; 64usize],
pub FontBuilderIO: *const ImFontBuilderIO,
pub FontBuilderFlags: cty::c_uint,
pub PackIdMouseCursors: cty::c_int,
pub PackIdLines: cty::c_int,
}
@ -1454,7 +1478,7 @@ impl Default for ImFontAtlas {
}
impl ::core::fmt::Debug for ImFontAtlas {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write ! (f , "ImFontAtlas {{ Locked: {:?}, Flags: {:?}, TexID: {:?}, TexDesiredWidth: {:?}, TexGlyphPadding: {:?}, TexPixelsAlpha8: {:?}, TexPixelsRGBA32: {:?}, TexWidth: {:?}, TexHeight: {:?}, TexUvScale: {:?}, TexUvWhitePixel: {:?}, Fonts: {:?}, CustomRects: {:?}, ConfigData: {:?}, TexUvLines: [...], PackIdMouseCursors: {:?}, PackIdLines: {:?} }}" , self . Locked , self . Flags , self . TexID , self . TexDesiredWidth , self . TexGlyphPadding , self . TexPixelsAlpha8 , self . TexPixelsRGBA32 , self . TexWidth , self . TexHeight , self . TexUvScale , self . TexUvWhitePixel , self . Fonts , self . CustomRects , self . ConfigData , self . PackIdMouseCursors , self . PackIdLines)
write ! (f , "ImFontAtlas {{ Locked: {:?}, Flags: {:?}, TexID: {:?}, TexDesiredWidth: {:?}, TexGlyphPadding: {:?}, TexPixelsAlpha8: {:?}, TexPixelsRGBA32: {:?}, TexWidth: {:?}, TexHeight: {:?}, TexUvScale: {:?}, TexUvWhitePixel: {:?}, Fonts: {:?}, CustomRects: {:?}, ConfigData: {:?}, TexUvLines: [...], FontBuilderIO: {:?}, FontBuilderFlags: {:?}, PackIdMouseCursors: {:?}, PackIdLines: {:?} }}" , self . Locked , self . Flags , self . TexID , self . TexDesiredWidth , self . TexGlyphPadding , self . TexPixelsAlpha8 , self . TexPixelsRGBA32 , self . TexWidth , self . TexHeight , self . TexUvScale , self . TexUvWhitePixel , self . Fonts , self . CustomRects , self . ConfigData , self . FontBuilderIO , self . FontBuilderFlags , self . PackIdMouseCursors , self . PackIdLines)
}
}
#[repr(C)]
@ -1483,6 +1507,20 @@ impl Default for ImFont {
unsafe { ::core::mem::zeroed() }
}
}
pub const ImGuiViewportFlags_None: ImGuiViewportFlags_ = 0;
pub const ImGuiViewportFlags_IsPlatformWindow: ImGuiViewportFlags_ = 1;
pub const ImGuiViewportFlags_IsPlatformMonitor: ImGuiViewportFlags_ = 2;
pub const ImGuiViewportFlags_OwnedByApp: ImGuiViewportFlags_ = 4;
pub type ImGuiViewportFlags_ = cty::c_uint;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct ImGuiViewport {
pub Flags: ImGuiViewportFlags,
pub Pos: ImVec2,
pub Size: ImVec2,
pub WorkPos: ImVec2,
pub WorkSize: ImVec2,
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn ImVec2_ImVec2Nil() -> *mut ImVec2;
@ -2757,6 +2795,14 @@ extern "C" {
) -> bool;
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igBeginListBox(label: *const cty::c_char, size: ImVec2) -> bool;
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igEndListBox();
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igListBoxStr_arr(
label: *const cty::c_char,
@ -2784,22 +2830,6 @@ extern "C" {
) -> bool;
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igListBoxHeaderVec2(label: *const cty::c_char, size: ImVec2) -> bool;
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igListBoxHeaderInt(
label: *const cty::c_char,
items_count: cty::c_int,
height_in_items: cty::c_int,
) -> bool;
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igListBoxFooter();
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igPlotLinesFloatPtr(
label: *const cty::c_char,
@ -3262,6 +3292,10 @@ extern "C" {
pub fn igSetItemAllowOverlap();
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igGetMainViewport() -> *mut ImGuiViewport;
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igIsRectVisibleNil(size: ImVec2) -> bool;
}
@ -4808,6 +4842,22 @@ extern "C" {
) -> bool;
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn ImGuiViewport_ImGuiViewport() -> *mut ImGuiViewport;
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn ImGuiViewport_destroy(self_: *mut ImGuiViewport);
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn ImGuiViewport_GetCenter(pOut: *mut ImVec2, self_: *mut ImGuiViewport);
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn ImGuiViewport_GetWorkCenter(pOut: *mut ImVec2, self_: *mut ImGuiViewport);
}
#[link(wasm_import_module = "imgui-sys-v0")]
extern "C" {
pub fn igLogText(fmt: *const cty::c_char, ...);
}

View File

@ -1,5 +1,5 @@
//This file is automatically generated by generator.lua from https://github.com/cimgui/cimgui
//based on imgui.h file version "1.80" from Dear ImGui https://github.com/ocornut/imgui
//based on imgui.h file version "1.81" from Dear ImGui https://github.com/ocornut/imgui
#include "./imgui/imgui.h"
#ifdef CIMGUI_FREETYPE
@ -940,6 +940,14 @@ CIMGUI_API bool igSelectableBoolPtr(const char* label,bool* p_selected,ImGuiSele
{
return ImGui::Selectable(label,p_selected,flags,size);
}
CIMGUI_API bool igBeginListBox(const char* label,const ImVec2 size)
{
return ImGui::BeginListBox(label,size);
}
CIMGUI_API void igEndListBox()
{
return ImGui::EndListBox();
}
CIMGUI_API bool igListBoxStr_arr(const char* label,int* current_item,const char* const items[],int items_count,int height_in_items)
{
return ImGui::ListBox(label,current_item,items,items_count,height_in_items);
@ -948,18 +956,6 @@ CIMGUI_API bool igListBoxFnBoolPtr(const char* label,int* current_item,bool(*ite
{
return ImGui::ListBox(label,current_item,items_getter,data,items_count,height_in_items);
}
CIMGUI_API bool igListBoxHeaderVec2(const char* label,const ImVec2 size)
{
return ImGui::ListBoxHeader(label,size);
}
CIMGUI_API bool igListBoxHeaderInt(const char* label,int items_count,int height_in_items)
{
return ImGui::ListBoxHeader(label,items_count,height_in_items);
}
CIMGUI_API void igListBoxFooter()
{
return ImGui::ListBoxFooter();
}
CIMGUI_API void igPlotLinesFloatPtr(const char* label,const float* values,int values_count,int values_offset,const char* overlay_text,float scale_min,float scale_max,ImVec2 graph_size,int stride)
{
return ImGui::PlotLines(label,values,values_count,values_offset,overlay_text,scale_min,scale_max,graph_size,stride);
@ -1335,6 +1331,10 @@ CIMGUI_API void igSetItemAllowOverlap()
{
return ImGui::SetItemAllowOverlap();
}
CIMGUI_API ImGuiViewport* igGetMainViewport()
{
return ImGui::GetMainViewport();
}
CIMGUI_API bool igIsRectVisibleNil(const ImVec2 size)
{
return ImGui::IsRectVisible(size);
@ -2411,6 +2411,22 @@ CIMGUI_API bool ImFont_IsGlyphRangeUnused(ImFont* self,unsigned int c_begin,unsi
{
return self->IsGlyphRangeUnused(c_begin,c_last);
}
CIMGUI_API ImGuiViewport* ImGuiViewport_ImGuiViewport(void)
{
return IM_NEW(ImGuiViewport)();
}
CIMGUI_API void ImGuiViewport_destroy(ImGuiViewport* self)
{
IM_DELETE(self);
}
CIMGUI_API void ImGuiViewport_GetCenter(ImVec2 *pOut,ImGuiViewport* self)
{
*pOut = self->GetCenter();
}
CIMGUI_API void ImGuiViewport_GetWorkCenter(ImVec2 *pOut,ImGuiViewport* self)
{
*pOut = self->GetWorkCenter();
}

View File

@ -1,5 +1,5 @@
//This file is automatically generated by generator.lua from https://github.com/cimgui/cimgui
//based on imgui.h file version "1.80" from Dear ImGui https://github.com/ocornut/imgui
//based on imgui.h file version "1.81" from Dear ImGui https://github.com/ocornut/imgui
#ifndef CIMGUI_INCLUDED
#define CIMGUI_INCLUDED
#include <stdio.h>
@ -47,6 +47,7 @@ typedef struct ImGuiStoragePair ImGuiStoragePair;
typedef struct ImGuiTextRange ImGuiTextRange;
typedef struct ImVec4 ImVec4;
typedef struct ImVec2 ImVec2;
typedef struct ImGuiViewport ImGuiViewport;
typedef struct ImGuiTextFilter ImGuiTextFilter;
typedef struct ImGuiTextBuffer ImGuiTextBuffer;
typedef struct ImGuiTableColumnSortSpecs ImGuiTableColumnSortSpecs;
@ -64,6 +65,7 @@ typedef struct ImColor ImColor;
typedef struct ImFontGlyphRangesBuilder ImFontGlyphRangesBuilder;
typedef struct ImFontGlyph ImFontGlyph;
typedef struct ImFontConfig ImFontConfig;
typedef struct ImFontBuilderIO ImFontBuilderIO;
typedef struct ImFontAtlas ImFontAtlas;
typedef struct ImFont ImFont;
typedef struct ImDrawVert ImDrawVert;
@ -83,6 +85,7 @@ struct ImDrawListSplitter;
struct ImDrawVert;
struct ImFont;
struct ImFontAtlas;
struct ImFontBuilderIO;
struct ImFontConfig;
struct ImFontGlyph;
struct ImFontGlyphRangesBuilder;
@ -100,6 +103,7 @@ struct ImGuiTableSortSpecs;
struct ImGuiTableColumnSortSpecs;
struct ImGuiTextBuffer;
struct ImGuiTextFilter;
struct ImGuiViewport;
typedef int ImGuiCol;
typedef int ImGuiCond;
typedef int ImGuiDataType;
@ -133,6 +137,7 @@ typedef int ImGuiTableFlags;
typedef int ImGuiTableColumnFlags;
typedef int ImGuiTableRowFlags;
typedef int ImGuiTreeNodeFlags;
typedef int ImGuiViewportFlags;
typedef int ImGuiWindowFlags;
typedef void* ImTextureID;
typedef unsigned int ImGuiID;
@ -960,10 +965,10 @@ struct ImDrawList
struct ImDrawData
{
bool Valid;
ImDrawList** CmdLists;
int CmdListsCount;
int TotalIdxCount;
int TotalVtxCount;
ImDrawList** CmdLists;
ImVec2 DisplayPos;
ImVec2 DisplaySize;
ImVec2 FramebufferScale;
@ -984,7 +989,7 @@ struct ImFontConfig
float GlyphMinAdvanceX;
float GlyphMaxAdvanceX;
bool MergeMode;
unsigned int RasterizerFlags;
unsigned int FontBuilderFlags;
float RasterizerMultiply;
ImWchar EllipsisChar;
char Name[40];
@ -992,8 +997,9 @@ struct ImFontConfig
};
struct ImFontGlyph
{
unsigned int Codepoint : 31;
unsigned int Colored : 1;
unsigned int Visible : 1;
unsigned int Codepoint : 30;
float AdvanceX;
float X0, Y0, X1, Y1;
float U0, V0, U1, V1;
@ -1034,6 +1040,8 @@ struct ImFontAtlas
ImVector_ImFontAtlasCustomRect CustomRects;
ImVector_ImFontConfig ConfigData;
ImVec4 TexUvLines[(63) + 1];
const ImFontBuilderIO* FontBuilderIO;
unsigned int FontBuilderFlags;
int PackIdMouseCursors;
int PackIdLines;
};
@ -1056,6 +1064,20 @@ struct ImFont
int MetricsTotalSurface;
ImU8 Used4kPagesMap[(0xFFFF +1)/4096/8];
};
typedef enum {
ImGuiViewportFlags_None = 0,
ImGuiViewportFlags_IsPlatformWindow = 1 << 0,
ImGuiViewportFlags_IsPlatformMonitor = 1 << 1,
ImGuiViewportFlags_OwnedByApp = 1 << 2
}ImGuiViewportFlags_;
struct ImGuiViewport
{
ImGuiViewportFlags Flags;
ImVec2 Pos;
ImVec2 Size;
ImVec2 WorkPos;
ImVec2 WorkSize;
};
#else
struct GLFWwindow;
struct SDL_Window;
@ -1307,11 +1329,10 @@ CIMGUI_API bool igCollapsingHeaderBoolPtr(const char* label,bool* p_visible,ImGu
CIMGUI_API void igSetNextItemOpen(bool is_open,ImGuiCond cond);
CIMGUI_API bool igSelectableBool(const char* label,bool selected,ImGuiSelectableFlags flags,const ImVec2 size);
CIMGUI_API bool igSelectableBoolPtr(const char* label,bool* p_selected,ImGuiSelectableFlags flags,const ImVec2 size);
CIMGUI_API bool igBeginListBox(const char* label,const ImVec2 size);
CIMGUI_API void igEndListBox(void);
CIMGUI_API bool igListBoxStr_arr(const char* label,int* current_item,const char* const items[],int items_count,int height_in_items);
CIMGUI_API bool igListBoxFnBoolPtr(const char* label,int* current_item,bool(*items_getter)(void* data,int idx,const char** out_text),void* data,int items_count,int height_in_items);
CIMGUI_API bool igListBoxHeaderVec2(const char* label,const ImVec2 size);
CIMGUI_API bool igListBoxHeaderInt(const char* label,int items_count,int height_in_items);
CIMGUI_API void igListBoxFooter(void);
CIMGUI_API void igPlotLinesFloatPtr(const char* label,const float* values,int values_count,int values_offset,const char* overlay_text,float scale_min,float scale_max,ImVec2 graph_size,int stride);
CIMGUI_API void igPlotLinesFnFloatPtr(const char* label,float(*values_getter)(void* data,int idx),void* data,int values_count,int values_offset,const char* overlay_text,float scale_min,float scale_max,ImVec2 graph_size);
CIMGUI_API void igPlotHistogramFloatPtr(const char* label,const float* values,int values_count,int values_offset,const char* overlay_text,float scale_min,float scale_max,ImVec2 graph_size,int stride);
@ -1405,6 +1426,7 @@ CIMGUI_API void igGetItemRectMin(ImVec2 *pOut);
CIMGUI_API void igGetItemRectMax(ImVec2 *pOut);
CIMGUI_API void igGetItemRectSize(ImVec2 *pOut);
CIMGUI_API void igSetItemAllowOverlap(void);
CIMGUI_API ImGuiViewport* igGetMainViewport(void);
CIMGUI_API bool igIsRectVisibleNil(const ImVec2 size);
CIMGUI_API bool igIsRectVisibleVec2(const ImVec2 rect_min,const ImVec2 rect_max);
CIMGUI_API double igGetTime(void);
@ -1674,6 +1696,10 @@ CIMGUI_API void ImFont_AddRemapChar(ImFont* self,ImWchar dst,ImWchar src,bool ov
CIMGUI_API void ImFont_SetGlyphVisible(ImFont* self,ImWchar c,bool visible);
CIMGUI_API void ImFont_SetFallbackChar(ImFont* self,ImWchar c);
CIMGUI_API bool ImFont_IsGlyphRangeUnused(ImFont* self,unsigned int c_begin,unsigned int c_last);
CIMGUI_API ImGuiViewport* ImGuiViewport_ImGuiViewport(void);
CIMGUI_API void ImGuiViewport_destroy(ImGuiViewport* self);
CIMGUI_API void ImGuiViewport_GetCenter(ImVec2 *pOut,ImGuiViewport* self);
CIMGUI_API void ImGuiViewport_GetWorkCenter(ImVec2 *pOut,ImGuiViewport* self);
/////////////////////////hand written functions

View File

@ -6,6 +6,7 @@ struct GLFWwindow;
struct SDL_Window;
typedef union SDL_Event SDL_Event;CIMGUI_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window,bool install_callbacks);
CIMGUI_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window,bool install_callbacks);
CIMGUI_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window,bool install_callbacks);
CIMGUI_API void ImGui_ImplGlfw_Shutdown();
CIMGUI_API void ImGui_ImplGlfw_NewFrame();
CIMGUI_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window,int button,int action,int mods);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit 58075c4414b985b352d10718b02a8c43f25efd7c
Subproject commit 4df57136e9832327c11e48b5bfe00b0326bd5b63

View File

@ -17,7 +17,7 @@
"cimguiname": "ImGui_ImplGlfw_CharCallback",
"defaults": {},
"funcname": "ImGui_ImplGlfw_CharCallback",
"location": "imgui_impl_glfw:35",
"location": "imgui_impl_glfw:36",
"ov_cimguiname": "ImGui_ImplGlfw_CharCallback",
"ret": "void",
"signature": "(GLFWwindow*,unsigned int)",
@ -49,6 +49,31 @@
"stname": ""
}
],
"ImGui_ImplGlfw_InitForOther": [
{
"args": "(GLFWwindow* window,bool install_callbacks)",
"argsT": [
{
"name": "window",
"type": "GLFWwindow*"
},
{
"name": "install_callbacks",
"type": "bool"
}
],
"argsoriginal": "(GLFWwindow* window,bool install_callbacks)",
"call_args": "(window,install_callbacks)",
"cimguiname": "ImGui_ImplGlfw_InitForOther",
"defaults": {},
"funcname": "ImGui_ImplGlfw_InitForOther",
"location": "imgui_impl_glfw:26",
"ov_cimguiname": "ImGui_ImplGlfw_InitForOther",
"ret": "bool",
"signature": "(GLFWwindow*,bool)",
"stname": ""
}
],
"ImGui_ImplGlfw_InitForVulkan": [
{
"args": "(GLFWwindow* window,bool install_callbacks)",
@ -104,7 +129,7 @@
"cimguiname": "ImGui_ImplGlfw_KeyCallback",
"defaults": {},
"funcname": "ImGui_ImplGlfw_KeyCallback",
"location": "imgui_impl_glfw:34",
"location": "imgui_impl_glfw:35",
"ov_cimguiname": "ImGui_ImplGlfw_KeyCallback",
"ret": "void",
"signature": "(GLFWwindow*,int,int,int,int)",
@ -137,7 +162,7 @@
"cimguiname": "ImGui_ImplGlfw_MouseButtonCallback",
"defaults": {},
"funcname": "ImGui_ImplGlfw_MouseButtonCallback",
"location": "imgui_impl_glfw:32",
"location": "imgui_impl_glfw:33",
"ov_cimguiname": "ImGui_ImplGlfw_MouseButtonCallback",
"ret": "void",
"signature": "(GLFWwindow*,int,int,int)",
@ -153,7 +178,7 @@
"cimguiname": "ImGui_ImplGlfw_NewFrame",
"defaults": {},
"funcname": "ImGui_ImplGlfw_NewFrame",
"location": "imgui_impl_glfw:27",
"location": "imgui_impl_glfw:28",
"ov_cimguiname": "ImGui_ImplGlfw_NewFrame",
"ret": "void",
"signature": "()",
@ -182,7 +207,7 @@
"cimguiname": "ImGui_ImplGlfw_ScrollCallback",
"defaults": {},
"funcname": "ImGui_ImplGlfw_ScrollCallback",
"location": "imgui_impl_glfw:33",
"location": "imgui_impl_glfw:34",
"ov_cimguiname": "ImGui_ImplGlfw_ScrollCallback",
"ret": "void",
"signature": "(GLFWwindow*,double,double)",
@ -198,7 +223,7 @@
"cimguiname": "ImGui_ImplGlfw_Shutdown",
"defaults": {},
"funcname": "ImGui_ImplGlfw_Shutdown",
"location": "imgui_impl_glfw:26",
"location": "imgui_impl_glfw:27",
"ov_cimguiname": "ImGui_ImplGlfw_Shutdown",
"ret": "void",
"signature": "()",

View File

@ -14,7 +14,7 @@ defs["ImGui_ImplGlfw_CharCallback"][1]["call_args"] = "(window,c)"
defs["ImGui_ImplGlfw_CharCallback"][1]["cimguiname"] = "ImGui_ImplGlfw_CharCallback"
defs["ImGui_ImplGlfw_CharCallback"][1]["defaults"] = {}
defs["ImGui_ImplGlfw_CharCallback"][1]["funcname"] = "ImGui_ImplGlfw_CharCallback"
defs["ImGui_ImplGlfw_CharCallback"][1]["location"] = "imgui_impl_glfw:35"
defs["ImGui_ImplGlfw_CharCallback"][1]["location"] = "imgui_impl_glfw:36"
defs["ImGui_ImplGlfw_CharCallback"][1]["ov_cimguiname"] = "ImGui_ImplGlfw_CharCallback"
defs["ImGui_ImplGlfw_CharCallback"][1]["ret"] = "void"
defs["ImGui_ImplGlfw_CharCallback"][1]["signature"] = "(GLFWwindow*,unsigned int)"
@ -41,6 +41,27 @@ defs["ImGui_ImplGlfw_InitForOpenGL"][1]["ret"] = "bool"
defs["ImGui_ImplGlfw_InitForOpenGL"][1]["signature"] = "(GLFWwindow*,bool)"
defs["ImGui_ImplGlfw_InitForOpenGL"][1]["stname"] = ""
defs["ImGui_ImplGlfw_InitForOpenGL"]["(GLFWwindow*,bool)"] = defs["ImGui_ImplGlfw_InitForOpenGL"][1]
defs["ImGui_ImplGlfw_InitForOther"] = {}
defs["ImGui_ImplGlfw_InitForOther"][1] = {}
defs["ImGui_ImplGlfw_InitForOther"][1]["args"] = "(GLFWwindow* window,bool install_callbacks)"
defs["ImGui_ImplGlfw_InitForOther"][1]["argsT"] = {}
defs["ImGui_ImplGlfw_InitForOther"][1]["argsT"][1] = {}
defs["ImGui_ImplGlfw_InitForOther"][1]["argsT"][1]["name"] = "window"
defs["ImGui_ImplGlfw_InitForOther"][1]["argsT"][1]["type"] = "GLFWwindow*"
defs["ImGui_ImplGlfw_InitForOther"][1]["argsT"][2] = {}
defs["ImGui_ImplGlfw_InitForOther"][1]["argsT"][2]["name"] = "install_callbacks"
defs["ImGui_ImplGlfw_InitForOther"][1]["argsT"][2]["type"] = "bool"
defs["ImGui_ImplGlfw_InitForOther"][1]["argsoriginal"] = "(GLFWwindow* window,bool install_callbacks)"
defs["ImGui_ImplGlfw_InitForOther"][1]["call_args"] = "(window,install_callbacks)"
defs["ImGui_ImplGlfw_InitForOther"][1]["cimguiname"] = "ImGui_ImplGlfw_InitForOther"
defs["ImGui_ImplGlfw_InitForOther"][1]["defaults"] = {}
defs["ImGui_ImplGlfw_InitForOther"][1]["funcname"] = "ImGui_ImplGlfw_InitForOther"
defs["ImGui_ImplGlfw_InitForOther"][1]["location"] = "imgui_impl_glfw:26"
defs["ImGui_ImplGlfw_InitForOther"][1]["ov_cimguiname"] = "ImGui_ImplGlfw_InitForOther"
defs["ImGui_ImplGlfw_InitForOther"][1]["ret"] = "bool"
defs["ImGui_ImplGlfw_InitForOther"][1]["signature"] = "(GLFWwindow*,bool)"
defs["ImGui_ImplGlfw_InitForOther"][1]["stname"] = ""
defs["ImGui_ImplGlfw_InitForOther"]["(GLFWwindow*,bool)"] = defs["ImGui_ImplGlfw_InitForOther"][1]
defs["ImGui_ImplGlfw_InitForVulkan"] = {}
defs["ImGui_ImplGlfw_InitForVulkan"][1] = {}
defs["ImGui_ImplGlfw_InitForVulkan"][1]["args"] = "(GLFWwindow* window,bool install_callbacks)"
@ -86,7 +107,7 @@ defs["ImGui_ImplGlfw_KeyCallback"][1]["call_args"] = "(window,key,scancode,actio
defs["ImGui_ImplGlfw_KeyCallback"][1]["cimguiname"] = "ImGui_ImplGlfw_KeyCallback"
defs["ImGui_ImplGlfw_KeyCallback"][1]["defaults"] = {}
defs["ImGui_ImplGlfw_KeyCallback"][1]["funcname"] = "ImGui_ImplGlfw_KeyCallback"
defs["ImGui_ImplGlfw_KeyCallback"][1]["location"] = "imgui_impl_glfw:34"
defs["ImGui_ImplGlfw_KeyCallback"][1]["location"] = "imgui_impl_glfw:35"
defs["ImGui_ImplGlfw_KeyCallback"][1]["ov_cimguiname"] = "ImGui_ImplGlfw_KeyCallback"
defs["ImGui_ImplGlfw_KeyCallback"][1]["ret"] = "void"
defs["ImGui_ImplGlfw_KeyCallback"][1]["signature"] = "(GLFWwindow*,int,int,int,int)"
@ -113,7 +134,7 @@ defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["call_args"] = "(window,button,act
defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["cimguiname"] = "ImGui_ImplGlfw_MouseButtonCallback"
defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["defaults"] = {}
defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["funcname"] = "ImGui_ImplGlfw_MouseButtonCallback"
defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["location"] = "imgui_impl_glfw:32"
defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["location"] = "imgui_impl_glfw:33"
defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["ov_cimguiname"] = "ImGui_ImplGlfw_MouseButtonCallback"
defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["ret"] = "void"
defs["ImGui_ImplGlfw_MouseButtonCallback"][1]["signature"] = "(GLFWwindow*,int,int,int)"
@ -128,7 +149,7 @@ defs["ImGui_ImplGlfw_NewFrame"][1]["call_args"] = "()"
defs["ImGui_ImplGlfw_NewFrame"][1]["cimguiname"] = "ImGui_ImplGlfw_NewFrame"
defs["ImGui_ImplGlfw_NewFrame"][1]["defaults"] = {}
defs["ImGui_ImplGlfw_NewFrame"][1]["funcname"] = "ImGui_ImplGlfw_NewFrame"
defs["ImGui_ImplGlfw_NewFrame"][1]["location"] = "imgui_impl_glfw:27"
defs["ImGui_ImplGlfw_NewFrame"][1]["location"] = "imgui_impl_glfw:28"
defs["ImGui_ImplGlfw_NewFrame"][1]["ov_cimguiname"] = "ImGui_ImplGlfw_NewFrame"
defs["ImGui_ImplGlfw_NewFrame"][1]["ret"] = "void"
defs["ImGui_ImplGlfw_NewFrame"][1]["signature"] = "()"
@ -152,7 +173,7 @@ defs["ImGui_ImplGlfw_ScrollCallback"][1]["call_args"] = "(window,xoffset,yoffset
defs["ImGui_ImplGlfw_ScrollCallback"][1]["cimguiname"] = "ImGui_ImplGlfw_ScrollCallback"
defs["ImGui_ImplGlfw_ScrollCallback"][1]["defaults"] = {}
defs["ImGui_ImplGlfw_ScrollCallback"][1]["funcname"] = "ImGui_ImplGlfw_ScrollCallback"
defs["ImGui_ImplGlfw_ScrollCallback"][1]["location"] = "imgui_impl_glfw:33"
defs["ImGui_ImplGlfw_ScrollCallback"][1]["location"] = "imgui_impl_glfw:34"
defs["ImGui_ImplGlfw_ScrollCallback"][1]["ov_cimguiname"] = "ImGui_ImplGlfw_ScrollCallback"
defs["ImGui_ImplGlfw_ScrollCallback"][1]["ret"] = "void"
defs["ImGui_ImplGlfw_ScrollCallback"][1]["signature"] = "(GLFWwindow*,double,double)"
@ -167,7 +188,7 @@ defs["ImGui_ImplGlfw_Shutdown"][1]["call_args"] = "()"
defs["ImGui_ImplGlfw_Shutdown"][1]["cimguiname"] = "ImGui_ImplGlfw_Shutdown"
defs["ImGui_ImplGlfw_Shutdown"][1]["defaults"] = {}
defs["ImGui_ImplGlfw_Shutdown"][1]["funcname"] = "ImGui_ImplGlfw_Shutdown"
defs["ImGui_ImplGlfw_Shutdown"][1]["location"] = "imgui_impl_glfw:26"
defs["ImGui_ImplGlfw_Shutdown"][1]["location"] = "imgui_impl_glfw:27"
defs["ImGui_ImplGlfw_Shutdown"][1]["ov_cimguiname"] = "ImGui_ImplGlfw_Shutdown"
defs["ImGui_ImplGlfw_Shutdown"][1]["ret"] = "void"
defs["ImGui_ImplGlfw_Shutdown"][1]["signature"] = "()"

View File

@ -72,9 +72,6 @@ igIsRectVisible 2
igListBox 2
1 bool igListBoxStr_arr (const char*,int*,const char* const[],int,int)
2 bool igListBoxFnBoolPtr (const char*,int*,bool(*)(void*,int,const char**),void*,int,int)
igListBoxHeader 2
1 bool igListBoxHeaderVec2 (const char*,const ImVec2)
2 bool igListBoxHeaderInt (const char*,int,int)
igMenuItem 2
1 bool igMenuItemBool (const char*,const char*,bool,bool)
2 bool igMenuItemBoolPtr (const char*,const char*,bool*,bool)
@ -135,4 +132,4 @@ igValue 4
2 void igValueInt (const char*,int)
3 void igValueUint (const char*,unsigned int)
4 void igValueFloat (const char*,float,const char*)
95 overloaded
93 overloaded

View File

@ -2176,6 +2176,28 @@
"value": "ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog"
}
],
"ImGuiViewportFlags_": [
{
"calc_value": 0,
"name": "ImGuiViewportFlags_None",
"value": "0"
},
{
"calc_value": 1,
"name": "ImGuiViewportFlags_IsPlatformWindow",
"value": "1 << 0"
},
{
"calc_value": 2,
"name": "ImGuiViewportFlags_IsPlatformMonitor",
"value": "1 << 1"
},
{
"calc_value": 4,
"name": "ImGuiViewportFlags_OwnedByApp",
"value": "1 << 2"
}
],
"ImGuiWindowFlags_": [
{
"calc_value": 0,
@ -2331,70 +2353,72 @@
},
"enumtypes": [],
"locations": {
"ImColor": "imgui:2179",
"ImDrawChannel": "imgui:2273",
"ImDrawCmd": "imgui:2228",
"ImDrawCmdHeader": "imgui:2265",
"ImDrawCornerFlags_": "imgui:2297",
"ImDrawData": "imgui:2452",
"ImDrawList": "imgui:2330",
"ImDrawListFlags_": "imgui:2313",
"ImDrawListSplitter": "imgui:2282",
"ImDrawVert": "imgui:2250",
"ImFont": "imgui:2663",
"ImFontAtlas": "imgui:2568",
"ImFontAtlasCustomRect": "imgui:2530",
"ImFontAtlasFlags_": "imgui:2543",
"ImFontConfig": "imgui:2475",
"ImFontGlyph": "imgui:2504",
"ImFontGlyphRangesBuilder": "imgui:2515",
"ImGuiBackendFlags_": "imgui:1355",
"ImGuiButtonFlags_": "imgui:1461",
"ImGuiCol_": "imgui:1365",
"ImGuiColorEditFlags_": "imgui:1474",
"ImGuiComboFlags_": "imgui:994",
"ImGuiCond_": "imgui:1566",
"ImGuiConfigFlags_": "imgui:1339",
"ImGuiDataType_": "imgui:1231",
"ImGuiDir_": "imgui:1247",
"ImGuiDragDropFlags_": "imgui:1209",
"ImGuiFocusedFlags_": "imgui:1181",
"ImGuiHoveredFlags_": "imgui:1193",
"ImGuiIO": "imgui:1726",
"ImGuiInputTextCallbackData": "imgui:1868",
"ImGuiInputTextFlags_": "imgui:909",
"ImGuiKeyModFlags_": "imgui:1294",
"ImGuiKey_": "imgui:1266",
"ImGuiListClipper": "imgui:2130",
"ImGuiMouseButton_": "imgui:1538",
"ImGuiMouseCursor_": "imgui:1548",
"ImGuiNavInput_": "imgui:1307",
"ImGuiOnceUponAFrame": "imgui:2008",
"ImGuiPayload": "imgui:1908",
"ImGuiPopupFlags_": "imgui:967",
"ImGuiSelectableFlags_": "imgui:983",
"ImGuiSizeCallbackData": "imgui:1899",
"ImGuiSliderFlags_": "imgui:1521",
"ImGuiSortDirection_": "imgui:1258",
"ImGuiStorage": "imgui:2070",
"ImGuiStoragePair": "imgui:2073",
"ImGuiStyle": "imgui:1672",
"ImGuiStyleVar_": "imgui:1430",
"ImGuiTabBarFlags_": "imgui:1008",
"ImGuiTabItemFlags_": "imgui:1024",
"ImGuiTableBgTarget_": "imgui:1172",
"ImGuiTableColumnFlags_": "imgui:1117",
"ImGuiTableColumnSortSpecs": "imgui:1930",
"ImGuiTableFlags_": "imgui:1060",
"ImGuiTableRowFlags_": "imgui:1157",
"ImGuiTableSortSpecs": "imgui:1944",
"ImGuiTextBuffer": "imgui:2043",
"ImGuiTextFilter": "imgui:2016",
"ImGuiTextRange": "imgui:2026",
"ImGuiTreeNodeFlags_": "imgui:938",
"ImGuiWindowFlags_": "imgui:869",
"ImVec2": "imgui:223",
"ImVec4": "imgui:236"
"ImColor": "imgui:2197",
"ImDrawChannel": "imgui:2291",
"ImDrawCmd": "imgui:2246",
"ImDrawCmdHeader": "imgui:2283",
"ImDrawCornerFlags_": "imgui:2315",
"ImDrawData": "imgui:2471",
"ImDrawList": "imgui:2349",
"ImDrawListFlags_": "imgui:2331",
"ImDrawListSplitter": "imgui:2300",
"ImDrawVert": "imgui:2268",
"ImFont": "imgui:2686",
"ImFontAtlas": "imgui:2587",
"ImFontAtlasCustomRect": "imgui:2549",
"ImFontAtlasFlags_": "imgui:2562",
"ImFontConfig": "imgui:2493",
"ImFontGlyph": "imgui:2522",
"ImFontGlyphRangesBuilder": "imgui:2534",
"ImGuiBackendFlags_": "imgui:1369",
"ImGuiButtonFlags_": "imgui:1475",
"ImGuiCol_": "imgui:1379",
"ImGuiColorEditFlags_": "imgui:1488",
"ImGuiComboFlags_": "imgui:1008",
"ImGuiCond_": "imgui:1580",
"ImGuiConfigFlags_": "imgui:1353",
"ImGuiDataType_": "imgui:1245",
"ImGuiDir_": "imgui:1261",
"ImGuiDragDropFlags_": "imgui:1223",
"ImGuiFocusedFlags_": "imgui:1195",
"ImGuiHoveredFlags_": "imgui:1207",
"ImGuiIO": "imgui:1740",
"ImGuiInputTextCallbackData": "imgui:1882",
"ImGuiInputTextFlags_": "imgui:923",
"ImGuiKeyModFlags_": "imgui:1308",
"ImGuiKey_": "imgui:1280",
"ImGuiListClipper": "imgui:2148",
"ImGuiMouseButton_": "imgui:1552",
"ImGuiMouseCursor_": "imgui:1562",
"ImGuiNavInput_": "imgui:1321",
"ImGuiOnceUponAFrame": "imgui:2026",
"ImGuiPayload": "imgui:1922",
"ImGuiPopupFlags_": "imgui:981",
"ImGuiSelectableFlags_": "imgui:997",
"ImGuiSizeCallbackData": "imgui:1913",
"ImGuiSliderFlags_": "imgui:1535",
"ImGuiSortDirection_": "imgui:1272",
"ImGuiStorage": "imgui:2088",
"ImGuiStoragePair": "imgui:2091",
"ImGuiStyle": "imgui:1686",
"ImGuiStyleVar_": "imgui:1444",
"ImGuiTabBarFlags_": "imgui:1022",
"ImGuiTabItemFlags_": "imgui:1038",
"ImGuiTableBgTarget_": "imgui:1186",
"ImGuiTableColumnFlags_": "imgui:1131",
"ImGuiTableColumnSortSpecs": "imgui:1944",
"ImGuiTableFlags_": "imgui:1074",
"ImGuiTableRowFlags_": "imgui:1171",
"ImGuiTableSortSpecs": "imgui:1958",
"ImGuiTextBuffer": "imgui:2061",
"ImGuiTextFilter": "imgui:2034",
"ImGuiTextRange": "imgui:2044",
"ImGuiTreeNodeFlags_": "imgui:952",
"ImGuiViewport": "imgui:2757",
"ImGuiViewportFlags_": "imgui:2742",
"ImGuiWindowFlags_": "imgui:883",
"ImVec2": "imgui:227",
"ImVec4": "imgui:240"
},
"structs": {
"ImColor": [
@ -2464,10 +2488,6 @@
"name": "Valid",
"type": "bool"
},
{
"name": "CmdLists",
"type": "ImDrawList**"
},
{
"name": "CmdListsCount",
"type": "int"
@ -2480,6 +2500,10 @@
"name": "TotalVtxCount",
"type": "int"
},
{
"name": "CmdLists",
"type": "ImDrawList**"
},
{
"name": "DisplayPos",
"type": "ImVec2"
@ -2729,6 +2753,14 @@
"size": 64,
"type": "ImVec4"
},
{
"name": "FontBuilderIO",
"type": "const ImFontBuilderIO*"
},
{
"name": "FontBuilderFlags",
"type": "unsigned int"
},
{
"name": "PackIdMouseCursors",
"type": "int"
@ -2830,7 +2862,7 @@
"type": "bool"
},
{
"name": "RasterizerFlags",
"name": "FontBuilderFlags",
"type": "unsigned int"
},
{
@ -2853,8 +2885,8 @@
],
"ImFontGlyph": [
{
"bitfield": "31",
"name": "Codepoint",
"bitfield": "1",
"name": "Colored",
"type": "unsigned int"
},
{
@ -2862,6 +2894,11 @@
"name": "Visible",
"type": "unsigned int"
},
{
"bitfield": "30",
"name": "Codepoint",
"type": "unsigned int"
},
{
"name": "AdvanceX",
"type": "float"
@ -3633,6 +3670,28 @@
"type": "const char*"
}
],
"ImGuiViewport": [
{
"name": "Flags",
"type": "ImGuiViewportFlags"
},
{
"name": "Pos",
"type": "ImVec2"
},
{
"name": "Size",
"type": "ImVec2"
},
{
"name": "WorkPos",
"type": "ImVec2"
},
{
"name": "WorkSize",
"type": "ImVec2"
}
],
"ImVec2": [
{
"name": "x",

View File

@ -1721,6 +1721,23 @@ defs["enums"]["ImGuiTreeNodeFlags_"][16] = {}
defs["enums"]["ImGuiTreeNodeFlags_"][16]["calc_value"] = 26
defs["enums"]["ImGuiTreeNodeFlags_"][16]["name"] = "ImGuiTreeNodeFlags_CollapsingHeader"
defs["enums"]["ImGuiTreeNodeFlags_"][16]["value"] = "ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog"
defs["enums"]["ImGuiViewportFlags_"] = {}
defs["enums"]["ImGuiViewportFlags_"][1] = {}
defs["enums"]["ImGuiViewportFlags_"][1]["calc_value"] = 0
defs["enums"]["ImGuiViewportFlags_"][1]["name"] = "ImGuiViewportFlags_None"
defs["enums"]["ImGuiViewportFlags_"][1]["value"] = "0"
defs["enums"]["ImGuiViewportFlags_"][2] = {}
defs["enums"]["ImGuiViewportFlags_"][2]["calc_value"] = 1
defs["enums"]["ImGuiViewportFlags_"][2]["name"] = "ImGuiViewportFlags_IsPlatformWindow"
defs["enums"]["ImGuiViewportFlags_"][2]["value"] = "1 << 0"
defs["enums"]["ImGuiViewportFlags_"][3] = {}
defs["enums"]["ImGuiViewportFlags_"][3]["calc_value"] = 2
defs["enums"]["ImGuiViewportFlags_"][3]["name"] = "ImGuiViewportFlags_IsPlatformMonitor"
defs["enums"]["ImGuiViewportFlags_"][3]["value"] = "1 << 1"
defs["enums"]["ImGuiViewportFlags_"][4] = {}
defs["enums"]["ImGuiViewportFlags_"][4]["calc_value"] = 4
defs["enums"]["ImGuiViewportFlags_"][4]["name"] = "ImGuiViewportFlags_OwnedByApp"
defs["enums"]["ImGuiViewportFlags_"][4]["value"] = "1 << 2"
defs["enums"]["ImGuiWindowFlags_"] = {}
defs["enums"]["ImGuiWindowFlags_"][1] = {}
defs["enums"]["ImGuiWindowFlags_"][1]["calc_value"] = 0
@ -1844,70 +1861,72 @@ defs["enums"]["ImGuiWindowFlags_"][30]["name"] = "ImGuiWindowFlags_ChildMenu"
defs["enums"]["ImGuiWindowFlags_"][30]["value"] = "1 << 28"
defs["enumtypes"] = {}
defs["locations"] = {}
defs["locations"]["ImColor"] = "imgui:2179"
defs["locations"]["ImDrawChannel"] = "imgui:2273"
defs["locations"]["ImDrawCmd"] = "imgui:2228"
defs["locations"]["ImDrawCmdHeader"] = "imgui:2265"
defs["locations"]["ImDrawCornerFlags_"] = "imgui:2297"
defs["locations"]["ImDrawData"] = "imgui:2452"
defs["locations"]["ImDrawList"] = "imgui:2330"
defs["locations"]["ImDrawListFlags_"] = "imgui:2313"
defs["locations"]["ImDrawListSplitter"] = "imgui:2282"
defs["locations"]["ImDrawVert"] = "imgui:2250"
defs["locations"]["ImFont"] = "imgui:2663"
defs["locations"]["ImFontAtlas"] = "imgui:2568"
defs["locations"]["ImFontAtlasCustomRect"] = "imgui:2530"
defs["locations"]["ImFontAtlasFlags_"] = "imgui:2543"
defs["locations"]["ImFontConfig"] = "imgui:2475"
defs["locations"]["ImFontGlyph"] = "imgui:2504"
defs["locations"]["ImFontGlyphRangesBuilder"] = "imgui:2515"
defs["locations"]["ImGuiBackendFlags_"] = "imgui:1355"
defs["locations"]["ImGuiButtonFlags_"] = "imgui:1461"
defs["locations"]["ImGuiCol_"] = "imgui:1365"
defs["locations"]["ImGuiColorEditFlags_"] = "imgui:1474"
defs["locations"]["ImGuiComboFlags_"] = "imgui:994"
defs["locations"]["ImGuiCond_"] = "imgui:1566"
defs["locations"]["ImGuiConfigFlags_"] = "imgui:1339"
defs["locations"]["ImGuiDataType_"] = "imgui:1231"
defs["locations"]["ImGuiDir_"] = "imgui:1247"
defs["locations"]["ImGuiDragDropFlags_"] = "imgui:1209"
defs["locations"]["ImGuiFocusedFlags_"] = "imgui:1181"
defs["locations"]["ImGuiHoveredFlags_"] = "imgui:1193"
defs["locations"]["ImGuiIO"] = "imgui:1726"
defs["locations"]["ImGuiInputTextCallbackData"] = "imgui:1868"
defs["locations"]["ImGuiInputTextFlags_"] = "imgui:909"
defs["locations"]["ImGuiKeyModFlags_"] = "imgui:1294"
defs["locations"]["ImGuiKey_"] = "imgui:1266"
defs["locations"]["ImGuiListClipper"] = "imgui:2130"
defs["locations"]["ImGuiMouseButton_"] = "imgui:1538"
defs["locations"]["ImGuiMouseCursor_"] = "imgui:1548"
defs["locations"]["ImGuiNavInput_"] = "imgui:1307"
defs["locations"]["ImGuiOnceUponAFrame"] = "imgui:2008"
defs["locations"]["ImGuiPayload"] = "imgui:1908"
defs["locations"]["ImGuiPopupFlags_"] = "imgui:967"
defs["locations"]["ImGuiSelectableFlags_"] = "imgui:983"
defs["locations"]["ImGuiSizeCallbackData"] = "imgui:1899"
defs["locations"]["ImGuiSliderFlags_"] = "imgui:1521"
defs["locations"]["ImGuiSortDirection_"] = "imgui:1258"
defs["locations"]["ImGuiStorage"] = "imgui:2070"
defs["locations"]["ImGuiStoragePair"] = "imgui:2073"
defs["locations"]["ImGuiStyle"] = "imgui:1672"
defs["locations"]["ImGuiStyleVar_"] = "imgui:1430"
defs["locations"]["ImGuiTabBarFlags_"] = "imgui:1008"
defs["locations"]["ImGuiTabItemFlags_"] = "imgui:1024"
defs["locations"]["ImGuiTableBgTarget_"] = "imgui:1172"
defs["locations"]["ImGuiTableColumnFlags_"] = "imgui:1117"
defs["locations"]["ImGuiTableColumnSortSpecs"] = "imgui:1930"
defs["locations"]["ImGuiTableFlags_"] = "imgui:1060"
defs["locations"]["ImGuiTableRowFlags_"] = "imgui:1157"
defs["locations"]["ImGuiTableSortSpecs"] = "imgui:1944"
defs["locations"]["ImGuiTextBuffer"] = "imgui:2043"
defs["locations"]["ImGuiTextFilter"] = "imgui:2016"
defs["locations"]["ImGuiTextRange"] = "imgui:2026"
defs["locations"]["ImGuiTreeNodeFlags_"] = "imgui:938"
defs["locations"]["ImGuiWindowFlags_"] = "imgui:869"
defs["locations"]["ImVec2"] = "imgui:223"
defs["locations"]["ImVec4"] = "imgui:236"
defs["locations"]["ImColor"] = "imgui:2197"
defs["locations"]["ImDrawChannel"] = "imgui:2291"
defs["locations"]["ImDrawCmd"] = "imgui:2246"
defs["locations"]["ImDrawCmdHeader"] = "imgui:2283"
defs["locations"]["ImDrawCornerFlags_"] = "imgui:2315"
defs["locations"]["ImDrawData"] = "imgui:2471"
defs["locations"]["ImDrawList"] = "imgui:2349"
defs["locations"]["ImDrawListFlags_"] = "imgui:2331"
defs["locations"]["ImDrawListSplitter"] = "imgui:2300"
defs["locations"]["ImDrawVert"] = "imgui:2268"
defs["locations"]["ImFont"] = "imgui:2686"
defs["locations"]["ImFontAtlas"] = "imgui:2587"
defs["locations"]["ImFontAtlasCustomRect"] = "imgui:2549"
defs["locations"]["ImFontAtlasFlags_"] = "imgui:2562"
defs["locations"]["ImFontConfig"] = "imgui:2493"
defs["locations"]["ImFontGlyph"] = "imgui:2522"
defs["locations"]["ImFontGlyphRangesBuilder"] = "imgui:2534"
defs["locations"]["ImGuiBackendFlags_"] = "imgui:1369"
defs["locations"]["ImGuiButtonFlags_"] = "imgui:1475"
defs["locations"]["ImGuiCol_"] = "imgui:1379"
defs["locations"]["ImGuiColorEditFlags_"] = "imgui:1488"
defs["locations"]["ImGuiComboFlags_"] = "imgui:1008"
defs["locations"]["ImGuiCond_"] = "imgui:1580"
defs["locations"]["ImGuiConfigFlags_"] = "imgui:1353"
defs["locations"]["ImGuiDataType_"] = "imgui:1245"
defs["locations"]["ImGuiDir_"] = "imgui:1261"
defs["locations"]["ImGuiDragDropFlags_"] = "imgui:1223"
defs["locations"]["ImGuiFocusedFlags_"] = "imgui:1195"
defs["locations"]["ImGuiHoveredFlags_"] = "imgui:1207"
defs["locations"]["ImGuiIO"] = "imgui:1740"
defs["locations"]["ImGuiInputTextCallbackData"] = "imgui:1882"
defs["locations"]["ImGuiInputTextFlags_"] = "imgui:923"
defs["locations"]["ImGuiKeyModFlags_"] = "imgui:1308"
defs["locations"]["ImGuiKey_"] = "imgui:1280"
defs["locations"]["ImGuiListClipper"] = "imgui:2148"
defs["locations"]["ImGuiMouseButton_"] = "imgui:1552"
defs["locations"]["ImGuiMouseCursor_"] = "imgui:1562"
defs["locations"]["ImGuiNavInput_"] = "imgui:1321"
defs["locations"]["ImGuiOnceUponAFrame"] = "imgui:2026"
defs["locations"]["ImGuiPayload"] = "imgui:1922"
defs["locations"]["ImGuiPopupFlags_"] = "imgui:981"
defs["locations"]["ImGuiSelectableFlags_"] = "imgui:997"
defs["locations"]["ImGuiSizeCallbackData"] = "imgui:1913"
defs["locations"]["ImGuiSliderFlags_"] = "imgui:1535"
defs["locations"]["ImGuiSortDirection_"] = "imgui:1272"
defs["locations"]["ImGuiStorage"] = "imgui:2088"
defs["locations"]["ImGuiStoragePair"] = "imgui:2091"
defs["locations"]["ImGuiStyle"] = "imgui:1686"
defs["locations"]["ImGuiStyleVar_"] = "imgui:1444"
defs["locations"]["ImGuiTabBarFlags_"] = "imgui:1022"
defs["locations"]["ImGuiTabItemFlags_"] = "imgui:1038"
defs["locations"]["ImGuiTableBgTarget_"] = "imgui:1186"
defs["locations"]["ImGuiTableColumnFlags_"] = "imgui:1131"
defs["locations"]["ImGuiTableColumnSortSpecs"] = "imgui:1944"
defs["locations"]["ImGuiTableFlags_"] = "imgui:1074"
defs["locations"]["ImGuiTableRowFlags_"] = "imgui:1171"
defs["locations"]["ImGuiTableSortSpecs"] = "imgui:1958"
defs["locations"]["ImGuiTextBuffer"] = "imgui:2061"
defs["locations"]["ImGuiTextFilter"] = "imgui:2034"
defs["locations"]["ImGuiTextRange"] = "imgui:2044"
defs["locations"]["ImGuiTreeNodeFlags_"] = "imgui:952"
defs["locations"]["ImGuiViewport"] = "imgui:2757"
defs["locations"]["ImGuiViewportFlags_"] = "imgui:2742"
defs["locations"]["ImGuiWindowFlags_"] = "imgui:883"
defs["locations"]["ImVec2"] = "imgui:227"
defs["locations"]["ImVec4"] = "imgui:240"
defs["structs"] = {}
defs["structs"]["ImColor"] = {}
defs["structs"]["ImColor"][1] = {}
@ -1959,17 +1978,17 @@ defs["structs"]["ImDrawData"][1] = {}
defs["structs"]["ImDrawData"][1]["name"] = "Valid"
defs["structs"]["ImDrawData"][1]["type"] = "bool"
defs["structs"]["ImDrawData"][2] = {}
defs["structs"]["ImDrawData"][2]["name"] = "CmdLists"
defs["structs"]["ImDrawData"][2]["type"] = "ImDrawList**"
defs["structs"]["ImDrawData"][2]["name"] = "CmdListsCount"
defs["structs"]["ImDrawData"][2]["type"] = "int"
defs["structs"]["ImDrawData"][3] = {}
defs["structs"]["ImDrawData"][3]["name"] = "CmdListsCount"
defs["structs"]["ImDrawData"][3]["name"] = "TotalIdxCount"
defs["structs"]["ImDrawData"][3]["type"] = "int"
defs["structs"]["ImDrawData"][4] = {}
defs["structs"]["ImDrawData"][4]["name"] = "TotalIdxCount"
defs["structs"]["ImDrawData"][4]["name"] = "TotalVtxCount"
defs["structs"]["ImDrawData"][4]["type"] = "int"
defs["structs"]["ImDrawData"][5] = {}
defs["structs"]["ImDrawData"][5]["name"] = "TotalVtxCount"
defs["structs"]["ImDrawData"][5]["type"] = "int"
defs["structs"]["ImDrawData"][5]["name"] = "CmdLists"
defs["structs"]["ImDrawData"][5]["type"] = "ImDrawList**"
defs["structs"]["ImDrawData"][6] = {}
defs["structs"]["ImDrawData"][6]["name"] = "DisplayPos"
defs["structs"]["ImDrawData"][6]["type"] = "ImVec2"
@ -2159,11 +2178,17 @@ defs["structs"]["ImFontAtlas"][15]["name"] = "TexUvLines[(63)+1]"
defs["structs"]["ImFontAtlas"][15]["size"] = 64
defs["structs"]["ImFontAtlas"][15]["type"] = "ImVec4"
defs["structs"]["ImFontAtlas"][16] = {}
defs["structs"]["ImFontAtlas"][16]["name"] = "PackIdMouseCursors"
defs["structs"]["ImFontAtlas"][16]["type"] = "int"
defs["structs"]["ImFontAtlas"][16]["name"] = "FontBuilderIO"
defs["structs"]["ImFontAtlas"][16]["type"] = "const ImFontBuilderIO*"
defs["structs"]["ImFontAtlas"][17] = {}
defs["structs"]["ImFontAtlas"][17]["name"] = "PackIdLines"
defs["structs"]["ImFontAtlas"][17]["type"] = "int"
defs["structs"]["ImFontAtlas"][17]["name"] = "FontBuilderFlags"
defs["structs"]["ImFontAtlas"][17]["type"] = "unsigned int"
defs["structs"]["ImFontAtlas"][18] = {}
defs["structs"]["ImFontAtlas"][18]["name"] = "PackIdMouseCursors"
defs["structs"]["ImFontAtlas"][18]["type"] = "int"
defs["structs"]["ImFontAtlas"][19] = {}
defs["structs"]["ImFontAtlas"][19]["name"] = "PackIdLines"
defs["structs"]["ImFontAtlas"][19]["type"] = "int"
defs["structs"]["ImFontAtlasCustomRect"] = {}
defs["structs"]["ImFontAtlasCustomRect"][1] = {}
defs["structs"]["ImFontAtlasCustomRect"][1]["name"] = "Width"
@ -2233,7 +2258,7 @@ defs["structs"]["ImFontConfig"][14] = {}
defs["structs"]["ImFontConfig"][14]["name"] = "MergeMode"
defs["structs"]["ImFontConfig"][14]["type"] = "bool"
defs["structs"]["ImFontConfig"][15] = {}
defs["structs"]["ImFontConfig"][15]["name"] = "RasterizerFlags"
defs["structs"]["ImFontConfig"][15]["name"] = "FontBuilderFlags"
defs["structs"]["ImFontConfig"][15]["type"] = "unsigned int"
defs["structs"]["ImFontConfig"][16] = {}
defs["structs"]["ImFontConfig"][16]["name"] = "RasterizerMultiply"
@ -2250,40 +2275,44 @@ defs["structs"]["ImFontConfig"][19]["name"] = "DstFont"
defs["structs"]["ImFontConfig"][19]["type"] = "ImFont*"
defs["structs"]["ImFontGlyph"] = {}
defs["structs"]["ImFontGlyph"][1] = {}
defs["structs"]["ImFontGlyph"][1]["bitfield"] = "31"
defs["structs"]["ImFontGlyph"][1]["name"] = "Codepoint"
defs["structs"]["ImFontGlyph"][1]["bitfield"] = "1"
defs["structs"]["ImFontGlyph"][1]["name"] = "Colored"
defs["structs"]["ImFontGlyph"][1]["type"] = "unsigned int"
defs["structs"]["ImFontGlyph"][2] = {}
defs["structs"]["ImFontGlyph"][2]["bitfield"] = "1"
defs["structs"]["ImFontGlyph"][2]["name"] = "Visible"
defs["structs"]["ImFontGlyph"][2]["type"] = "unsigned int"
defs["structs"]["ImFontGlyph"][3] = {}
defs["structs"]["ImFontGlyph"][3]["name"] = "AdvanceX"
defs["structs"]["ImFontGlyph"][3]["type"] = "float"
defs["structs"]["ImFontGlyph"][3]["bitfield"] = "30"
defs["structs"]["ImFontGlyph"][3]["name"] = "Codepoint"
defs["structs"]["ImFontGlyph"][3]["type"] = "unsigned int"
defs["structs"]["ImFontGlyph"][4] = {}
defs["structs"]["ImFontGlyph"][4]["name"] = "X0"
defs["structs"]["ImFontGlyph"][4]["name"] = "AdvanceX"
defs["structs"]["ImFontGlyph"][4]["type"] = "float"
defs["structs"]["ImFontGlyph"][5] = {}
defs["structs"]["ImFontGlyph"][5]["name"] = "Y0"
defs["structs"]["ImFontGlyph"][5]["name"] = "X0"
defs["structs"]["ImFontGlyph"][5]["type"] = "float"
defs["structs"]["ImFontGlyph"][6] = {}
defs["structs"]["ImFontGlyph"][6]["name"] = "X1"
defs["structs"]["ImFontGlyph"][6]["name"] = "Y0"
defs["structs"]["ImFontGlyph"][6]["type"] = "float"
defs["structs"]["ImFontGlyph"][7] = {}
defs["structs"]["ImFontGlyph"][7]["name"] = "Y1"
defs["structs"]["ImFontGlyph"][7]["name"] = "X1"
defs["structs"]["ImFontGlyph"][7]["type"] = "float"
defs["structs"]["ImFontGlyph"][8] = {}
defs["structs"]["ImFontGlyph"][8]["name"] = "U0"
defs["structs"]["ImFontGlyph"][8]["name"] = "Y1"
defs["structs"]["ImFontGlyph"][8]["type"] = "float"
defs["structs"]["ImFontGlyph"][9] = {}
defs["structs"]["ImFontGlyph"][9]["name"] = "V0"
defs["structs"]["ImFontGlyph"][9]["name"] = "U0"
defs["structs"]["ImFontGlyph"][9]["type"] = "float"
defs["structs"]["ImFontGlyph"][10] = {}
defs["structs"]["ImFontGlyph"][10]["name"] = "U1"
defs["structs"]["ImFontGlyph"][10]["name"] = "V0"
defs["structs"]["ImFontGlyph"][10]["type"] = "float"
defs["structs"]["ImFontGlyph"][11] = {}
defs["structs"]["ImFontGlyph"][11]["name"] = "V1"
defs["structs"]["ImFontGlyph"][11]["name"] = "U1"
defs["structs"]["ImFontGlyph"][11]["type"] = "float"
defs["structs"]["ImFontGlyph"][12] = {}
defs["structs"]["ImFontGlyph"][12]["name"] = "V1"
defs["structs"]["ImFontGlyph"][12]["type"] = "float"
defs["structs"]["ImFontGlyphRangesBuilder"] = {}
defs["structs"]["ImFontGlyphRangesBuilder"][1] = {}
defs["structs"]["ImFontGlyphRangesBuilder"][1]["name"] = "UsedChars"
@ -2834,6 +2863,22 @@ defs["structs"]["ImGuiTextRange"][1]["type"] = "const char*"
defs["structs"]["ImGuiTextRange"][2] = {}
defs["structs"]["ImGuiTextRange"][2]["name"] = "e"
defs["structs"]["ImGuiTextRange"][2]["type"] = "const char*"
defs["structs"]["ImGuiViewport"] = {}
defs["structs"]["ImGuiViewport"][1] = {}
defs["structs"]["ImGuiViewport"][1]["name"] = "Flags"
defs["structs"]["ImGuiViewport"][1]["type"] = "ImGuiViewportFlags"
defs["structs"]["ImGuiViewport"][2] = {}
defs["structs"]["ImGuiViewport"][2]["name"] = "Pos"
defs["structs"]["ImGuiViewport"][2]["type"] = "ImVec2"
defs["structs"]["ImGuiViewport"][3] = {}
defs["structs"]["ImGuiViewport"][3]["name"] = "Size"
defs["structs"]["ImGuiViewport"][3]["type"] = "ImVec2"
defs["structs"]["ImGuiViewport"][4] = {}
defs["structs"]["ImGuiViewport"][4]["name"] = "WorkPos"
defs["structs"]["ImGuiViewport"][4]["type"] = "ImVec2"
defs["structs"]["ImGuiViewport"][5] = {}
defs["structs"]["ImGuiViewport"][5]["name"] = "WorkSize"
defs["structs"]["ImGuiViewport"][5]["type"] = "ImVec2"
defs["structs"]["ImVec2"] = {}
defs["structs"]["ImVec2"][1] = {}
defs["structs"]["ImVec2"][1]["name"] = "x"

View File

@ -16,6 +16,7 @@
"ImFontAtlas": "struct ImFontAtlas",
"ImFontAtlasCustomRect": "struct ImFontAtlasCustomRect",
"ImFontAtlasFlags": "int",
"ImFontBuilderIO": "struct ImFontBuilderIO",
"ImFontConfig": "struct ImFontConfig",
"ImFontGlyph": "struct ImFontGlyph",
"ImFontGlyphRangesBuilder": "struct ImFontGlyphRangesBuilder",
@ -67,6 +68,8 @@
"ImGuiTextFilter": "struct ImGuiTextFilter",
"ImGuiTextRange": "struct ImGuiTextRange",
"ImGuiTreeNodeFlags": "int",
"ImGuiViewport": "struct ImGuiViewport",
"ImGuiViewportFlags": "int",
"ImGuiWindowFlags": "int",
"ImS16": "signed short",
"ImS32": "signed int",

View File

@ -16,6 +16,7 @@ defs["ImFont"] = "struct ImFont"
defs["ImFontAtlas"] = "struct ImFontAtlas"
defs["ImFontAtlasCustomRect"] = "struct ImFontAtlasCustomRect"
defs["ImFontAtlasFlags"] = "int"
defs["ImFontBuilderIO"] = "struct ImFontBuilderIO"
defs["ImFontConfig"] = "struct ImFontConfig"
defs["ImFontGlyph"] = "struct ImFontGlyph"
defs["ImFontGlyphRangesBuilder"] = "struct ImFontGlyphRangesBuilder"
@ -67,6 +68,8 @@ defs["ImGuiTextBuffer"] = "struct ImGuiTextBuffer"
defs["ImGuiTextFilter"] = "struct ImGuiTextFilter"
defs["ImGuiTextRange"] = "struct ImGuiTextRange"
defs["ImGuiTreeNodeFlags"] = "int"
defs["ImGuiViewport"] = "struct ImGuiViewport"
defs["ImGuiViewportFlags"] = "int"
defs["ImGuiWindowFlags"] = "int"
defs["ImS16"] = "signed short"
defs["ImS32"] = "signed int"

View File

@ -4,53 +4,65 @@ use crate::Ui;
/// # Columns
impl<'ui> Ui<'ui> {
#[doc(alias = "Columns")]
pub fn columns(&self, count: i32, id: &ImStr, border: bool) {
unsafe { sys::igColumns(count, id.as_ptr(), border) }
}
/// Switches to the next column.
///
/// If the current row is finished, switches to first column of the next row
#[doc(alias = "NextColumn")]
pub fn next_column(&self) {
unsafe { sys::igNextColumn() }
}
/// Returns the index of the current column
#[doc(alias = "GetColumnIndex")]
pub fn current_column_index(&self) -> i32 {
unsafe { sys::igGetColumnIndex() }
}
/// Returns the width of the current column (in pixels)
#[doc(alias = "GetColumnWidth")]
pub fn current_column_width(&self) -> f32 {
unsafe { sys::igGetColumnWidth(-1) }
}
#[doc(alias = "GetColumnWidth")]
/// Returns the width of the given column (in pixels)
pub fn column_width(&self, column_index: i32) -> f32 {
unsafe { sys::igGetColumnWidth(column_index) }
}
#[doc(alias = "SetColumnWidth")]
/// Sets the width of the current column (in pixels)
pub fn set_current_column_width(&self, width: f32) {
unsafe { sys::igSetColumnWidth(-1, width) };
}
#[doc(alias = "SetColumnWidth")]
/// Sets the width of the given column (in pixels)
pub fn set_column_width(&self, column_index: i32, width: f32) {
unsafe { sys::igSetColumnWidth(column_index, width) };
}
/// Returns the offset of the current column (in pixels from the left side of the content
/// region)
#[doc(alias = "GetColumnOffset")]
pub fn current_column_offset(&self) -> f32 {
unsafe { sys::igGetColumnOffset(-1) }
}
/// Returns the offset of the given column (in pixels from the left side of the content region)
#[doc(alias = "GetColumnOffset")]
pub fn column_offset(&self, column_index: i32) -> f32 {
unsafe { sys::igGetColumnOffset(column_index) }
}
/// Sets the offset of the current column (in pixels from the left side of the content region)
#[doc(alias = "SetColumnOffset")]
pub fn set_current_column_offset(&self, offset_x: f32) {
unsafe { sys::igSetColumnOffset(-1, offset_x) };
}
/// Sets the offset of the given column (in pixels from the left side of the content region)
#[doc(alias = "SetColumnOffset")]
pub fn set_column_offset(&self, column_index: i32, offset_x: f32) {
unsafe { sys::igSetColumnOffset(column_index, offset_x) };
}
/// Returns the current amount of columns
#[doc(alias = "GetColumnCount")]
pub fn column_count(&self) -> i32 {
unsafe { sys::igGetColumnsCount() }
}

View File

@ -79,6 +79,7 @@ impl Context {
/// # Panics
///
/// Panics if an active context already exists
#[doc(alias = "CreateContext")]
pub fn create() -> Self {
Self::create_internal(None)
}
@ -87,10 +88,12 @@ impl Context {
/// # Panics
///
/// Panics if an active context already exists
#[doc(alias = "CreateContext")]
pub fn create_with_shared_font_atlas(shared_font_atlas: Rc<RefCell<SharedFontAtlas>>) -> Self {
Self::create_internal(Some(shared_font_atlas))
}
/// Suspends this context so another context can be the active context.
#[doc(alias = "CreateContext")]
pub fn suspend(self) -> SuspendedContext {
let _guard = CTX_MUTEX.lock();
assert!(
@ -183,10 +186,12 @@ impl Context {
self.renderer_name = renderer_name;
}
/// Loads settings from a string slice containing settings in .Ini file format
#[doc(alias = "LoadIniSettingsFromMemory")]
pub fn load_ini_settings(&mut self, data: &str) {
unsafe { sys::igLoadIniSettingsFromMemory(data.as_ptr() as *const _, data.len()) }
}
/// Saves settings to a mutable string buffer in .Ini file format
#[doc(alias = "SaveInitSettingsToMemory")]
pub fn save_ini_settings(&mut self, buf: &mut String) {
let data = unsafe { CStr::from_ptr(sys::igSaveIniSettingsToMemory(ptr::null_mut())) };
buf.push_str(&data.to_string_lossy());
@ -236,6 +241,7 @@ impl Context {
}
impl Drop for Context {
#[doc(alias = "DestroyContext")]
fn drop(&mut self) {
let _guard = CTX_MUTEX.lock();
// If this context is the active context, Dear ImGui automatically deactivates it during
@ -270,6 +276,7 @@ pub struct SuspendedContext(Context);
impl SuspendedContext {
/// Creates a new suspended imgui-rs context.
#[doc(alias = "CreateContext")]
pub fn create() -> Self {
Self::create_internal(None)
}
@ -283,6 +290,7 @@ impl SuspendedContext {
/// containing the activated context.
/// If there is already an active context, nothing happens and `Err` is returned, containing
/// the original suspended context.
#[doc(alias = "SetCurrentContext")]
pub fn activate(self) -> Result<Context, SuspendedContext> {
let _guard = CTX_MUTEX.lock();
if no_current_context() {
@ -465,6 +473,7 @@ impl Context {
}
}
/// Returns an immutable reference to the user interface style
#[doc(alias = "GetStyle")]
pub fn style(&self) -> &Style {
unsafe {
// safe because Style is a transparent wrapper around sys::ImGuiStyle
@ -472,6 +481,7 @@ impl Context {
}
}
/// Returns a mutable reference to the user interface style
#[doc(alias = "GetStyle")]
pub fn style_mut(&mut self) -> &mut Style {
unsafe {
// safe because Style is a transparent wrapper around sys::ImGuiStyle
@ -498,6 +508,7 @@ impl Context {
/// # Panics
///
/// Panics if the context uses a shared font atlas that is already borrowed
#[doc(alias = "NewFame")]
pub fn frame(&mut self) -> Ui {
// Clear default font if it no longer exists. This could be an error in the future
let default_font = self.io().font_default;

View File

@ -75,7 +75,7 @@ bitflags!(
/// ```no_run
/// # use imgui::*;
/// fn show_ui(ui: &Ui<'_>) {
/// ui.button(im_str!("Hello, I am a drag source!"), [0.0, 0.0]);
/// ui.button(im_str!("Hello, I am a drag source!"));
///
/// // Creates an empty DragSource with no tooltip
/// DragDropSource::new(im_str!("BUTTON_DRAG")).begin(ui);
@ -143,7 +143,7 @@ impl<'a> DragDropSource<'a> {
/// ```no_run
/// # use imgui::*;
/// fn show_ui(ui: &Ui<'_>, drop_message: &mut Option<String>) {
/// ui.button(im_str!("Drag me!"), [0.0, 0.0]);
/// ui.button(im_str!("Drag me!"));
///
/// let drag_drop_name = im_str!("Test Drag");
///
@ -155,7 +155,7 @@ impl<'a> DragDropSource<'a> {
/// *drop_message = Some("Test Payload".to_string());
/// }
///
/// ui.button(im_str!("Target me!"), [0.0, 0.0]);
/// ui.button(im_str!("Target me!"));
///
/// // drag drop TARGET
/// if let Some(target) = imgui::DragDropTarget::new(ui) {
@ -196,7 +196,7 @@ impl<'a> DragDropSource<'a> {
/// ```no_run
/// # use imgui::*;
/// fn show_ui(ui: &Ui<'_>) {
/// ui.button(im_str!("Drag me!"), [0.0, 0.0]);
/// ui.button(im_str!("Drag me!"));
///
/// let drag_drop_name = im_str!("Test Drag");
/// let msg_to_send = "hello there sailor";
@ -207,7 +207,7 @@ impl<'a> DragDropSource<'a> {
/// tooltip.end();
/// }
///
/// ui.button(im_str!("Target me!"), [0.0, 0.0]);
/// ui.button(im_str!("Target me!"));
///
/// // drag drop TARGET
/// if let Some(target) = imgui::DragDropTarget::new(ui) {
@ -313,7 +313,7 @@ impl Drop for DragDropSourceToolTip<'_> {
/// # use imgui::*;
/// fn show_ui(ui: &Ui<'_>) {
/// // Drop something on this button please!
/// ui.button(im_str!("Hello, I am a drag Target!"), [0.0, 0.0]);
/// ui.button(im_str!("Hello, I am a drag Target!"));
///
/// if let Some(target) = DragDropTarget::new(ui) {
/// // accepting an empty payload (which is really just raising an event)
@ -346,6 +346,7 @@ impl<'ui> DragDropTarget<'ui> {
/// Creates a new DragDropTarget, holding the [Ui]'s lifetime for the duration
/// of its existence. This is required since this struct runs some code on its Drop
/// to end the DragDropTarget code.
#[doc(alias = "BeginDragDropTarget")]
pub fn new(_ui: &Ui<'_>) -> Option<Self> {
let should_begin = unsafe { sys::igBeginDragDropTarget() };
if should_begin {

View File

@ -92,6 +92,7 @@ impl<'ui> DrawListMut<'ui> {
}
}
#[doc(alias = "GetWindowDrawList")]
pub(crate) fn window(_: &Ui<'ui>) -> Self {
Self::lock_draw_list();
Self {
@ -100,6 +101,7 @@ impl<'ui> DrawListMut<'ui> {
}
}
#[doc(alias = "GetBackgroundDrawList")]
pub(crate) fn background(_: &Ui<'ui>) -> Self {
Self::lock_draw_list();
Self {
@ -108,6 +110,7 @@ impl<'ui> DrawListMut<'ui> {
}
}
#[doc(alias = "GetForegroundDrawList")]
pub(crate) fn foreground(_: &Ui<'ui>) -> Self {
Self::lock_draw_list();
Self {
@ -135,6 +138,7 @@ impl<'ui> DrawListMut<'ui> {
/// });
/// }
/// ```
#[doc(alias = "ChannelsSplit")]
pub fn channels_split<F: FnOnce(&ChannelsSplit)>(&self, channels_count: u32, f: F) {
unsafe { sys::ImDrawList_ChannelsSplit(self.draw_list, channels_count as i32) };
f(&ChannelsSplit {
@ -157,6 +161,7 @@ impl<'ui> ChannelsSplit<'ui> {
/// Change current channel.
///
/// Panic if channel_index overflows the number of channels.
#[doc(alias = "ChannelsSetCurrent")]
pub fn set_current(&self, channel_index: u32) {
assert!(
channel_index < self.channels_count,
@ -173,6 +178,7 @@ impl<'ui> ChannelsSplit<'ui> {
/// Drawing functions
impl<'ui> DrawListMut<'ui> {
/// Returns a line from point `p1` to `p2` with color `c`.
#[doc(alias = "AddLine")]
pub fn add_line<C>(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Line<'ui>
where
C: Into<ImColor32>,
@ -182,6 +188,7 @@ impl<'ui> DrawListMut<'ui> {
/// Returns a rectangle whose upper-left corner is at point `p1`
/// and lower-right corner is at point `p2`, with color `c`.
#[doc(alias = "AddRectFilled", alias = "AddRect")]
pub fn add_rect<C>(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Rect<'ui>
where
C: Into<ImColor32>,
@ -194,6 +201,7 @@ impl<'ui> DrawListMut<'ui> {
/// The remains parameters are the respective color of the corners
/// in the counter-clockwise starting from the upper-left corner
/// first.
#[doc(alias = "AddRectFilledMultiColor")]
pub fn add_rect_filled_multicolor<C1, C2, C3, C4>(
&self,
p1: [f32; 2],
@ -223,6 +231,7 @@ impl<'ui> DrawListMut<'ui> {
/// Returns a triangle with the given 3 vertices `p1`, `p2` and `p3`
/// and color `c`.
#[doc(alias = "AddTriangleFilled", alias = "AddTriangle")]
pub fn add_triangle<C>(
&'ui self,
p1: [f32; 2],
@ -237,6 +246,7 @@ impl<'ui> DrawListMut<'ui> {
}
/// Returns a circle with the given `center`, `radius` and `color`.
#[doc(alias = "AddCircleFilled", alias = "AddCircle")]
pub fn add_circle<C>(&'ui self, center: [f32; 2], radius: f32, color: C) -> Circle<'ui>
where
C: Into<ImColor32>,
@ -245,6 +255,7 @@ impl<'ui> DrawListMut<'ui> {
}
/// Draw a text whose upper-left corner is at point `pos`.
#[doc(alias = "AddText")]
pub fn add_text<C, T>(&self, pos: [f32; 2], col: C, text: T)
where
C: Into<ImColor32>,
@ -262,6 +273,7 @@ impl<'ui> DrawListMut<'ui> {
/// Returns a Bezier curve stretching from `pos0` to `pos1`, whose
/// curvature is defined by `cp0` and `cp1`.
#[doc(alias = "AddBezier", alias = "AddBezierCubic")]
pub fn add_bezier_curve<C>(
&'ui self,
pos0: [f32; 2],
@ -280,6 +292,7 @@ impl<'ui> DrawListMut<'ui> {
///
/// Clip all drawings done within the closure `f` in the given
/// rectangle.
#[doc(alias = "PushClipRect", alias = "PopClipRect")]
pub fn with_clip_rect<F>(&self, min: [f32; 2], max: [f32; 2], f: F)
where
F: FnOnce(),
@ -294,6 +307,7 @@ impl<'ui> DrawListMut<'ui> {
/// Clip all drawings done within the closure `f` in the given
/// rectangle. Intersect with all clipping rectangle previously on
/// the stack.
#[doc(alias = "PushClipRect", alias = "PopClipRect")]
pub fn with_clip_rect_intersect<F>(&self, min: [f32; 2], max: [f32; 2], f: F)
where
F: FnOnce(),

View File

@ -58,6 +58,8 @@ pub struct FontAtlas {
custom_rects: sys::ImVector_ImFontAtlasCustomRect,
config_data: sys::ImVector_ImFontConfig,
tex_uv_lines: [[f32; 4]; 64],
font_builder_io: *const sys::ImFontBuilderIO,
font_builder_flags: i32,
pack_id_mouse_cursors: i32,
pack_id_lines: i32,
}
@ -65,6 +67,7 @@ pub struct FontAtlas {
unsafe impl RawCast<sys::ImFontAtlas> for FontAtlas {}
impl FontAtlas {
#[doc(alias = "AddFontDefault", alias = "AddFont")]
pub fn add_font(&mut self, font_sources: &[FontSource]) -> FontId {
let (head, tail) = font_sources.split_first().unwrap();
let font_id = self.add_font_internal(head, false);
@ -130,10 +133,12 @@ impl FontAtlas {
None
}
/// Returns true if the font atlas has been built
#[doc(alias = "IsBuilt")]
pub fn is_built(&self) -> bool {
unsafe { sys::ImFontAtlas_IsBuilt(self.raw() as *const sys::ImFontAtlas as *mut _) }
}
/// Builds a 1 byte per-pixel font atlas texture
#[doc(alias = "GetTextDataAsAlpha8")]
pub fn build_alpha8_texture(&mut self) -> FontAtlasTexture {
let mut pixels: *mut c_uchar = ptr::null_mut();
let mut width: c_int = 0;
@ -167,6 +172,7 @@ impl FontAtlas {
}
}
/// Builds a 4 byte per-pixel font atlas texture
#[doc(alias = "GetTextDataAsRGBA32")]
pub fn build_rgba32_texture(&mut self) -> FontAtlasTexture {
let mut pixels: *mut c_uchar = ptr::null_mut();
let mut width: c_int = 0;
@ -200,12 +206,14 @@ impl FontAtlas {
}
}
/// Clears the font atlas completely (both input and output data)
#[doc(alias = "Clear")]
pub fn clear(&mut self) {
unsafe {
sys::ImFontAtlas_Clear(self.raw_mut());
}
}
/// Clears output font data (glyph storage, UV coordinates)
#[doc(alias = "ClearFonts")]
pub fn clear_fonts(&mut self) {
unsafe {
sys::ImFontAtlas_ClearFonts(self.raw_mut());
@ -214,12 +222,14 @@ impl FontAtlas {
/// Clears output texture data.
///
/// Can be used to save RAM once the texture has been transferred to the GPU.
#[doc(alias = "ClearTexData")]
pub fn clear_tex_data(&mut self) {
unsafe {
sys::ImFontAtlas_ClearTexData(self.raw_mut());
}
}
/// Clears all the data used to build the textures and fonts
#[doc(alias = "ClearInputData")]
pub fn clear_input_data(&mut self) {
unsafe {
sys::ImFontAtlas_ClearInputData(self.raw_mut());
@ -302,7 +312,7 @@ pub struct FontConfig {
/// Maximum advance_x for glyphs
pub glyph_max_advance_x: f32,
/// Settings for a custom font rasterizer if used
pub rasterizer_flags: u32,
pub font_builder_flags: u32,
/// Brighten (>1.0) or darken (<1.0) font output
pub rasterizer_multiply: f32,
/// Explicitly specify the ellipsis character.
@ -324,7 +334,7 @@ impl Default for FontConfig {
glyph_ranges: FontGlyphRanges::default(),
glyph_min_advance_x: 0.0,
glyph_max_advance_x: f32::MAX,
rasterizer_flags: 0,
font_builder_flags: 0,
rasterizer_multiply: 1.0,
ellipsis_char: None,
name: None,
@ -343,7 +353,7 @@ impl FontConfig {
raw.GlyphRanges = unsafe { self.glyph_ranges.to_ptr(atlas) };
raw.GlyphMinAdvanceX = self.glyph_min_advance_x;
raw.GlyphMaxAdvanceX = self.glyph_max_advance_x;
raw.RasterizerFlags = self.rasterizer_flags;
raw.FontBuilderFlags = self.font_builder_flags;
raw.RasterizerMultiply = self.rasterizer_multiply;
raw.EllipsisChar = self.ellipsis_char.map(|x| x as u16).unwrap_or(0xffff);
if let Some(name) = self.name.as_ref() {
@ -396,8 +406,8 @@ fn test_font_config_default() {
sys_font_config.GlyphMaxAdvanceX
);
assert_eq!(
font_config.rasterizer_flags,
sys_font_config.RasterizerFlags
font_config.font_builder_flags,
sys_font_config.FontBuilderFlags
);
assert_eq!(
font_config.rasterizer_multiply,
@ -423,12 +433,14 @@ pub struct FontAtlasTexture<'a> {
pub struct SharedFontAtlas(pub(crate) *mut sys::ImFontAtlas);
impl SharedFontAtlas {
#[doc(alias = "ImFontAtlas", alias = "ImFontAtlas::ImFontAtlas")]
pub fn create() -> SharedFontAtlas {
SharedFontAtlas(unsafe { sys::ImFontAtlas_ImFontAtlas() })
}
}
impl Drop for SharedFontAtlas {
#[doc(alias = "ImFontAtlas::Destory")]
fn drop(&mut self) {
unsafe { sys::ImFontAtlas_destroy(self.0) };
}

View File

@ -10,22 +10,26 @@ pub mod glyph_ranges;
/// # Fonts
impl<'ui> Ui<'ui> {
/// Returns the current font
#[doc(alias = "GetFont")]
pub fn current_font(&self) -> &Font {
unsafe { Font::from_raw(&*sys::igGetFont()) }
}
/// Returns the current font size (= height in pixels) with font scale applied
#[doc(alias = "GetFontSize")]
pub fn current_font_size(&self) -> f32 {
unsafe { sys::igGetFontSize() }
}
/// Returns the UV coordinate for a white pixel.
///
/// Useful for drawing custom shapes with the draw list API.
#[doc(alias = "FontTexUvWhitePixel")]
pub fn font_tex_uv_white_pixel(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetFontTexUvWhitePixel(&mut out) };
out.into()
}
/// Sets the font scale of the current window
#[doc(alias = "SetWindowFontScale")]
pub fn set_window_font_scale(&self, scale: f32) {
unsafe { sys::igSetWindowFontScale(scale) }
}

View File

@ -96,6 +96,7 @@ impl<'ui> Ui<'ui> {
///
/// Equivalent to indexing the Io struct `key_map` field: `ui.io().key_map[key]`
#[inline]
#[doc(alias = "GetKeyIndex")]
fn key_index(&self, key: Key) -> i32 {
unsafe { sys::igGetKeyIndex(key as i32) }
}
@ -103,36 +104,64 @@ impl<'ui> Ui<'ui> {
///
/// Equivalent to indexing the Io struct `keys_down` field: `ui.io().keys_down[key_index]`
#[inline]
#[doc(alias = "IsKeyDown")]
pub fn is_key_down(&self, key: Key) -> bool {
let key_index = self.key_index(key);
unsafe { sys::igIsKeyDown(key_index) }
}
/// Returns true if the key was pressed (went from !down to down).
///
/// Affected by key repeat settings (`io.key_repeat_delay`, `io.key_repeat_rate`)
#[inline]
#[doc(alias = "IsKeyPressed")]
pub fn is_key_pressed(&self, key: Key) -> bool {
let key_index = self.key_index(key);
unsafe { sys::igIsKeyPressed(key_index, true) }
}
/// Returns true if the key was pressed (went from !down to down).
///
/// Is **not** affected by key repeat settings (`io.key_repeat_delay`, `io.key_repeat_rate`)
#[inline]
pub fn is_key_pressed_no_repeat(&self, key: Key) -> bool {
let key_index = self.key_index(key);
unsafe { sys::igIsKeyPressed(key_index, false) }
}
/// Returns true if the key was released (went from down to !down)
#[inline]
#[doc(alias = "IsKeyReleased")]
pub fn is_key_released(&self, key: Key) -> bool {
let key_index = self.key_index(key);
unsafe { sys::igIsKeyReleased(key_index) }
}
/// Returns a count of key presses using the given repeat rate/delay settings.
///
/// Usually returns 0 or 1, but might be >1 if `rate` is small enough that `io.delta_time` >
/// `rate`.
#[inline]
#[doc(alias = "GetKeyPressedAmount")]
pub fn key_pressed_amount(&self, key: Key, repeat_delay: f32, rate: f32) -> u32 {
let key_index = self.key_index(key);
unsafe { sys::igGetKeyPressedAmount(key_index, repeat_delay, rate) as u32 }
}
/// Focuses keyboard on a widget relative to current position
/// Focuses keyboard on the next widget.
///
/// This is the equivalent to [set_keyboard_focus_here_with_offset](Self::set_keyboard_focus_here_with_offset)
/// with `target_widget` set to `FocusedWidget::Next`.
#[inline]
pub fn set_keyboard_focus_here(&self, target_widget: FocusedWidget) {
#[doc(alias = "SetKeyboardFocusHere")]
pub fn set_keyboard_focus_here(&self) {
self.set_keyboard_focus_here_with_offset(FocusedWidget::Next);
}
/// Focuses keyboard on a widget relative to current position.
#[inline]
#[doc(alias = "SetKeyboardFocusHere")]
pub fn set_keyboard_focus_here_with_offset(&self, target_widget: FocusedWidget) {
unsafe {
sys::igSetKeyboardFocusHere(target_widget.as_offset());
}

View File

@ -92,26 +92,32 @@ impl<'ui> Ui<'ui> {
/// Returns true if the given mouse button is held down.
///
/// Equivalent to indexing the Io struct with the button, e.g. `ui.io()[button]`.
#[doc(alias = "IsMouseDown")]
pub fn is_mouse_down(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDown(button as i32) }
}
/// Returns true if any mouse button is held down
#[doc(alias = "IsAnyMouseDown")]
pub fn is_any_mouse_down(&self) -> bool {
unsafe { sys::igIsAnyMouseDown() }
}
/// Returns true if the given mouse button was clicked (went from !down to down)
#[doc(alias = "IsMouseClicked")]
pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseClicked(button as i32, false) }
}
/// Returns true if the given mouse button was double-clicked
#[doc(alias = "IsMouseDoubleClicked")]
pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDoubleClicked(button as i32) }
}
/// Returns true if the given mouse button was released (went from down to !down)
#[doc(alias = "IsMouseReleased")]
pub fn is_mouse_released(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseReleased(button as i32) }
}
/// Returns true if the mouse is currently dragging with the given mouse button held down
#[doc(alias = "IsMouseDragging")]
pub fn is_mouse_dragging(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDragging(button as i32, -1.0) }
}
@ -119,6 +125,7 @@ impl<'ui> Ui<'ui> {
///
/// If the given threshold is invalid or negative, the global distance threshold is used
/// (`io.mouse_drag_threshold`).
#[doc(alias = "IsMouseDragging")]
pub fn is_mouse_dragging_with_threshold(&self, button: MouseButton, threshold: f32) -> bool {
unsafe { sys::igIsMouseDragging(button as i32, threshold) }
}
@ -130,31 +137,49 @@ impl<'ui> Ui<'ui> {
unsafe { sys::igIsMouseHoveringRect(r_min.into(), r_max.into(), true) }
}
/// Returns the mouse position backed up at the time of opening a popup
#[doc(alias = "GetMousePosOnOpeningCurrentPopup")]
pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetMousePosOnOpeningCurrentPopup(&mut out) };
out.into()
}
/// Returns the delta from the initial clicking position.
/// Returns the delta from the initial position when the left mouse button clicked.
///
/// This is locked and returns [0.0, 0.0] until the mouse has moved past the global distance
/// threshold (`io.mouse_drag_threshold`).
pub fn mouse_drag_delta(&self, button: MouseButton) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetMouseDragDelta(&mut out, button as i32, -1.0) };
out.into()
///
/// This is the same as [mouse_drag_delta_with_button](Self::mouse_drag_delta_with_button) with
/// `button` set to `MouseButton::Left`.
#[doc(alias = "GetMouseDragDelta")]
pub fn mouse_drag_delta(&self) -> [f32; 2] {
self.mouse_drag_delta_with_button(MouseButton::Left)
}
/// Returns the delta from the initial position when the given button was clicked.
///
/// This is locked and returns [0.0, 0.0] until the mouse has moved past the global distance
/// threshold (`io.mouse_drag_threshold`).
///
/// This is the same as [mouse_drag_delta_with_threshold](Self::mouse_drag_delta_with_threshold) with
/// `threshold` set to `-1.0`, which uses the global threshold `io.mouse_drag_threshold`.
#[doc(alias = "GetMouseDragDelta")]
pub fn mouse_drag_delta_with_button(&self, button: MouseButton) -> [f32; 2] {
self.mouse_drag_delta_with_threshold(button, -1.0)
}
/// Returns the delta from the initial clicking position.
///
/// This is locked and returns [0.0, 0.0] until the mouse has moved past the given threshold.
/// If the given threshold is invalid or negative, the global distance threshold is used
/// (`io.mouse_drag_threshold`).
#[doc(alias = "GetMouseDragDelta")]
pub fn mouse_drag_delta_with_threshold(&self, button: MouseButton, threshold: f32) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetMouseDragDelta(&mut out, button as i32, threshold) };
out.into()
}
/// Resets the current delta from initial clicking position.
#[doc(alias = "ResetMouseDragDelta")]
pub fn reset_mouse_drag_delta(&self, button: MouseButton) {
// This mutates the Io struct, but targets an internal field so there can't be any
// references to it
@ -163,6 +188,7 @@ impl<'ui> Ui<'ui> {
/// Returns the currently desired mouse cursor type.
///
/// Returns `None` if no cursor should be displayed
#[doc(alias = "GetMouseCursor")]
pub fn mouse_cursor(&self) -> Option<MouseCursor> {
match unsafe { sys::igGetMouseCursor() } {
sys::ImGuiMouseCursor_Arrow => Some(MouseCursor::Arrow),
@ -180,6 +206,7 @@ impl<'ui> Ui<'ui> {
/// Sets the desired mouse cursor type.
///
/// Passing `None` hides the mouse cursor.
#[doc(alias = "SetMouseCursor")]
pub fn set_mouse_cursor(&self, cursor_type: Option<MouseCursor>) {
unsafe {
sys::igSetMouseCursor(
@ -189,9 +216,11 @@ impl<'ui> Ui<'ui> {
);
}
}
#[doc(alias = "IsMousePosValid")]
pub fn is_current_mouse_pos_valid(&self) -> bool {
unsafe { sys::igIsMousePosValid(ptr::null()) }
}
#[doc(alias = "IsMousePosValid")]
pub fn is_mouse_pos_valid(&self, mouse_pos: [f32; 2]) -> bool {
unsafe { sys::igIsMousePosValid(&mouse_pos.into()) }
}
@ -353,7 +382,7 @@ fn test_mouse_drags() {
let ui = ctx.frame();
assert!(!ui.is_mouse_dragging(button));
assert!(!ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [0.0, 0.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [0.0, 0.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[0.0, 0.0]
@ -364,7 +393,7 @@ fn test_mouse_drags() {
let ui = ctx.frame();
assert!(!ui.is_mouse_dragging(button));
assert!(!ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [0.0, 0.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [0.0, 0.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[0.0, 0.0]
@ -375,7 +404,7 @@ fn test_mouse_drags() {
let ui = ctx.frame();
assert!(ui.is_mouse_dragging(button));
assert!(!ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [0.0, 100.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [0.0, 100.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[0.0, 0.0]
@ -386,7 +415,7 @@ fn test_mouse_drags() {
let ui = ctx.frame();
assert!(ui.is_mouse_dragging(button));
assert!(ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [0.0, 200.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [0.0, 200.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[0.0, 200.0]
@ -398,7 +427,7 @@ fn test_mouse_drags() {
let ui = ctx.frame();
assert!(!ui.is_mouse_dragging(button));
assert!(!ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [10.0, 10.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [10.0, 10.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[10.0, 10.0]
@ -409,7 +438,7 @@ fn test_mouse_drags() {
let ui = ctx.frame();
assert!(!ui.is_mouse_dragging(button));
assert!(!ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [0.0, 0.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [0.0, 0.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[0.0, 0.0]
@ -420,7 +449,7 @@ fn test_mouse_drags() {
let ui = ctx.frame();
assert!(ui.is_mouse_dragging(button));
assert!(ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [170.0, 170.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [170.0, 170.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[170.0, 170.0]
@ -428,7 +457,7 @@ fn test_mouse_drags() {
ui.reset_mouse_drag_delta(button);
assert!(ui.is_mouse_dragging(button));
assert!(ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [0.0, 0.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [0.0, 0.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[0.0, 0.0]
@ -439,7 +468,7 @@ fn test_mouse_drags() {
let ui = ctx.frame();
assert!(ui.is_mouse_dragging(button));
assert!(ui.is_mouse_dragging_with_threshold(button, 200.0));
assert_eq!(ui.mouse_drag_delta(button), [20.0, 20.0]);
assert_eq!(ui.mouse_drag_delta_with_button(button), [20.0, 20.0]);
assert_eq!(
ui.mouse_drag_delta_with_threshold(button, 200.0),
[20.0, 20.0]

View File

@ -317,6 +317,7 @@ unsafe impl RawCast<sys::ImGuiIO> for Io {}
impl Io {
/// Queue new character input
#[doc(alias = "AddInputCharactersUTF8")]
pub fn add_input_character(&mut self, character: char) {
let mut buf = [0; 5];
character.encode_utf8(&mut buf);
@ -325,6 +326,7 @@ impl Io {
}
}
/// Clear character input buffer
#[doc(alias = "ClearCharacters")]
pub fn clear_input_characters(&mut self) {
unsafe {
sys::ImGuiIO_ClearInputCharacters(self.raw_mut());

View File

@ -1,79 +1,97 @@
use std::ptr;
use std::thread;
use crate::context::Context;
use crate::sys;
use crate::Ui;
/// Tracks a layout group that must be ended by calling `.end()`
#[must_use]
pub struct GroupToken {
ctx: *const Context,
}
create_token!(
/// Tracks a layout group that can be ended with `end` or by dropping.
pub struct GroupToken<'ui>;
impl GroupToken {
/// Ends a layout group
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndGroup() };
}
}
impl Drop for GroupToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A GroupToken was leaked. Did you call .end()?");
}
}
}
/// Drops the layout group manually. You can also just allow this token
/// to drop on its own.
drop { sys::igEndGroup() }
);
/// # Cursor / Layout
impl<'ui> Ui<'ui> {
/// Renders a separator (generally horizontal).
///
/// This becomes a vertical separator inside a menu bar or in horizontal layout mode.
#[doc(alias = "Separator")]
pub fn separator(&self) {
unsafe { sys::igSeparator() }
}
/// Call between widgets or groups to layout them horizontally.
///
/// X position is given in window coordinates.
pub fn same_line(&self, pos_x: f32) {
unsafe { sys::igSameLine(pos_x, -1.0f32) }
///
/// This is equivalent to calling [same_line_with_pos](Self::same_line_with_pos)
/// with the `pos` set to 0.0, which uses `Style::item_spacing`.
#[doc(alias = "SameLine")]
pub fn same_line(&self) {
self.same_line_with_pos(0.0);
}
/// Call between widgets or groups to layout them horizontally.
///
/// X position is given in window coordinates.
///
/// This is equivalent to calling [same_line_with_spacing](Self::same_line_with_spacing)
/// with the `spacing` set to -1.0, which means no extra spacing.
#[doc(alias = "SameLine")]
pub fn same_line_with_pos(&self, pos_x: f32) {
self.same_line_with_spacing(pos_x, -1.0)
}
/// Call between widgets or groups to layout them horizontally.
///
/// X position is given in window coordinates.
#[doc(alias = "SameLine")]
pub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32) {
unsafe { sys::igSameLine(pos_x, spacing_w) }
}
/// Undo a `same_line` call or force a new line when in horizontal layout mode
#[doc(alias = "NewLine")]
pub fn new_line(&self) {
unsafe { sys::igNewLine() }
}
/// Adds vertical spacing
#[doc(alias = "Spacing")]
pub fn spacing(&self) {
unsafe { sys::igSpacing() }
}
/// Fills a space of `size` in pixels with nothing on the current window.
///
/// Can be used to move the cursor on the window.
#[doc(alias = "Dummy")]
pub fn dummy(&self, size: [f32; 2]) {
unsafe { sys::igDummy(size.into()) }
}
/// Moves content position to the right by `Style::indent_spacing`
///
/// This is equivalent to [indent_by](Self::indent_by) with `width` set to
/// `Style::ident_spacing`.
#[doc(alias = "Indent")]
pub fn indent(&self) {
unsafe { sys::igIndent(0.0) };
self.indent_by(0.0)
}
/// Moves content position to the right by `width`
#[doc(alias = "Indent")]
pub fn indent_by(&self, width: f32) {
unsafe { sys::igIndent(width) };
}
/// Moves content position to the left by `Style::indent_spacing`
///
/// This is equivalent to [unindent_by](Self::unindent_by) with `width` set to
/// `Style::ident_spacing`.
#[doc(alias = "Unindent")]
pub fn unindent(&self) {
unsafe { sys::igUnindent(0.0) };
self.unindent_by(0.0)
}
/// Moves content position to the left by `width`
#[doc(alias = "Unindent")]
pub fn unindent_by(&self, width: f32) {
unsafe { sys::igUnindent(width) };
}
@ -82,20 +100,23 @@ impl<'ui> Ui<'ui> {
/// May be useful to handle the same mouse event on a group of items, for example.
///
/// Returns a `GroupToken` that must be ended by calling `.end()`
#[doc(alias = "BeginGroup")]
pub fn begin_group(&self) -> GroupToken {
unsafe { sys::igBeginGroup() };
GroupToken { ctx: self.ctx }
GroupToken::new(self)
}
/// Creates a layout group and runs a closure to construct the contents.
///
/// May be useful to handle the same mouse event on a group of items, for example.
#[doc(alias = "BeginGroup")]
pub fn group<R, F: FnOnce() -> R>(&self, f: F) -> R {
let group = self.begin_group();
let result = f();
group.end(self);
group.end();
result
}
/// Returns the cursor position (in window coordinates)
#[doc(alias = "GetCursorPos")]
pub fn cursor_pos(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetCursorPos(&mut out) };
@ -104,10 +125,12 @@ impl<'ui> Ui<'ui> {
/// Sets the cursor position (in window coordinates).
///
/// This sets the point on which the next widget will be drawn.
#[doc(alias = "SetCursorPos")]
pub fn set_cursor_pos(&self, pos: [f32; 2]) {
unsafe { sys::igSetCursorPos(pos.into()) };
}
/// Returns the initial cursor position (in window coordinates)
#[doc(alias = "GetCursorStartPos")]
pub fn cursor_start_pos(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetCursorStartPos(&mut out) };
@ -116,30 +139,37 @@ impl<'ui> Ui<'ui> {
/// Returns the cursor position (in absolute screen coordinates).
///
/// This is especially useful for drawing, as the drawing API uses screen coordinates.
#[doc(alias = "GetCursorScreenPos")]
pub fn cursor_screen_pos(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetCursorScreenPos(&mut out) };
out.into()
}
/// Sets the cursor position (in absolute screen coordinates)
#[doc(alias = "SetCursorScreenPos")]
pub fn set_cursor_screen_pos(&self, pos: [f32; 2]) {
unsafe { sys::igSetCursorScreenPos(pos.into()) }
}
/// Vertically aligns text baseline so that it will align properly to regularly frame items.
///
/// Call this if you have text on a line before a framed item.
#[doc(alias = "AlignTextToFramePadding")]
pub fn align_text_to_frame_padding(&self) {
unsafe { sys::igAlignTextToFramePadding() };
}
#[doc(alias = "GetTextLineHeight")]
pub fn text_line_height(&self) -> f32 {
unsafe { sys::igGetTextLineHeight() }
}
#[doc(alias = "GetTextLineHeightWithSpacing")]
pub fn text_line_height_with_spacing(&self) -> f32 {
unsafe { sys::igGetTextLineHeightWithSpacing() }
}
#[doc(alias = "GetFrameHeight")]
pub fn frame_height(&self) -> f32 {
unsafe { sys::igGetFrameHeight() }
}
#[doc(alias = "GetFrameLineHeightWithSpacing")]
pub fn frame_height_with_spacing(&self) -> f32 {
unsafe { sys::igGetFrameHeightWithSpacing() }
}

View File

@ -28,7 +28,7 @@ pub use self::layout::*;
pub use self::list_clipper::ListClipper;
pub use self::plothistogram::PlotHistogram;
pub use self::plotlines::PlotLines;
pub use self::popup_modal::PopupModal;
pub use self::popups::*;
pub use self::render::draw_data::*;
pub use self::render::renderer::*;
pub use self::stacks::*;
@ -53,6 +53,9 @@ use internal::RawCast;
#[macro_use]
mod string;
#[macro_use]
mod tokens;
mod clipboard;
pub mod color;
mod columns;
@ -68,7 +71,7 @@ mod layout;
mod list_clipper;
mod plothistogram;
mod plotlines;
mod popup_modal;
mod popups;
mod render;
mod stacks;
mod style;
@ -84,6 +87,7 @@ mod window;
pub use core as __core;
/// Returns the underlying Dear ImGui library version
#[doc(alias = "GetVersion")]
pub fn dear_imgui_version() -> &'static str {
unsafe {
let bytes = CStr::from_ptr(sys::igGetVersion()).to_bytes();
@ -94,19 +98,21 @@ pub fn dear_imgui_version() -> &'static str {
#[test]
fn test_version() {
// TODO: what's the point of this test?
assert_eq!(dear_imgui_version(), "1.80");
assert_eq!(dear_imgui_version(), "1.81");
}
impl Context {
/// Returns the global imgui-rs time.
///
/// Incremented by Io::delta_time every frame.
#[doc(alias = "GetTime")]
pub fn time(&self) -> f64 {
unsafe { sys::igGetTime() }
}
/// Returns the global imgui-rs frame count.
///
/// Incremented by 1 every frame.
#[doc(alias = "GetFrameCount")]
pub fn frame_count(&self) -> i32 {
unsafe { sys::igGetFrameCount() }
}
@ -120,6 +126,7 @@ pub struct Ui<'ui> {
impl<'ui> Ui<'ui> {
/// Returns an immutable reference to the inputs/outputs object
#[doc(alias = "GetIO")]
pub fn io(&self) -> &Io {
unsafe { &*(sys::igGetIO() as *const Io) }
}
@ -138,6 +145,7 @@ impl<'ui> Ui<'ui> {
*self.ctx.style()
}
/// Renders the frame and returns a reference to the resulting draw data
#[doc(alias = "Render", alias = "GetDrawData")]
pub fn render(self) -> &'ui DrawData {
unsafe {
sys::igRender();
@ -147,6 +155,7 @@ impl<'ui> Ui<'ui> {
}
impl<'a> Drop for Ui<'a> {
#[doc(alias = "EndFrame")]
fn drop(&mut self) {
if !thread::panicking() {
unsafe {
@ -160,6 +169,7 @@ impl<'a> Drop for Ui<'a> {
impl<'ui> Ui<'ui> {
/// Renders a demo window (previously called a test window), which demonstrates most
/// Dear Imgui features.
#[doc(alias = "SnowDemoWindow")]
pub fn show_demo_window(&self, opened: &mut bool) {
unsafe {
sys::igShowDemoWindow(opened);
@ -168,6 +178,7 @@ impl<'ui> Ui<'ui> {
/// Renders an about window.
///
/// Displays the Dear ImGui version/credits, and build/system information.
#[doc(alias = "ShowAboutWindow")]
pub fn show_about_window(&self, opened: &mut bool) {
unsafe {
sys::igShowAboutWindow(opened);
@ -177,22 +188,26 @@ impl<'ui> Ui<'ui> {
///
/// Displays Dear ImGui internals: draw commands (with individual draw calls and vertices),
/// window list, basic internal state, etc.
#[doc(alias = "ShowMetricsWindow")]
pub fn show_metrics_window(&self, opened: &mut bool) {
unsafe {
sys::igShowMetricsWindow(opened);
}
}
/// Renders a style editor block (not a window) for the given `Style` structure
#[doc(alias = "ShowStyleEditor")]
pub fn show_style_editor(&self, style: &mut Style) {
unsafe {
sys::igShowStyleEditor(style.raw_mut());
}
}
/// Renders a style editor block (not a window) for the currently active style
#[doc(alias = "ShowStyleEditor")]
pub fn show_default_style_editor(&self) {
unsafe { sys::igShowStyleEditor(ptr::null_mut()) };
}
/// Renders a basic help/info block (not a window)
#[doc(alias = "ShowUserGuide")]
pub fn show_user_guide(&self) {
unsafe { sys::igShowUserGuide() };
}
@ -236,9 +251,11 @@ impl<T> From<*mut T> for Id<'static> {
// Widgets: Input
impl<'ui> Ui<'ui> {
#[doc(alias = "InputText", alias = "InputTextWithHint")]
pub fn input_text<'p>(&self, label: &'p ImStr, buf: &'p mut ImString) -> InputText<'ui, 'p> {
InputText::new(self, label, buf)
}
#[doc(alias = "InputText", alias = "InputTextMultiline")]
pub fn input_text_multiline<'p>(
&self,
label: &'p ImStr,
@ -247,6 +264,7 @@ impl<'ui> Ui<'ui> {
) -> InputTextMultiline<'ui, 'p> {
InputTextMultiline::new(self, label, buf, size)
}
#[doc(alias = "InputFloat2")]
pub fn input_float<'p>(&self, label: &'p ImStr, value: &'p mut f32) -> InputFloat<'ui, 'p> {
InputFloat::new(self, label, value)
}
@ -257,6 +275,7 @@ impl<'ui> Ui<'ui> {
) -> InputFloat2<'ui, 'p> {
InputFloat2::new(self, label, value)
}
#[doc(alias = "InputFloat3")]
pub fn input_float3<'p>(
&self,
label: &'p ImStr,
@ -264,6 +283,7 @@ impl<'ui> Ui<'ui> {
) -> InputFloat3<'ui, 'p> {
InputFloat3::new(self, label, value)
}
#[doc(alias = "InputFloat4")]
pub fn input_float4<'p>(
&self,
label: &'p ImStr,
@ -271,41 +291,32 @@ impl<'ui> Ui<'ui> {
) -> InputFloat4<'ui, 'p> {
InputFloat4::new(self, label, value)
}
#[doc(alias = "InputInt")]
pub fn input_int<'p>(&self, label: &'p ImStr, value: &'p mut i32) -> InputInt<'ui, 'p> {
InputInt::new(self, label, value)
}
#[doc(alias = "InputInt2")]
pub fn input_int2<'p>(&self, label: &'p ImStr, value: &'p mut [i32; 2]) -> InputInt2<'ui, 'p> {
InputInt2::new(self, label, value)
}
#[doc(alias = "InputInt3")]
pub fn input_int3<'p>(&self, label: &'p ImStr, value: &'p mut [i32; 3]) -> InputInt3<'ui, 'p> {
InputInt3::new(self, label, value)
}
#[doc(alias = "InputInt4")]
pub fn input_int4<'p>(&self, label: &'p ImStr, value: &'p mut [i32; 4]) -> InputInt4<'ui, 'p> {
InputInt4::new(self, label, value)
}
}
/// Tracks a layout tooltip that must be ended by calling `.end()`
#[must_use]
pub struct TooltipToken {
ctx: *const Context,
}
create_token!(
/// Tracks a layout tooltip that can be ended by calling `.end()` or by dropping.
pub struct TooltipToken<'ui>;
impl TooltipToken {
/// Ends a layout tooltip
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndTooltip() };
}
}
impl Drop for TooltipToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A TooltipToken was leaked. Did you call .end()?");
}
}
}
/// Drops the layout tooltip manually. You can also just allow this token
/// to drop on its own.
drop { sys::igEndTooltip() }
);
/// # Tooltips
impl<'ui> Ui<'ui> {
@ -326,6 +337,7 @@ impl<'ui> Ui<'ui> {
/// }
/// }
/// ```
#[doc(alias = "BeginTooltip", alias = "EndTootip")]
pub fn tooltip<F: FnOnce()>(&self, f: F) {
unsafe { sys::igBeginTooltip() };
f();
@ -334,9 +346,10 @@ impl<'ui> Ui<'ui> {
/// Construct a tooltip window that can have any kind of content.
///
/// Returns a `TooltipToken` that must be ended by calling `.end()`
pub fn begin_tooltip(&self) -> TooltipToken {
#[doc(alias = "BeginTooltip")]
pub fn begin_tooltip(&self) -> TooltipToken<'_> {
unsafe { sys::igBeginTooltip() };
TooltipToken { ctx: self.ctx }
TooltipToken::new(self)
}
/// Construct a tooltip window with simple text content.
///
@ -353,56 +366,15 @@ impl<'ui> Ui<'ui> {
/// }
/// }
/// ```
#[doc(alias = "BeginTooltip", alias = "EndTootip")]
pub fn tooltip_text<T: AsRef<str>>(&self, text: T) {
self.tooltip(|| self.text(text));
}
}
// Widgets: Popups
impl<'ui> Ui<'ui> {
pub fn open_popup(&self, str_id: &ImStr) {
unsafe { sys::igOpenPopup(str_id.as_ptr(), 0) };
}
pub fn popup<F>(&self, str_id: &ImStr, f: F)
where
F: FnOnce(),
{
let render =
unsafe { sys::igBeginPopup(str_id.as_ptr(), WindowFlags::empty().bits() as i32) };
if render {
f();
unsafe { sys::igEndPopup() };
}
}
/// Create a modal pop-up.
///
/// # Example
/// ```rust,no_run
/// # use imgui::*;
/// # let mut imgui = Context::create();
/// # let ui = imgui.frame();
/// if ui.button(im_str!("Show modal"), [0.0, 0.0]) {
/// ui.open_popup(im_str!("modal"));
/// }
/// ui.popup_modal(im_str!("modal")).build(|| {
/// ui.text("Content of my modal");
/// if ui.button(im_str!("OK"), [0.0, 0.0]) {
/// ui.close_current_popup();
/// }
/// });
/// ```
pub fn popup_modal<'p>(&self, str_id: &'p ImStr) -> PopupModal<'ui, 'p> {
PopupModal::new(self, str_id)
}
/// Close a popup. Should be called within the closure given as argument to
/// [`Ui::popup`] or [`Ui::popup_modal`].
pub fn close_current_popup(&self) {
unsafe { sys::igCloseCurrentPopup() };
}
}
// Widgets: ListBox
impl<'ui> Ui<'ui> {
#[doc(alias = "ListBox")]
pub fn list_box<'p, StringType: AsRef<ImStr> + ?Sized>(
&self,
label: &'p ImStr,
@ -425,12 +397,14 @@ impl<'ui> Ui<'ui> {
}
impl<'ui> Ui<'ui> {
#[doc(alias = "PlotLines")]
pub fn plot_lines<'p>(&self, label: &'p ImStr, values: &'p [f32]) -> PlotLines<'ui, 'p> {
PlotLines::new(self, label, values)
}
}
impl<'ui> Ui<'ui> {
#[doc(alias = "PlotHistogram")]
pub fn plot_histogram<'p>(
&self,
label: &'p ImStr,
@ -441,24 +415,39 @@ impl<'ui> Ui<'ui> {
}
impl<'ui> Ui<'ui> {
/// Calculate the size required for a given text string.
///
/// This is the same as [calc_text_size_with_opts](Self::calc_text_size_with_opts)
/// with `hide_text_after_double_hash` set to false and `wrap_width` set to `-1.0`.
#[doc(alias = "CalcTextSize")]
pub fn calc_text_size<T: AsRef<str>>(&self, text: T) -> [f32; 2] {
self.calc_text_size_with_opts(text, false, -1.0)
}
/// Calculate the size required for a given text string.
///
/// hide_text_after_double_hash allows the user to insert comments into their text, using a double hash-tag prefix.
/// This is a feature of imgui.
///
/// wrap_width allows you to request a width at which to wrap the text to a newline for the calculation.
pub fn calc_text_size(
#[doc(alias = "CalcTextSize")]
pub fn calc_text_size_with_opts<T: AsRef<str>>(
&self,
text: &ImStr,
text: T,
hide_text_after_double_hash: bool,
wrap_width: f32,
) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
let text = text.as_ref();
unsafe {
let start = text.as_ptr();
let end = start.add(text.len());
sys::igCalcTextSize(
&mut out,
text.as_ptr(),
std::ptr::null(),
start as *const c_char,
end as *const c_char,
hide_text_after_double_hash,
wrap_width,
)
@ -499,16 +488,19 @@ impl<'ui> Ui<'ui> {
/// }
/// ```
#[must_use]
#[doc(alias = "GetWindowDrawList")]
pub fn get_window_draw_list(&'ui self) -> DrawListMut<'ui> {
DrawListMut::window(self)
}
#[must_use]
#[doc(alias = "GetBackgroundDrawList")]
pub fn get_background_draw_list(&'ui self) -> DrawListMut<'ui> {
DrawListMut::background(self)
}
#[must_use]
#[doc(alias = "GetForegroundDrawList")]
pub fn get_foreground_draw_list(&'ui self) -> DrawListMut<'ui> {
DrawListMut::foreground(self)
}

View File

@ -71,7 +71,11 @@ impl<'ui> Drop for ListClipperToken<'ui> {
sys::ImGuiListClipper_destroy(self.list_clipper);
};
} else if !thread::panicking() {
panic!("Forgot to call End(), or to Step() until false?");
panic!(
"Forgot to call End(), or to Step() until false? \
This is the only token in the repository which users must call `.end()` or `.step()` \
with. See https://github.com/imgui-rs/imgui-rs/issues/438"
);
}
}
}

View File

@ -1,120 +0,0 @@
use std::marker::PhantomData;
use std::ptr;
use crate::sys;
use crate::window::WindowFlags;
use crate::{ImStr, Ui};
/// Created by call to [`Ui::popup_modal`].
#[must_use]
pub struct PopupModal<'ui, 'p> {
label: &'p ImStr,
opened: Option<&'p mut bool>,
flags: WindowFlags,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui, 'p> PopupModal<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
PopupModal {
label,
opened: None,
flags: WindowFlags::empty(),
_phantom: PhantomData,
}
}
/// Pass a mutable boolean which will be updated to refer to the current
/// "open" state of the modal.
pub fn opened(mut self, opened: &'p mut bool) -> Self {
self.opened = Some(opened);
self
}
pub fn flags(mut self, flags: WindowFlags) -> Self {
self.flags = flags;
self
}
pub fn title_bar(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_TITLE_BAR, !value);
self
}
pub fn resizable(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_RESIZE, !value);
self
}
pub fn movable(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_MOVE, !value);
self
}
pub fn scroll_bar(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_SCROLLBAR, !value);
self
}
pub fn scrollable(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_SCROLL_WITH_MOUSE, !value);
self
}
pub fn collapsible(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_COLLAPSE, !value);
self
}
pub fn always_auto_resize(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::ALWAYS_AUTO_RESIZE, value);
self
}
pub fn save_settings(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_SAVED_SETTINGS, !value);
self
}
pub fn inputs(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_INPUTS, !value);
self
}
pub fn menu_bar(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::MENU_BAR, value);
self
}
pub fn horizontal_scrollbar(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::HORIZONTAL_SCROLLBAR, value);
self
}
pub fn no_focus_on_appearing(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_FOCUS_ON_APPEARING, value);
self
}
pub fn no_bring_to_front_on_focus(mut self, value: bool) -> Self {
self.flags
.set(WindowFlags::NO_BRING_TO_FRONT_ON_FOCUS, value);
self
}
pub fn always_vertical_scrollbar(mut self, value: bool) -> Self {
self.flags
.set(WindowFlags::ALWAYS_VERTICAL_SCROLLBAR, value);
self
}
pub fn always_horizontal_scrollbar(mut self, value: bool) -> Self {
self.flags
.set(WindowFlags::ALWAYS_HORIZONTAL_SCROLLBAR, value);
self
}
pub fn always_use_window_padding(mut self, value: bool) -> Self {
self.flags
.set(WindowFlags::ALWAYS_USE_WINDOW_PADDING, value);
self
}
/// Consume and draw the PopupModal.
pub fn build<F: FnOnce()>(self, f: F) {
let render = unsafe {
sys::igBeginPopupModal(
self.label.as_ptr(),
self.opened
.map(|x| x as *mut bool)
.unwrap_or(ptr::null_mut()),
self.flags.bits() as i32,
)
};
if render {
f();
unsafe { sys::igEndPopup() };
}
}
}

218
imgui/src/popups.rs Normal file
View File

@ -0,0 +1,218 @@
use std::ptr;
use crate::sys;
use crate::window::WindowFlags;
use crate::{ImStr, Ui};
create_token!(
/// Tracks a popup token that can be ended with `end` or by dropping.
pub struct PopupToken<'ui>;
/// Drops the popup token manually. You can also just allow this token
/// to drop on its own.
drop { sys::igEndPopup() }
);
/// Create a modal pop-up.
///
/// # Example
/// ```rust,no_run
/// # use imgui::*;
/// # let mut imgui = Context::create();
/// # let ui = imgui.frame();
/// if ui.button(im_str!("Show modal")) {
/// ui.open_popup(im_str!("modal"));
/// }
/// if let Some(_token) = PopupModal::new(im_str!("modal")).begin_popup(&ui) {
/// ui.text("Content of my modal");
/// if ui.button(im_str!("OK")) {
/// ui.close_current_popup();
/// }
/// };
/// ```
#[must_use]
pub struct PopupModal<'p> {
label: &'p ImStr,
opened: Option<&'p mut bool>,
flags: WindowFlags,
}
impl<'p> PopupModal<'p> {
pub fn new(label: &'p ImStr) -> Self {
PopupModal {
label,
opened: None,
flags: WindowFlags::empty(),
}
}
/// Pass a mutable boolean which will be updated to refer to the current
/// "open" state of the modal.
pub fn opened(mut self, opened: &'p mut bool) -> Self {
self.opened = Some(opened);
self
}
pub fn flags(mut self, flags: WindowFlags) -> Self {
self.flags = flags;
self
}
pub fn title_bar(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_TITLE_BAR, !value);
self
}
pub fn resizable(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_RESIZE, !value);
self
}
pub fn movable(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_MOVE, !value);
self
}
pub fn scroll_bar(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_SCROLLBAR, !value);
self
}
pub fn scrollable(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_SCROLL_WITH_MOUSE, !value);
self
}
pub fn collapsible(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_COLLAPSE, !value);
self
}
pub fn always_auto_resize(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::ALWAYS_AUTO_RESIZE, value);
self
}
pub fn save_settings(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_SAVED_SETTINGS, !value);
self
}
pub fn inputs(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_INPUTS, !value);
self
}
pub fn menu_bar(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::MENU_BAR, value);
self
}
pub fn horizontal_scrollbar(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::HORIZONTAL_SCROLLBAR, value);
self
}
pub fn no_focus_on_appearing(mut self, value: bool) -> Self {
self.flags.set(WindowFlags::NO_FOCUS_ON_APPEARING, value);
self
}
pub fn no_bring_to_front_on_focus(mut self, value: bool) -> Self {
self.flags
.set(WindowFlags::NO_BRING_TO_FRONT_ON_FOCUS, value);
self
}
pub fn always_vertical_scrollbar(mut self, value: bool) -> Self {
self.flags
.set(WindowFlags::ALWAYS_VERTICAL_SCROLLBAR, value);
self
}
pub fn always_horizontal_scrollbar(mut self, value: bool) -> Self {
self.flags
.set(WindowFlags::ALWAYS_HORIZONTAL_SCROLLBAR, value);
self
}
pub fn always_use_window_padding(mut self, value: bool) -> Self {
self.flags
.set(WindowFlags::ALWAYS_USE_WINDOW_PADDING, value);
self
}
/// Consume and draw the PopupModal.
#[doc(alias = "BeginPopupModal")]
pub fn build<F: FnOnce()>(self, ui: &Ui<'_>, f: F) {
if let Some(_popup) = self.begin_popup(ui) {
f();
}
}
/// Consume and draw the PopupModal.
/// Construct a popup that can have any kind of content.
///
/// This should be called *per frame*, whereas [`open_popup`](Self::open_popup) should be called *once*
/// when you want to actual create the popup.
#[doc(alias = "BeginPopupModal")]
pub fn begin_popup<'ui>(self, ui: &Ui<'ui>) -> Option<PopupToken<'ui>> {
let render = unsafe {
sys::igBeginPopupModal(
self.label.as_ptr(),
self.opened
.map(|x| x as *mut bool)
.unwrap_or(ptr::null_mut()),
self.flags.bits() as i32,
)
};
if render {
Some(PopupToken::new(ui))
} else {
None
}
}
}
// Widgets: Popups
impl<'ui> Ui<'ui> {
/// Instructs ImGui to open a popup, which must be began with either [`begin_popup`](Self::begin_popup)
/// or [`popup`](Self::popup). You also use this function to begin [ModalPopups].
///
/// The confusing aspect to popups is that ImGui holds "control" over the popup fundamentally, so that ImGui
/// can also force close a popup when a user clicks outside a popup. If you do not want users to be
/// able to close a popup without selected an option, use [`PopupModal`].
#[doc(alias = "OpenPopup")]
pub fn open_popup(&self, str_id: &ImStr) {
unsafe { sys::igOpenPopup(str_id.as_ptr(), 0) };
}
/// Construct a popup that can have any kind of content.
///
/// This should be called *per frame*, whereas [`open_popup`](Self::open_popup) should be called *once*
/// when you want to actual create the popup.
#[doc(alias = "BeginPopup")]
pub fn begin_popup(&self, str_id: &ImStr) -> Option<PopupToken<'_>> {
let render =
unsafe { sys::igBeginPopup(str_id.as_ptr(), WindowFlags::empty().bits() as i32) };
if render {
Some(PopupToken::new(self))
} else {
None
}
}
/// Construct a popup that can have any kind of content.
///
/// This should be called *per frame*, whereas [`open_popup`](Self::open_popup) should be called *once*
/// when you want to actual create the popup.
#[doc(alias = "BeginPopup")]
pub fn popup<F>(&self, str_id: &ImStr, f: F)
where
F: FnOnce(),
{
let render =
unsafe { sys::igBeginPopup(str_id.as_ptr(), WindowFlags::empty().bits() as i32) };
if render {
f();
unsafe { sys::igEndPopup() };
}
}
/// Creates a PopupModal directly.
#[deprecated = "Please use PopupModal to create a modal popup."]
pub fn popup_modal<'p>(&self, str_id: &'p ImStr) -> PopupModal<'p> {
PopupModal::new(str_id)
}
/// Close a popup. Should be called within the closure given as argument to
/// [`Ui::popup`] or [`Ui::popup_modal`].
#[doc(alias = "CloseCurrentPopup")]
pub fn close_current_popup(&self) {
unsafe { sys::igCloseCurrentPopup() };
}
}

View File

@ -9,14 +9,14 @@ use crate::sys;
pub struct DrawData {
/// Only valid after render() is called and before the next new frame() is called.
valid: bool,
// Array of DrawList.
cmd_lists: *mut *mut DrawList,
/// Number of DrawList to render.
cmd_lists_count: i32,
/// For convenience, sum of all draw list index buffer sizes.
pub total_idx_count: i32,
/// For convenience, sum of all draw list vertex buffer sizes.
pub total_vtx_count: i32,
// Array of DrawList.
cmd_lists: *mut *mut DrawList,
/// Upper-left position of the viewport to render.
///
/// (= upper-left corner of the orthogonal projection matrix to use)
@ -61,6 +61,7 @@ impl DrawData {
/// buffers.
///
/// **This is slow and most likely a waste of resources. Always prefer indexed rendering!**
#[doc(alias = "DeIndexAllBuffers")]
pub fn deindex_all_buffers(&mut self) {
unsafe {
sys::ImDrawData_DeIndexAllBuffers(self.raw_mut());
@ -70,6 +71,7 @@ impl DrawData {
///
/// Can be used if your final output buffer is at a different scale than imgui-rs expects, or
/// if there is a difference between your window resolution and framebuffer resolution.
#[doc(alias = "ScaleClipRects")]
pub fn scale_clip_rects(&mut self, fb_scale: [f32; 2]) {
unsafe {
sys::ImDrawData_ScaleClipRects(self.raw_mut(), fb_scale.into());

View File

@ -32,15 +32,16 @@ impl<'ui> Ui<'ui> {
/// // During UI construction
/// let font = ui.push_font(my_custom_font);
/// ui.text("I use the custom font!");
/// font.pop(&ui);
/// font.pop();
/// ```
pub fn push_font(&self, id: FontId) -> FontStackToken {
#[doc(alias = "PushFont")]
pub fn push_font(&self, id: FontId) -> FontStackToken<'_> {
let fonts = self.fonts();
let font = fonts
.get_font(id)
.expect("Font atlas did not contain the given font");
unsafe { sys::igPushFont(font.raw() as *const _ as *mut _) };
FontStackToken { ctx: self.ctx }
FontStackToken::new(self)
}
/// Changes a style color by pushing a change to the color stack.
///
@ -55,15 +56,14 @@ impl<'ui> Ui<'ui> {
/// const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
/// let color = ui.push_style_color(StyleColor::Text, RED);
/// ui.text("I'm red!");
/// color.pop(&ui);
/// color.pop();
/// ```
#[doc(alias = "PushStyleColorVec4")]
pub fn push_style_color(&self, style_color: StyleColor, color: [f32; 4]) -> ColorStackToken {
unsafe { sys::igPushStyleColorVec4(style_color as i32, color.into()) };
ColorStackToken {
count: 1,
ctx: self.ctx,
}
ColorStackToken::new(self)
}
/// Changes style colors by pushing several changes to the color stack.
///
/// Returns a `ColorStackToken` that must be popped by calling `.pop()`
@ -84,7 +84,8 @@ impl<'ui> Ui<'ui> {
/// ui.text_disabled("I'm green!");
/// colors.pop(&ui);
/// ```
pub fn push_style_colors<'a, I>(&self, style_colors: I) -> ColorStackToken
#[deprecated = "deprecated in 0.7.0. Use `push_style_color` multiple times for similar effect."]
pub fn push_style_colors<'a, I>(&self, style_colors: I) -> MultiColorStackToken
where
I: IntoIterator<Item = &'a (StyleColor, [f32; 4])>,
{
@ -93,14 +94,15 @@ impl<'ui> Ui<'ui> {
unsafe { sys::igPushStyleColorVec4(style_color as i32, color.into()) };
count += 1;
}
ColorStackToken {
MultiColorStackToken {
count,
ctx: self.ctx,
}
}
/// Changes a style variable by pushing a change to the style stack.
///
/// Returns a `StyleStackToken` that must be popped by calling `.pop()`
/// Returns a `StyleStackToken` that can be popped by calling `.end()`
/// or by allowing to drop.
///
/// # Examples
///
@ -110,14 +112,12 @@ impl<'ui> Ui<'ui> {
/// # let ui = ctx.frame();
/// let style = ui.push_style_var(StyleVar::Alpha(0.2));
/// ui.text("I'm transparent!");
/// style.pop(&ui);
/// style.pop();
/// ```
#[doc(alias = "PushStyleVar")]
pub fn push_style_var(&self, style_var: StyleVar) -> StyleStackToken {
unsafe { push_style_var(style_var) };
StyleStackToken {
count: 1,
ctx: self.ctx,
}
StyleStackToken::new(self)
}
/// Changes style variables by pushing several changes to the style stack.
///
@ -137,7 +137,8 @@ impl<'ui> Ui<'ui> {
/// ui.text("...with large spacing as well");
/// styles.pop(&ui);
/// ```
pub fn push_style_vars<'a, I>(&self, style_vars: I) -> StyleStackToken
#[deprecated = "deprecated in 0.7.0. Use `push_style_var` multiple times for similar effect."]
pub fn push_style_vars<'a, I>(&self, style_vars: I) -> MultiStyleStackToken
where
I: IntoIterator<Item = &'a StyleVar>,
{
@ -146,51 +147,62 @@ impl<'ui> Ui<'ui> {
unsafe { push_style_var(style_var) };
count += 1;
}
StyleStackToken {
MultiStyleStackToken {
count,
ctx: self.ctx,
}
}
}
/// Tracks a font pushed to the font stack that must be popped by calling `.pop()`
#[must_use]
pub struct FontStackToken {
ctx: *const Context,
}
create_token!(
/// Tracks a font pushed to the font stack that can be popped by calling `.end()`
/// or by dropping.
pub struct FontStackToken<'ui>;
impl FontStackToken {
/// Pops a change from the font stack
pub fn pop(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igPopFont() };
/// Pops a change from the font stack.
drop { sys::igPopFont() }
);
impl FontStackToken<'_> {
/// Pops a change from the font stack.
pub fn pop(self) {
self.end()
}
}
impl Drop for FontStackToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A FontStackToken was leaked. Did you call .pop()?");
}
create_token!(
/// Tracks a color pushed to the color stack that can be popped by calling `.end()`
/// or by dropping.
pub struct ColorStackToken<'ui>;
/// Pops a change from the color stack.
drop { sys::igPopStyleColor(1) }
);
impl ColorStackToken<'_> {
/// Pops a change from the color stack.
pub fn pop(self) {
self.end()
}
}
/// Tracks one or more changes pushed to the color stack that must be popped by calling `.pop()`
#[must_use]
pub struct ColorStackToken {
pub struct MultiColorStackToken {
count: usize,
ctx: *const Context,
}
impl ColorStackToken {
impl MultiColorStackToken {
/// Pops changes from the color stack
#[doc(alias = "PopStyleColor")]
pub fn pop(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igPopStyleColor(self.count as i32) };
}
}
impl Drop for ColorStackToken {
impl Drop for MultiColorStackToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A ColorStackToken was leaked. Did you call .pop()?");
@ -198,22 +210,39 @@ impl Drop for ColorStackToken {
}
}
create_token!(
/// Tracks a style pushed to the style stack that can be popped by calling `.end()`
/// or by dropping.
pub struct StyleStackToken<'ui>;
/// Pops a change from the style stack.
drop { sys::igPopStyleVar(1) }
);
impl StyleStackToken<'_> {
/// Pops a change from the style stack.
pub fn pop(self) {
self.end()
}
}
/// Tracks one or more changes pushed to the style stack that must be popped by calling `.pop()`
#[must_use]
pub struct StyleStackToken {
pub struct MultiStyleStackToken {
count: usize,
ctx: *const Context,
}
impl StyleStackToken {
impl MultiStyleStackToken {
/// Pops changes from the style stack
#[doc(alias = "PopStyleVar")]
pub fn pop(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igPopStyleVar(self.count as i32) };
}
}
impl Drop for StyleStackToken {
impl Drop for MultiStyleStackToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A StyleStackToken was leaked. Did you call .pop()?");
@ -270,6 +299,7 @@ impl<'ui> Ui<'ui> {
/// - `= 0.0`: default to ~2/3 of window width
/// - `< 0.0`: `item_width` pixels relative to the right of window (-1.0 always aligns width to
/// the right side)
#[doc(alias = "PushItemWith")]
pub fn push_item_width(&self, item_width: f32) -> ItemWidthStackToken {
unsafe { sys::igPushItemWidth(item_width) };
ItemWidthStackToken { _ctx: self.ctx }
@ -280,15 +310,30 @@ impl<'ui> Ui<'ui> {
/// - `= 0.0`: default to ~2/3 of window width
/// - `< 0.0`: `item_width` pixels relative to the right of window (-1.0 always aligns width to
/// the right side)
#[doc(alias = "SetNextItemWidth")]
pub fn set_next_item_width(&self, item_width: f32) {
unsafe { sys::igSetNextItemWidth(item_width) };
}
/// Returns the width of the item given the pushed settings and the current cursor position.
///
/// This is NOT necessarily the width of last item.
#[doc(alias = "CalcItemWidth")]
pub fn calc_item_width(&self) -> f32 {
unsafe { sys::igCalcItemWidth() }
}
/// Changes the text wrapping position to the end of window (or column), which
/// is generally the default.
///
/// This is the same as calling [push_text_wrap_pos_with_pos](Self::push_text_wrap_pos_with_pos)
/// with `wrap_pos_x` set to 0.0.
///
/// Returns a `TextWrapPosStackToken` that may be popped by calling `.pop()`
#[doc(alias = "PushTextWrapPos")]
pub fn push_text_wrap_pos(&self) -> TextWrapPosStackToken {
self.push_text_wrap_pos_with_pos(0.0)
}
/// Changes the text wrapping position by pushing a change to the text wrapping position stack.
///
/// Returns a `TextWrapPosStackToken` that may be popped by calling `.pop()`
@ -296,13 +341,16 @@ impl<'ui> Ui<'ui> {
/// - `> 0.0`: wrap at `wrap_pos_x` position in window local space
/// - `= 0.0`: wrap to end of window (or column)
/// - `< 0.0`: no wrapping
pub fn push_text_wrap_pos(&self, wrap_pos_x: f32) -> TextWrapPosStackToken {
#[doc(alias = "PushTextWrapPos")]
pub fn push_text_wrap_pos_with_pos(&self, wrap_pos_x: f32) -> TextWrapPosStackToken {
unsafe { sys::igPushTextWrapPos(wrap_pos_x) };
TextWrapPosStackToken { _ctx: self.ctx }
}
/// Changes an item flag by pushing a change to the item flag stack.
///
/// Returns a `ItemFlagsStackToken` that may be popped by calling `.pop()`
#[doc(alias = "PushItemFlag")]
pub fn push_item_flag(&self, item_flag: ItemFlag) -> ItemFlagsStackToken {
use self::ItemFlag::*;
match item_flag {
@ -323,13 +371,13 @@ pub enum ItemFlag {
ButtonRepeat(bool),
}
/// Tracks a change pushed to the item width stack
pub struct ItemWidthStackToken {
_ctx: *const Context,
}
impl ItemWidthStackToken {
/// Pops a change from the item width stack
#[doc(alias = "PopItemWidth")]
pub fn pop(mut self, _: &Ui) {
self._ctx = ptr::null();
unsafe { sys::igPopItemWidth() };
@ -343,6 +391,7 @@ pub struct TextWrapPosStackToken {
impl TextWrapPosStackToken {
/// Pops a change from the text wrap position stack
#[doc(alias = "PopTextWrapPos")]
pub fn pop(mut self, _: &Ui) {
self._ctx = ptr::null();
unsafe { sys::igPopTextWrapPos() };
@ -357,6 +406,8 @@ pub struct ItemFlagsStackToken {
impl ItemFlagsStackToken {
/// Pops a change from the item flags stack
#[doc(alias = "PopAllowKeyboardFocus", alias = "PopButtonRepeat")]
pub fn pop(mut self, _: &Ui) {
self._ctx = ptr::null();
const ALLOW_KEYBOARD_FOCUS: ItemFlag = ItemFlag::AllowKeyboardFocus(true);
@ -372,13 +423,30 @@ impl ItemFlagsStackToken {
}
}
create_token!(
/// Tracks an ID pushed to the ID stack that can be popped by calling `.pop()`
/// or by dropping.
pub struct IdStackToken<'ui>;
/// Pops a change from the ID stack
drop { sys::igPopID() }
);
impl IdStackToken<'_> {
/// Pops a change from the ID stack
pub fn pop(self) {
self.end()
}
}
/// # ID stack
impl<'ui> Ui<'ui> {
/// Pushes an identifier to the ID stack.
///
/// Returns an `IdStackToken` that must be popped by calling `.pop()`
///
pub fn push_id<'a, I: Into<Id<'a>>>(&self, id: I) -> IdStackToken {
/// Returns an `IdStackToken` that can be popped by calling `.end()`
/// or by dropping manually.
#[doc(alias = "PushId")]
pub fn push_id<'a, I: Into<Id<'a>>>(&self, id: I) -> IdStackToken<'ui> {
let id = id.into();
unsafe {
@ -392,28 +460,6 @@ impl<'ui> Ui<'ui> {
Id::Ptr(p) => sys::igPushIDPtr(p as *const c_void),
}
}
IdStackToken { ctx: self.ctx }
}
}
/// Tracks an ID pushed to the ID stack that must be popped by calling `.pop()`
#[must_use]
pub struct IdStackToken {
ctx: *const Context,
}
impl IdStackToken {
/// Pops a change from the ID stack
pub fn pop(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igPopID() };
}
}
impl Drop for IdStackToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A IdStackToken was leaked. Did you call .pop()?");
}
IdStackToken::new(self)
}
}

View File

@ -153,12 +153,14 @@ unsafe impl RawCast<sys::ImGuiStyle> for Style {}
impl Style {
/// Scales all sizes in the style
#[doc(alias = "ScaleAllSizes")]
pub fn scale_all_sizes(&mut self, scale_factor: f32) {
unsafe {
sys::ImGuiStyle_ScaleAllSizes(self.raw_mut(), scale_factor);
}
}
/// Replaces current colors with classic Dear ImGui style
#[doc(alias = "StyleColors", alias = "StlyeColorsClassic")]
pub fn use_classic_colors(&mut self) -> &mut Self {
unsafe {
sys::igStyleColorsClassic(self.raw_mut());
@ -166,6 +168,7 @@ impl Style {
self
}
/// Replaces current colors with a new, recommended style
#[doc(alias = "StyleColors", alias = "StyleColorsDark")]
pub fn use_dark_colors(&mut self) -> &mut Self {
unsafe {
sys::igStyleColorsDark(self.raw_mut());
@ -174,6 +177,7 @@ impl Style {
}
/// Replaces current colors with a light style. Best used with borders and a custom, thicker
/// font
#[doc(alias = "StyleColors", alias = "StyleColorsLight")]
pub fn use_light_colors(&mut self) -> &mut Self {
unsafe {
sys::igStyleColorsLight(self.raw_mut());

43
imgui/src/tokens.rs Normal file
View File

@ -0,0 +1,43 @@
#[macro_export]
/// This is a macro used internally by imgui-rs to create StackTokens
/// representing various global state in DearImGui.
///
/// These tokens can either be allowed to drop or dropped manually
/// by called `end` on them. Preventing this token from dropping,
/// or moving this token out of the block it was made in can have
/// unintended side effects, including failed asserts in the DearImGui C++.
///
/// In general, if you're looking at this, don't overthink these -- just slap
/// a '_token` as their binding name and allow them to drop.
macro_rules! create_token {
(
$(#[$struct_meta:meta])*
$v:vis struct $token_name:ident<'ui>;
$(#[$end_meta:meta])*
drop { $on_drop:expr }
) => {
#[must_use]
$(#[$struct_meta])*
pub struct $token_name<'a>($crate::__core::marker::PhantomData<crate::Ui<'a>>);
impl<'a> $token_name<'a> {
/// Creates a new token type.
pub(crate) fn new(_: &crate::Ui<'a>) -> Self {
Self(std::marker::PhantomData)
}
$(#[$end_meta])*
#[inline]
pub fn end(self) {
// left empty for drop
}
}
impl Drop for $token_name<'_> {
fn drop(&mut self) {
unsafe { $on_drop }
}
}
}
}

View File

@ -25,75 +25,101 @@ bitflags! {
/// # Item/widget utilities
impl<'ui> Ui<'ui> {
/// Returns `true` if the last item is hovered
#[doc(alias = "IsItemHovered")]
pub fn is_item_hovered(&self) -> bool {
unsafe { sys::igIsItemHovered(0) }
}
/// Returns `true` if the last item is hovered based on the given flags
#[doc(alias = "IsItemHovered")]
pub fn is_item_hovered_with_flags(&self, flags: ItemHoveredFlags) -> bool {
unsafe { sys::igIsItemHovered(flags.bits() as i32) }
}
/// Returns `true` if the last item is active
#[doc(alias = "IsItemActive")]
pub fn is_item_active(&self) -> bool {
unsafe { sys::igIsItemActive() }
}
#[doc(alias = "IsItemFocused")]
/// Returns `true` if the last item is focused for keyboard/gamepad navigation
pub fn is_item_focused(&self) -> bool {
unsafe { sys::igIsItemFocused() }
}
/// Returns `true` if the last item is being clicked by `MouseButton::Left`.
///
/// This is the same as [is_item_clicked_with_button](Self::is_item_clicked_with_button)
/// with `button` set to `MouseButton::Left`.
#[doc(alias = "IsItemClicked")]
pub fn is_item_clicked(&self) -> bool {
self.is_item_clicked_with_button(MouseButton::Left)
}
/// Returns `true` if the last item is being clicked
pub fn is_item_clicked(&self, button: MouseButton) -> bool {
#[doc(alias = "IsItemClicked")]
pub fn is_item_clicked_with_button(&self, button: MouseButton) -> bool {
unsafe { sys::igIsItemClicked(button as i32) }
}
/// Returns `true` if the last item is visible
#[doc(alias = "IsItemVisible")]
pub fn is_item_visible(&self) -> bool {
unsafe { sys::igIsItemVisible() }
}
/// Returns `true` if the last item modified its underlying value this frame or was pressed
#[doc(alias = "IsItemEdited")]
pub fn is_item_edited(&self) -> bool {
unsafe { sys::igIsItemEdited() }
}
/// Returns `true` if the last item was just made active
#[doc(alias = "IsItemActivated")]
pub fn is_item_activated(&self) -> bool {
unsafe { sys::igIsItemActivated() }
}
/// Returns `true` if the last item was just made inactive
#[doc(alias = "IsItemDeactivated")]
pub fn is_item_deactivated(&self) -> bool {
unsafe { sys::igIsItemDeactivated() }
}
/// Returns `true` if the last item was just made inactive and made a value change when it was
#[doc(alias = "IsItemDeactivatedAfterEdit")]
/// active
pub fn is_item_deactivated_after_edit(&self) -> bool {
unsafe { sys::igIsItemDeactivatedAfterEdit() }
}
/// Returns `true` if the last item open state was toggled
#[doc(alias = "IsItemToggledOpen")]
pub fn is_item_toggled_open(&self) -> bool {
unsafe { sys::igIsItemToggledOpen() }
}
/// Returns `true` if any item is hovered
#[doc(alias = "IsAnyItemHovered")]
pub fn is_any_item_hovered(&self) -> bool {
unsafe { sys::igIsAnyItemHovered() }
}
/// Returns `true` if any item is active
#[doc(alias = "IsAnyItemActive")]
pub fn is_any_item_active(&self) -> bool {
unsafe { sys::igIsAnyItemActive() }
}
/// Returns `true` if any item is focused
#[doc(alias = "IsAnyItemFocused")]
pub fn is_any_item_focused(&self) -> bool {
unsafe { sys::igIsAnyItemFocused() }
}
/// Returns the upper-left bounding rectangle of the last item (in screen coordinates)
#[doc(alias = "GetItemRectMin")]
pub fn item_rect_min(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectMin(&mut out) }
out.into()
}
/// Returns the lower-right bounding rectangle of the last item (in screen coordinates)
#[doc(alias = "GetItemRectMax")]
pub fn item_rect_max(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectMax(&mut out) }
out.into()
}
/// Returns the size of the last item
#[doc(alias = "GetItemRectSize")]
pub fn item_rect_size(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectSize(&mut out) }
@ -102,10 +128,12 @@ impl<'ui> Ui<'ui> {
/// Allows the last item to be overlapped by a subsequent item.
///
/// Both may be activated during the same frame before the later one takes priority.
#[doc(alias = "SetItemAllowOverlap")]
pub fn set_item_allow_overlap(&self) {
unsafe { sys::igSetItemAllowOverlap() };
}
/// Makes the last item the default focused item of the window
#[doc(alias = "SetItemDefaultFocus")]
pub fn set_item_default_focus(&self) {
unsafe { sys::igSetItemDefaultFocus() };
}
@ -114,22 +142,26 @@ impl<'ui> Ui<'ui> {
/// # Miscellaneous utilities
impl<'ui> Ui<'ui> {
/// Returns `true` if the rectangle (of given size, starting from cursor position) is visible
#[doc(alias = "IsRectVisibleNil")]
pub fn is_cursor_rect_visible(&self, size: [f32; 2]) -> bool {
unsafe { sys::igIsRectVisibleNil(size.into()) }
}
/// Returns `true` if the rectangle (in screen coordinates) is visible
#[doc(alias = "IsRectVisibleNilVec2")]
pub fn is_rect_visible(&self, rect_min: [f32; 2], rect_max: [f32; 2]) -> bool {
unsafe { sys::igIsRectVisibleVec2(rect_min.into(), rect_max.into()) }
}
/// Returns the global imgui-rs time.
///
/// Incremented by Io::delta_time every frame.
#[doc(alias = "GetTime")]
pub fn time(&self) -> f64 {
unsafe { sys::igGetTime() }
}
/// Returns the global imgui-rs frame count.
///
/// Incremented by 1 every frame.
#[doc(alias = "GetFrameCount")]
pub fn frame_count(&self) -> i32 {
unsafe { sys::igGetFrameCount() }
}
@ -137,6 +169,7 @@ impl<'ui> Ui<'ui> {
///
/// Use this function if you need to access the colors, but don't want to clone the entire
/// style object.
#[doc(alias = "GetStyle")]
pub fn style_color(&self, style_color: StyleColor) -> [f32; 4] {
self.ctx.style()[style_color]
}

View File

@ -192,6 +192,7 @@ pub struct ColorEdit<'a> {
impl<'a> ColorEdit<'a> {
/// Constructs a new color editor builder.
#[doc(alias = "ColorEdit3", alias = "ColorEdit4")]
pub fn new<T: Into<EditableColor<'a>>>(label: &'a ImStr, value: T) -> ColorEdit<'a> {
ColorEdit {
label,
@ -366,6 +367,7 @@ pub struct ColorPicker<'a> {
impl<'a> ColorPicker<'a> {
/// Constructs a new color picker builder.
#[doc(alias = "ColorButton")]
pub fn new<T: Into<EditableColor<'a>>>(label: &'a ImStr, value: T) -> ColorPicker<'a> {
ColorPicker {
label,
@ -637,6 +639,7 @@ impl<'ui> Ui<'ui> {
/// Initializes current color editor/picker options (generally on application startup) if you
/// want to select a default format, picker type, etc. Users will be able to change many
/// settings, unless you use .options(false) in your widget builders.
#[doc(alias = "SetColorEditOptions")]
pub fn set_color_edit_options(&self, flags: ColorEditFlags) {
unsafe {
sys::igSetColorEditOptions(flags.bits() as i32);

View File

@ -1,9 +1,7 @@
use bitflags::bitflags;
use std::borrow::Cow;
use std::ptr;
use std::thread;
use crate::context::Context;
use crate::string::ImStr;
use crate::sys;
use crate::Ui;
@ -66,6 +64,7 @@ pub struct ComboBox<'a> {
impl<'a> ComboBox<'a> {
/// Constructs a new combo box builder.
#[doc(alias = "BeginCombo")]
pub const fn new(label: &'a ImStr) -> ComboBox<'a> {
ComboBox {
label,
@ -141,7 +140,7 @@ impl<'a> ComboBox<'a> {
///
/// Returns `None` if the combo box is not open and no content should be rendered.
#[must_use]
pub fn begin(self, ui: &Ui) -> Option<ComboBoxToken> {
pub fn begin<'ui>(self, ui: &Ui<'ui>) -> Option<ComboBoxToken<'ui>> {
let should_render = unsafe {
sys::igBeginCombo(
self.label.as_ptr(),
@ -150,7 +149,7 @@ impl<'a> ComboBox<'a> {
)
};
if should_render {
Some(ComboBoxToken { ctx: ui.ctx })
Some(ComboBoxToken::new(ui))
} else {
None
}
@ -159,38 +158,25 @@ impl<'a> ComboBox<'a> {
///
/// Note: the closure is not called if the combo box is not open.
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
if let Some(combo) = self.begin(ui) {
if let Some(_combo) = self.begin(ui) {
f();
combo.end(ui);
}
}
}
/// Tracks a combo box that must be ended by calling `.end()`
#[must_use]
pub struct ComboBoxToken {
ctx: *const Context,
}
create_token!(
/// Tracks a combo box that can be ended by calling `.end()`
/// or by dropping.
pub struct ComboBoxToken<'ui>;
impl ComboBoxToken {
/// Ends a combo box
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndCombo() };
}
}
impl Drop for ComboBoxToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A ComboBoxToken was leaked. Did you call .end()?");
}
}
}
drop { sys::igEndCombo() }
);
/// # Convenience functions
impl<'a> ComboBox<'a> {
/// Builds a simple combo box for choosing from a slice of values
#[doc(alias = "BeginCombo")]
pub fn build_simple<T, L>(
self,
ui: &Ui,
@ -219,11 +205,11 @@ impl<'a> ComboBox<'a> {
result = true;
}
}
_cb.end(ui);
}
result
}
/// Builds a simple combo box for choosing from a slice of strings
#[doc(alias = "BeginCombo")]
pub fn build_simple_string<S>(self, ui: &Ui, current_item: &mut usize, items: &[&S]) -> bool
where
S: AsRef<ImStr> + ?Sized,

View File

@ -21,6 +21,7 @@ pub struct Drag<'a, T: DataTypeKind> {
impl<'a, T: DataTypeKind> Drag<'a, T> {
/// Constructs a new drag slider builder.
#[doc(alias = "DragScalar", alias = "DragScalarN")]
pub fn new(label: &ImStr) -> Drag<T> {
Drag {
label,
@ -126,6 +127,7 @@ pub struct DragRange<'a, T: DataTypeKind> {
impl<'a, T: DataTypeKind> DragRange<'a, T> {
/// Constructs a new drag slider builder.
#[doc(alias = "DragIntRange2", alias = "DragFloatRange2")]
pub fn new(label: &ImStr) -> DragRange<T> {
DragRange {
label,
@ -175,6 +177,7 @@ impl<'a> DragRange<'a, f32> {
/// Builds a drag range slider that is bound to the given min/max values.
///
/// Returns true if the slider value was changed.
#[doc(alias = "DragFloatRange2")]
pub fn build(self, _: &Ui, min: &mut f32, max: &mut f32) -> bool {
unsafe {
sys::igDragFloatRange2(
@ -200,6 +203,7 @@ impl<'a> DragRange<'a, i32> {
/// Builds a drag range slider that is bound to the given min/max values.
///
/// Returns true if the slider value was changed.
#[doc(alias = "DragIntRange2")]
pub fn build(self, _: &Ui, min: &mut i32, max: &mut i32) -> bool {
unsafe {
sys::igDragIntRange2(

View File

@ -18,6 +18,7 @@ pub struct Image {
impl Image {
/// Creates a new image builder with the given texture and size
#[doc(alias = "Image")]
pub const fn new(texture_id: TextureId, size: [f32; 2]) -> Image {
Image {
texture_id,
@ -83,6 +84,7 @@ pub struct ImageButton {
impl ImageButton {
/// Creates a new image button builder with the given texture and size
#[doc(alias = "ImageButton")]
pub fn new(texture_id: TextureId, size: [f32; 2]) -> ImageButton {
ImageButton {
texture_id,

View File

@ -1,48 +1,26 @@
use std::borrow::Cow;
use std::ptr;
use std::thread;
use crate::context::Context;
use crate::string::ImStr;
use crate::sys;
use crate::Ui;
#[derive(Copy, Clone, Debug)]
enum Size {
Vec(sys::ImVec2),
Items {
items_count: i32,
height_in_items: i32,
},
}
/// Builder for a list box widget
#[derive(Copy, Clone, Debug)]
#[must_use]
pub struct ListBox<'a> {
label: &'a ImStr,
size: Size,
size: sys::ImVec2,
}
impl<'a> ListBox<'a> {
/// Constructs a new list box builder.
#[doc(alias = "ListBoxHeaderVec2", alias = "ListBoxHeaderInt")]
pub const fn new(label: &'a ImStr) -> ListBox<'a> {
ListBox {
label,
size: Size::Vec(sys::ImVec2::zero()),
size: sys::ImVec2::zero(),
}
}
/// Sets the list box size based on the number of items that you want to make visible
/// Size default to hold ~7.25 items.
/// We add +25% worth of item height to allow the user to see at a glance if there are more items up/down, without looking at the scrollbar.
/// We don't add this extra bit if items_count <= height_in_items. It is slightly dodgy, because it means a dynamic list of items will make the widget resize occasionally when it crosses that size.
#[inline]
pub const fn calculate_size(mut self, items_count: i32, height_in_items: i32) -> Self {
self.size = Size::Items {
items_count,
height_in_items,
};
self
}
/// Sets the list box size based on the given width and height
/// If width or height are 0 or smaller, a default value is calculated
@ -52,7 +30,7 @@ impl<'a> ListBox<'a> {
/// Default: [0.0, 0.0], in which case the combobox calculates a sensible width and height
#[inline]
pub const fn size(mut self, size: [f32; 2]) -> Self {
self.size = Size::Vec(sys::ImVec2::new(size[0], size[1]));
self.size = sys::ImVec2::new(size[0], size[1]);
self
}
/// Creates a list box and starts appending to it.
@ -62,18 +40,10 @@ impl<'a> ListBox<'a> {
///
/// Returns `None` if the list box is not open and no content should be rendered.
#[must_use]
pub fn begin(self, ui: &Ui) -> Option<ListBoxToken> {
let should_render = unsafe {
match self.size {
Size::Vec(size) => sys::igListBoxHeaderVec2(self.label.as_ptr(), size),
Size::Items {
items_count,
height_in_items,
} => sys::igListBoxHeaderInt(self.label.as_ptr(), items_count, height_in_items),
}
};
pub fn begin<'ui>(self, ui: &Ui<'ui>) -> Option<ListBoxToken<'ui>> {
let should_render = unsafe { sys::igBeginListBox(self.label.as_ptr(), self.size) };
if should_render {
Some(ListBoxToken { ctx: ui.ctx })
Some(ListBoxToken::new(ui))
} else {
None
}
@ -82,34 +52,20 @@ impl<'a> ListBox<'a> {
///
/// Note: the closure is not called if the list box is not open.
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
if let Some(list) = self.begin(ui) {
if let Some(_list) = self.begin(ui) {
f();
list.end(ui);
}
}
}
/// Tracks a list box that must be ended by calling `.end()`
#[must_use]
pub struct ListBoxToken {
ctx: *const Context,
}
create_token!(
/// Tracks a list box that can be ended by calling `.end()`
/// or by dropping
pub struct ListBoxToken<'ui>;
impl ListBoxToken {
/// Ends a list box
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igListBoxFooter() };
}
}
impl Drop for ListBoxToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A ListBoxToken was leaked. Did you call .end()?");
}
}
}
drop { sys::igEndListBox() }
);
/// # Convenience functions
impl<'a> ListBox<'a> {
@ -136,7 +92,6 @@ impl<'a> ListBox<'a> {
result = true;
}
}
_cb.end(ui);
}
result
}

View File

@ -1,7 +1,5 @@
use std::ptr;
use std::thread;
use crate::context::Context;
use crate::string::ImStr;
use crate::sys;
use crate::Ui;
@ -15,9 +13,10 @@ impl<'ui> Ui<'ui> {
///
/// Returns `None` if the menu bar is not visible and no content should be rendered.
#[must_use]
pub fn begin_main_menu_bar(&self) -> Option<MainMenuBarToken> {
#[doc(alias = "BeginMainMenuBar")]
pub fn begin_main_menu_bar(&self) -> Option<MainMenuBarToken<'ui>> {
if unsafe { sys::igBeginMainMenuBar() } {
Some(MainMenuBarToken { ctx: self.ctx })
Some(MainMenuBarToken::new(self))
} else {
None
}
@ -25,10 +24,10 @@ impl<'ui> Ui<'ui> {
/// Creates a full-screen main menu bar and runs a closure to construct the contents.
///
/// Note: the closure is not called if the menu bar is not visible.
#[doc(alias = "BeginMenuBar")]
pub fn main_menu_bar<F: FnOnce()>(&self, f: F) {
if let Some(menu_bar) = self.begin_main_menu_bar() {
if let Some(_menu_bar) = self.begin_main_menu_bar() {
f();
menu_bar.end(self);
}
}
/// Creates and starts appending to the menu bar of the current window.
@ -38,9 +37,10 @@ impl<'ui> Ui<'ui> {
///
/// Returns `None` if the menu bar is not visible and no content should be rendered.
#[must_use]
pub fn begin_menu_bar(&self) -> Option<MenuBarToken> {
#[doc(alias = "BeginMenuBar")]
pub fn begin_menu_bar(&self) -> Option<MenuBarToken<'_>> {
if unsafe { sys::igBeginMenuBar() } {
Some(MenuBarToken { ctx: self.ctx })
Some(MenuBarToken::new(self))
} else {
None
}
@ -48,12 +48,28 @@ impl<'ui> Ui<'ui> {
/// Creates a menu bar in the current window and runs a closure to construct the contents.
///
/// Note: the closure is not called if the menu bar is not visible.
#[doc(alias = "BeginMenuBar")]
pub fn menu_bar<F: FnOnce()>(&self, f: F) {
if let Some(menu_bar) = self.begin_menu_bar() {
if let Some(_menu_bar) = self.begin_menu_bar() {
f();
menu_bar.end(self);
}
}
/// Creates and starts appending to a sub-menu entry.
///
/// Returns `Some(MenuToken)` if the menu is visible. After content has been
/// rendered, the token must be ended by calling `.end()`.
///
/// Returns `None` if the menu is not visible and no content should be rendered.
///
/// This is the equivalent of [begin_menu_with_enabled](Self::begin_menu_with_enabled)
/// with `enabled` set to `true`.
#[must_use]
#[doc(alias = "BeginMenu")]
pub fn begin_menu(&self, label: &ImStr) -> Option<MenuToken<'_>> {
self.begin_menu_with_enabled(label, true)
}
/// Creates and starts appending to a sub-menu entry.
///
/// Returns `Some(MenuToken)` if the menu is visible. After content has been
@ -61,9 +77,10 @@ impl<'ui> Ui<'ui> {
///
/// Returns `None` if the menu is not visible and no content should be rendered.
#[must_use]
pub fn begin_menu(&self, label: &ImStr, enabled: bool) -> Option<MenuToken> {
#[doc(alias = "BeginMenu")]
pub fn begin_menu_with_enabled(&self, label: &ImStr, enabled: bool) -> Option<MenuToken<'_>> {
if unsafe { sys::igBeginMenu(label.as_ptr(), enabled) } {
Some(MenuToken { ctx: self.ctx })
Some(MenuToken::new(self))
} else {
None
}
@ -71,10 +88,21 @@ impl<'ui> Ui<'ui> {
/// Creates a menu and runs a closure to construct the contents.
///
/// Note: the closure is not called if the menu is not visible.
pub fn menu<F: FnOnce()>(&self, label: &ImStr, enabled: bool, f: F) {
if let Some(menu) = self.begin_menu(label, enabled) {
///
/// This is the equivalent of [menu_with_enabled](Self::menu_with_enabled)
/// with `enabled` set to `true`.
#[doc(alias = "BeginMenu")]
pub fn menu<F: FnOnce()>(&self, label: &ImStr, f: F) {
self.menu_with_enabled(label, true, f);
}
/// Creates a menu and runs a closure to construct the contents.
///
/// Note: the closure is not called if the menu is not visible.
#[doc(alias = "BeginMenu")]
pub fn menu_with_enabled<F: FnOnce()>(&self, label: &ImStr, enabled: bool, f: F) {
if let Some(_menu) = self.begin_menu_with_enabled(label, enabled) {
f();
menu.end(self);
}
}
}
@ -126,6 +154,7 @@ impl<'a> MenuItem<'a> {
/// Builds the menu item.
///
/// Returns true if the menu item is activated.
#[doc(alias = "MenuItemBool")]
pub fn build(self, _: &Ui) -> bool {
unsafe {
sys::igMenuItemBool(
@ -151,68 +180,29 @@ impl<'a> MenuItem<'a> {
}
}
/// Tracks a main menu bar that must be ended by calling `.end()`
#[must_use]
pub struct MainMenuBarToken {
ctx: *const Context,
}
create_token!(
/// Tracks a main menu bar that can be ended by calling `.end()`
/// or by dropping
pub struct MainMenuBarToken<'ui>;
impl MainMenuBarToken {
/// Ends a main menu bar
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndMainMenuBar() };
}
}
drop { sys::igEndMainMenuBar() }
);
impl Drop for MainMenuBarToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A MainMenuBarToken was leaked. Did you call .end()?");
}
}
}
create_token!(
/// Tracks a menu bar that can be ended by calling `.end()`
/// or by dropping
pub struct MenuBarToken<'ui>;
/// Tracks a menu bar that must be ended by calling `.end()`
#[must_use]
pub struct MenuBarToken {
ctx: *const Context,
}
impl MenuBarToken {
/// Ends a menu bar
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndMenuBar() };
}
}
drop { sys::igEndMenuBar() }
);
impl Drop for MenuBarToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A MenuBarToken was leaked. Did you call .end()?");
}
}
}
create_token!(
/// Tracks a menu that can be ended by calling `.end()`
/// or by dropping
pub struct MenuToken<'ui>;
/// Tracks a menu that must be ended by calling `.end()`
#[must_use]
pub struct MenuToken {
ctx: *const Context,
}
impl MenuToken {
/// Ends a menu
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndMenu() };
}
}
impl Drop for MenuToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A MenuToken was leaked. Did you call .end()?");
}
}
}
drop { sys::igEndMenu() }
);

View File

@ -23,36 +23,58 @@ impl<'ui> Ui<'ui> {
/// Renders a clickable button.
///
/// Returns true if this button was clicked.
pub fn button(&self, label: &ImStr, size: [f32; 2]) -> bool {
///
/// This is the equivalent of [button_with_size](Self::button_with_size)
/// with `size` set to `[0.0, 0.0]`, which will size the button to the
/// label's width in the current style.
/// the current style.
#[doc("Button")]
pub fn button(&self, label: &ImStr) -> bool {
self.button_with_size(label, [0.0, 0.0])
}
/// Renders a clickable button.
///
/// Returns true if this button was clicked.
///
/// Setting `size` as `[0.0, 0.0]` will size the button to the label's width in
/// the current style.
#[doc("Button")]
pub fn button_with_size(&self, label: &ImStr, size: [f32; 2]) -> bool {
unsafe { sys::igButton(label.as_ptr(), size.into()) }
}
/// Renders a small clickable button that is easy to embed in text.
///
/// Returns true if this button was clicked.
#[doc("SmallButton")]
pub fn small_button(&self, label: &ImStr) -> bool {
unsafe { sys::igSmallButton(label.as_ptr()) }
}
/// Renders a widget with button behaviour without the visual look.
///
/// Returns true if this button was clicked.
#[doc("InvisibleButton")]
pub fn invisible_button(&self, id: &ImStr, size: [f32; 2]) -> bool {
unsafe { sys::igInvisibleButton(id.as_ptr(), size.into(), 0) }
}
/// Renders a widget with button behaviour without the visual look.
///
/// Returns true if this button was clicked.
#[doc("InvisibleButton")]
pub fn invisible_button_flags(&self, id: &ImStr, size: [f32; 2], flags: ButtonFlags) -> bool {
unsafe { sys::igInvisibleButton(id.as_ptr(), size.into(), flags.bits() as i32) }
}
/// Renders a square button with an arrow shape.
///
/// Returns true if this button was clicked.
#[doc("ArrowButton")]
pub fn arrow_button(&self, id: &ImStr, direction: Direction) -> bool {
unsafe { sys::igArrowButton(id.as_ptr(), direction as i32) }
}
/// Renders a simple checkbox.
///
/// Returns true if this checkbox was clicked.
#[doc("Checkbox")]
pub fn checkbox(&self, label: &ImStr, value: &mut bool) -> bool {
unsafe { sys::igCheckbox(label.as_ptr(), value as *mut bool) }
}
@ -77,12 +99,14 @@ impl<'ui> Ui<'ui> {
/// Renders a simple radio button.
///
/// Returns true if this radio button was clicked.
#[doc("RadioButtonBool")]
pub fn radio_button_bool(&self, label: &ImStr, active: bool) -> bool {
unsafe { sys::igRadioButtonBool(label.as_ptr(), active) }
}
/// Renders a radio button suitable for choosing an arbitrary value.
///
/// Returns true if this radio button was clicked.
#[doc("RadioButtonBool")]
pub fn radio_button<T>(&self, label: &ImStr, value: &mut T, button_value: T) -> bool
where
T: Copy + PartialEq,
@ -94,6 +118,7 @@ impl<'ui> Ui<'ui> {
pressed
}
/// Renders a small circle and keeps the cursor on the same line
#[doc("Bullet")]
pub fn bullet(&self) {
unsafe { sys::igBullet() };
}

View File

@ -32,6 +32,7 @@ impl<'a> ProgressBar<'a> {
/// The progress bar will be automatically sized to fill the entire width of the window if no
/// custom size is specified.
#[inline]
#[doc(alias = "ProgressBar")]
pub const fn new(fraction: f32) -> ProgressBar<'a> {
ProgressBar {
fraction,

View File

@ -34,6 +34,7 @@ pub struct Selectable<'a> {
impl<'a> Selectable<'a> {
/// Constructs a new selectable builder.
#[inline]
#[doc(alias = "Selectable")]
pub const fn new(label: &ImStr) -> Selectable {
Selectable {
label,

View File

@ -37,6 +37,7 @@ pub struct Slider<'a, T: DataTypeKind> {
impl<'a, T: DataTypeKind> Slider<'a, T> {
/// Constructs a new slider builder with the given range.
#[doc(alias = "SliderScalar", alias = "SliderScalarN")]
pub fn new(label: &ImStr) -> Slider<T> {
Slider {
label,
@ -118,6 +119,7 @@ pub struct VerticalSlider<'a, T: DataTypeKind + Copy> {
impl<'a, T: DataTypeKind> VerticalSlider<'a, T> {
/// Constructs a new vertical slider builder with the given size and range.
#[doc(alias = "VSliderScalar")]
pub fn new(label: &ImStr, size: [f32; 2]) -> VerticalSlider<T> {
VerticalSlider {
label,
@ -181,6 +183,7 @@ pub struct AngleSlider<'a> {
impl<'a> AngleSlider<'a> {
/// Constructs a new angle slider builder.
#[doc(alias = "SliderAngle")]
pub fn new(label: &ImStr) -> AngleSlider {
AngleSlider {
label,

View File

@ -19,12 +19,11 @@
//! ```
//!
//! See `test_window_impl.rs` for a more complicated example.
use crate::context::Context;
use crate::string::ImStr;
use crate::sys;
use crate::Ui;
use bitflags::bitflags;
use std::{ptr, thread};
use std::ptr;
bitflags! {
#[repr(transparent)]
@ -64,6 +63,7 @@ pub struct TabBar<'a> {
impl<'a> TabBar<'a> {
#[inline]
#[doc(alias = "BeginTabBar")]
pub const fn new(id: &'a ImStr) -> Self {
Self {
id,
@ -90,12 +90,12 @@ impl<'a> TabBar<'a> {
}
#[must_use]
pub fn begin(self, ui: &Ui) -> Option<TabBarToken> {
pub fn begin<'ui>(self, ui: &Ui<'ui>) -> Option<TabBarToken<'ui>> {
let should_render =
unsafe { sys::igBeginTabBar(self.id.as_ptr(), self.flags.bits() as i32) };
if should_render {
Some(TabBarToken { ctx: ui.ctx })
Some(TabBarToken::new(ui))
} else {
unsafe { sys::igEndTabBar() };
None
@ -106,33 +106,20 @@ impl<'a> TabBar<'a> {
///
/// Note: the closure is not called if no tabbar content is visible
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
if let Some(tab) = self.begin(ui) {
if let Some(_tab) = self.begin(ui) {
f();
tab.end(ui);
}
}
}
/// Tracks a window that must be ended by calling `.end()`
pub struct TabBarToken {
ctx: *const Context,
}
create_token!(
/// Tracks a window that can be ended by calling `.end()`
/// or by dropping
pub struct TabBarToken<'ui>;
impl TabBarToken {
/// Ends a tab bar
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndTabBar() };
}
}
impl Drop for TabBarToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A TabBarToken was leaked. Did you call .end()?");
}
}
}
/// Ends a tab bar.
drop { sys::igEndTabBar() }
);
pub struct TabItem<'a> {
name: &'a ImStr,
@ -141,6 +128,7 @@ pub struct TabItem<'a> {
}
impl<'a> TabItem<'a> {
#[doc(alias = "BeginTabItem")]
pub fn new(name: &'a ImStr) -> Self {
Self {
name,
@ -168,7 +156,7 @@ impl<'a> TabItem<'a> {
}
#[must_use]
pub fn begin(self, ui: &Ui) -> Option<TabItemToken> {
pub fn begin<'ui>(self, ui: &Ui<'ui>) -> Option<TabItemToken<'ui>> {
let should_render = unsafe {
sys::igBeginTabItem(
self.name.as_ptr(),
@ -180,7 +168,7 @@ impl<'a> TabItem<'a> {
};
if should_render {
Some(TabItemToken { ctx: ui.ctx })
Some(TabItemToken::new(ui))
} else {
None
}
@ -190,28 +178,17 @@ impl<'a> TabItem<'a> {
///
/// Note: the closure is not called if the tab item is not selected
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
if let Some(tab) = self.begin(ui) {
if let Some(_tab) = self.begin(ui) {
f();
tab.end(ui);
}
}
}
pub struct TabItemToken {
ctx: *const Context,
}
create_token!(
/// Tracks a tab bar item that can be ended by calling `.end()`
/// or by dropping
pub struct TabItemToken<'ui>;
impl TabItemToken {
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndTabItem() };
}
}
impl Drop for TabItemToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A TabItemToken was leaked. Did you call .end()?");
}
}
}
/// Ends a tab bar item.
drop { sys::igEndTabItem() }
);

View File

@ -14,6 +14,7 @@ fn fmt_ptr() -> *const c_char {
/// # Widgets: Text
impl<'ui> Ui<'ui> {
/// Renders simple text
#[doc(alias = "TextUnformatted")]
pub fn text<T: AsRef<str>>(&self, text: T) {
let s = text.as_ref();
unsafe {
@ -26,24 +27,27 @@ impl<'ui> Ui<'ui> {
pub fn text_colored<T: AsRef<str>>(&self, color: [f32; 4], text: T) {
let style = self.push_style_color(StyleColor::Text, color);
self.text(text);
style.pop(self);
style.end();
}
/// Renders simple text using `StyleColor::TextDisabled` color
pub fn text_disabled<T: AsRef<str>>(&self, text: T) {
let color = self.style_color(StyleColor::TextDisabled);
let style = self.push_style_color(StyleColor::Text, color);
self.text(text);
style.pop(self);
style.end();
}
/// Renders text wrapped to the end of window (or column)
#[doc(alias = "TextWrapperd")]
pub fn text_wrapped(&self, text: &ImStr) {
unsafe { sys::igTextWrapped(fmt_ptr(), text.as_ptr()) }
}
/// Render a text + label combination aligned the same way as value+label widgets
#[doc(alias = "LabelText")]
pub fn label_text(&self, label: &ImStr, text: &ImStr) {
unsafe { sys::igLabelText(label.as_ptr(), fmt_ptr(), text.as_ptr()) }
}
/// Renders text with a little bullet aligned to the typical tree node
#[doc(alias = "BulletText")]
pub fn bullet_text(&self, text: &ImStr) {
unsafe { sys::igBulletText(fmt_ptr(), text.as_ptr()) }
}

View File

@ -1,9 +1,6 @@
use bitflags::bitflags;
use std::os::raw::{c_char, c_void};
use std::ptr;
use std::thread;
use crate::context::Context;
use crate::string::ImStr;
use crate::sys;
use crate::{Condition, Ui};
@ -234,11 +231,10 @@ impl<'a> TreeNode<'a> {
/// Pushes a tree node and starts appending to it.
///
/// Returns `Some(TreeNodeToken)` if the tree node is open. After content has been
/// rendered, the token must be popped by calling `.pop()`.
/// rendered, the token can be popped by calling `.pop()`.
///
/// Returns `None` if the tree node is not open and no content should be rendered.
#[must_use]
pub fn push(self, ui: &Ui) -> Option<TreeNodeToken> {
pub fn push<'ui>(self, ui: &Ui<'ui>) -> Option<TreeNodeToken<'ui>> {
let open = unsafe {
if self.opened_cond != Condition::Never {
sys::igSetNextItemOpen(self.opened, self.opened_cond as i32);
@ -259,13 +255,10 @@ impl<'a> TreeNode<'a> {
}
};
if open {
Some(TreeNodeToken {
ctx: if self.flags.contains(TreeNodeFlags::NO_TREE_PUSH_ON_OPEN) {
ptr::null()
} else {
ui.ctx
},
})
Some(TreeNodeToken::new(
ui,
!self.flags.contains(TreeNodeFlags::NO_TREE_PUSH_ON_OPEN),
))
} else {
None
}
@ -274,37 +267,43 @@ impl<'a> TreeNode<'a> {
///
/// Note: the closure is not called if the tree node is not open.
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
if let Some(node) = self.push(ui) {
if let Some(_node) = self.push(ui) {
f();
node.pop(ui);
}
}
}
/// Tracks a tree node that must be popped by calling `.pop()`.
/// Tracks a tree node that can be popped by calling `.pop()`, `end()`, or by dropping.
///
/// If `TreeNodeFlags::NO_TREE_PUSH_ON_OPEN` was used when this token was created, calling `.pop()`
/// is not mandatory and is a no-op.
#[must_use]
pub struct TreeNodeToken {
ctx: *const Context,
}
pub struct TreeNodeToken<'a>(core::marker::PhantomData<crate::Ui<'a>>, bool);
impl<'a> TreeNodeToken<'a> {
/// Creates a new token type. This takes a bool for the no-op variant on NO_TREE_PUSH_ON_OPEN.
pub(crate) fn new(_: &crate::Ui<'a>, execute_drop: bool) -> Self {
Self(std::marker::PhantomData, execute_drop)
}
impl TreeNodeToken {
/// Pops a tree node
#[inline]
pub fn pop(mut self, _: &Ui) {
if !self.ctx.is_null() {
self.ctx = ptr::null();
unsafe { sys::igTreePop() };
}
pub fn end(self) {
// left empty for drop
}
/// Pops a tree node
#[inline]
pub fn pop(self) {
self.end()
}
}
impl Drop for TreeNodeToken {
impl Drop for TreeNodeToken<'_> {
#[doc(alias = "TreePop")]
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A TreeNodeToken was leaked. Did you call .pop()?");
if self.1 {
unsafe { sys::igTreePop() }
}
}
}
@ -319,6 +318,7 @@ pub struct CollapsingHeader<'a> {
impl<'a> CollapsingHeader<'a> {
/// Constructs a new collapsing header builder
#[doc(alias = "CollapsingHeader")]
pub fn new(label: &ImStr) -> CollapsingHeader {
CollapsingHeader {
label,

View File

@ -1,9 +1,6 @@
use std::f32;
use std::os::raw::{c_char, c_void};
use std::ptr;
use std::thread;
use crate::context::Context;
use crate::sys;
use crate::window::WindowFlags;
use crate::{Id, Ui};
@ -23,6 +20,7 @@ pub struct ChildWindow<'a> {
impl<'a> ChildWindow<'a> {
/// Creates a new child window builder with the given ID
#[doc(alas = "BeginChildID")]
pub fn new<T: Into<Id<'a>>>(id: T) -> ChildWindow<'a> {
ChildWindow {
id: id.into(),
@ -57,12 +55,14 @@ impl<'a> ChildWindow<'a> {
/// Does not include window decorations (title bar, menu bar, etc.). Set one of the values to
/// 0.0 to leave the size automatic.
#[inline]
#[doc(alias = "SetNextWindowContentSize")]
pub fn content_size(mut self, size: [f32; 2]) -> Self {
self.content_size = size;
self
}
/// Sets the window focused state, which can be used to bring the window to front
#[inline]
#[doc(alias = "SetNextWindwowFocus")]
pub fn focused(mut self, focused: bool) -> Self {
self.focused = focused;
self
@ -71,6 +71,7 @@ impl<'a> ChildWindow<'a> {
///
/// See also `draw_background`
#[inline]
#[doc(alias = "SetNextWindowContentBgAlpha")]
pub fn bg_alpha(mut self, bg_alpha: f32) -> Self {
self.bg_alpha = bg_alpha;
self
@ -244,7 +245,7 @@ impl<'a> ChildWindow<'a> {
/// rendered, the token must be ended by calling `.end()`.
///
/// Returns `None` if the window is not visible and no content should be rendered.
pub fn begin(self, ui: &Ui) -> Option<ChildWindowToken> {
pub fn begin<'ui>(self, ui: &Ui<'ui>) -> Option<ChildWindowToken<'ui>> {
if self.content_size[0] != 0.0 || self.content_size[1] != 0.0 {
unsafe { sys::igSetNextWindowContentSize(self.content_size.into()) };
}
@ -269,7 +270,7 @@ impl<'a> ChildWindow<'a> {
sys::igBeginChildID(id, self.size.into(), self.border, self.flags.bits() as i32)
};
if should_render {
Some(ChildWindowToken { ctx: ui.ctx })
Some(ChildWindowToken::new(ui))
} else {
unsafe { sys::igEndChild() };
None
@ -280,30 +281,17 @@ impl<'a> ChildWindow<'a> {
/// Note: the closure is not called if no window content is visible (e.g. window is collapsed
/// or fully clipped).
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
if let Some(window) = self.begin(ui) {
if let Some(_window) = self.begin(ui) {
f();
window.end(ui);
}
}
}
/// Tracks a child window that must be ended by calling `.end()`
pub struct ChildWindowToken {
ctx: *const Context,
}
create_token!(
/// Tracks a child window that can be ended by calling `.end()`
/// or by dropping
pub struct ChildWindowToken<'ui>;
impl ChildWindowToken {
/// Ends a window
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndChild() };
}
}
impl Drop for ChildWindowToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A ChildWindowToken was leaked. Did you call .end()?");
}
}
}
drop { sys::igEndChild() }
);

View File

@ -4,12 +4,14 @@ use crate::Ui;
/// # Content region
impl<'ui> Ui<'ui> {
/// Returns the current content boundaries (in *window coordinates*)
#[doc(alias = "GetContentRegionMax")]
pub fn content_region_max(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetContentRegionMax(&mut out) };
out.into()
}
/// Equal to `ui.content_region_max()` - `ui.cursor_pos()`
#[doc(alias = "GetContentRegionAvail")]
pub fn content_region_avail(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetContentRegionAvail(&mut out) };
@ -18,6 +20,7 @@ impl<'ui> Ui<'ui> {
/// Content boundaries min (in *window coordinates*).
///
/// Roughly equal to [0.0, 0.0] - scroll.
#[doc(alias = "GetContentRegionMin")]
pub fn window_content_region_min(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetWindowContentRegionMin(&mut out) };
@ -26,11 +29,13 @@ impl<'ui> Ui<'ui> {
/// Content boundaries max (in *window coordinates*).
///
/// Roughly equal to [0.0, 0.0] + size - scroll.
#[doc(alias = "GetContentRegionMax")]
pub fn window_content_region_max(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetWindowContentRegionMax(&mut out) };
out.into()
}
#[doc(alias = "GetContentRegionWidth")]
pub fn window_content_region_width(&self) -> f32 {
unsafe { sys::igGetWindowContentRegionWidth() }
}

View File

@ -1,9 +1,7 @@
use bitflags::bitflags;
use std::f32;
use std::ptr;
use std::thread;
use crate::context::Context;
use crate::string::ImStr;
use crate::sys;
use crate::{Condition, Ui};
@ -115,36 +113,44 @@ bitflags! {
/// # Window utilities
impl<'ui> Ui<'ui> {
/// Returns true if the current window appeared during this frame
#[doc(alias = "IsWindowAppearing")]
pub fn is_window_appearing(&self) -> bool {
unsafe { sys::igIsWindowAppearing() }
}
/// Returns true if the current window is in collapsed state (= only the title bar is visible)
#[doc(alias = "IsWindowCollapsed")]
pub fn is_window_collapsed(&self) -> bool {
unsafe { sys::igIsWindowCollapsed() }
}
/// Returns true if the current window is focused
#[doc(alias = "IsWindowFocused")]
pub fn is_window_focused(&self) -> bool {
unsafe { sys::igIsWindowFocused(0) }
}
/// Returns true if the current window is focused based on the given flags
#[doc(alias = "IsWindowFocused")]
pub fn is_window_focused_with_flags(&self, flags: WindowFocusedFlags) -> bool {
unsafe { sys::igIsWindowFocused(flags.bits() as i32) }
}
/// Returns true if the current window is hovered
#[doc(alias = "IsWindowHovered")]
pub fn is_window_hovered(&self) -> bool {
unsafe { sys::igIsWindowHovered(0) }
}
/// Returns true if the current window is hovered based on the given flags
#[doc(alias = "IsWindowHovered")]
pub fn is_window_hovered_with_flags(&self, flags: WindowHoveredFlags) -> bool {
unsafe { sys::igIsWindowHovered(flags.bits() as i32) }
}
/// Returns the position of the current window (in screen space)
#[doc(alias = "GetWindowPos")]
pub fn window_pos(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetWindowPos(&mut out) };
out.into()
}
/// Returns the size of the current window
#[doc(alias = "GetWindowPos")]
pub fn window_size(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetWindowSize(&mut out) };
@ -482,7 +488,7 @@ impl<'a> Window<'a> {
///
/// Returns `None` if the window is not visible and no content should be rendered.
#[must_use]
pub fn begin(self, ui: &Ui) -> Option<WindowToken> {
pub fn begin<'ui>(self, ui: &Ui<'ui>) -> Option<WindowToken<'ui>> {
if self.pos_cond != Condition::Never {
unsafe {
sys::igSetNextWindowPos(
@ -528,7 +534,7 @@ impl<'a> Window<'a> {
)
};
if should_render {
Some(WindowToken { ctx: ui.ctx })
Some(WindowToken::new(ui))
} else {
unsafe { sys::igEnd() };
None
@ -539,30 +545,17 @@ impl<'a> Window<'a> {
/// Note: the closure is not called if no window content is visible (e.g. window is collapsed
/// or fully clipped).
pub fn build<F: FnOnce()>(self, ui: &Ui, f: F) {
if let Some(window) = self.begin(ui) {
if let Some(_window) = self.begin(ui) {
f();
window.end(ui);
}
}
}
/// Tracks a window that must be ended by calling `.end()`
pub struct WindowToken {
ctx: *const Context,
}
create_token!(
/// Tracks a window that can be ended by calling `.end()`
/// or by dropping.
pub struct WindowToken<'ui>;
impl WindowToken {
/// Ends a window
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEnd() };
}
}
impl Drop for WindowToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A WindowToken was leaked. Did you call .end()?");
}
}
}
drop { sys::igEnd() }
);

View File

@ -6,38 +6,47 @@ impl<'ui> Ui<'ui> {
/// Returns the horizontal scrolling position.
///
/// Value is between 0.0 and self.scroll_max_x().
#[doc(alias = "GetScrollX")]
pub fn scroll_x(&self) -> f32 {
unsafe { sys::igGetScrollX() }
}
/// Returns the vertical scrolling position.
///
/// Value is between 0.0 and self.scroll_max_y().
#[doc(alias = "GetScrollY")]
pub fn scroll_y(&self) -> f32 {
unsafe { sys::igGetScrollY() }
}
/// Returns the maximum horizontal scrolling position.
///
/// Roughly equal to content size X - window size X.
#[doc(alias = "GetScrollMaxX")]
pub fn scroll_max_x(&self) -> f32 {
unsafe { sys::igGetScrollMaxX() }
}
/// Returns the maximum vertical scrolling position.
///
/// Roughly equal to content size Y - window size Y.
#[doc(alias = "GetScrollMaxY")]
pub fn scroll_max_y(&self) -> f32 {
unsafe { sys::igGetScrollMaxY() }
}
/// Sets the horizontal scrolling position
#[doc(alias = "SetScrollX")]
pub fn set_scroll_x(&self, scroll_x: f32) {
unsafe { sys::igSetScrollX(scroll_x) };
}
/// Sets the vertical scroll position
#[doc(alias = "SetScrollY")]
pub fn set_scroll_y(&self, scroll_y: f32) {
unsafe { sys::igSetScrollY(scroll_y) };
}
/// Adjusts the horizontal scroll position to make the current cursor position visible
/// Adjusts the horizontal scroll position to make the current cursor position visible.
///
/// This is the same as [set_scroll_here_x_with_ratio](Self::set_scroll_here_x_with_ratio) but with `ratio` at 0.5.
#[doc(alias = "SetScrollHereX")]
pub fn set_scroll_here_x(&self) {
unsafe { sys::igSetScrollHereX(0.5) };
self.set_scroll_here_x_with_ratio(0.5);
}
/// Adjusts the horizontal scroll position to make the current cursor position visible.
///
@ -46,12 +55,16 @@ impl<'ui> Ui<'ui> {
/// - `0.0`: left
/// - `0.5`: center
/// - `1.0`: right
#[doc(alias = "SetScrollHereX")]
pub fn set_scroll_here_x_with_ratio(&self, center_x_ratio: f32) {
unsafe { sys::igSetScrollHereX(center_x_ratio) };
}
/// Adjusts the vertical scroll position to make the current cursor position visible
///
/// This is the same as [set_scroll_here_y_with_ratio](Self::set_scroll_here_y_with_ratio) but with `ratio` at 0.5.
#[doc(alias = "SetScrollHereY")]
pub fn set_scroll_here_y(&self) {
unsafe { sys::igSetScrollHereY(0.5) };
self.set_scroll_here_y_with_ratio(0.5);
}
/// Adjusts the vertical scroll position to make the current cursor position visible.
///
@ -60,12 +73,17 @@ impl<'ui> Ui<'ui> {
/// - `0.0`: top
/// - `0.5`: center
/// - `1.0`: bottom
#[doc(alias = "SetScrollHereY")]
pub fn set_scroll_here_y_with_ratio(&self, center_y_ratio: f32) {
unsafe { sys::igSetScrollHereY(center_y_ratio) };
}
#[doc(alias = "SetScrollFromPosX")]
/// Adjusts the horizontal scroll position to make the given position visible
///
/// This is the same as [set_scroll_from_pos_x_with_ratio](Self::set_scroll_from_pos_x_with_ratio)
/// but with `ratio` at 0.5.
pub fn set_scroll_from_pos_x(&self, local_x: f32) {
unsafe { sys::igSetScrollFromPosX(local_x, 0.5) };
self.set_scroll_from_pos_x_with_ratio(local_x, 0.5);
}
/// Adjusts the horizontal scroll position to make the given position visible.
///
@ -74,12 +92,17 @@ impl<'ui> Ui<'ui> {
/// - `0.0`: left
/// - `0.5`: center
/// - `1.0`: right
#[doc(alias = "SetScrollFromPosX")]
pub fn set_scroll_from_pos_x_with_ratio(&self, local_x: f32, center_x_ratio: f32) {
unsafe { sys::igSetScrollFromPosX(local_x, center_x_ratio) };
}
/// Adjusts the vertical scroll position to make the given position visible
///
/// This is the same as [set_scroll_from_pos_y_with_ratio](Self::set_scroll_from_pos_y_with_ratio)
/// but with `ratio` at 0.5.
#[doc(alias = "SetScrollFromPosY")]
pub fn set_scroll_from_pos_y(&self, local_y: f32) {
unsafe { sys::igSetScrollFromPosY(local_y, 0.5) };
self.set_scroll_from_pos_y_with_ratio(local_y, 0.5);
}
/// Adjusts the vertical scroll position to make the given position visible.
///
@ -88,6 +111,7 @@ impl<'ui> Ui<'ui> {
/// - `0.0`: top
/// - `0.5`: center
/// - `1.0`: bottom
#[doc(alias = "SetScrollFromPosY")]
pub fn set_scroll_from_pos_y_with_ratio(&self, local_y: f32, center_y_ratio: f32) {
unsafe { sys::igSetScrollFromPosY(local_y, center_y_ratio) };
}