mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 13:38:35 +00:00
Reformat with rustfmt 0.9.0
This commit is contained in:
parent
08a5429e4c
commit
907f9dbdeb
@ -117,12 +117,17 @@ fn main() {
|
||||
|
||||
fn show_user_guide<'a>(ui: &Ui<'a>) {
|
||||
ui.bullet_text(im_str!("Double-click on title bar to collapse window."));
|
||||
ui.bullet_text(im_str!("Click and drag on lower right corner to resize window."));
|
||||
ui.bullet_text(im_str!(
|
||||
"Click and drag on lower right corner to resize window."
|
||||
));
|
||||
ui.bullet_text(im_str!("Click and drag on any empty space to move window."));
|
||||
ui.bullet_text(im_str!("Mouse Wheel to scroll."));
|
||||
ui.bullet_text(im_str!("TAB/SHIFT+TAB to cycle through keyboard editable fields."));
|
||||
ui.bullet_text(im_str!(
|
||||
"TAB/SHIFT+TAB to cycle through keyboard editable fields."
|
||||
));
|
||||
ui.bullet_text(im_str!("CTRL+Click on a slider or drag box to input text."));
|
||||
ui.bullet_text(im_str!("While editing text:
|
||||
ui.bullet_text(im_str!(
|
||||
"While editing text:
|
||||
- Hold SHIFT or use mouse to select text
|
||||
- \
|
||||
CTRL+Left/Right to word jump
|
||||
@ -134,7 +139,8 @@ fn show_user_guide<'a>(ui: &Ui<'a>) {
|
||||
to revert
|
||||
- You can apply arithmetic operators +,*,/ on numerical \
|
||||
values.
|
||||
Use +- to subtract."));
|
||||
Use +- to subtract."
|
||||
));
|
||||
}
|
||||
|
||||
fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
|
||||
@ -145,9 +151,11 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
|
||||
show_example_app_main_menu_bar(ui, state)
|
||||
}
|
||||
if state.show_app_auto_resize {
|
||||
show_example_app_auto_resize(ui,
|
||||
&mut state.auto_resize_state,
|
||||
&mut state.show_app_auto_resize);
|
||||
show_example_app_auto_resize(
|
||||
ui,
|
||||
&mut state.auto_resize_state,
|
||||
&mut state.show_app_auto_resize,
|
||||
);
|
||||
}
|
||||
if state.show_app_fixed_overlay {
|
||||
show_example_app_fixed_overlay(ui, &mut state.show_app_fixed_overlay);
|
||||
@ -163,8 +171,10 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
|
||||
ui.text(im_str!("ImGui {}", imgui::get_version()));
|
||||
ui.separator();
|
||||
ui.text(im_str!("By Omar Cornut and all github contributors."));
|
||||
ui.text(im_str!("ImGui is licensed under the MIT License, see LICENSE for more \
|
||||
information."));
|
||||
ui.text(im_str!(
|
||||
"ImGui is licensed under the MIT License, see LICENSE for more \
|
||||
information."
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
@ -182,50 +192,51 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
|
||||
.build(|| {
|
||||
ui.text(im_str!("ImGui says hello."));
|
||||
ui.menu_bar(|| {
|
||||
ui.menu(im_str!("Menu"))
|
||||
.build(|| { show_example_menu_file(ui, &mut state.file_menu); });
|
||||
ui.menu(im_str!("Examples"))
|
||||
.build(|| {
|
||||
ui.menu_item(im_str!("Main menu bar"))
|
||||
.selected(&mut state.show_app_main_menu_bar)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Console"))
|
||||
.selected(&mut state.show_app_console)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Simple layout"))
|
||||
.selected(&mut state.show_app_layout)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Long text display"))
|
||||
.selected(&mut state.show_app_long_text)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Auto-resizing window"))
|
||||
.selected(&mut state.show_app_auto_resize)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Simple overlay"))
|
||||
.selected(&mut state.show_app_fixed_overlay)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Manipulating window title"))
|
||||
.selected(&mut state.show_app_manipulating_window_title)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Custom rendering"))
|
||||
.selected(&mut state.show_app_custom_rendering)
|
||||
.build();
|
||||
});
|
||||
ui.menu(im_str!("Help"))
|
||||
.build(|| {
|
||||
ui.menu_item(im_str!("Metrics"))
|
||||
.selected(&mut state.show_app_metrics)
|
||||
.build();
|
||||
ui.menu_item(im_str!("About ImGui"))
|
||||
.selected(&mut state.show_app_about)
|
||||
.build();
|
||||
});
|
||||
ui.menu(im_str!("Menu")).build(|| {
|
||||
show_example_menu_file(ui, &mut state.file_menu);
|
||||
});
|
||||
ui.menu(im_str!("Examples")).build(|| {
|
||||
ui.menu_item(im_str!("Main menu bar"))
|
||||
.selected(&mut state.show_app_main_menu_bar)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Console"))
|
||||
.selected(&mut state.show_app_console)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Simple layout"))
|
||||
.selected(&mut state.show_app_layout)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Long text display"))
|
||||
.selected(&mut state.show_app_long_text)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Auto-resizing window"))
|
||||
.selected(&mut state.show_app_auto_resize)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Simple overlay"))
|
||||
.selected(&mut state.show_app_fixed_overlay)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Manipulating window title"))
|
||||
.selected(&mut state.show_app_manipulating_window_title)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Custom rendering"))
|
||||
.selected(&mut state.show_app_custom_rendering)
|
||||
.build();
|
||||
});
|
||||
ui.menu(im_str!("Help")).build(|| {
|
||||
ui.menu_item(im_str!("Metrics"))
|
||||
.selected(&mut state.show_app_metrics)
|
||||
.build();
|
||||
ui.menu_item(im_str!("About ImGui"))
|
||||
.selected(&mut state.show_app_about)
|
||||
.build();
|
||||
});
|
||||
});
|
||||
ui.spacing();
|
||||
if ui.collapsing_header(im_str!("Help")).build() {
|
||||
ui.text_wrapped(im_str!("This window is being created by the show_test_window() \
|
||||
ui.text_wrapped(im_str!(
|
||||
"This window is being created by the show_test_window() \
|
||||
function. Please refer to the code for programming \
|
||||
reference.\n\nUser Guide:"));
|
||||
reference.\n\nUser Guide:"
|
||||
));
|
||||
show_user_guide(ui);
|
||||
}
|
||||
|
||||
@ -244,55 +255,53 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
|
||||
ui.slider_float(im_str!("bg alpha"), &mut state.bg_alpha, 0.0, 1.0)
|
||||
.build();
|
||||
|
||||
ui.tree_node(im_str!("Style"))
|
||||
.build(|| {
|
||||
// TODO: Reimplement style editor
|
||||
ui.show_default_style_editor();
|
||||
});
|
||||
ui.tree_node(im_str!("Style")).build(|| {
|
||||
// TODO: Reimplement style editor
|
||||
ui.show_default_style_editor();
|
||||
});
|
||||
ui.tree_node(im_str!("Fonts"))
|
||||
.label(im_str!("Fonts ({})", "TODO"))
|
||||
.build(|| {
|
||||
ui.text_wrapped(im_str!("Tip: Load fonts with \
|
||||
io.Fonts->AddFontFromFileTTF()."));
|
||||
ui.tree_node(im_str!("Atlas texture"))
|
||||
.build(|| {
|
||||
// TODO
|
||||
});
|
||||
});
|
||||
ui.text_wrapped(im_str!(
|
||||
"Tip: Load fonts with \
|
||||
io.Fonts->AddFontFromFileTTF()."
|
||||
));
|
||||
ui.tree_node(im_str!("Atlas texture")).build(|| {
|
||||
// TODO
|
||||
});
|
||||
});
|
||||
}
|
||||
if ui.collapsing_header(im_str!("Widgets")).build() {
|
||||
ui.tree_node(im_str!("Tree"))
|
||||
.build(|| for i in 0..5 {
|
||||
ui.tree_node(im_str!("Child {}", i))
|
||||
.build(|| {
|
||||
ui.text(im_str!("blah blah"));
|
||||
ui.same_line(0.0);
|
||||
if ui.small_button(im_str!("print")) {
|
||||
println!("Child {} pressed", i);
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.tree_node(im_str!("Bullets"))
|
||||
.build(|| {
|
||||
ui.bullet_text(im_str!("Bullet point 1"));
|
||||
ui.bullet_text(im_str!("Bullet point 2\nOn multiple lines"));
|
||||
ui.bullet();
|
||||
ui.text(im_str!("Bullet point 3 (two calls)"));
|
||||
|
||||
ui.bullet();
|
||||
ui.small_button(im_str!("Button"));
|
||||
ui.tree_node(im_str!("Tree")).build(|| for i in 0..5 {
|
||||
ui.tree_node(im_str!("Child {}", i)).build(|| {
|
||||
ui.text(im_str!("blah blah"));
|
||||
ui.same_line(0.0);
|
||||
if ui.small_button(im_str!("print")) {
|
||||
println!("Child {} pressed", i);
|
||||
}
|
||||
});
|
||||
ui.tree_node(im_str!("Colored text"))
|
||||
.build(|| {
|
||||
ui.text_colored((1.0, 0.0, 1.0, 1.0), im_str!("Pink"));
|
||||
ui.text_colored((1.0, 1.0, 0.0, 1.0), im_str!("Yellow"));
|
||||
ui.text_disabled(im_str!("Disabled"));
|
||||
});
|
||||
});
|
||||
ui.tree_node(im_str!("Bullets")).build(|| {
|
||||
ui.bullet_text(im_str!("Bullet point 1"));
|
||||
ui.bullet_text(im_str!("Bullet point 2\nOn multiple lines"));
|
||||
ui.bullet();
|
||||
ui.text(im_str!("Bullet point 3 (two calls)"));
|
||||
|
||||
ui.bullet();
|
||||
ui.small_button(im_str!("Button"));
|
||||
});
|
||||
ui.tree_node(im_str!("Colored text")).build(|| {
|
||||
ui.text_colored((1.0, 0.0, 1.0, 1.0), im_str!("Pink"));
|
||||
ui.text_colored((1.0, 1.0, 0.0, 1.0), im_str!("Yellow"));
|
||||
ui.text_disabled(im_str!("Disabled"));
|
||||
});
|
||||
ui.tree_node(im_str!("Word Wrapping")).build(|| {
|
||||
ui.text_wrapped(im_str!("This text should automatically wrap on the edge of \
|
||||
ui.text_wrapped(im_str!(
|
||||
"This text should automatically wrap on the edge of \
|
||||
the window.The current implementation for text \
|
||||
wrapping follows simple rulessuitable for English \
|
||||
and possibly other languages."));
|
||||
and possibly other languages."
|
||||
));
|
||||
ui.spacing();
|
||||
|
||||
ui.slider_float(im_str!("Wrap width"), &mut state.wrap_width, -20.0, 600.0)
|
||||
@ -305,18 +314,19 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
|
||||
ui.text(im_str!("Test paragraph 2:"));
|
||||
// TODO
|
||||
});
|
||||
ui.tree_node(im_str!("UTF-8 Text"))
|
||||
.build(|| {
|
||||
ui.text_wrapped(im_str!("CJK text will only appear if the font was loaded \
|
||||
ui.tree_node(im_str!("UTF-8 Text")).build(|| {
|
||||
ui.text_wrapped(im_str!(
|
||||
"CJK text will only appear if the font was loaded \
|
||||
with theappropriate CJK character ranges. Call \
|
||||
io.Font->LoadFromFileTTF()manually to load extra \
|
||||
character ranges."));
|
||||
character ranges."
|
||||
));
|
||||
|
||||
ui.text(im_str!("Hiragana: かきくけこ (kakikukeko)"));
|
||||
ui.text(im_str!("Kanjis: 日本語 (nihongo)"));
|
||||
ui.input_text(im_str!("UTF-8 input"), &mut state.buf)
|
||||
.build();
|
||||
});
|
||||
ui.text(im_str!("Hiragana: かきくけこ (kakikukeko)"));
|
||||
ui.text(im_str!("Kanjis: 日本語 (nihongo)"));
|
||||
ui.input_text(im_str!("UTF-8 input"), &mut state.buf)
|
||||
.build();
|
||||
});
|
||||
|
||||
ui.radio_button(im_str!("radio a"), &mut state.radio_button, 0);
|
||||
ui.same_line(0.0);
|
||||
@ -326,25 +336,31 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
|
||||
|
||||
ui.separator();
|
||||
ui.label_text(im_str!("label"), im_str!("Value"));
|
||||
ui.combo(im_str!("combo"),
|
||||
&mut state.item,
|
||||
&[im_str!("aaaa"),
|
||||
im_str!("bbbb"),
|
||||
im_str!("cccc"),
|
||||
im_str!("dddd"),
|
||||
im_str!("eeee")],
|
||||
-1);
|
||||
let items = [im_str!("AAAA"),
|
||||
im_str!("BBBB"),
|
||||
im_str!("CCCC"),
|
||||
im_str!("DDDD"),
|
||||
im_str!("EEEE"),
|
||||
im_str!("FFFF"),
|
||||
im_str!("GGGG"),
|
||||
im_str!("HHHH"),
|
||||
im_str!("IIII"),
|
||||
im_str!("JJJJ"),
|
||||
im_str!("KKKK")];
|
||||
ui.combo(
|
||||
im_str!("combo"),
|
||||
&mut state.item,
|
||||
&[
|
||||
im_str!("aaaa"),
|
||||
im_str!("bbbb"),
|
||||
im_str!("cccc"),
|
||||
im_str!("dddd"),
|
||||
im_str!("eeee"),
|
||||
],
|
||||
-1,
|
||||
);
|
||||
let items = [
|
||||
im_str!("AAAA"),
|
||||
im_str!("BBBB"),
|
||||
im_str!("CCCC"),
|
||||
im_str!("DDDD"),
|
||||
im_str!("EEEE"),
|
||||
im_str!("FFFF"),
|
||||
im_str!("GGGG"),
|
||||
im_str!("HHHH"),
|
||||
im_str!("IIII"),
|
||||
im_str!("JJJJ"),
|
||||
im_str!("KKKK"),
|
||||
];
|
||||
ui.combo(im_str!("combo scroll"), &mut state.item2, &items, -1);
|
||||
ui.input_text(im_str!("input text"), &mut state.text)
|
||||
.build();
|
||||
@ -356,127 +372,126 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) {
|
||||
ui.input_float3(im_str!("input float3"), &mut state.vec3f)
|
||||
.build();
|
||||
|
||||
ui.tree_node(im_str!("Multi-component Widgets"))
|
||||
.build(|| {
|
||||
ui.input_float2(im_str!("input float2"), &mut state.vec2f)
|
||||
.build();
|
||||
ui.input_int2(im_str!("input int2"), &mut state.vec2i)
|
||||
.build();
|
||||
ui.spacing();
|
||||
ui.tree_node(im_str!("Multi-component Widgets")).build(|| {
|
||||
ui.input_float2(im_str!("input float2"), &mut state.vec2f)
|
||||
.build();
|
||||
ui.input_int2(im_str!("input int2"), &mut state.vec2i)
|
||||
.build();
|
||||
ui.spacing();
|
||||
|
||||
ui.input_float3(im_str!("input float3"), &mut state.vec3f)
|
||||
.build();
|
||||
ui.input_int3(im_str!("input int3"), &mut state.vec3i)
|
||||
.build();
|
||||
ui.spacing();
|
||||
});
|
||||
ui.input_float3(im_str!("input float3"), &mut state.vec3f)
|
||||
.build();
|
||||
ui.input_int3(im_str!("input int3"), &mut state.vec3i)
|
||||
.build();
|
||||
ui.spacing();
|
||||
});
|
||||
}
|
||||
if ui.collapsing_header(im_str!("Popups & Modal windows"))
|
||||
.build() {
|
||||
ui.tree_node(im_str!("Popups"))
|
||||
.build(|| {
|
||||
ui.text_wrapped(im_str!("When a popup is active, it inhibits interacting \
|
||||
.build()
|
||||
{
|
||||
ui.tree_node(im_str!("Popups")).build(|| {
|
||||
ui.text_wrapped(im_str!(
|
||||
"When a popup is active, it inhibits interacting \
|
||||
with windows that are behind the popup. Clicking \
|
||||
outside the popup closes it."));
|
||||
let names = [im_str!("Bream"),
|
||||
im_str!("Haddock"),
|
||||
im_str!("Mackerel"),
|
||||
im_str!("Pollock"),
|
||||
im_str!("Tilefish")];
|
||||
if ui.small_button(im_str!("Select..")) {
|
||||
ui.open_popup(im_str!("select"));
|
||||
}
|
||||
ui.same_line(0.0);
|
||||
ui.text(match state.selected_fish {
|
||||
Some(index) => names[index].clone(),
|
||||
None => im_str!("<None>"),
|
||||
});
|
||||
ui.popup(im_str!("select"), || {
|
||||
ui.text(im_str!("Aquarium"));
|
||||
ui.separator();
|
||||
for (index, name) in names.iter().enumerate() {
|
||||
if ui.selectable(name.clone(),
|
||||
false,
|
||||
ImGuiSelectableFlags::empty(),
|
||||
ImVec2::new(0.0, 0.0)) {
|
||||
state.selected_fish = Some(index);
|
||||
}
|
||||
}
|
||||
});
|
||||
outside the popup closes it."
|
||||
));
|
||||
let names = [
|
||||
im_str!("Bream"),
|
||||
im_str!("Haddock"),
|
||||
im_str!("Mackerel"),
|
||||
im_str!("Pollock"),
|
||||
im_str!("Tilefish"),
|
||||
];
|
||||
if ui.small_button(im_str!("Select..")) {
|
||||
ui.open_popup(im_str!("select"));
|
||||
}
|
||||
ui.same_line(0.0);
|
||||
ui.text(match state.selected_fish {
|
||||
Some(index) => names[index].clone(),
|
||||
None => im_str!("<None>"),
|
||||
});
|
||||
ui.popup(im_str!("select"), || {
|
||||
ui.text(im_str!("Aquarium"));
|
||||
ui.separator();
|
||||
for (index, name) in names.iter().enumerate() {
|
||||
if ui.selectable(
|
||||
name.clone(),
|
||||
false,
|
||||
ImGuiSelectableFlags::empty(),
|
||||
ImVec2::new(0.0, 0.0),
|
||||
)
|
||||
{
|
||||
state.selected_fish = Some(index);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn show_example_app_main_menu_bar<'a>(ui: &Ui<'a>, state: &mut State) {
|
||||
ui.main_menu_bar(|| {
|
||||
ui.menu(im_str!("File"))
|
||||
.build(|| { show_example_menu_file(ui, &mut state.file_menu); });
|
||||
ui.menu(im_str!("Edit"))
|
||||
.build(|| {
|
||||
ui.menu_item(im_str!("Undo"))
|
||||
.shortcut(im_str!("CTRL+Z"))
|
||||
.build();
|
||||
ui.menu_item(im_str!("Redo"))
|
||||
.shortcut(im_str!("CTRL+Y"))
|
||||
.enabled(false)
|
||||
.build();
|
||||
ui.separator();
|
||||
ui.menu_item(im_str!("Cut"))
|
||||
.shortcut(im_str!("CTRL+X"))
|
||||
.build();
|
||||
ui.menu_item(im_str!("Copy"))
|
||||
.shortcut(im_str!("CTRL+C"))
|
||||
.build();
|
||||
ui.menu_item(im_str!("Paste"))
|
||||
.shortcut(im_str!("CTRL+V"))
|
||||
.build();
|
||||
});
|
||||
ui.menu(im_str!("File")).build(|| {
|
||||
show_example_menu_file(ui, &mut state.file_menu);
|
||||
});
|
||||
ui.menu(im_str!("Edit")).build(|| {
|
||||
ui.menu_item(im_str!("Undo"))
|
||||
.shortcut(im_str!("CTRL+Z"))
|
||||
.build();
|
||||
ui.menu_item(im_str!("Redo"))
|
||||
.shortcut(im_str!("CTRL+Y"))
|
||||
.enabled(false)
|
||||
.build();
|
||||
ui.separator();
|
||||
ui.menu_item(im_str!("Cut"))
|
||||
.shortcut(im_str!("CTRL+X"))
|
||||
.build();
|
||||
ui.menu_item(im_str!("Copy"))
|
||||
.shortcut(im_str!("CTRL+C"))
|
||||
.build();
|
||||
ui.menu_item(im_str!("Paste"))
|
||||
.shortcut(im_str!("CTRL+V"))
|
||||
.build();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
|
||||
ui.menu_item(im_str!("(dummy menu)"))
|
||||
.enabled(false)
|
||||
.build();
|
||||
ui.menu_item(im_str!("(dummy menu)")).enabled(false).build();
|
||||
ui.menu_item(im_str!("New")).build();
|
||||
ui.menu_item(im_str!("Open"))
|
||||
.shortcut(im_str!("Ctrl+O"))
|
||||
.build();
|
||||
ui.menu(im_str!("Open Recent"))
|
||||
.build(|| {
|
||||
ui.menu_item(im_str!("fish_hat.c")).build();
|
||||
ui.menu_item(im_str!("fish_hat.inl")).build();
|
||||
ui.menu_item(im_str!("fish_hat.h")).build();
|
||||
ui.menu(im_str!("More.."))
|
||||
.build(|| {
|
||||
ui.menu_item(im_str!("Hello")).build();
|
||||
ui.menu_item(im_str!("Sailor")).build();
|
||||
ui.menu(im_str!("Recurse.."))
|
||||
.build(|| { show_example_menu_file(ui, state); });
|
||||
});
|
||||
ui.menu(im_str!("Open Recent")).build(|| {
|
||||
ui.menu_item(im_str!("fish_hat.c")).build();
|
||||
ui.menu_item(im_str!("fish_hat.inl")).build();
|
||||
ui.menu_item(im_str!("fish_hat.h")).build();
|
||||
ui.menu(im_str!("More..")).build(|| {
|
||||
ui.menu_item(im_str!("Hello")).build();
|
||||
ui.menu_item(im_str!("Sailor")).build();
|
||||
ui.menu(im_str!("Recurse..")).build(|| {
|
||||
show_example_menu_file(ui, state);
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.menu_item(im_str!("Save"))
|
||||
.shortcut(im_str!("Ctrl+S"))
|
||||
.build();
|
||||
ui.menu_item(im_str!("Save As..")).build();
|
||||
ui.separator();
|
||||
ui.menu(im_str!("Options"))
|
||||
.build(|| {
|
||||
ui.menu_item(im_str!("Enabled"))
|
||||
.selected(&mut state.enabled)
|
||||
.build();
|
||||
// TODO
|
||||
});
|
||||
ui.menu(im_str!("Colors"))
|
||||
.build(|| {
|
||||
// TODO
|
||||
});
|
||||
ui.menu(im_str!("Disabled"))
|
||||
.enabled(false)
|
||||
.build(|| {
|
||||
unreachable!();
|
||||
});
|
||||
ui.menu(im_str!("Options")).build(|| {
|
||||
ui.menu_item(im_str!("Enabled"))
|
||||
.selected(&mut state.enabled)
|
||||
.build();
|
||||
// TODO
|
||||
});
|
||||
ui.menu(im_str!("Colors")).build(|| {
|
||||
// TODO
|
||||
});
|
||||
ui.menu(im_str!("Disabled")).enabled(false).build(|| {
|
||||
unreachable!();
|
||||
});
|
||||
let mut checked = true;
|
||||
ui.menu_item(im_str!("Checked"))
|
||||
.selected(&mut checked)
|
||||
@ -491,9 +506,11 @@ fn show_example_app_auto_resize<'a>(ui: &Ui<'a>, state: &mut AutoResizeState, op
|
||||
.opened(opened)
|
||||
.always_auto_resize(true)
|
||||
.build(|| {
|
||||
ui.text(im_str!("Window will resize every-ui to the size of its content.
|
||||
ui.text(im_str!(
|
||||
"Window will resize every-ui to the size of its content.
|
||||
Note that you probably don't want to query the window size to
|
||||
output your content because that would create a feedback loop."));
|
||||
output your content because that would create a feedback loop."
|
||||
));
|
||||
ui.slider_int(im_str!("Number of lines"), &mut state.lines, 1, 20)
|
||||
.build();
|
||||
for i in 0..state.lines {
|
||||
@ -511,26 +528,36 @@ fn show_example_app_fixed_overlay<'a>(ui: &Ui<'a>, opened: &mut bool) {
|
||||
.movable(false)
|
||||
.save_settings(false)
|
||||
.build(|| {
|
||||
ui.text(im_str!("Simple overlay\non the top-left side of the screen."));
|
||||
ui.separator();
|
||||
let mouse_pos = ui.imgui().mouse_pos();
|
||||
ui.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1));
|
||||
})
|
||||
ui.text(im_str!(
|
||||
"Simple overlay\non the top-left side of the screen."
|
||||
));
|
||||
ui.separator();
|
||||
let mouse_pos = ui.imgui().mouse_pos();
|
||||
ui.text(im_str!(
|
||||
"Mouse Position: ({:.1},{:.1})",
|
||||
mouse_pos.0,
|
||||
mouse_pos.1
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
fn show_example_app_manipulating_window_title<'a>(ui: &Ui<'a>) {
|
||||
ui.window(im_str!("Same title as another window##1"))
|
||||
.position((100.0, 100.0), ImGuiCond::FirstUseEver)
|
||||
.build(|| {
|
||||
ui.text(im_str!("This is window 1.
|
||||
My title is the same as window 2, but my identifier is unique."));
|
||||
});
|
||||
ui.text(im_str!(
|
||||
"This is window 1.
|
||||
My title is the same as window 2, but my identifier is unique."
|
||||
));
|
||||
});
|
||||
ui.window(im_str!("Same title as another window##2"))
|
||||
.position((100.0, 200.0), ImGuiCond::FirstUseEver)
|
||||
.build(|| {
|
||||
ui.text(im_str!("This is window 2.
|
||||
My title is the same as window 1, but my identifier is unique."));
|
||||
});
|
||||
ui.text(im_str!(
|
||||
"This is window 2.
|
||||
My title is the same as window 1, but my identifier is unique."
|
||||
));
|
||||
});
|
||||
let chars = ['|', '/', '-', '\\'];
|
||||
let ch_idx = (ui.imgui().get_time() / 0.25) as usize & 3;
|
||||
let num = ui.imgui().get_frame_count(); // The C++ version uses rand() here
|
||||
|
||||
@ -14,7 +14,7 @@ pub enum RendererError {
|
||||
Update(gfx::UpdateError<usize>),
|
||||
Buffer(gfx::buffer::CreationError),
|
||||
Pipeline(gfx::PipelineStateError<String>),
|
||||
Combined(gfx::CombinedError)
|
||||
Combined(gfx::CombinedError),
|
||||
}
|
||||
|
||||
impl From<gfx::UpdateError<usize>> for RendererError {
|
||||
@ -86,32 +86,50 @@ pub struct Renderer<R: Resources> {
|
||||
}
|
||||
|
||||
impl<R: Resources> Renderer<R> {
|
||||
pub fn init<F: Factory<R>>(imgui: &mut ImGui,
|
||||
factory: &mut F,
|
||||
shaders: Shaders,
|
||||
out: RenderTargetView<R, gfx::format::Rgba8>)
|
||||
-> RendererResult<Renderer<R>> {
|
||||
pub fn init<F: Factory<R>>(
|
||||
imgui: &mut ImGui,
|
||||
factory: &mut F,
|
||||
shaders: Shaders,
|
||||
out: RenderTargetView<R, gfx::format::Rgba8>,
|
||||
) -> RendererResult<Renderer<R>> {
|
||||
let (vs_code, ps_code) = shaders.get_program_code();
|
||||
let pso = factory.create_pipeline_simple(vs_code, ps_code, pipe::new())?;
|
||||
let vertex_buffer = factory.create_buffer::<ImDrawVert>(256,
|
||||
gfx::buffer::Role::Vertex,
|
||||
gfx::memory::Usage::Dynamic,
|
||||
Bind::empty())?;
|
||||
let index_buffer = factory.create_buffer::<ImDrawIdx>(256,
|
||||
gfx::buffer::Role::Index,
|
||||
gfx::memory::Usage::Dynamic,
|
||||
Bind::empty())?;
|
||||
let pso = factory.create_pipeline_simple(
|
||||
vs_code,
|
||||
ps_code,
|
||||
pipe::new(),
|
||||
)?;
|
||||
let vertex_buffer = factory.create_buffer::<ImDrawVert>(
|
||||
256,
|
||||
gfx::buffer::Role::Vertex,
|
||||
gfx::memory::Usage::Dynamic,
|
||||
Bind::empty(),
|
||||
)?;
|
||||
let index_buffer = factory.create_buffer::<ImDrawIdx>(
|
||||
256,
|
||||
gfx::buffer::Role::Index,
|
||||
gfx::memory::Usage::Dynamic,
|
||||
Bind::empty(),
|
||||
)?;
|
||||
let (_, texture) = imgui.prepare_texture(|handle| {
|
||||
factory.create_texture_immutable_u8::<gfx::format::Rgba8>(gfx::texture::Kind::D2(handle.width as u16, handle.height as u16, gfx::texture::AaMode::Single), &[handle.pixels])
|
||||
factory.create_texture_immutable_u8::<gfx::format::Rgba8>(
|
||||
gfx::texture::Kind::D2(
|
||||
handle.width as u16,
|
||||
handle.height as u16,
|
||||
gfx::texture::AaMode::Single,
|
||||
),
|
||||
&[handle.pixels],
|
||||
)
|
||||
})?;
|
||||
// TODO: set texture id in imgui
|
||||
let sampler = factory.create_sampler_linear();
|
||||
let data = pipe::Data {
|
||||
vertex_buffer: vertex_buffer,
|
||||
matrix: [[0.0, 0.0, 0.0, 0.0],
|
||||
[0.0, 0.0, 0.0, 0.0],
|
||||
[0.0, 0.0, -1.0, 0.0],
|
||||
[-1.0, 1.0, 0.0, 1.0]],
|
||||
matrix: [
|
||||
[0.0, 0.0, 0.0, 0.0],
|
||||
[0.0, 0.0, 0.0, 0.0],
|
||||
[0.0, 0.0, -1.0, 0.0],
|
||||
[-1.0, 1.0, 0.0, 1.0],
|
||||
],
|
||||
tex: (texture, sampler),
|
||||
out: out,
|
||||
scissor: Rect {
|
||||
@ -136,37 +154,51 @@ impl<R: Resources> Renderer<R> {
|
||||
pub fn update_render_target(&mut self, out: RenderTargetView<R, gfx::format::Rgba8>) {
|
||||
self.bundle.data.out = out;
|
||||
}
|
||||
pub fn render<'a, F: Factory<R>, C: CommandBuffer<R>>(&mut self,
|
||||
ui: Ui<'a>,
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>)
|
||||
-> RendererResult<()> {
|
||||
pub fn render<'a, F: Factory<R>, C: CommandBuffer<R>>(
|
||||
&mut self,
|
||||
ui: Ui<'a>,
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
) -> RendererResult<()> {
|
||||
let (width, height) = ui.imgui().display_size();
|
||||
|
||||
if width == 0.0 || height == 0.0 {
|
||||
return Ok(());
|
||||
}
|
||||
self.bundle.data.matrix = [[2.0 / width as f32, 0.0, 0.0, 0.0],
|
||||
[0.0, -2.0 / height as f32, 0.0, 0.0],
|
||||
[0.0, 0.0, -1.0, 0.0],
|
||||
[-1.0, 1.0, 0.0, 1.0]];
|
||||
self.bundle.data.matrix = [
|
||||
[2.0 / width as f32, 0.0, 0.0, 0.0],
|
||||
[0.0, -2.0 / height as f32, 0.0, 0.0],
|
||||
[0.0, 0.0, -1.0, 0.0],
|
||||
[-1.0, 1.0, 0.0, 1.0],
|
||||
];
|
||||
|
||||
ui.render(|ui, draw_list| self.render_draw_list(ui, factory, encoder, draw_list))
|
||||
ui.render(|ui, draw_list| {
|
||||
self.render_draw_list(ui, factory, encoder, draw_list)
|
||||
})
|
||||
}
|
||||
fn render_draw_list<'a, F: Factory<R>, C: CommandBuffer<R>>(&mut self,
|
||||
ui: &'a Ui<'a>,
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
draw_list: DrawList<'a>)
|
||||
-> RendererResult<()> {
|
||||
fn render_draw_list<'a, F: Factory<R>, C: CommandBuffer<R>>(
|
||||
&mut self,
|
||||
ui: &'a Ui<'a>,
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
draw_list: DrawList<'a>,
|
||||
) -> RendererResult<()> {
|
||||
let (scale_width, scale_height) = ui.imgui().display_framebuffer_scale();
|
||||
|
||||
self.bundle.slice.start = 0;
|
||||
for cmd in draw_list.cmd_buffer {
|
||||
// TODO: check cmd.texture_id
|
||||
|
||||
self.upload_vertex_buffer(factory, encoder, draw_list.vtx_buffer)?;
|
||||
self.upload_index_buffer(factory, encoder, draw_list.idx_buffer)?;
|
||||
self.upload_vertex_buffer(
|
||||
factory,
|
||||
encoder,
|
||||
draw_list.vtx_buffer,
|
||||
)?;
|
||||
self.upload_index_buffer(
|
||||
factory,
|
||||
encoder,
|
||||
draw_list.idx_buffer,
|
||||
)?;
|
||||
|
||||
self.bundle.slice.end = self.bundle.slice.start + cmd.elem_count;
|
||||
self.bundle.data.scissor = Rect {
|
||||
@ -180,29 +212,39 @@ impl<R: Resources> Renderer<R> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn upload_vertex_buffer<F: Factory<R>, C: CommandBuffer<R>>(&mut self,
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
vtx_buffer: &[ImDrawVert])
|
||||
-> RendererResult<()> {
|
||||
fn upload_vertex_buffer<F: Factory<R>, C: CommandBuffer<R>>(
|
||||
&mut self,
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
vtx_buffer: &[ImDrawVert],
|
||||
) -> RendererResult<()> {
|
||||
if self.bundle.data.vertex_buffer.len() < vtx_buffer.len() {
|
||||
self.bundle.data.vertex_buffer = factory.create_buffer::<ImDrawVert>(vtx_buffer.len(),
|
||||
gfx::buffer::Role::Vertex,
|
||||
gfx::memory::Usage::Dynamic,
|
||||
Bind::empty())?;
|
||||
self.bundle.data.vertex_buffer = factory.create_buffer::<ImDrawVert>(
|
||||
vtx_buffer.len(),
|
||||
gfx::buffer::Role::Vertex,
|
||||
gfx::memory::Usage::Dynamic,
|
||||
Bind::empty(),
|
||||
)?;
|
||||
}
|
||||
Ok(encoder.update_buffer(&self.bundle.data.vertex_buffer, vtx_buffer, 0)?)
|
||||
Ok(encoder.update_buffer(
|
||||
&self.bundle.data.vertex_buffer,
|
||||
vtx_buffer,
|
||||
0,
|
||||
)?)
|
||||
}
|
||||
fn upload_index_buffer<F: Factory<R>, C: CommandBuffer<R>>(&mut self,
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
idx_buffer: &[ImDrawIdx])
|
||||
-> RendererResult<()> {
|
||||
fn upload_index_buffer<F: Factory<R>, C: CommandBuffer<R>>(
|
||||
&mut self,
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
idx_buffer: &[ImDrawIdx],
|
||||
) -> RendererResult<()> {
|
||||
if self.index_buffer.len() < idx_buffer.len() {
|
||||
self.index_buffer = factory.create_buffer::<ImDrawIdx>(idx_buffer.len(),
|
||||
gfx::buffer::Role::Index,
|
||||
gfx::memory::Usage::Dynamic,
|
||||
Bind::empty())?;
|
||||
self.index_buffer = factory.create_buffer::<ImDrawIdx>(
|
||||
idx_buffer.len(),
|
||||
gfx::buffer::Role::Index,
|
||||
gfx::memory::Usage::Dynamic,
|
||||
Bind::empty(),
|
||||
)?;
|
||||
self.bundle.slice.buffer = self.index_buffer.clone().into_index_buffer(factory);
|
||||
}
|
||||
Ok(encoder.update_buffer(&self.index_buffer, idx_buffer, 0)?)
|
||||
|
||||
@ -73,21 +73,30 @@ impl Renderer {
|
||||
|
||||
pub fn render<'a, S: Surface>(&mut self, surface: &mut S, ui: Ui<'a>) -> RendererResult<()> {
|
||||
let _ = self.ctx.insert_debug_marker("imgui-rs: starting rendering");
|
||||
let result = ui.render(|ui, draw_list| self.render_draw_list(surface, ui, draw_list));
|
||||
let result = ui.render(|ui, draw_list| {
|
||||
self.render_draw_list(surface, ui, draw_list)
|
||||
});
|
||||
let _ = self.ctx.insert_debug_marker("imgui-rs: rendering finished");
|
||||
result
|
||||
}
|
||||
|
||||
fn render_draw_list<'a, S: Surface>(&mut self,
|
||||
surface: &mut S,
|
||||
ui: &'a Ui<'a>,
|
||||
draw_list: DrawList<'a>)
|
||||
-> RendererResult<()> {
|
||||
fn render_draw_list<'a, S: Surface>(
|
||||
&mut self,
|
||||
surface: &mut S,
|
||||
ui: &'a Ui<'a>,
|
||||
draw_list: DrawList<'a>,
|
||||
) -> RendererResult<()> {
|
||||
use glium::{Blend, DrawParameters, Rect};
|
||||
use glium::uniforms::{MinifySamplerFilter, MagnifySamplerFilter};
|
||||
|
||||
try!(self.device_objects.upload_vertex_buffer(&self.ctx, draw_list.vtx_buffer));
|
||||
try!(self.device_objects.upload_index_buffer(&self.ctx, draw_list.idx_buffer));
|
||||
try!(self.device_objects.upload_vertex_buffer(
|
||||
&self.ctx,
|
||||
draw_list.vtx_buffer,
|
||||
));
|
||||
try!(self.device_objects.upload_index_buffer(
|
||||
&self.ctx,
|
||||
draw_list.idx_buffer,
|
||||
));
|
||||
|
||||
let (width, height) = ui.imgui().display_size();
|
||||
let (scale_width, scale_height) = ui.imgui().display_framebuffer_scale();
|
||||
@ -96,10 +105,12 @@ impl Renderer {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let matrix = [[2.0 / width as f32, 0.0, 0.0, 0.0],
|
||||
[0.0, 2.0 / -(height as f32), 0.0, 0.0],
|
||||
[0.0, 0.0, -1.0, 0.0],
|
||||
[-1.0, 1.0, 0.0, 1.0]];
|
||||
let matrix = [
|
||||
[2.0 / width as f32, 0.0, 0.0, 0.0],
|
||||
[0.0, 2.0 / -(height as f32), 0.0, 0.0],
|
||||
[0.0, 0.0, -1.0, 0.0],
|
||||
[-1.0, 1.0, 0.0, 1.0],
|
||||
];
|
||||
let font_texture_id = self.device_objects.texture.get_id() as usize;
|
||||
|
||||
let mut idx_start = 0;
|
||||
@ -109,31 +120,32 @@ impl Renderer {
|
||||
|
||||
let idx_end = idx_start + cmd.elem_count as usize;
|
||||
|
||||
try!(surface.draw(&self.device_objects.vertex_buffer,
|
||||
&self.device_objects
|
||||
.index_buffer
|
||||
.slice(idx_start..idx_end)
|
||||
.expect("Invalid index buffer range"),
|
||||
&self.device_objects.program,
|
||||
&uniform! {
|
||||
try!(
|
||||
surface.draw(
|
||||
&self.device_objects.vertex_buffer,
|
||||
&self.device_objects
|
||||
.index_buffer
|
||||
.slice(idx_start..idx_end)
|
||||
.expect("Invalid index buffer range"),
|
||||
&self.device_objects.program,
|
||||
&uniform! {
|
||||
matrix: matrix,
|
||||
tex: self.device_objects.texture.sampled()
|
||||
.magnify_filter(MagnifySamplerFilter::Nearest)
|
||||
.minify_filter(MinifySamplerFilter::Nearest),
|
||||
},
|
||||
&DrawParameters {
|
||||
blend: Blend::alpha_blending(),
|
||||
scissor: Some(Rect {
|
||||
left: (cmd.clip_rect.x * scale_width) as u32,
|
||||
bottom: ((height - cmd.clip_rect.w) * scale_height) as u32,
|
||||
width: ((cmd.clip_rect.z - cmd.clip_rect.x) * scale_width) as
|
||||
u32,
|
||||
height: ((cmd.clip_rect.w - cmd.clip_rect.y) *
|
||||
scale_height) as
|
||||
u32,
|
||||
}),
|
||||
..DrawParameters::default()
|
||||
}));
|
||||
&DrawParameters {
|
||||
blend: Blend::alpha_blending(),
|
||||
scissor: Some(Rect {
|
||||
left: (cmd.clip_rect.x * scale_width) as u32,
|
||||
bottom: ((height - cmd.clip_rect.w) * scale_height) as u32,
|
||||
width: ((cmd.clip_rect.z - cmd.clip_rect.x) * scale_width) as u32,
|
||||
height: ((cmd.clip_rect.w - cmd.clip_rect.y) * scale_height) as u32,
|
||||
}),
|
||||
..DrawParameters::default()
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
idx_start = idx_end;
|
||||
}
|
||||
@ -149,8 +161,9 @@ pub struct DeviceObjects {
|
||||
texture: Texture2d,
|
||||
}
|
||||
|
||||
fn compile_default_program<F: Facade>(ctx: &F)
|
||||
-> Result<Program, program::ProgramChooserCreationError> {
|
||||
fn compile_default_program<F: Facade>(
|
||||
ctx: &F,
|
||||
) -> Result<Program, program::ProgramChooserCreationError> {
|
||||
program!(
|
||||
ctx,
|
||||
400 => {
|
||||
@ -186,7 +199,11 @@ impl DeviceObjects {
|
||||
use glium::texture::{ClientFormat, RawImage2d};
|
||||
|
||||
let vertex_buffer = try!(VertexBuffer::empty_dynamic(ctx, 0));
|
||||
let index_buffer = try!(IndexBuffer::empty_dynamic(ctx, PrimitiveType::TrianglesList, 0));
|
||||
let index_buffer = try!(IndexBuffer::empty_dynamic(
|
||||
ctx,
|
||||
PrimitiveType::TrianglesList,
|
||||
0,
|
||||
));
|
||||
|
||||
let program = try!(compile_default_program(ctx));
|
||||
let texture = try!(im_gui.prepare_texture(|handle| {
|
||||
@ -207,35 +224,42 @@ impl DeviceObjects {
|
||||
texture: texture,
|
||||
})
|
||||
}
|
||||
pub fn upload_vertex_buffer<F: Facade>(&mut self,
|
||||
ctx: &F,
|
||||
vtx_buffer: &[ImDrawVert])
|
||||
-> RendererResult<()> {
|
||||
pub fn upload_vertex_buffer<F: Facade>(
|
||||
&mut self,
|
||||
ctx: &F,
|
||||
vtx_buffer: &[ImDrawVert],
|
||||
) -> RendererResult<()> {
|
||||
self.vertex_buffer.invalidate();
|
||||
if let Some(slice) = self.vertex_buffer.slice_mut(0..vtx_buffer.len()) {
|
||||
slice.write(vtx_buffer);
|
||||
return Ok(());
|
||||
}
|
||||
self.vertex_buffer = try!(VertexBuffer::dynamic(ctx, vtx_buffer));
|
||||
let _ = ctx.get_context()
|
||||
.insert_debug_marker(&format!("imgui-rs: resized vertex buffer to {} bytes",
|
||||
self.vertex_buffer.get_size()));
|
||||
let _ = ctx.get_context().insert_debug_marker(&format!(
|
||||
"imgui-rs: resized vertex buffer to {} bytes",
|
||||
self.vertex_buffer.get_size()
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
pub fn upload_index_buffer<F: Facade>(&mut self,
|
||||
ctx: &F,
|
||||
idx_buffer: &[ImDrawIdx])
|
||||
-> RendererResult<()> {
|
||||
pub fn upload_index_buffer<F: Facade>(
|
||||
&mut self,
|
||||
ctx: &F,
|
||||
idx_buffer: &[ImDrawIdx],
|
||||
) -> RendererResult<()> {
|
||||
self.index_buffer.invalidate();
|
||||
if let Some(slice) = self.index_buffer.slice_mut(0..idx_buffer.len()) {
|
||||
slice.write(idx_buffer);
|
||||
return Ok(());
|
||||
}
|
||||
self.index_buffer =
|
||||
try!(IndexBuffer::dynamic(ctx, PrimitiveType::TrianglesList, idx_buffer));
|
||||
let _ = ctx.get_context()
|
||||
.insert_debug_marker(&format!("imgui-rs: resized index buffer to {} bytes",
|
||||
self.index_buffer.get_size()));
|
||||
self.index_buffer = try!(IndexBuffer::dynamic(
|
||||
ctx,
|
||||
PrimitiveType::TrianglesList,
|
||||
idx_buffer,
|
||||
));
|
||||
let _ = ctx.get_context().insert_debug_marker(&format!(
|
||||
"imgui-rs: resized index buffer to {} bytes",
|
||||
self.index_buffer.get_size()
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,10 @@ impl Structure<Format> for ImDrawVert {
|
||||
Some(s) if s.starts_with('.') => &s[1..],
|
||||
_ => name,
|
||||
};
|
||||
(sub_name, array_id * (mem::size_of::<ImDrawVert>() as ElemOffset))
|
||||
(
|
||||
sub_name,
|
||||
array_id * (mem::size_of::<ImDrawVert>() as ElemOffset),
|
||||
)
|
||||
}
|
||||
None => (name, 0),
|
||||
}
|
||||
@ -31,21 +34,21 @@ impl Structure<Format> for ImDrawVert {
|
||||
Some(Element {
|
||||
format: <ImVec2 as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.pos) } as ElemOffset +
|
||||
big_offset,
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
"uv" => {
|
||||
Some(Element {
|
||||
format: <ImVec2 as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.uv) } as ElemOffset +
|
||||
big_offset,
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
"col" => {
|
||||
Some(Element {
|
||||
format: <[U8Norm; 4] as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.col) } as ElemOffset +
|
||||
big_offset,
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
|
||||
1607
imgui-sys/src/lib.rs
1607
imgui-sys/src/lib.rs
File diff suppressed because it is too large
Load Diff
@ -107,7 +107,9 @@ impl<'ui, 'p> ChildFrame<'ui, 'p> {
|
||||
// https://github.com/Gekkio/imgui-rs/pull/58
|
||||
let show_border = false;
|
||||
|
||||
let render_child_frame = unsafe { imgui_sys::igBeginChild(self.name.as_ptr(), self.size, show_border, self.flags) };
|
||||
let render_child_frame = unsafe {
|
||||
imgui_sys::igBeginChild(self.name.as_ptr(), self.size, show_border, self.flags)
|
||||
};
|
||||
if render_child_frame {
|
||||
f();
|
||||
}
|
||||
|
||||
40
src/input.rs
40
src/input.rs
@ -143,12 +143,14 @@ impl<'ui, 'p> InputText<'ui, 'p> {
|
||||
|
||||
pub fn build(self) -> bool {
|
||||
unsafe {
|
||||
imgui_sys::igInputText(self.label.as_ptr(),
|
||||
self.buf.as_mut_ptr(),
|
||||
self.buf.capacity_with_nul(),
|
||||
self.flags,
|
||||
None,
|
||||
ptr::null_mut())
|
||||
imgui_sys::igInputText(
|
||||
self.label.as_ptr(),
|
||||
self.buf.as_mut_ptr(),
|
||||
self.buf.capacity_with_nul(),
|
||||
self.flags,
|
||||
None,
|
||||
ptr::null_mut(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,11 +179,13 @@ impl<'ui, 'p> InputInt<'ui, 'p> {
|
||||
|
||||
pub fn build(self) -> bool {
|
||||
unsafe {
|
||||
imgui_sys::igInputInt(self.label.as_ptr(),
|
||||
self.value as *mut i32,
|
||||
self.step,
|
||||
self.step_fast,
|
||||
self.flags)
|
||||
imgui_sys::igInputInt(
|
||||
self.label.as_ptr(),
|
||||
self.value as *mut i32,
|
||||
self.step,
|
||||
self.step_fast,
|
||||
self.flags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,12 +219,14 @@ impl<'ui, 'p> InputFloat<'ui, 'p> {
|
||||
|
||||
pub fn build(self) -> bool {
|
||||
unsafe {
|
||||
imgui_sys::igInputFloat(self.label.as_ptr(),
|
||||
self.value as *mut f32,
|
||||
self.step,
|
||||
self.step_fast,
|
||||
self.decimal_precision,
|
||||
self.flags)
|
||||
imgui_sys::igInputFloat(
|
||||
self.label.as_ptr(),
|
||||
self.value as *mut f32,
|
||||
self.step,
|
||||
self.step_fast,
|
||||
self.decimal_precision,
|
||||
self.flags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
402
src/lib.rs
402
src/lib.rs
@ -9,25 +9,24 @@ use std::str;
|
||||
use imgui_sys::ImGuiStyleVar;
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub use imgui_sys::{ImGuiInputTextFlags_AllowTabInput,
|
||||
ImGuiInputTextFlags_AlwaysInsertMode, ImGuiInputTextFlags_AutoSelectAll,
|
||||
ImGuiInputTextFlags_CallbackAlways, ImGuiInputTextFlags_CallbackCharFilter,
|
||||
pub use imgui_sys::{ImGuiInputTextFlags_AllowTabInput, ImGuiInputTextFlags_AlwaysInsertMode,
|
||||
ImGuiInputTextFlags_AutoSelectAll, ImGuiInputTextFlags_CallbackAlways,
|
||||
ImGuiInputTextFlags_CallbackCharFilter,
|
||||
ImGuiInputTextFlags_CallbackCompletion, ImGuiInputTextFlags_CallbackHistory,
|
||||
ImGuiInputTextFlags_CharsDecimal, ImGuiInputTextFlags_CharsHexadecimal,
|
||||
ImGuiInputTextFlags_CharsNoBlank, ImGuiInputTextFlags_CharsUppercase,
|
||||
ImGuiInputTextFlags_CtrlEnterForNewLine, ImGuiInputTextFlags_EnterReturnsTrue,
|
||||
ImGuiInputTextFlags_NoHorizontalScroll, ImGuiInputTextFlags_Password,
|
||||
ImGuiInputTextFlags_ReadOnly,
|
||||
ImGuiSelectableFlags_DontClosePopups, ImGuiSelectableFlags_SpanAllColumns,
|
||||
ImGuiSetCond_Always, ImGuiSetCond_Appearing,
|
||||
ImGuiSetCond_FirstUseEver, ImGuiSetCond_Once,
|
||||
ImGuiInputTextFlags_ReadOnly, ImGuiSelectableFlags_DontClosePopups,
|
||||
ImGuiSelectableFlags_SpanAllColumns, ImGuiSetCond_Always,
|
||||
ImGuiSetCond_Appearing, ImGuiSetCond_FirstUseEver, ImGuiSetCond_Once,
|
||||
ImGuiTreeNodeFlags_AllowOverlapMode, ImGuiTreeNodeFlags_Bullet,
|
||||
ImGuiTreeNodeFlags_CollapsingHeader, ImGuiTreeNodeFlags_DefaultOpen,
|
||||
ImGuiTreeNodeFlags_Framed, ImGuiTreeNodeFlags_Leaf,
|
||||
ImGuiTreeNodeFlags_NoAutoOpenOnLog, ImGuiTreeNodeFlags_NoTreePushOnOpen,
|
||||
ImGuiTreeNodeFlags_OpenOnArrow, ImGuiTreeNodeFlags_OpenOnDoubleClick,
|
||||
ImGuiTreeNodeFlags_Selected,
|
||||
ImGuiWindowFlags_AlwaysAutoResize, ImGuiWindowFlags_AlwaysHorizontalScrollbar,
|
||||
ImGuiTreeNodeFlags_Selected, ImGuiWindowFlags_AlwaysAutoResize,
|
||||
ImGuiWindowFlags_AlwaysHorizontalScrollbar,
|
||||
ImGuiWindowFlags_AlwaysUseWindowPadding,
|
||||
ImGuiWindowFlags_AlwaysVerticalScrollbar,
|
||||
ImGuiWindowFlags_HorizontalScrollbar, ImGuiWindowFlags_MenuBar,
|
||||
@ -39,10 +38,11 @@ pub use imgui_sys::{ImGuiInputTextFlags_AllowTabInput,
|
||||
ImGuiWindowFlags_ShowBorders};
|
||||
|
||||
pub use imgui_sys::{ImDrawIdx, ImDrawVert, ImGuiInputTextFlags, ImGuiKey, ImGuiSelectableFlags,
|
||||
ImGuiCond, ImGuiCol, ImGuiStyle, ImGuiTreeNodeFlags, ImGuiWindowFlags,
|
||||
ImVec2, ImVec4};
|
||||
ImGuiCond, ImGuiCol, ImGuiStyle, ImGuiTreeNodeFlags, ImGuiWindowFlags, ImVec2,
|
||||
ImVec4};
|
||||
pub use child_frame::ChildFrame;
|
||||
pub use input::{InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputInt2, InputInt3, InputInt4, InputText};
|
||||
pub use input::{InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputInt2, InputInt3,
|
||||
InputInt4, InputText};
|
||||
pub use menus::{Menu, MenuItem};
|
||||
pub use plothistogram::PlotHistogram;
|
||||
pub use plotlines::PlotLines;
|
||||
@ -113,7 +113,8 @@ impl ImGui {
|
||||
pub fn style(&self) -> &ImGuiStyle { unsafe { &*imgui_sys::igGetStyle() } }
|
||||
pub fn style_mut(&mut self) -> &mut ImGuiStyle { unsafe { &mut *imgui_sys::igGetStyle() } }
|
||||
pub fn prepare_texture<'a, F, T>(&mut self, f: F) -> T
|
||||
where F: FnOnce(TextureHandle<'a>) -> T
|
||||
where
|
||||
F: FnOnce(TextureHandle<'a>) -> T,
|
||||
{
|
||||
let io = self.io();
|
||||
let mut pixels: *mut c_uchar = ptr::null_mut();
|
||||
@ -121,17 +122,18 @@ impl ImGui {
|
||||
let mut height: c_int = 0;
|
||||
let mut bytes_per_pixel: c_int = 0;
|
||||
unsafe {
|
||||
imgui_sys::ImFontAtlas_GetTexDataAsRGBA32(io.fonts,
|
||||
&mut pixels,
|
||||
&mut width,
|
||||
&mut height,
|
||||
&mut bytes_per_pixel);
|
||||
imgui_sys::ImFontAtlas_GetTexDataAsRGBA32(
|
||||
io.fonts,
|
||||
&mut pixels,
|
||||
&mut width,
|
||||
&mut height,
|
||||
&mut bytes_per_pixel,
|
||||
);
|
||||
f(TextureHandle {
|
||||
width: width as u32,
|
||||
height: height as u32,
|
||||
pixels: slice::from_raw_parts(pixels,
|
||||
(width * height * bytes_per_pixel) as usize),
|
||||
})
|
||||
width: width as u32,
|
||||
height: height as u32,
|
||||
pixels: slice::from_raw_parts(pixels, (width * height * bytes_per_pixel) as usize),
|
||||
})
|
||||
}
|
||||
}
|
||||
pub fn set_texture_id(&mut self, value: usize) {
|
||||
@ -193,7 +195,10 @@ impl ImGui {
|
||||
}
|
||||
pub fn display_framebuffer_scale(&self) -> (f32, f32) {
|
||||
let io = self.io();
|
||||
(io.display_framebuffer_scale.x, io.display_framebuffer_scale.y)
|
||||
(
|
||||
io.display_framebuffer_scale.x,
|
||||
io.display_framebuffer_scale.y,
|
||||
)
|
||||
}
|
||||
pub fn mouse_pos(&self) -> (f32, f32) {
|
||||
let io = self.io();
|
||||
@ -250,11 +255,12 @@ impl ImGui {
|
||||
pub fn get_time(&self) -> f32 { unsafe { imgui_sys::igGetTime() } }
|
||||
pub fn get_frame_count(&self) -> i32 { unsafe { imgui_sys::igGetFrameCount() } }
|
||||
pub fn get_frame_rate(&self) -> f32 { self.io().framerate }
|
||||
pub fn frame<'ui, 'a: 'ui>(&'a mut self,
|
||||
size_points: (u32, u32),
|
||||
size_pixels: (u32, u32),
|
||||
delta_time: f32)
|
||||
-> Ui<'ui> {
|
||||
pub fn frame<'ui, 'a: 'ui>(
|
||||
&'a mut self,
|
||||
size_points: (u32, u32),
|
||||
size_pixels: (u32, u32),
|
||||
delta_time: f32,
|
||||
) -> Ui<'ui> {
|
||||
{
|
||||
let io = self.io_mut();
|
||||
io.display_size.x = size_points.0 as c_float;
|
||||
@ -335,7 +341,8 @@ impl<'ui> Ui<'ui> {
|
||||
io.metrics_active_windows
|
||||
}
|
||||
pub fn render<F, E>(self, mut f: F) -> Result<(), E>
|
||||
where F: FnMut(&Ui, DrawList) -> Result<(), E>
|
||||
where
|
||||
F: FnMut(&Ui, DrawList) -> Result<(), E>,
|
||||
{
|
||||
unsafe {
|
||||
imgui_sys::igRender();
|
||||
@ -396,7 +403,8 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
/// Runs a function after temporarily pushing a value to the item width stack.
|
||||
pub fn with_item_width<F>(&self, width: f32, f: F)
|
||||
where F: FnOnce()
|
||||
where
|
||||
F: FnOnce(),
|
||||
{
|
||||
self.push_item_width(width);
|
||||
f();
|
||||
@ -447,7 +455,8 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
/// Runs a function after temporarily pushing a value to the ID stack.
|
||||
pub fn with_id<F>(&self, id: i32, f: F)
|
||||
where F: FnOnce()
|
||||
where
|
||||
F: FnOnce(),
|
||||
{
|
||||
self.push_id(id);
|
||||
f();
|
||||
@ -464,7 +473,8 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
}
|
||||
pub fn text_colored<'p, A>(&self, col: A, text: &'p ImStr)
|
||||
where A: Into<ImVec4>
|
||||
where
|
||||
A: Into<ImVec4>,
|
||||
{
|
||||
unsafe {
|
||||
imgui_sys::igTextColored(col.into(), fmt_ptr(), text.as_ptr());
|
||||
@ -514,22 +524,25 @@ impl<'ui> Ui<'ui> {
|
||||
pub fn input_float<'p>(&self, label: &'p ImStr, value: &'p mut f32) -> InputFloat<'ui, 'p> {
|
||||
InputFloat::new(self, label, value)
|
||||
}
|
||||
pub fn input_float2<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 2])
|
||||
-> InputFloat2<'ui, 'p> {
|
||||
pub fn input_float2<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 2],
|
||||
) -> InputFloat2<'ui, 'p> {
|
||||
InputFloat2::new(self, label, value)
|
||||
}
|
||||
pub fn input_float3<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 3])
|
||||
-> InputFloat3<'ui, 'p> {
|
||||
pub fn input_float3<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 3],
|
||||
) -> InputFloat3<'ui, 'p> {
|
||||
InputFloat3::new(self, label, value)
|
||||
}
|
||||
pub fn input_float4<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 4])
|
||||
-> InputFloat4<'ui, 'p> {
|
||||
pub fn input_float4<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 4],
|
||||
) -> InputFloat4<'ui, 'p> {
|
||||
InputFloat4::new(self, label, value)
|
||||
}
|
||||
pub fn input_int<'p>(&self, label: &'p ImStr, value: &'p mut i32) -> InputInt<'ui, 'p> {
|
||||
@ -548,68 +561,76 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
// Widgets: Sliders
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn slider_float<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut f32,
|
||||
min: f32,
|
||||
max: f32)
|
||||
-> SliderFloat<'ui, 'p> {
|
||||
pub fn slider_float<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut f32,
|
||||
min: f32,
|
||||
max: f32,
|
||||
) -> SliderFloat<'ui, 'p> {
|
||||
SliderFloat::new(self, label, value, min, max)
|
||||
}
|
||||
pub fn slider_float2<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 2],
|
||||
min: f32,
|
||||
max: f32)
|
||||
-> SliderFloat2<'ui, 'p> {
|
||||
pub fn slider_float2<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 2],
|
||||
min: f32,
|
||||
max: f32,
|
||||
) -> SliderFloat2<'ui, 'p> {
|
||||
SliderFloat2::new(self, label, value, min, max)
|
||||
}
|
||||
pub fn slider_float3<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 3],
|
||||
min: f32,
|
||||
max: f32)
|
||||
-> SliderFloat3<'ui, 'p> {
|
||||
pub fn slider_float3<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 3],
|
||||
min: f32,
|
||||
max: f32,
|
||||
) -> SliderFloat3<'ui, 'p> {
|
||||
SliderFloat3::new(self, label, value, min, max)
|
||||
}
|
||||
pub fn slider_float4<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 4],
|
||||
min: f32,
|
||||
max: f32)
|
||||
-> SliderFloat4<'ui, 'p> {
|
||||
pub fn slider_float4<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; 4],
|
||||
min: f32,
|
||||
max: f32,
|
||||
) -> SliderFloat4<'ui, 'p> {
|
||||
SliderFloat4::new(self, label, value, min, max)
|
||||
}
|
||||
pub fn slider_int<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut i32,
|
||||
min: i32,
|
||||
max: i32)
|
||||
-> SliderInt<'ui, 'p> {
|
||||
pub fn slider_int<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut i32,
|
||||
min: i32,
|
||||
max: i32,
|
||||
) -> SliderInt<'ui, 'p> {
|
||||
SliderInt::new(self, label, value, min, max)
|
||||
}
|
||||
pub fn slider_int2<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32; 2],
|
||||
min: i32,
|
||||
max: i32)
|
||||
-> SliderInt2<'ui, 'p> {
|
||||
pub fn slider_int2<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32; 2],
|
||||
min: i32,
|
||||
max: i32,
|
||||
) -> SliderInt2<'ui, 'p> {
|
||||
SliderInt2::new(self, label, value, min, max)
|
||||
}
|
||||
pub fn slider_int3<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32; 3],
|
||||
min: i32,
|
||||
max: i32)
|
||||
-> SliderInt3<'ui, 'p> {
|
||||
pub fn slider_int3<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32; 3],
|
||||
min: i32,
|
||||
max: i32,
|
||||
) -> SliderInt3<'ui, 'p> {
|
||||
SliderInt3::new(self, label, value, min, max)
|
||||
}
|
||||
pub fn slider_int4<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32; 4],
|
||||
min: i32,
|
||||
max: i32)
|
||||
-> SliderInt4<'ui, 'p> {
|
||||
pub fn slider_int4<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32; 4],
|
||||
min: i32,
|
||||
max: i32,
|
||||
) -> SliderInt4<'ui, 'p> {
|
||||
SliderInt4::new(self, label, value, min, max)
|
||||
}
|
||||
}
|
||||
@ -624,12 +645,13 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
// Widgets: Selectable / Lists
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn selectable<'p, S: Into<ImVec2>>(&self,
|
||||
label: &'p ImStr,
|
||||
selected: bool,
|
||||
flags: ImGuiSelectableFlags,
|
||||
size: S)
|
||||
-> bool {
|
||||
pub fn selectable<'p, S: Into<ImVec2>>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
selected: bool,
|
||||
flags: ImGuiSelectableFlags,
|
||||
size: S,
|
||||
) -> bool {
|
||||
unsafe { imgui_sys::igSelectable(label.as_ptr(), selected, flags, size.into()) }
|
||||
}
|
||||
}
|
||||
@ -637,7 +659,8 @@ impl<'ui> Ui<'ui> {
|
||||
// Widgets: Menus
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn main_menu_bar<F>(&self, f: F)
|
||||
where F: FnOnce()
|
||||
where
|
||||
F: FnOnce(),
|
||||
{
|
||||
let render = unsafe { imgui_sys::igBeginMainMenuBar() };
|
||||
if render {
|
||||
@ -646,7 +669,8 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
}
|
||||
pub fn menu_bar<F>(&self, f: F)
|
||||
where F: FnOnce()
|
||||
where
|
||||
F: FnOnce(),
|
||||
{
|
||||
let render = unsafe { imgui_sys::igBeginMenuBar() };
|
||||
if render {
|
||||
@ -655,7 +679,9 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
}
|
||||
pub fn menu<'p>(&self, label: &'p ImStr) -> Menu<'ui, 'p> { Menu::new(self, label) }
|
||||
pub fn menu_item<'p>(&self, label: &'p ImStr) -> MenuItem<'ui, 'p> { MenuItem::new(self, label) }
|
||||
pub fn menu_item<'p>(&self, label: &'p ImStr) -> MenuItem<'ui, 'p> {
|
||||
MenuItem::new(self, label)
|
||||
}
|
||||
}
|
||||
|
||||
// Widgets: Popups
|
||||
@ -664,7 +690,8 @@ impl<'ui> Ui<'ui> {
|
||||
unsafe { imgui_sys::igOpenPopup(str_id.as_ptr()) };
|
||||
}
|
||||
pub fn popup<'p, F>(&self, str_id: &'p ImStr, f: F)
|
||||
where F: FnOnce()
|
||||
where
|
||||
F: FnOnce(),
|
||||
{
|
||||
let render = unsafe { imgui_sys::igBeginPopup(str_id.as_ptr()) };
|
||||
if render {
|
||||
@ -677,38 +704,44 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
// Widgets: Combos
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn combo<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
current_item: &mut i32,
|
||||
items: &'p [&'p ImStr],
|
||||
height_in_items: i32)
|
||||
-> bool {
|
||||
pub fn combo<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
current_item: &mut i32,
|
||||
items: &'p [&'p ImStr],
|
||||
height_in_items: i32,
|
||||
) -> bool {
|
||||
let items_inner: Vec<*const c_char> = items.into_iter().map(|item| item.as_ptr()).collect();
|
||||
unsafe {
|
||||
imgui_sys::igCombo(label.as_ptr(),
|
||||
current_item,
|
||||
items_inner.as_ptr() as *mut *const c_char,
|
||||
items_inner.len() as i32,
|
||||
height_in_items)
|
||||
imgui_sys::igCombo(
|
||||
label.as_ptr(),
|
||||
current_item,
|
||||
items_inner.as_ptr() as *mut *const c_char,
|
||||
items_inner.len() as i32,
|
||||
height_in_items,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Widgets: ListBox
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn list_box<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
current_item: &mut i32,
|
||||
items: &'p [&'p ImStr],
|
||||
height_in_items: i32)
|
||||
-> bool {
|
||||
pub fn list_box<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
current_item: &mut i32,
|
||||
items: &'p [&'p ImStr],
|
||||
height_in_items: i32,
|
||||
) -> bool {
|
||||
let items_inner: Vec<*const c_char> = items.into_iter().map(|item| item.as_ptr()).collect();
|
||||
unsafe {
|
||||
imgui_sys::igListBox(label.as_ptr(),
|
||||
current_item,
|
||||
items_inner.as_ptr() as *mut *const c_char,
|
||||
items_inner.len() as i32,
|
||||
height_in_items)
|
||||
imgui_sys::igListBox(
|
||||
label.as_ptr(),
|
||||
current_item,
|
||||
items_inner.as_ptr() as *mut *const c_char,
|
||||
items_inner.len() as i32,
|
||||
height_in_items,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -728,13 +761,8 @@ impl<'ui> Ui<'ui> {
|
||||
/// ui.radio_button(im_str!("Item 2"), &mut selected_radio_value, 2);
|
||||
/// ui.radio_button(im_str!("Item 3"), &mut selected_radio_value, 3);
|
||||
/// ```
|
||||
pub fn radio_button<'p>(&self,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut i32,
|
||||
wanted: i32) -> bool {
|
||||
unsafe {
|
||||
imgui_sys::igRadioButton(label.as_ptr(), value, wanted)
|
||||
}
|
||||
pub fn radio_button<'p>(&self, label: &'p ImStr, value: &'p mut i32, wanted: i32) -> bool {
|
||||
unsafe { imgui_sys::igRadioButton(label.as_ptr(), value, wanted) }
|
||||
}
|
||||
|
||||
/// Creates a radio button that shows as selected if the given value is true.
|
||||
@ -754,9 +782,7 @@ impl<'ui> Ui<'ui> {
|
||||
/// }
|
||||
/// ```
|
||||
pub fn radio_button_bool<'p>(&self, label: &'p ImStr, value: bool) -> bool {
|
||||
unsafe {
|
||||
imgui_sys::igRadioButtonBool(label.as_ptr(), value)
|
||||
}
|
||||
unsafe { imgui_sys::igRadioButtonBool(label.as_ptr(), value) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -767,7 +793,11 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn plot_histogram<'p>(&self, label: &'p ImStr, values: &'p [f32]) -> PlotHistogram<'ui, 'p> {
|
||||
pub fn plot_histogram<'p>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
values: &'p [f32],
|
||||
) -> PlotHistogram<'ui, 'p> {
|
||||
PlotHistogram::new(self, label, values)
|
||||
}
|
||||
}
|
||||
@ -779,9 +809,22 @@ impl<'ui> Ui<'ui> {
|
||||
/// 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(&self, text: &ImStr, hide_text_after_double_hash: bool, wrap_width: f32) -> ImVec2 {
|
||||
pub fn calc_text_size(
|
||||
&self,
|
||||
text: &ImStr,
|
||||
hide_text_after_double_hash: bool,
|
||||
wrap_width: f32,
|
||||
) -> ImVec2 {
|
||||
let mut buffer = ImVec2::new(0.0, 0.0);
|
||||
unsafe { imgui_sys::igCalcTextSize(&mut buffer as *mut ImVec2, text.as_ptr(), std::ptr::null(), hide_text_after_double_hash, wrap_width); }
|
||||
unsafe {
|
||||
imgui_sys::igCalcTextSize(
|
||||
&mut buffer as *mut ImVec2,
|
||||
text.as_ptr(),
|
||||
std::ptr::null(),
|
||||
hide_text_after_double_hash,
|
||||
wrap_width,
|
||||
);
|
||||
}
|
||||
buffer
|
||||
}
|
||||
}
|
||||
@ -799,31 +842,39 @@ impl<'ui> Ui<'ui> {
|
||||
/// .overlay_text(im_str!("Progress!"))
|
||||
/// .build();
|
||||
/// ```
|
||||
pub fn progress_bar<'p>(&self, fraction: f32) -> ProgressBar<'ui, 'p> { ProgressBar::new(self, fraction) }
|
||||
pub fn progress_bar<'p>(&self, fraction: f32) -> ProgressBar<'ui, 'p> {
|
||||
ProgressBar::new(self, fraction)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Creates a child frame. Size is size of child_frame within parent window.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust,no_run
|
||||
/// # use imgui::*;
|
||||
/// # let mut imgui = ImGui::init();
|
||||
/// # let ui = imgui.frame((0, 0), (0, 0), 0.1);
|
||||
/// ui.window(im_str!("ChatWindow"))
|
||||
/// .title_bar(true)
|
||||
/// .scrollable(false)
|
||||
/// .build(|| {
|
||||
/// ui.separator();
|
||||
///
|
||||
/// ui.child_frame(im_str!("child frame"), (400.0, 100.0))
|
||||
/// .show_borders(true)
|
||||
/// .always_show_vertical_scroll_bar(true)
|
||||
/// .build(|| {
|
||||
/// ui.text_colored((1.0, 0.0, 0.0, 1.0), im_str!("hello mate!"));
|
||||
/// });
|
||||
/// });
|
||||
pub fn child_frame<'p, S: Into<ImVec2>>(&self, name: &'p ImStr, size: S) -> ChildFrame<'ui, 'p> { ChildFrame::new(self, name, size.into()) }
|
||||
/// Creates a child frame. Size is size of child_frame within parent window.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust,no_run
|
||||
/// # use imgui::*;
|
||||
/// # let mut imgui = ImGui::init();
|
||||
/// # let ui = imgui.frame((0, 0), (0, 0), 0.1);
|
||||
/// ui.window(im_str!("ChatWindow"))
|
||||
/// .title_bar(true)
|
||||
/// .scrollable(false)
|
||||
/// .build(|| {
|
||||
/// ui.separator();
|
||||
///
|
||||
/// ui.child_frame(im_str!("child frame"), (400.0, 100.0))
|
||||
/// .show_borders(true)
|
||||
/// .always_show_vertical_scroll_bar(true)
|
||||
/// .build(|| {
|
||||
/// ui.text_colored((1.0, 0.0, 0.0, 1.0), im_str!("hello mate!"));
|
||||
/// });
|
||||
/// });
|
||||
pub fn child_frame<'p, S: Into<ImVec2>>(
|
||||
&self,
|
||||
name: &'p ImStr,
|
||||
size: S,
|
||||
) -> ChildFrame<'ui, 'p> {
|
||||
ChildFrame::new(self, name, size.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ui> Ui<'ui> {
|
||||
@ -877,14 +928,16 @@ impl<'ui> Ui<'ui> {
|
||||
WindowPadding(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::WindowPadding, v) },
|
||||
WindowRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::WindowRounding, v) },
|
||||
WindowMinSize(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::WindowMinSize, v) },
|
||||
ChildWindowRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::ChildWindowRounding, v) },
|
||||
ChildWindowRounding(v) => unsafe {
|
||||
igPushStyleVar(ImGuiStyleVar::ChildWindowRounding, v)
|
||||
},
|
||||
FramePadding(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::FramePadding, v) },
|
||||
FrameRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::FrameRounding, v) },
|
||||
ItemSpacing(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ItemSpacing, v) },
|
||||
ItemInnerSpacing(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ItemInnerSpacing, v) },
|
||||
IndentSpacing(v) => unsafe { igPushStyleVar(ImGuiStyleVar::IndentSpacing, v) },
|
||||
GrabMinSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::GrabMinSize, v) },
|
||||
ButtonTextAlign(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ButtonTextAlign, v) }
|
||||
ButtonTextAlign(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ButtonTextAlign, v) },
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -901,10 +954,19 @@ impl<'ui> Ui<'ui> {
|
||||
/// ui.text_wrapped(im_str!("AB"));
|
||||
/// });
|
||||
/// ```
|
||||
pub fn with_color_var<F: FnOnce(), C: Into<ImVec4> + Copy>(&self, var: ImGuiCol, color: C, f: F) {
|
||||
unsafe { imgui_sys::igPushStyleColor(var, color.into()); }
|
||||
pub fn with_color_var<F: FnOnce(), C: Into<ImVec4> + Copy>(
|
||||
&self,
|
||||
var: ImGuiCol,
|
||||
color: C,
|
||||
f: F,
|
||||
) {
|
||||
unsafe {
|
||||
imgui_sys::igPushStyleColor(var, color.into());
|
||||
}
|
||||
f();
|
||||
unsafe {imgui_sys::igPopStyleColor(1); }
|
||||
unsafe {
|
||||
imgui_sys::igPopStyleColor(1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs a function after temporarily pushing an array of values to the color stack.
|
||||
@ -921,9 +983,15 @@ impl<'ui> Ui<'ui> {
|
||||
/// ui.text_wrapped(im_str!("AB"));
|
||||
/// });
|
||||
/// ```
|
||||
pub fn with_color_vars<F: FnOnce(), C: Into<ImVec4> + Copy>(&self, color_vars: &[(ImGuiCol, C)], f: F) {
|
||||
pub fn with_color_vars<F: FnOnce(), C: Into<ImVec4> + Copy>(
|
||||
&self,
|
||||
color_vars: &[(ImGuiCol, C)],
|
||||
f: F,
|
||||
) {
|
||||
for &(color_var, color) in color_vars {
|
||||
unsafe { imgui_sys::igPushStyleColor(color_var, color.into()); }
|
||||
unsafe {
|
||||
imgui_sys::igPushStyleColor(color_var, color.into());
|
||||
}
|
||||
}
|
||||
f();
|
||||
unsafe { imgui_sys::igPopStyleColor(color_vars.len() as i32) };
|
||||
|
||||
@ -70,9 +70,9 @@ impl<'ui, 'p> MenuItem<'ui, 'p> {
|
||||
pub fn build(self) -> bool {
|
||||
let label = self.label.as_ptr();
|
||||
let shortcut = self.shortcut.map(|x| x.as_ptr()).unwrap_or(ptr::null());
|
||||
let selected = self.selected
|
||||
.map(|x| x as *mut bool)
|
||||
.unwrap_or(ptr::null_mut());
|
||||
let selected = self.selected.map(|x| x as *mut bool).unwrap_or(
|
||||
ptr::null_mut(),
|
||||
);
|
||||
let enabled = self.enabled;
|
||||
unsafe { imgui_sys::igMenuItemPtr(label, shortcut, selected, enabled) }
|
||||
}
|
||||
|
||||
@ -63,17 +63,17 @@ impl<'ui, 'p> PlotHistogram<'ui, 'p> {
|
||||
|
||||
pub fn build(self) {
|
||||
unsafe {
|
||||
imgui_sys::igPlotHistogram(self.label.as_ptr(),
|
||||
self.values.as_ptr() as *const c_float,
|
||||
self.values.len() as i32,
|
||||
self.values_offset as i32,
|
||||
self.overlay_text
|
||||
.map(|x| x.as_ptr())
|
||||
.unwrap_or(ptr::null()),
|
||||
self.scale_min,
|
||||
self.scale_max,
|
||||
self.graph_size,
|
||||
mem::size_of::<f32>() as i32);
|
||||
imgui_sys::igPlotHistogram(
|
||||
self.label.as_ptr(),
|
||||
self.values.as_ptr() as *const c_float,
|
||||
self.values.len() as i32,
|
||||
self.values_offset as i32,
|
||||
self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()),
|
||||
self.scale_min,
|
||||
self.scale_max,
|
||||
self.graph_size,
|
||||
mem::size_of::<f32>() as i32,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,17 +63,17 @@ impl<'ui, 'p> PlotLines<'ui, 'p> {
|
||||
|
||||
pub fn build(self) {
|
||||
unsafe {
|
||||
imgui_sys::igPlotLines(self.label.as_ptr(),
|
||||
self.values.as_ptr() as *const c_float,
|
||||
self.values.len() as i32,
|
||||
self.values_offset as i32,
|
||||
self.overlay_text
|
||||
.map(|x| x.as_ptr())
|
||||
.unwrap_or(ptr::null()),
|
||||
self.scale_min,
|
||||
self.scale_max,
|
||||
self.graph_size,
|
||||
mem::size_of::<f32>() as i32);
|
||||
imgui_sys::igPlotLines(
|
||||
self.label.as_ptr(),
|
||||
self.values.as_ptr() as *const c_float,
|
||||
self.values.len() as i32,
|
||||
self.values_offset as i32,
|
||||
self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()),
|
||||
self.scale_min,
|
||||
self.scale_max,
|
||||
self.graph_size,
|
||||
mem::size_of::<f32>() as i32,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,11 +49,11 @@ impl<'ui, 'p> ProgressBar<'ui, 'p> {
|
||||
/// of the progress bar, otherwise the it will not be shown.
|
||||
pub fn build(self) {
|
||||
unsafe {
|
||||
imgui_sys::igProgressBar(self.fraction,
|
||||
&self.size,
|
||||
self.overlay_text
|
||||
.map(|x| x.as_ptr())
|
||||
.unwrap_or(ptr::null()));
|
||||
imgui_sys::igProgressBar(
|
||||
self.fraction,
|
||||
&self.size,
|
||||
self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,11 +33,13 @@ impl<'ui, 'p> SliderInt<'ui, 'p> {
|
||||
}
|
||||
pub fn build(self) -> bool {
|
||||
unsafe {
|
||||
imgui_sys::igSliderInt(self.label.as_ptr(),
|
||||
self.value,
|
||||
self.min,
|
||||
self.max,
|
||||
self.display_format.as_ptr())
|
||||
imgui_sys::igSliderInt(
|
||||
self.label.as_ptr(),
|
||||
self.value,
|
||||
self.min,
|
||||
self.max,
|
||||
self.display_format.as_ptr(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,12 +125,14 @@ impl<'ui, 'p> SliderFloat<'ui, 'p> {
|
||||
}
|
||||
pub fn build(self) -> bool {
|
||||
unsafe {
|
||||
imgui_sys::igSliderFloat(self.label.as_ptr(),
|
||||
self.value,
|
||||
self.min,
|
||||
self.max,
|
||||
self.display_format.as_ptr(),
|
||||
self.power)
|
||||
imgui_sys::igSliderFloat(
|
||||
self.label.as_ptr(),
|
||||
self.value,
|
||||
self.min,
|
||||
self.max,
|
||||
self.display_format.as_ptr(),
|
||||
self.power,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use std::borrow::Borrow;
|
||||
use std::ffi::{CStr};
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
@ -22,9 +22,7 @@ impl ImString {
|
||||
v.push(b'\0');
|
||||
ImString(v)
|
||||
}
|
||||
pub unsafe fn from_utf8_with_nul_unchecked(v: Vec<u8>) -> ImString {
|
||||
ImString(v)
|
||||
}
|
||||
pub unsafe fn from_utf8_with_nul_unchecked(v: Vec<u8>) -> ImString { ImString(v) }
|
||||
pub fn clear(&mut self) {
|
||||
self.0.clear();
|
||||
self.0.push(b'\0');
|
||||
@ -40,12 +38,8 @@ impl ImString {
|
||||
}
|
||||
pub fn capacity(&self) -> usize { self.0.capacity() - 1 }
|
||||
pub fn capacity_with_nul(&self) -> usize { self.0.capacity() }
|
||||
pub fn reserve(&mut self, additional: usize) {
|
||||
self.0.reserve(additional);
|
||||
}
|
||||
pub fn reserve_exact(&mut self, additional: usize) {
|
||||
self.0.reserve_exact(additional);
|
||||
}
|
||||
pub fn reserve(&mut self, additional: usize) { self.0.reserve(additional); }
|
||||
pub fn reserve_exact(&mut self, additional: usize) { self.0.reserve_exact(additional); }
|
||||
pub fn as_ptr(&self) -> *const c_char { self.0.as_ptr() as *const _ }
|
||||
pub fn as_mut_ptr(&mut self) -> *mut c_char { self.0.as_mut_ptr() as *mut _ }
|
||||
|
||||
@ -101,19 +95,13 @@ impl<'a> Default for &'a ImStr {
|
||||
}
|
||||
|
||||
impl fmt::Debug for ImStr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Debug::fmt(&self.0, f)
|
||||
}
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&self.0, f) }
|
||||
}
|
||||
|
||||
impl ImStr {
|
||||
pub unsafe fn from_utf8_with_nul_unchecked(bytes: &[u8]) -> &ImStr {
|
||||
mem::transmute(bytes)
|
||||
}
|
||||
pub unsafe fn from_utf8_with_nul_unchecked(bytes: &[u8]) -> &ImStr { mem::transmute(bytes) }
|
||||
pub fn as_ptr(&self) -> *const c_char { self.0.as_ptr() }
|
||||
pub fn to_str(&self) -> &str {
|
||||
unsafe { str::from_utf8_unchecked(self.0.to_bytes()) }
|
||||
}
|
||||
pub fn to_str(&self) -> &str { unsafe { str::from_utf8_unchecked(self.0.to_bytes()) } }
|
||||
}
|
||||
|
||||
impl<'a> Into<&'a CStr> for &'a ImStr {
|
||||
@ -135,7 +123,5 @@ impl ToOwned for ImStr {
|
||||
|
||||
impl Deref for ImStr {
|
||||
type Target = str;
|
||||
fn deref(&self) -> &str {
|
||||
unsafe { str::from_utf8_unchecked(self.0.to_bytes()) }
|
||||
}
|
||||
fn deref(&self) -> &str { unsafe { str::from_utf8_unchecked(self.0.to_bytes()) } }
|
||||
}
|
||||
|
||||
11
src/trees.rs
11
src/trees.rs
@ -38,9 +38,11 @@ impl<'ui, 'p> TreeNode<'ui, 'p> {
|
||||
if !self.opened_cond.is_empty() {
|
||||
imgui_sys::igSetNextTreeNodeOpen(self.opened, self.opened_cond);
|
||||
}
|
||||
imgui_sys::igTreeNodeStr(self.id.as_ptr(),
|
||||
super::fmt_ptr(),
|
||||
self.label.unwrap_or(self.id).as_ptr())
|
||||
imgui_sys::igTreeNodeStr(
|
||||
self.id.as_ptr(),
|
||||
super::fmt_ptr(),
|
||||
self.label.unwrap_or(self.id).as_ptr(),
|
||||
)
|
||||
};
|
||||
if render {
|
||||
f();
|
||||
@ -83,8 +85,7 @@ impl<'ui, 'p> CollapsingHeader<'ui, 'p> {
|
||||
}
|
||||
#[inline]
|
||||
pub fn open_on_double_click(mut self, value: bool) -> Self {
|
||||
self.flags
|
||||
.set(ImGuiTreeNodeFlags::OpenOnDoubleClick, value);
|
||||
self.flags.set(ImGuiTreeNodeFlags::OpenOnDoubleClick, value);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
|
||||
@ -80,8 +80,7 @@ impl<'ui, 'p> Window<'ui, 'p> {
|
||||
}
|
||||
#[inline]
|
||||
pub fn scrollable(mut self, value: bool) -> Self {
|
||||
self.flags
|
||||
.set(ImGuiWindowFlags::NoScrollWithMouse, !value);
|
||||
self.flags.set(ImGuiWindowFlags::NoScrollWithMouse, !value);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
@ -116,38 +115,44 @@ impl<'ui, 'p> Window<'ui, 'p> {
|
||||
}
|
||||
#[inline]
|
||||
pub fn horizontal_scrollbar(mut self, value: bool) -> Self {
|
||||
self.flags
|
||||
.set(ImGuiWindowFlags::HorizontalScrollbar, value);
|
||||
self.flags.set(ImGuiWindowFlags::HorizontalScrollbar, value);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn no_focus_on_appearing(mut self, value: bool) -> Self {
|
||||
self.flags
|
||||
.set(ImGuiWindowFlags::NoFocusOnAppearing, value);
|
||||
self.flags.set(ImGuiWindowFlags::NoFocusOnAppearing, value);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn no_bring_to_front_on_focus(mut self, value: bool) -> Self {
|
||||
self.flags
|
||||
.set(ImGuiWindowFlags::NoBringToFrontOnFocus, value);
|
||||
self.flags.set(
|
||||
ImGuiWindowFlags::NoBringToFrontOnFocus,
|
||||
value,
|
||||
);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn always_vertical_scrollbar(mut self, value: bool) -> Self {
|
||||
self.flags
|
||||
.set(ImGuiWindowFlags::AlwaysVerticalScrollbar, value);
|
||||
self.flags.set(
|
||||
ImGuiWindowFlags::AlwaysVerticalScrollbar,
|
||||
value,
|
||||
);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn always_horizontal_scrollbar(mut self, value: bool) -> Self {
|
||||
self.flags
|
||||
.set(ImGuiWindowFlags::AlwaysHorizontalScrollbar, value);
|
||||
self.flags.set(
|
||||
ImGuiWindowFlags::AlwaysHorizontalScrollbar,
|
||||
value,
|
||||
);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn always_use_window_padding(mut self, value: bool) -> Self {
|
||||
self.flags
|
||||
.set(ImGuiWindowFlags::AlwaysUseWindowPadding, value);
|
||||
self.flags.set(
|
||||
ImGuiWindowFlags::AlwaysUseWindowPadding,
|
||||
value,
|
||||
);
|
||||
self
|
||||
}
|
||||
pub fn build<F: FnOnce()>(self, f: F) {
|
||||
@ -158,13 +163,15 @@ impl<'ui, 'p> Window<'ui, 'p> {
|
||||
if !self.size_cond.is_empty() {
|
||||
imgui_sys::igSetNextWindowSize(self.size.into(), self.size_cond);
|
||||
}
|
||||
imgui_sys::igBegin2(self.name.as_ptr(),
|
||||
self.opened
|
||||
.map(|x| x as *mut bool)
|
||||
.unwrap_or(ptr::null_mut()),
|
||||
ImVec2::new(0.0, 0.0),
|
||||
self.bg_alpha,
|
||||
self.flags)
|
||||
imgui_sys::igBegin2(
|
||||
self.name.as_ptr(),
|
||||
self.opened.map(|x| x as *mut bool).unwrap_or(
|
||||
ptr::null_mut(),
|
||||
),
|
||||
ImVec2::new(0.0, 0.0),
|
||||
self.bg_alpha,
|
||||
self.flags,
|
||||
)
|
||||
};
|
||||
if render {
|
||||
f();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user