mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 13:38:35 +00:00
Reformat everything
This commit is contained in:
parent
558e5efe1c
commit
319f7aa4c6
@ -15,7 +15,9 @@ struct State {
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn reset(&mut self) { self.notify_text = ""; }
|
||||
fn reset(&mut self) {
|
||||
self.notify_text = "";
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
@ -61,27 +63,30 @@ fn example_1(state: &mut State, ui: &Ui) {
|
||||
.build(|| {
|
||||
ui.text_wrapped(im_str!(
|
||||
"Color button is a widget that displays a color value as a clickable rectangle. \
|
||||
It also supports a tooltip with detailed information about the color value. \
|
||||
Try hovering over and clicking these buttons!"
|
||||
It also supports a tooltip with detailed information about the color value. \
|
||||
Try hovering over and clicking these buttons!"
|
||||
));
|
||||
ui.text(state.notify_text);
|
||||
|
||||
ui.text("This button is black:");
|
||||
if ui.color_button(im_str!("Black color"), (0.0, 0.0, 0.0, 1.0))
|
||||
if ui
|
||||
.color_button(im_str!("Black color"), (0.0, 0.0, 0.0, 1.0))
|
||||
.build()
|
||||
{
|
||||
state.notify_text = "*** Black button was clicked";
|
||||
}
|
||||
|
||||
ui.text("This button is red:");
|
||||
if ui.color_button(im_str!("Red color"), (1.0, 0.0, 0.0, 1.0))
|
||||
if ui
|
||||
.color_button(im_str!("Red color"), (1.0, 0.0, 0.0, 1.0))
|
||||
.build()
|
||||
{
|
||||
state.notify_text = "*** Red button was clicked";
|
||||
}
|
||||
|
||||
ui.text("This button is BIG because it has a custom size:");
|
||||
if ui.color_button(im_str!("Green color"), (0.0, 1.0, 0.0, 1.0))
|
||||
if ui
|
||||
.color_button(im_str!("Green color"), (0.0, 1.0, 0.0, 1.0))
|
||||
.size((100.0, 50.0))
|
||||
.build()
|
||||
{
|
||||
@ -89,7 +94,8 @@ fn example_1(state: &mut State, ui: &Ui) {
|
||||
}
|
||||
|
||||
ui.text("This button doesn't use the tooltip at all:");
|
||||
if ui.color_button(im_str!("No tooltip"), (0.0, 0.0, 1.0, 1.0))
|
||||
if ui
|
||||
.color_button(im_str!("No tooltip"), (0.0, 0.0, 1.0, 1.0))
|
||||
.tooltip(false)
|
||||
.build()
|
||||
{
|
||||
@ -105,8 +111,8 @@ fn example_2(ui: &Ui) {
|
||||
.build(|| {
|
||||
ui.text_wrapped(im_str!(
|
||||
"The displayed color is passed to the button as four float values between \
|
||||
0.0 - 1.0 (RGBA). If you don't care about the alpha component, it can be \
|
||||
disabled and it won't show up in the tooltip"
|
||||
0.0 - 1.0 (RGBA). If you don't care about the alpha component, it can be \
|
||||
disabled and it won't show up in the tooltip"
|
||||
));
|
||||
|
||||
ui.text("This button ignores the alpha component:");
|
||||
@ -119,7 +125,7 @@ fn example_2(ui: &Ui) {
|
||||
ui.spacing();
|
||||
ui.text_wrapped(im_str!(
|
||||
"If you *do* care about the alpha component, you can choose how it's \
|
||||
displayed in the button and the tooltip"
|
||||
displayed in the button and the tooltip"
|
||||
));
|
||||
|
||||
ui.separator();
|
||||
@ -133,7 +139,7 @@ fn example_2(ui: &Ui) {
|
||||
ui.separator();
|
||||
ui.text_wrapped(im_str!(
|
||||
"ColorPreview::HalfAlpha divides the color area into two halves and uses a \
|
||||
checkerboard pattern in one half to illustrate the alpha component"
|
||||
checkerboard pattern in one half to illustrate the alpha component"
|
||||
));
|
||||
ui.color_button(
|
||||
im_str!("Red + ColorPreview::HalfAlpha"),
|
||||
@ -144,7 +150,7 @@ fn example_2(ui: &Ui) {
|
||||
ui.separator();
|
||||
ui.text_wrapped(im_str!(
|
||||
"ColorPreview::Alpha uses a checkerboard pattern in the entire color area to \
|
||||
illustrate the alpha component"
|
||||
illustrate the alpha component"
|
||||
));
|
||||
ui.color_button(im_str!("Red + ColorPreview::Alpha"), (1.0, 0.0, 0.0, 0.5))
|
||||
.preview(ColorPreview::Alpha)
|
||||
|
||||
@ -11,7 +11,9 @@ mod support_gfx;
|
||||
|
||||
const CLEAR_COLOR: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
|
||||
|
||||
fn main() { support_gfx::run("hello_gfx.rs".to_owned(), CLEAR_COLOR, hello_world); }
|
||||
fn main() {
|
||||
support_gfx::run("hello_gfx.rs".to_owned(), CLEAR_COLOR, hello_world);
|
||||
}
|
||||
|
||||
fn hello_world<'a>(ui: &Ui<'a>) -> bool {
|
||||
ui.window(im_str!("Hello world"))
|
||||
|
||||
@ -9,7 +9,9 @@ mod support;
|
||||
|
||||
const CLEAR_COLOR: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
|
||||
|
||||
fn main() { support::run("hello_world.rs".to_owned(), CLEAR_COLOR, hello_world); }
|
||||
fn main() {
|
||||
support::run("hello_world.rs".to_owned(), CLEAR_COLOR, hello_world);
|
||||
}
|
||||
|
||||
fn hello_world<'a>(ui: &Ui<'a>) -> bool {
|
||||
ui.window(im_str!("Hello world"))
|
||||
|
||||
@ -34,12 +34,15 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
.pixel_snap_h(true)
|
||||
.size_pixels(13.0)
|
||||
.rasterizer_multiply(1.75),
|
||||
&FontGlyphRange::japanese());
|
||||
&FontGlyphRange::japanese(),
|
||||
);
|
||||
|
||||
imgui.fonts().add_default_font_with_config(ImFontConfig::new()
|
||||
.merge_mode(true)
|
||||
.oversample_h(font_oversample)
|
||||
.oversample_v(font_oversample));
|
||||
imgui.fonts().add_default_font_with_config(
|
||||
ImFontConfig::new()
|
||||
.merge_mode(true)
|
||||
.oversample_h(font_oversample)
|
||||
.oversample_v(font_oversample),
|
||||
);
|
||||
|
||||
let mut renderer = Renderer::init(&mut imgui, &display).expect("Failed to initialize renderer");
|
||||
|
||||
@ -51,8 +54,8 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
|
||||
loop {
|
||||
events_loop.poll_events(|event| {
|
||||
use glium::glutin::WindowEvent::*;
|
||||
use glium::glutin::ElementState::Pressed;
|
||||
use glium::glutin::WindowEvent::*;
|
||||
use glium::glutin::{Event, MouseButton, MouseScrollDelta, TouchPhase};
|
||||
|
||||
if let Event::WindowEvent { event, .. } = event {
|
||||
@ -82,24 +85,22 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
Some(Key::X) => imgui.set_key(16, pressed),
|
||||
Some(Key::Y) => imgui.set_key(17, pressed),
|
||||
Some(Key::Z) => imgui.set_key(18, pressed),
|
||||
Some(Key::LControl) |
|
||||
Some(Key::RControl) => imgui.set_key_ctrl(pressed),
|
||||
Some(Key::LShift) |
|
||||
Some(Key::RShift) => imgui.set_key_shift(pressed),
|
||||
Some(Key::LControl) | Some(Key::RControl) => {
|
||||
imgui.set_key_ctrl(pressed)
|
||||
}
|
||||
Some(Key::LShift) | Some(Key::RShift) => imgui.set_key_shift(pressed),
|
||||
Some(Key::LAlt) | Some(Key::RAlt) => imgui.set_key_alt(pressed),
|
||||
Some(Key::LWin) | Some(Key::RWin) => imgui.set_key_super(pressed),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
CursorMoved { position: pos, .. } => mouse_state.pos = pos.into(),
|
||||
MouseInput { state, button, .. } => {
|
||||
match button {
|
||||
MouseButton::Left => mouse_state.pressed.0 = state == Pressed,
|
||||
MouseButton::Right => mouse_state.pressed.1 = state == Pressed,
|
||||
MouseButton::Middle => mouse_state.pressed.2 = state == Pressed,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
MouseInput { state, button, .. } => match button {
|
||||
MouseButton::Left => mouse_state.pressed.0 = state == Pressed,
|
||||
MouseButton::Right => mouse_state.pressed.1 = state == Pressed,
|
||||
MouseButton::Middle => mouse_state.pressed.2 = state == Pressed,
|
||||
_ => {}
|
||||
},
|
||||
MouseWheel {
|
||||
delta: MouseScrollDelta::LineDelta(_, y),
|
||||
phase: TouchPhase::Moved,
|
||||
@ -196,15 +197,13 @@ fn configure_keys(imgui: &mut ImGui) {
|
||||
|
||||
fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
|
||||
imgui.set_mouse_pos(mouse_state.pos.0 as f32, mouse_state.pos.1 as f32);
|
||||
imgui.set_mouse_down(
|
||||
&[
|
||||
mouse_state.pressed.0,
|
||||
mouse_state.pressed.1,
|
||||
mouse_state.pressed.2,
|
||||
false,
|
||||
false,
|
||||
],
|
||||
);
|
||||
imgui.set_mouse_down(&[
|
||||
mouse_state.pressed.0,
|
||||
mouse_state.pressed.1,
|
||||
mouse_state.pressed.2,
|
||||
false,
|
||||
false,
|
||||
]);
|
||||
imgui.set_mouse_wheel(mouse_state.wheel);
|
||||
mouse_state.wheel = 0.0;
|
||||
}
|
||||
|
||||
@ -70,12 +70,15 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
.pixel_snap_h(true)
|
||||
.size_pixels(13.0)
|
||||
.rasterizer_multiply(1.75),
|
||||
&FontGlyphRange::japanese());
|
||||
&FontGlyphRange::japanese(),
|
||||
);
|
||||
|
||||
imgui.fonts().add_default_font_with_config(ImFontConfig::new()
|
||||
.merge_mode(true)
|
||||
.oversample_h(font_oversample)
|
||||
.oversample_v(font_oversample));
|
||||
imgui.fonts().add_default_font_with_config(
|
||||
ImFontConfig::new()
|
||||
.merge_mode(true)
|
||||
.oversample_h(font_oversample)
|
||||
.oversample_v(font_oversample),
|
||||
);
|
||||
|
||||
let mut renderer = Renderer::init(&mut imgui, &mut factory, shaders, main_color.clone())
|
||||
.expect("Failed to initialize renderer");
|
||||
@ -88,8 +91,8 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
|
||||
loop {
|
||||
events_loop.poll_events(|event| {
|
||||
use glutin::WindowEvent::*;
|
||||
use glutin::ElementState::Pressed;
|
||||
use glutin::WindowEvent::*;
|
||||
use glutin::{Event, MouseButton, MouseScrollDelta, TouchPhase};
|
||||
|
||||
if let Event::WindowEvent { event, .. } = event {
|
||||
@ -123,24 +126,22 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
Some(Key::X) => imgui.set_key(16, pressed),
|
||||
Some(Key::Y) => imgui.set_key(17, pressed),
|
||||
Some(Key::Z) => imgui.set_key(18, pressed),
|
||||
Some(Key::LControl) |
|
||||
Some(Key::RControl) => imgui.set_key_ctrl(pressed),
|
||||
Some(Key::LShift) |
|
||||
Some(Key::RShift) => imgui.set_key_shift(pressed),
|
||||
Some(Key::LControl) | Some(Key::RControl) => {
|
||||
imgui.set_key_ctrl(pressed)
|
||||
}
|
||||
Some(Key::LShift) | Some(Key::RShift) => imgui.set_key_shift(pressed),
|
||||
Some(Key::LAlt) | Some(Key::RAlt) => imgui.set_key_alt(pressed),
|
||||
Some(Key::LWin) | Some(Key::RWin) => imgui.set_key_super(pressed),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
CursorMoved { position: pos, .. } => mouse_state.pos = pos.into(),
|
||||
MouseInput { state, button, .. } => {
|
||||
match button {
|
||||
MouseButton::Left => mouse_state.pressed.0 = state == Pressed,
|
||||
MouseButton::Right => mouse_state.pressed.1 = state == Pressed,
|
||||
MouseButton::Middle => mouse_state.pressed.2 = state == Pressed,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
MouseInput { state, button, .. } => match button {
|
||||
MouseButton::Left => mouse_state.pressed.0 = state == Pressed,
|
||||
MouseButton::Right => mouse_state.pressed.1 = state == Pressed,
|
||||
MouseButton::Middle => mouse_state.pressed.2 = state == Pressed,
|
||||
_ => {}
|
||||
},
|
||||
MouseWheel {
|
||||
delta: MouseScrollDelta::LineDelta(_, y),
|
||||
phase: TouchPhase::Moved,
|
||||
@ -199,9 +200,9 @@ pub fn run<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
|
||||
}
|
||||
|
||||
encoder.clear(&main_color, clear_color);
|
||||
renderer.render(ui, &mut factory, &mut encoder).expect(
|
||||
"Rendering failed",
|
||||
);
|
||||
renderer
|
||||
.render(ui, &mut factory, &mut encoder)
|
||||
.expect("Rendering failed");
|
||||
encoder.flush(&mut device);
|
||||
window.context().swap_buffers().unwrap();
|
||||
device.cleanup();
|
||||
@ -234,15 +235,13 @@ fn configure_keys(imgui: &mut ImGui) {
|
||||
|
||||
fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
|
||||
imgui.set_mouse_pos(mouse_state.pos.0 as f32, mouse_state.pos.1 as f32);
|
||||
imgui.set_mouse_down(
|
||||
&[
|
||||
mouse_state.pressed.0,
|
||||
mouse_state.pressed.1,
|
||||
mouse_state.pressed.2,
|
||||
false,
|
||||
false,
|
||||
],
|
||||
);
|
||||
imgui.set_mouse_down(&[
|
||||
mouse_state.pressed.0,
|
||||
mouse_state.pressed.1,
|
||||
mouse_state.pressed.2,
|
||||
false,
|
||||
false,
|
||||
]);
|
||||
imgui.set_mouse_wheel(mouse_state.wheel);
|
||||
mouse_state.wheel = 0.0;
|
||||
}
|
||||
|
||||
@ -158,7 +158,9 @@ struct AutoResizeState {
|
||||
}
|
||||
|
||||
impl Default for AutoResizeState {
|
||||
fn default() -> Self { AutoResizeState { lines: 10 } }
|
||||
fn default() -> Self {
|
||||
AutoResizeState { lines: 10 }
|
||||
}
|
||||
}
|
||||
|
||||
struct CustomRenderingState {
|
||||
@ -194,7 +196,9 @@ fn main() {
|
||||
fn show_help_marker(ui: &Ui, desc: &str) {
|
||||
ui.text_disabled(im_str!("(?)"));
|
||||
if ui.is_item_hovered() {
|
||||
ui.tooltip(|| { ui.text(desc); });
|
||||
ui.tooltip(|| {
|
||||
ui.text(desc);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,7 +262,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
|
||||
ui.text("By Omar Cornut and all github contributors.");
|
||||
ui.text(
|
||||
"ImGui is licensed under the MIT License, see LICENSE for more \
|
||||
information.",
|
||||
information.",
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -271,7 +275,8 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
|
||||
);
|
||||
}
|
||||
|
||||
let mut window = ui.window(im_str!("ImGui Demo"))
|
||||
let mut window = ui
|
||||
.window(im_str!("ImGui Demo"))
|
||||
.title_bar(!state.no_titlebar)
|
||||
.resizable(!state.no_resize)
|
||||
.movable(!state.no_move)
|
||||
@ -283,88 +288,88 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
|
||||
window = window.opened(opened)
|
||||
}
|
||||
window.build(|| {
|
||||
ui.push_item_width(-140.0);
|
||||
ui.text(format!("dear imgui says hello. ({})", imgui::get_version()));
|
||||
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!("Log"))
|
||||
.selected(&mut state.show_app_log)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Simple layout"))
|
||||
.selected(&mut state.show_app_layout)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Property editor"))
|
||||
.selected(&mut state.show_app_property_editor)
|
||||
.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!("Constrained-resizing window"))
|
||||
.selected(&mut state.show_app_constrained_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!("Style Editor"))
|
||||
.selected(&mut state.show_app_style_editor)
|
||||
.build();
|
||||
ui.menu_item(im_str!("About ImGui"))
|
||||
.selected(&mut state.show_app_about)
|
||||
.build();
|
||||
});
|
||||
ui.push_item_width(-140.0);
|
||||
ui.text(format!("dear imgui says hello. ({})", imgui::get_version()));
|
||||
ui.menu_bar(|| {
|
||||
ui.menu(im_str!("Menu")).build(|| {
|
||||
show_example_menu_file(ui, &mut state.file_menu);
|
||||
});
|
||||
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() \
|
||||
function. Please refer to the code for programming \
|
||||
reference.\n\nUser Guide:"
|
||||
));
|
||||
show_user_guide(ui);
|
||||
}
|
||||
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!("Log"))
|
||||
.selected(&mut state.show_app_log)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Simple layout"))
|
||||
.selected(&mut state.show_app_layout)
|
||||
.build();
|
||||
ui.menu_item(im_str!("Property editor"))
|
||||
.selected(&mut state.show_app_property_editor)
|
||||
.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!("Constrained-resizing window"))
|
||||
.selected(&mut state.show_app_constrained_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!("Style Editor"))
|
||||
.selected(&mut state.show_app_style_editor)
|
||||
.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() \
|
||||
function. Please refer to the code for programming \
|
||||
reference.\n\nUser Guide:"
|
||||
));
|
||||
show_user_guide(ui);
|
||||
}
|
||||
|
||||
if ui.collapsing_header(im_str!("Window options")).build() {
|
||||
ui.checkbox(im_str!("No titlebar"), &mut state.no_titlebar);
|
||||
ui.same_line(150.0);
|
||||
ui.checkbox(im_str!("No scrollbar"), &mut state.no_scrollbar);
|
||||
ui.same_line(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.checkbox(im_str!("No resize"), &mut state.no_resize);
|
||||
ui.same_line(300.0);
|
||||
ui.checkbox(im_str!("No collapse"), &mut state.no_collapse);
|
||||
ui.checkbox(im_str!("No close"), &mut state.no_close);
|
||||
if ui.collapsing_header(im_str!("Window options")).build() {
|
||||
ui.checkbox(im_str!("No titlebar"), &mut state.no_titlebar);
|
||||
ui.same_line(150.0);
|
||||
ui.checkbox(im_str!("No scrollbar"), &mut state.no_scrollbar);
|
||||
ui.same_line(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.checkbox(im_str!("No resize"), &mut state.no_resize);
|
||||
ui.same_line(300.0);
|
||||
ui.checkbox(im_str!("No collapse"), &mut state.no_collapse);
|
||||
ui.checkbox(im_str!("No close"), &mut state.no_close);
|
||||
|
||||
ui.tree_node(im_str!("Style")).build(|| {
|
||||
ui.show_default_style_editor()
|
||||
});
|
||||
}
|
||||
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!("Style"))
|
||||
.build(|| ui.show_default_style_editor());
|
||||
}
|
||||
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);
|
||||
@ -372,267 +377,273 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
|
||||
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.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.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!("Multi-line text")).build(|| {
|
||||
ui.input_text_multiline(im_str!("multiline"), &mut state.text_multiline, (300., 100.)).build();
|
||||
});
|
||||
ui.tree_node(im_str!("Multi-line text")).build(|| {
|
||||
ui.input_text_multiline(
|
||||
im_str!("multiline"),
|
||||
&mut state.text_multiline,
|
||||
(300., 100.),
|
||||
).build();
|
||||
});
|
||||
|
||||
ui.tree_node(im_str!("Word Wrapping")).build(|| {
|
||||
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."
|
||||
));
|
||||
ui.spacing();
|
||||
ui.tree_node(im_str!("Word Wrapping")).build(|| {
|
||||
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."
|
||||
));
|
||||
ui.spacing();
|
||||
|
||||
ui.slider_float(im_str!("Wrap width"), &mut state.wrap_width, -20.0, 600.0)
|
||||
.display_format(im_str!("%.0f"))
|
||||
.build();
|
||||
|
||||
ui.text(im_str!("Test paragraph 1:"));
|
||||
// TODO
|
||||
|
||||
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 \
|
||||
with theappropriate CJK character ranges. Call \
|
||||
io.Font->LoadFromFileTTF()manually to load extra \
|
||||
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.radio_button(im_str!("radio a"), &mut state.radio_button, 0);
|
||||
ui.same_line(0.0);
|
||||
ui.radio_button(im_str!("radio b"), &mut state.radio_button, 1);
|
||||
ui.same_line(0.0);
|
||||
ui.radio_button(im_str!("radio c"), &mut state.radio_button, 2);
|
||||
|
||||
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 scroll"), &mut state.item2, &items, -1);
|
||||
ui.input_text(im_str!("input text"), &mut state.text)
|
||||
ui.slider_float(im_str!("Wrap width"), &mut state.wrap_width, -20.0, 600.0)
|
||||
.display_format(im_str!("%.0f"))
|
||||
.build();
|
||||
ui.input_int(im_str!("input int"), &mut state.i0).build();
|
||||
ui.drag_int(im_str!("drag int"), &mut state.i0).build();
|
||||
ui.input_float(im_str!("input float"), &mut state.f0)
|
||||
.step(0.01)
|
||||
.step_fast(1.0)
|
||||
|
||||
ui.text(im_str!("Test paragraph 1:"));
|
||||
// TODO
|
||||
|
||||
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 \
|
||||
with theappropriate CJK character ranges. Call \
|
||||
io.Font->LoadFromFileTTF()manually to load extra \
|
||||
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.drag_float(im_str!("drag float"), &mut state.f0)
|
||||
.speed(0.001)
|
||||
.min(-1.0)
|
||||
.max(1.0)
|
||||
});
|
||||
|
||||
ui.radio_button(im_str!("radio a"), &mut state.radio_button, 0);
|
||||
ui.same_line(0.0);
|
||||
ui.radio_button(im_str!("radio b"), &mut state.radio_button, 1);
|
||||
ui.same_line(0.0);
|
||||
ui.radio_button(im_str!("radio c"), &mut state.radio_button, 2);
|
||||
|
||||
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 scroll"), &mut state.item2, &items, -1);
|
||||
ui.input_text(im_str!("input text"), &mut state.text)
|
||||
.build();
|
||||
ui.input_int(im_str!("input int"), &mut state.i0).build();
|
||||
ui.drag_int(im_str!("drag int"), &mut state.i0).build();
|
||||
ui.input_float(im_str!("input float"), &mut state.f0)
|
||||
.step(0.01)
|
||||
.step_fast(1.0)
|
||||
.build();
|
||||
ui.drag_float(im_str!("drag float"), &mut state.f0)
|
||||
.speed(0.001)
|
||||
.min(-1.0)
|
||||
.max(1.0)
|
||||
.build();
|
||||
ui.input_float3(im_str!("input float3"), &mut state.vec3f)
|
||||
.build();
|
||||
ui.color_edit(im_str!("color 1"), &mut state.col1).build();
|
||||
ui.color_edit(im_str!("color 2"), &mut state.col2).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.input_float3(im_str!("input float3"), &mut state.vec3f)
|
||||
.build();
|
||||
ui.color_edit(im_str!("color 1"), &mut state.col1).build();
|
||||
ui.color_edit(im_str!("color 2"), &mut state.col2).build();
|
||||
ui.input_int3(im_str!("input int3"), &mut state.vec3i)
|
||||
.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.tree_node(im_str!("Color/Picker Widgets")).build(|| {
|
||||
let s = &mut state.color_edit;
|
||||
ui.checkbox(im_str!("With HDR"), &mut s.hdr);
|
||||
ui.same_line(0.0);
|
||||
show_help_marker(
|
||||
ui,
|
||||
"Currently all this does is to lift the 0..1 \
|
||||
limits on dragging widgets.",
|
||||
);
|
||||
|
||||
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.checkbox(im_str!("With Alpha Preview"), &mut s.alpha_preview);
|
||||
ui.checkbox(
|
||||
im_str!("With Half Alpha Preview"),
|
||||
&mut s.alpha_half_preview,
|
||||
);
|
||||
ui.checkbox(im_str!("With Options Menu"), &mut s.options_menu);
|
||||
ui.same_line(0.0);
|
||||
show_help_marker(
|
||||
ui,
|
||||
"Right-click on the individual color widget to \
|
||||
show options.",
|
||||
);
|
||||
let misc_flags = {
|
||||
let mut f = ImGuiColorEditFlags::empty();
|
||||
f.set(ImGuiColorEditFlags::HDR, s.hdr);
|
||||
f.set(ImGuiColorEditFlags::AlphaPreviewHalf, s.alpha_half_preview);
|
||||
if !s.alpha_half_preview {
|
||||
f.set(ImGuiColorEditFlags::AlphaPreview, s.alpha_preview);
|
||||
}
|
||||
f.set(ImGuiColorEditFlags::NoOptions, !s.options_menu);
|
||||
f
|
||||
};
|
||||
|
||||
ui.tree_node(im_str!("Color/Picker Widgets")).build(|| {
|
||||
let s = &mut state.color_edit;
|
||||
ui.checkbox(im_str!("With HDR"), &mut s.hdr);
|
||||
ui.same_line(0.0);
|
||||
show_help_marker(
|
||||
ui,
|
||||
"Currently all this does is to lift the 0..1 \
|
||||
limits on dragging widgets.",
|
||||
);
|
||||
|
||||
ui.checkbox(im_str!("With Alpha Preview"), &mut s.alpha_preview);
|
||||
ui.checkbox(
|
||||
im_str!("With Half Alpha Preview"),
|
||||
&mut s.alpha_half_preview,
|
||||
);
|
||||
ui.checkbox(im_str!("With Options Menu"), &mut s.options_menu);
|
||||
ui.same_line(0.0);
|
||||
show_help_marker(
|
||||
ui,
|
||||
"Right-click on the individual color widget to \
|
||||
show options.",
|
||||
);
|
||||
let misc_flags = {
|
||||
let mut f = ImGuiColorEditFlags::empty();
|
||||
f.set(ImGuiColorEditFlags::HDR, s.hdr);
|
||||
f.set(ImGuiColorEditFlags::AlphaPreviewHalf, s.alpha_half_preview);
|
||||
if !s.alpha_half_preview {
|
||||
f.set(ImGuiColorEditFlags::AlphaPreview, s.alpha_preview);
|
||||
}
|
||||
f.set(ImGuiColorEditFlags::NoOptions, !s.options_menu);
|
||||
f
|
||||
};
|
||||
|
||||
ui.text(im_str!("Color widget:"));
|
||||
ui.same_line(0.0);
|
||||
show_help_marker(
|
||||
ui,
|
||||
"Click on the colored square to open a color picker.
|
||||
ui.text(im_str!("Color widget:"));
|
||||
ui.same_line(0.0);
|
||||
show_help_marker(
|
||||
ui,
|
||||
"Click on the colored square to open a color picker.
|
||||
CTRL+click on individual component to input value.\n",
|
||||
);
|
||||
ui.color_edit(im_str!("MyColor##1"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.alpha(false)
|
||||
.build();
|
||||
);
|
||||
ui.color_edit(im_str!("MyColor##1"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.alpha(false)
|
||||
.build();
|
||||
|
||||
ui.text(im_str!("Color widget HSV with Alpha:"));
|
||||
ui.color_edit(im_str!("MyColor##2"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.mode(ColorEditMode::HSV)
|
||||
.build();
|
||||
ui.text(im_str!("Color widget HSV with Alpha:"));
|
||||
ui.color_edit(im_str!("MyColor##2"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.mode(ColorEditMode::HSV)
|
||||
.build();
|
||||
|
||||
ui.text(im_str!("Color widget with Float Display:"));
|
||||
ui.color_edit(im_str!("MyColor##2f"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.format(ColorFormat::Float)
|
||||
.build();
|
||||
ui.text(im_str!("Color widget with Float Display:"));
|
||||
ui.color_edit(im_str!("MyColor##2f"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.format(ColorFormat::Float)
|
||||
.build();
|
||||
|
||||
ui.text(im_str!("Color button with Picker:"));
|
||||
ui.text(im_str!("Color button with Picker:"));
|
||||
ui.same_line(0.0);
|
||||
show_help_marker(
|
||||
ui,
|
||||
"With the inputs(false) function you can hide all \
|
||||
the slider/text inputs.\n \
|
||||
With the label(false) function you can pass a non-empty label which \
|
||||
will only be used for the tooltip and picker popup.",
|
||||
);
|
||||
ui.color_edit(im_str!("MyColor##3"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.inputs(false)
|
||||
.label(false)
|
||||
.build();
|
||||
|
||||
ui.text(im_str!("Color picker:"));
|
||||
ui.checkbox(im_str!("With Alpha"), &mut s.alpha);
|
||||
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);
|
||||
show_help_marker(
|
||||
ui,
|
||||
"With the inputs(false) function you can hide all \
|
||||
the slider/text inputs.\n \
|
||||
With the label(false) function you can pass a non-empty label which \
|
||||
will only be used for the tooltip and picker popup.",
|
||||
);
|
||||
ui.color_edit(im_str!("MyColor##3"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.inputs(false)
|
||||
.label(false)
|
||||
.build();
|
||||
|
||||
ui.text(im_str!("Color picker:"));
|
||||
ui.checkbox(im_str!("With Alpha"), &mut s.alpha);
|
||||
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.checkbox(im_str!("With Ref Color"), &mut s.ref_color);
|
||||
if s.ref_color {
|
||||
ui.same_line(0.0);
|
||||
ui.color_edit(im_str!("##RefColor"), &mut s.ref_color_v)
|
||||
.flags(misc_flags)
|
||||
.inputs(false)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
let mut b = ui.color_picker(im_str!("MyColor##4"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.alpha(s.alpha)
|
||||
.alpha_bar(s.alpha_bar)
|
||||
.side_preview(s.side_preview)
|
||||
.rgb(true);
|
||||
|
||||
ui.checkbox(im_str!("With Ref Color"), &mut s.ref_color);
|
||||
if s.ref_color {
|
||||
b = b.reference_color(&s.ref_color_v)
|
||||
ui.same_line(0.0);
|
||||
ui.color_edit(im_str!("##RefColor"), &mut s.ref_color_v)
|
||||
.flags(misc_flags)
|
||||
.inputs(false)
|
||||
.build();
|
||||
}
|
||||
b.build();
|
||||
}
|
||||
let mut b = ui
|
||||
.color_picker(im_str!("MyColor##4"), &mut s.color)
|
||||
.flags(misc_flags)
|
||||
.alpha(s.alpha)
|
||||
.alpha_bar(s.alpha_bar)
|
||||
.side_preview(s.side_preview)
|
||||
.rgb(true);
|
||||
|
||||
if s.ref_color {
|
||||
b = b.reference_color(&s.ref_color_v)
|
||||
}
|
||||
b.build();
|
||||
});
|
||||
}
|
||||
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 \
|
||||
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],
|
||||
None => im_str!("<None>"),
|
||||
});
|
||||
}
|
||||
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 \
|
||||
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],
|
||||
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,
|
||||
false,
|
||||
ImGuiSelectableFlags::empty(),
|
||||
ImVec2::new(0.0, 0.0),
|
||||
)
|
||||
{
|
||||
state.selected_fish = Some(index);
|
||||
}
|
||||
ui.popup(im_str!("select"), || {
|
||||
ui.text(im_str!("Aquarium"));
|
||||
ui.separator();
|
||||
for (index, name) in names.iter().enumerate() {
|
||||
if ui.selectable(
|
||||
name,
|
||||
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) {
|
||||
@ -691,8 +702,10 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
|
||||
.build();
|
||||
ui.child_frame(im_str!("child"), (0.0, 60.0))
|
||||
.show_borders(true)
|
||||
.build(|| for i in 0..10 {
|
||||
ui.text(format!("Scrolling Text {}", i));
|
||||
.build(|| {
|
||||
for i in 0..10 {
|
||||
ui.text(format!("Scrolling Text {}", i));
|
||||
}
|
||||
});
|
||||
ui.slider_float(im_str!("Value"), &mut state.f, 0.0, 1.0)
|
||||
.build();
|
||||
@ -703,10 +716,10 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
|
||||
ui.combo(im_str!("Combo"), &mut state.n, &items, -1);
|
||||
ui.checkbox(im_str!("Check"), &mut state.b);
|
||||
});
|
||||
ui.menu(im_str!("Colors")).build(|| for &col in
|
||||
ImGuiCol::values()
|
||||
{
|
||||
ui.menu_item(imgui::get_style_color_name(col)).build();
|
||||
ui.menu(im_str!("Colors")).build(|| {
|
||||
for &col in ImGuiCol::values() {
|
||||
ui.menu_item(imgui::get_style_color_name(col)).build();
|
||||
}
|
||||
});
|
||||
ui.menu(im_str!("Disabled")).enabled(false).build(|| {
|
||||
unreachable!();
|
||||
@ -741,23 +754,22 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) {
|
||||
let window_pos = (DISTANCE, DISTANCE);
|
||||
ui.with_color_var(ImGuiCol::WindowBg, (0.0, 0.0, 0.0, 0.3), || {
|
||||
ui.window(im_str!("Example: Fixed Overlay"))
|
||||
.opened(opened)
|
||||
.position(window_pos, ImGuiCond::Always)
|
||||
.title_bar(false)
|
||||
.resizable(false)
|
||||
.always_auto_resize(true)
|
||||
.movable(false)
|
||||
.save_settings(false)
|
||||
.build(|| {
|
||||
ui.text("Simple overlay\nin the corner of the screen.\n(right-click to change position)");
|
||||
ui.separator();
|
||||
let mouse_pos = ui.imgui().mouse_pos();
|
||||
ui.text(format!(
|
||||
"Mouse Position: ({:.1},{:.1})",
|
||||
mouse_pos.0,
|
||||
mouse_pos.1
|
||||
));
|
||||
})
|
||||
.opened(opened)
|
||||
.position(window_pos, ImGuiCond::Always)
|
||||
.title_bar(false)
|
||||
.resizable(false)
|
||||
.always_auto_resize(true)
|
||||
.movable(false)
|
||||
.save_settings(false)
|
||||
.build(|| {
|
||||
ui.text("Simple overlay\nin the corner of the screen.\n(right-click to change position)");
|
||||
ui.separator();
|
||||
let mouse_pos = ui.imgui().mouse_pos();
|
||||
ui.text(format!(
|
||||
"Mouse Position: ({:.1},{:.1})",
|
||||
mouse_pos.0, mouse_pos.1
|
||||
));
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
extern crate gfx;
|
||||
extern crate imgui;
|
||||
|
||||
use gfx::{Bundle, CommandBuffer, Encoder, Factory, IntoIndexBuffer, Rect, Resources, Slice};
|
||||
use gfx::memory::Bind;
|
||||
use gfx::handle::{Buffer, RenderTargetView};
|
||||
use gfx::memory::Bind;
|
||||
use gfx::texture::{FilterMethod, SamplerInfo, WrapMode};
|
||||
use gfx::traits::FactoryExt;
|
||||
use gfx::{Bundle, CommandBuffer, Encoder, Factory, IntoIndexBuffer, Rect, Resources, Slice};
|
||||
use imgui::{DrawList, FrameSize, ImDrawIdx, ImDrawVert, ImGui, Ui};
|
||||
|
||||
pub type RendererResult<T> = Result<T, RendererError>;
|
||||
@ -20,19 +20,27 @@ pub enum RendererError {
|
||||
}
|
||||
|
||||
impl From<gfx::UpdateError<usize>> for RendererError {
|
||||
fn from(e: gfx::UpdateError<usize>) -> RendererError { RendererError::Update(e) }
|
||||
fn from(e: gfx::UpdateError<usize>) -> RendererError {
|
||||
RendererError::Update(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gfx::buffer::CreationError> for RendererError {
|
||||
fn from(e: gfx::buffer::CreationError) -> RendererError { RendererError::Buffer(e) }
|
||||
fn from(e: gfx::buffer::CreationError) -> RendererError {
|
||||
RendererError::Buffer(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gfx::PipelineStateError<String>> for RendererError {
|
||||
fn from(e: gfx::PipelineStateError<String>) -> RendererError { RendererError::Pipeline(e) }
|
||||
fn from(e: gfx::PipelineStateError<String>) -> RendererError {
|
||||
RendererError::Pipeline(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gfx::CombinedError> for RendererError {
|
||||
fn from(e: gfx::CombinedError) -> RendererError { RendererError::Combined(e) }
|
||||
fn from(e: gfx::CombinedError) -> RendererError {
|
||||
RendererError::Combined(e)
|
||||
}
|
||||
}
|
||||
|
||||
gfx_defines!{
|
||||
@ -51,9 +59,9 @@ gfx_defines!{
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Shaders {
|
||||
GlSl400, // OpenGL 4.0+
|
||||
GlSl130, // OpenGL 3.0+
|
||||
GlSl110, // OpenGL 2.0+
|
||||
GlSl400, // OpenGL 4.0+
|
||||
GlSl130, // OpenGL 3.0+
|
||||
GlSl110, // OpenGL 2.0+
|
||||
GlSlEs300, // OpenGL ES 3.0+
|
||||
GlSlEs100, // OpenGL ES 2.0+
|
||||
}
|
||||
@ -99,11 +107,7 @@ impl<R: Resources> Renderer<R> {
|
||||
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 pso = factory.create_pipeline_simple(vs_code, ps_code, pipe::new())?;
|
||||
let vertex_buffer = factory.create_buffer::<ImDrawVert>(
|
||||
256,
|
||||
gfx::buffer::Role::Vertex,
|
||||
@ -168,12 +172,18 @@ impl<R: Resources> Renderer<R> {
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
) -> RendererResult<()> {
|
||||
let FrameSize { logical_size: (width, height), hidpi_factor } = ui.frame_size();
|
||||
let FrameSize {
|
||||
logical_size: (width, height),
|
||||
hidpi_factor,
|
||||
} = ui.frame_size();
|
||||
|
||||
if !(width > 0.0 && height > 0.0) {
|
||||
return Ok(());
|
||||
}
|
||||
let fb_size = ((width * hidpi_factor) as f32, (height * hidpi_factor) as f32);
|
||||
let fb_size = (
|
||||
(width * hidpi_factor) as f32,
|
||||
(height * hidpi_factor) as f32,
|
||||
);
|
||||
|
||||
self.bundle.data.matrix = [
|
||||
[(2.0 / width) as f32, 0.0, 0.0, 0.0],
|
||||
@ -195,7 +205,7 @@ impl<R: Resources> Renderer<R> {
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
draw_list: &DrawList<'a>,
|
||||
fb_size: (f32, f32)
|
||||
fb_size: (f32, f32),
|
||||
) -> RendererResult<()> {
|
||||
let (fb_width, fb_height) = fb_size;
|
||||
|
||||
@ -210,8 +220,14 @@ impl<R: Resources> Renderer<R> {
|
||||
self.bundle.data.scissor = Rect {
|
||||
x: cmd.clip_rect.x.max(0.0).round() as u16,
|
||||
y: cmd.clip_rect.y.max(0.0).round() as u16,
|
||||
w: (cmd.clip_rect.z - cmd.clip_rect.x).abs().min(fb_width).round() as u16,
|
||||
h: (cmd.clip_rect.w - cmd.clip_rect.y).abs().min(fb_height).round() as u16,
|
||||
w: (cmd.clip_rect.z - cmd.clip_rect.x)
|
||||
.abs()
|
||||
.min(fb_width)
|
||||
.round() as u16,
|
||||
h: (cmd.clip_rect.w - cmd.clip_rect.y)
|
||||
.abs()
|
||||
.min(fb_height)
|
||||
.round() as u16,
|
||||
};
|
||||
self.bundle.encode(encoder);
|
||||
self.bundle.slice.start = self.bundle.slice.end;
|
||||
@ -232,11 +248,7 @@ impl<R: Resources> Renderer<R> {
|
||||
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,
|
||||
|
||||
@ -2,12 +2,12 @@
|
||||
extern crate glium;
|
||||
extern crate imgui;
|
||||
|
||||
use glium::{DrawError, GlObject, IndexBuffer, Program, Surface, Texture2d, VertexBuffer};
|
||||
use glium::backend::{Context, Facade};
|
||||
use glium::program;
|
||||
use glium::index::{self, PrimitiveType};
|
||||
use glium::program;
|
||||
use glium::texture;
|
||||
use glium::vertex;
|
||||
use glium::{DrawError, GlObject, IndexBuffer, Program, Surface, Texture2d, VertexBuffer};
|
||||
use imgui::{DrawList, FrameSize, ImDrawIdx, ImDrawVert, ImGui, Ui};
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
@ -38,23 +38,33 @@ impl fmt::Display for RendererError {
|
||||
}
|
||||
|
||||
impl From<vertex::BufferCreationError> for RendererError {
|
||||
fn from(e: vertex::BufferCreationError) -> RendererError { RendererError::Vertex(e) }
|
||||
fn from(e: vertex::BufferCreationError) -> RendererError {
|
||||
RendererError::Vertex(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<index::BufferCreationError> for RendererError {
|
||||
fn from(e: index::BufferCreationError) -> RendererError { RendererError::Index(e) }
|
||||
fn from(e: index::BufferCreationError) -> RendererError {
|
||||
RendererError::Index(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<program::ProgramChooserCreationError> for RendererError {
|
||||
fn from(e: program::ProgramChooserCreationError) -> RendererError { RendererError::Program(e) }
|
||||
fn from(e: program::ProgramChooserCreationError) -> RendererError {
|
||||
RendererError::Program(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<texture::TextureCreationError> for RendererError {
|
||||
fn from(e: texture::TextureCreationError) -> RendererError { RendererError::Texture(e) }
|
||||
fn from(e: texture::TextureCreationError) -> RendererError {
|
||||
RendererError::Texture(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DrawError> for RendererError {
|
||||
fn from(e: DrawError) -> RendererError { RendererError::Draw(e) }
|
||||
fn from(e: DrawError) -> RendererError {
|
||||
RendererError::Draw(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Renderer {
|
||||
@ -73,11 +83,17 @@ 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 FrameSize { logical_size: (width, height), hidpi_factor } = ui.frame_size();
|
||||
let FrameSize {
|
||||
logical_size: (width, height),
|
||||
hidpi_factor,
|
||||
} = ui.frame_size();
|
||||
if !(width > 0.0 && height > 0.0) {
|
||||
return Ok(());
|
||||
}
|
||||
let fb_size = ((width * hidpi_factor) as f32, (height * hidpi_factor) as f32);
|
||||
let fb_size = (
|
||||
(width * hidpi_factor) as f32,
|
||||
(height * hidpi_factor) as f32,
|
||||
);
|
||||
|
||||
let matrix = [
|
||||
[(2.0 / width) as f32, 0.0, 0.0, 0.0],
|
||||
@ -103,19 +119,15 @@ impl Renderer {
|
||||
fb_size: (f32, f32),
|
||||
matrix: [[f32; 4]; 4],
|
||||
) -> RendererResult<()> {
|
||||
use glium::uniforms::{MagnifySamplerFilter, MinifySamplerFilter};
|
||||
use glium::{Blend, DrawParameters, Rect};
|
||||
use glium::uniforms::{MinifySamplerFilter, MagnifySamplerFilter};
|
||||
|
||||
let (fb_width, fb_height) = fb_size;
|
||||
|
||||
self.device_objects.upload_vertex_buffer(
|
||||
&self.ctx,
|
||||
draw_list.vtx_buffer,
|
||||
)?;
|
||||
self.device_objects.upload_index_buffer(
|
||||
&self.ctx,
|
||||
draw_list.idx_buffer,
|
||||
)?;
|
||||
self.device_objects
|
||||
.upload_vertex_buffer(&self.ctx, draw_list.vtx_buffer)?;
|
||||
self.device_objects
|
||||
.upload_index_buffer(&self.ctx, draw_list.idx_buffer)?;
|
||||
|
||||
let font_texture_id = self.device_objects.texture.get_id() as usize;
|
||||
|
||||
@ -128,24 +140,31 @@ impl Renderer {
|
||||
|
||||
surface.draw(
|
||||
&self.device_objects.vertex_buffer,
|
||||
&self.device_objects
|
||||
&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::Linear)
|
||||
.minify_filter(MinifySamplerFilter::Linear),
|
||||
},
|
||||
matrix: matrix,
|
||||
tex: self.device_objects.texture.sampled()
|
||||
.magnify_filter(MagnifySamplerFilter::Linear)
|
||||
.minify_filter(MinifySamplerFilter::Linear),
|
||||
},
|
||||
&DrawParameters {
|
||||
blend: Blend::alpha_blending(),
|
||||
scissor: Some(Rect {
|
||||
left: cmd.clip_rect.x.max(0.0).round() as u32,
|
||||
bottom: (fb_height - cmd.clip_rect.w).max(0.0).round() as u32,
|
||||
width: (cmd.clip_rect.z - cmd.clip_rect.x).abs().max(fb_width).round() as u32,
|
||||
height: (cmd.clip_rect.w - cmd.clip_rect.y).abs().max(fb_height).round() as u32,
|
||||
width: (cmd.clip_rect.z - cmd.clip_rect.x)
|
||||
.abs()
|
||||
.max(fb_width)
|
||||
.round() as u32,
|
||||
height: (cmd.clip_rect.w - cmd.clip_rect.y)
|
||||
.abs()
|
||||
.max(fb_height)
|
||||
.round() as u32,
|
||||
}),
|
||||
..DrawParameters::default()
|
||||
},
|
||||
@ -203,11 +222,7 @@ impl DeviceObjects {
|
||||
use glium::texture::{ClientFormat, RawImage2d};
|
||||
|
||||
let vertex_buffer = VertexBuffer::empty_dynamic(ctx, 0)?;
|
||||
let index_buffer = IndexBuffer::empty_dynamic(
|
||||
ctx,
|
||||
PrimitiveType::TrianglesList,
|
||||
0,
|
||||
)?;
|
||||
let index_buffer = IndexBuffer::empty_dynamic(ctx, PrimitiveType::TrianglesList, 0)?;
|
||||
|
||||
let program = compile_default_program(ctx)?;
|
||||
let texture = im_gui.prepare_texture(|handle| {
|
||||
@ -255,11 +270,7 @@ impl DeviceObjects {
|
||||
slice.write(idx_buffer);
|
||||
return Ok(());
|
||||
}
|
||||
self.index_buffer = IndexBuffer::dynamic(
|
||||
ctx,
|
||||
PrimitiveType::TrianglesList,
|
||||
idx_buffer,
|
||||
)?;
|
||||
self.index_buffer = 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()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use gfx::format::{Format, Formatted, U8Norm};
|
||||
use gfx::pso::buffer::{Element, ElemOffset, Structure};
|
||||
use gfx::pso::buffer::{ElemOffset, Element, Structure};
|
||||
use gfx::traits::Pod;
|
||||
use std::mem;
|
||||
|
||||
@ -30,27 +30,20 @@ impl Structure<Format> for ImDrawVert {
|
||||
};
|
||||
let dummy: &ImDrawVert = unsafe { mem::transmute(0usize) };
|
||||
match sub_name {
|
||||
"pos" => {
|
||||
Some(Element {
|
||||
format: <ImVec2 as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.pos) } as ElemOffset +
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
"uv" => {
|
||||
Some(Element {
|
||||
format: <ImVec2 as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.uv) } as ElemOffset +
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
"col" => {
|
||||
Some(Element {
|
||||
format: <[U8Norm; 4] as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.col) } as ElemOffset +
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
"pos" => Some(Element {
|
||||
format: <ImVec2 as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.pos) } as ElemOffset
|
||||
+ big_offset,
|
||||
}),
|
||||
"uv" => Some(Element {
|
||||
format: <ImVec2 as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.uv) } as ElemOffset + big_offset,
|
||||
}),
|
||||
"col" => Some(Element {
|
||||
format: <[U8Norm; 4] as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.col) } as ElemOffset
|
||||
+ big_offset,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,9 @@ use super::{ImDrawVert, ImVec2, ImVec4};
|
||||
|
||||
#[cfg(feature = "glium")]
|
||||
unsafe impl Attribute for ImVec2 {
|
||||
fn get_type() -> AttributeType { <(c_float, c_float) as Attribute>::get_type() }
|
||||
fn get_type() -> AttributeType {
|
||||
<(c_float, c_float) as Attribute>::get_type()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "glium")]
|
||||
@ -27,19 +29,19 @@ impl Vertex for ImDrawVert {
|
||||
"pos".into(),
|
||||
mem::transmute(&dummy.pos),
|
||||
<ImVec2 as Attribute>::get_type(),
|
||||
false
|
||||
false,
|
||||
),
|
||||
(
|
||||
"uv".into(),
|
||||
mem::transmute(&dummy.uv),
|
||||
<ImVec2 as Attribute>::get_type(),
|
||||
false
|
||||
false,
|
||||
),
|
||||
(
|
||||
"col".into(),
|
||||
mem::transmute(&dummy.col),
|
||||
AttributeType::U8U8U8U8,
|
||||
false
|
||||
false,
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ mod gfx_support;
|
||||
mod glium_support;
|
||||
|
||||
/// ImGui context (opaque)
|
||||
pub enum ImGuiContext { }
|
||||
pub enum ImGuiContext {}
|
||||
|
||||
/// 32-bit unsigned integer (typically used to store packed colors)
|
||||
pub type ImU32 = c_uint;
|
||||
@ -87,7 +87,9 @@ pub enum ImGuiCol {
|
||||
DragDropTarget,
|
||||
}
|
||||
impl ImGuiCol {
|
||||
#[deprecated(since = "0.0.19", note = "ComboBg has been merged with PopupBg. Please use PopupBg instead")]
|
||||
#[deprecated(
|
||||
since = "0.0.19", note = "ComboBg has been merged with PopupBg. Please use PopupBg instead"
|
||||
)]
|
||||
pub const ComboBg: ImGuiCol = ImGuiCol::PopupBg;
|
||||
#[deprecated(since = "0.0.19", note = "please use ChildBg instead")]
|
||||
pub const ChildWindowBg: ImGuiCol = ImGuiCol::ChildBg;
|
||||
@ -450,9 +452,8 @@ bitflags!(
|
||||
}
|
||||
);
|
||||
|
||||
pub type ImGuiTextEditCallback = Option<
|
||||
extern "C" fn(data: *mut ImGuiTextEditCallbackData) -> c_int,
|
||||
>;
|
||||
pub type ImGuiTextEditCallback =
|
||||
Option<extern "C" fn(data: *mut ImGuiTextEditCallbackData) -> c_int>;
|
||||
|
||||
pub type ImGuiSizeConstraintCallback =
|
||||
Option<extern "C" fn(data: *mut ImGuiSizeConstraintCallbackData)>;
|
||||
@ -481,19 +482,27 @@ impl ImVec2 {
|
||||
}
|
||||
|
||||
impl From<[f32; 2]> for ImVec2 {
|
||||
fn from(array: [f32; 2]) -> ImVec2 { ImVec2::new(array[0], array[1]) }
|
||||
fn from(array: [f32; 2]) -> ImVec2 {
|
||||
ImVec2::new(array[0], array[1])
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(f32, f32)> for ImVec2 {
|
||||
fn from((x, y): (f32, f32)) -> ImVec2 { ImVec2::new(x, y) }
|
||||
fn from((x, y): (f32, f32)) -> ImVec2 {
|
||||
ImVec2::new(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[f32; 2]> for ImVec2 {
|
||||
fn into(self) -> [f32; 2] { [self.x, self.y] }
|
||||
fn into(self) -> [f32; 2] {
|
||||
[self.x, self.y]
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<(f32, f32)> for ImVec2 {
|
||||
fn into(self) -> (f32, f32) { (self.x, self.y) }
|
||||
fn into(self) -> (f32, f32) {
|
||||
(self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
||||
/// A tuple of 4 floating-point values
|
||||
@ -526,19 +535,27 @@ impl ImVec4 {
|
||||
}
|
||||
|
||||
impl From<[f32; 4]> for ImVec4 {
|
||||
fn from(array: [f32; 4]) -> ImVec4 { ImVec4::new(array[0], array[1], array[2], array[3]) }
|
||||
fn from(array: [f32; 4]) -> ImVec4 {
|
||||
ImVec4::new(array[0], array[1], array[2], array[3])
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(f32, f32, f32, f32)> for ImVec4 {
|
||||
fn from((x, y, z, w): (f32, f32, f32, f32)) -> ImVec4 { ImVec4::new(x, y, z, w) }
|
||||
fn from((x, y, z, w): (f32, f32, f32, f32)) -> ImVec4 {
|
||||
ImVec4::new(x, y, z, w)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[f32; 4]> for ImVec4 {
|
||||
fn into(self) -> [f32; 4] { [self.x, self.y, self.z, self.w] }
|
||||
fn into(self) -> [f32; 4] {
|
||||
[self.x, self.y, self.z, self.w]
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<(f32, f32, f32, f32)> for ImVec4 {
|
||||
fn into(self) -> (f32, f32, f32, f32) { (self.x, self.y, self.z, self.w) }
|
||||
fn into(self) -> (f32, f32, f32, f32) {
|
||||
(self.x, self.y, self.z, self.w)
|
||||
}
|
||||
}
|
||||
|
||||
/// Runtime data for styling/colors
|
||||
@ -698,7 +715,9 @@ pub struct ImVector<T> {
|
||||
}
|
||||
|
||||
impl<T> ImVector<T> {
|
||||
pub unsafe fn as_slice(&self) -> &[T] { slice::from_raw_parts(self.data, self.size as usize) }
|
||||
pub unsafe fn as_slice(&self) -> &[T] {
|
||||
slice::from_raw_parts(self.data, self.size as usize)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -804,10 +823,8 @@ pub struct ImGuiListClipper {
|
||||
pub display_end: c_int,
|
||||
}
|
||||
|
||||
pub type ImDrawCallback = Option<
|
||||
extern "C" fn(parent_list: *const ImDrawList,
|
||||
cmd: *const ImDrawCmd),
|
||||
>;
|
||||
pub type ImDrawCallback =
|
||||
Option<extern "C" fn(parent_list: *const ImDrawList, cmd: *const ImDrawCmd)>;
|
||||
|
||||
/// A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call)
|
||||
#[repr(C)]
|
||||
@ -1002,7 +1019,7 @@ extern "C" {
|
||||
#[allow(non_snake_case)]
|
||||
#[deprecated(since = "0.0.19", note = "please use igShowDemoWindow instead")]
|
||||
pub unsafe fn igShowTestWindow(opened: *mut bool) {
|
||||
igShowDemoWindow(opened)
|
||||
igShowDemoWindow(opened)
|
||||
}
|
||||
|
||||
// Window
|
||||
@ -1279,7 +1296,8 @@ extern "C" {
|
||||
pub fn igCombo3(
|
||||
label: *const c_char,
|
||||
current_item: *mut c_int,
|
||||
items_getter: extern "C" fn(data: *mut c_void, idx: c_int, out_text: *mut *const c_char) -> bool,
|
||||
items_getter: extern "C" fn(data: *mut c_void, idx: c_int, out_text: *mut *const c_char)
|
||||
-> bool,
|
||||
data: *mut c_void,
|
||||
items_count: c_int,
|
||||
height_in_items: c_int,
|
||||
@ -1630,7 +1648,7 @@ extern "C" {
|
||||
label: *const c_char,
|
||||
current_item: *mut c_int,
|
||||
items_getter: extern "C" fn(data: *mut c_void, idx: c_int, out_text: *mut *const c_char)
|
||||
-> bool,
|
||||
-> bool,
|
||||
data: *mut c_void,
|
||||
items_count: c_int,
|
||||
height_in_items: c_int,
|
||||
@ -1725,10 +1743,18 @@ extern "C" {
|
||||
/// 3. pcall [`igEndDragDropSource`]
|
||||
pub fn igBeginDragDropSource(flags: ImGuiDragDropFlags, mouse_button: c_int) -> bool;
|
||||
/// Use 'cond' to choose to submit payload on drag start or every frame
|
||||
pub fn igSetDragDropPayload(type_: *const c_char, data: *const c_void, size: libc::size_t, cond: ImGuiCond) -> bool;
|
||||
pub fn igSetDragDropPayload(
|
||||
type_: *const c_char,
|
||||
data: *const c_void,
|
||||
size: libc::size_t,
|
||||
cond: ImGuiCond,
|
||||
) -> bool;
|
||||
pub fn igEndDragDropSource();
|
||||
pub fn igBeginDragDropTarget() -> bool;
|
||||
pub fn igAcceptDragDropPayload(type_: *const c_char, flags: ImGuiDragDropFlags) -> *const ImGuiPayload;
|
||||
pub fn igAcceptDragDropPayload(
|
||||
type_: *const c_char,
|
||||
flags: ImGuiDragDropFlags,
|
||||
) -> *const ImGuiPayload;
|
||||
pub fn igEndDragDropTarget();
|
||||
}
|
||||
|
||||
@ -1819,17 +1845,25 @@ extern "C" {
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[deprecated(since = "0.0.19", note = "please use igIsWindowFocused(ImGuiFocusedFlags::RootWindow) instead")]
|
||||
#[deprecated(
|
||||
since = "0.0.19", note = "please use igIsWindowFocused(ImGuiFocusedFlags::RootWindow) instead"
|
||||
)]
|
||||
pub unsafe fn igIsRootWindowFocused() -> bool {
|
||||
igIsWindowFocused(ImGuiFocusedFlags::RootWindow)
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
#[deprecated(since = "0.0.19", note = "please use igIsWindowFocused(ImGuiFocusedFlags::RootAndChildWindows) instead")]
|
||||
#[deprecated(
|
||||
since = "0.0.19",
|
||||
note = "please use igIsWindowFocused(ImGuiFocusedFlags::RootAndChildWindows) instead"
|
||||
)]
|
||||
pub unsafe fn igIsRootWindowOrAnyChildFocused() -> bool {
|
||||
igIsWindowFocused(ImGuiFocusedFlags::RootAndChildWindows)
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
#[deprecated(since = "0.0.19", note = "please use igIsWindowFocused(ImGuiFocusedFlags::RootAndChildWindows) instead")]
|
||||
#[deprecated(
|
||||
since = "0.0.19",
|
||||
note = "please use igIsWindowFocused(ImGuiFocusedFlags::RootAndChildWindows) instead"
|
||||
)]
|
||||
pub unsafe fn igIsRootWindowOrAnyChildHovered(_flags: ImGuiHoveredFlags) -> bool {
|
||||
igIsWindowHovered(ImGuiHoveredFlags::RootAndChildWindows)
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use sys;
|
||||
|
||||
use super::{ImStr, ImVec2, ImGuiWindowFlags, Ui};
|
||||
use super::{ImGuiWindowFlags, ImStr, ImVec2, Ui};
|
||||
|
||||
#[must_use]
|
||||
pub struct ChildFrame<'ui, 'p> {
|
||||
@ -74,34 +74,26 @@ impl<'ui, 'p> ChildFrame<'ui, 'p> {
|
||||
}
|
||||
#[inline]
|
||||
pub fn 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_show_vertical_scroll_bar(mut self, value: bool) -> Self {
|
||||
self.flags.set(
|
||||
ImGuiWindowFlags::AlwaysVerticalScrollbar,
|
||||
value,
|
||||
);
|
||||
self.flags
|
||||
.set(ImGuiWindowFlags::AlwaysVerticalScrollbar, value);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn always_show_horizontal_scroll_bar(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) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#![warn(missing_docs)]
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
use sys;
|
||||
|
||||
use {ImGuiColorEditFlags, ImStr, ImVec2, ImVec4, Ui};
|
||||
|
||||
@ -25,11 +25,15 @@ impl<'p> EditableColor<'p> {
|
||||
}
|
||||
|
||||
impl<'p> From<&'p mut [f32; 3]> for EditableColor<'p> {
|
||||
fn from(value: &'p mut [f32; 3]) -> EditableColor<'p> { EditableColor::Float3(value) }
|
||||
fn from(value: &'p mut [f32; 3]) -> EditableColor<'p> {
|
||||
EditableColor::Float3(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'p> From<&'p mut [f32; 4]> for EditableColor<'p> {
|
||||
fn from(value: &'p mut [f32; 4]) -> EditableColor<'p> { EditableColor::Float4(value) }
|
||||
fn from(value: &'p mut [f32; 4]) -> EditableColor<'p> {
|
||||
EditableColor::Float4(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Color editor mode.
|
||||
@ -171,31 +175,21 @@ impl<'ui, 'p> ColorEdit<'ui, 'p> {
|
||||
/// Sets the color editor mode.
|
||||
#[inline]
|
||||
pub fn mode(mut self, mode: ColorEditMode) -> Self {
|
||||
self.flags.set(
|
||||
ImGuiColorEditFlags::RGB,
|
||||
mode == ColorEditMode::RGB,
|
||||
);
|
||||
self.flags.set(
|
||||
ImGuiColorEditFlags::HSV,
|
||||
mode == ColorEditMode::HSV,
|
||||
);
|
||||
self.flags.set(
|
||||
ImGuiColorEditFlags::HEX,
|
||||
mode == ColorEditMode::HEX,
|
||||
);
|
||||
self.flags
|
||||
.set(ImGuiColorEditFlags::RGB, mode == ColorEditMode::RGB);
|
||||
self.flags
|
||||
.set(ImGuiColorEditFlags::HSV, mode == ColorEditMode::HSV);
|
||||
self.flags
|
||||
.set(ImGuiColorEditFlags::HEX, mode == ColorEditMode::HEX);
|
||||
self
|
||||
}
|
||||
/// Sets the formatting style of color components.
|
||||
#[inline]
|
||||
pub fn format(mut self, format: ColorFormat) -> Self {
|
||||
self.flags.set(
|
||||
ImGuiColorEditFlags::Uint8,
|
||||
format == ColorFormat::U8,
|
||||
);
|
||||
self.flags.set(
|
||||
ImGuiColorEditFlags::Float,
|
||||
format == ColorFormat::Float,
|
||||
);
|
||||
self.flags
|
||||
.set(ImGuiColorEditFlags::Uint8, format == ColorFormat::U8);
|
||||
self.flags
|
||||
.set(ImGuiColorEditFlags::Float, format == ColorFormat::Float);
|
||||
self
|
||||
}
|
||||
/// Builds the color editor.
|
||||
@ -328,14 +322,10 @@ impl<'ui, 'p> ColorPicker<'ui, 'p> {
|
||||
/// Sets the formatting style of color components.
|
||||
#[inline]
|
||||
pub fn format(mut self, format: ColorFormat) -> Self {
|
||||
self.flags.set(
|
||||
ImGuiColorEditFlags::Uint8,
|
||||
format == ColorFormat::U8,
|
||||
);
|
||||
self.flags.set(
|
||||
ImGuiColorEditFlags::Float,
|
||||
format == ColorFormat::Float,
|
||||
);
|
||||
self.flags
|
||||
.set(ImGuiColorEditFlags::Uint8, format == ColorFormat::U8);
|
||||
self.flags
|
||||
.set(ImGuiColorEditFlags::Float, format == ColorFormat::Float);
|
||||
self
|
||||
}
|
||||
/// Sets the shown reference color.
|
||||
|
||||
32
src/drag.rs
32
src/drag.rs
@ -1,10 +1,9 @@
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
use sys;
|
||||
|
||||
use super::{ImStr, Ui};
|
||||
|
||||
|
||||
macro_rules! impl_display_format {
|
||||
($InputType:ident) => {
|
||||
#[inline]
|
||||
@ -51,7 +50,6 @@ macro_rules! impl_min_max {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[must_use]
|
||||
pub struct DragFloat<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
@ -64,7 +62,6 @@ pub struct DragFloat<'ui, 'p> {
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
|
||||
|
||||
impl<'ui, 'p> DragFloat<'ui, 'p> {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32) -> Self {
|
||||
DragFloat {
|
||||
@ -99,23 +96,22 @@ impl<'ui, 'p> DragFloat<'ui, 'p> {
|
||||
impl_power!(DragFloat);
|
||||
}
|
||||
|
||||
|
||||
macro_rules! impl_drag_floatn {
|
||||
($DragFloatN:ident, $N:expr, $igDragFloatN:ident) => {
|
||||
#[must_use]
|
||||
pub struct $DragFloatN<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32;$N],
|
||||
value: &'p mut [f32; $N],
|
||||
speed: f32,
|
||||
min: f32,
|
||||
max: f32,
|
||||
display_format: &'p ImStr,
|
||||
power: f32,
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
|
||||
impl<'ui, 'p> $DragFloatN<'ui, 'p> {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32;$N]) -> Self {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N]) -> Self {
|
||||
$DragFloatN {
|
||||
label: label,
|
||||
value: value,
|
||||
@ -124,7 +120,7 @@ macro_rules! impl_drag_floatn {
|
||||
max: 0.0,
|
||||
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.3f\0") },
|
||||
power: 1.0,
|
||||
_phantom: PhantomData
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,7 +143,7 @@ macro_rules! impl_drag_floatn {
|
||||
impl_speed!(DragFloat);
|
||||
impl_power!(DragFloat);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_drag_floatn!(DragFloat2, 2, igDragFloat2);
|
||||
@ -168,7 +164,6 @@ pub struct DragFloatRange2<'ui, 'p> {
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
|
||||
|
||||
impl<'ui, 'p> DragFloatRange2<'ui, 'p> {
|
||||
pub fn new(
|
||||
_: &Ui<'ui>,
|
||||
@ -218,7 +213,6 @@ impl<'ui, 'p> DragFloatRange2<'ui, 'p> {
|
||||
impl_power!(DragFloatRange2);
|
||||
}
|
||||
|
||||
|
||||
#[must_use]
|
||||
pub struct DragInt<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
@ -230,7 +224,6 @@ pub struct DragInt<'ui, 'p> {
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
|
||||
|
||||
impl<'ui, 'p> DragInt<'ui, 'p> {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32) -> Self {
|
||||
DragInt {
|
||||
@ -262,22 +255,21 @@ impl<'ui, 'p> DragInt<'ui, 'p> {
|
||||
impl_speed!(DragInt);
|
||||
}
|
||||
|
||||
|
||||
macro_rules! impl_drag_intn {
|
||||
($DragIntN:ident, $N:expr, $igDragIntN:ident) => {
|
||||
#[must_use]
|
||||
pub struct $DragIntN<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32;$N],
|
||||
value: &'p mut [i32; $N],
|
||||
speed: f32,
|
||||
min: i32,
|
||||
max: i32,
|
||||
display_format: &'p ImStr,
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
|
||||
impl<'ui, 'p> $DragIntN<'ui, 'p> {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32;$N]) -> Self {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N]) -> Self {
|
||||
$DragIntN {
|
||||
label: label,
|
||||
value: value,
|
||||
@ -285,7 +277,7 @@ macro_rules! impl_drag_intn {
|
||||
min: 0,
|
||||
max: 0,
|
||||
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.0f\0") },
|
||||
_phantom: PhantomData
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@ -306,15 +298,13 @@ macro_rules! impl_drag_intn {
|
||||
impl_min_max!(DragInt, i32);
|
||||
impl_speed!(DragInt);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_drag_intn!(DragInt2, 2, igDragInt2);
|
||||
impl_drag_intn!(DragInt3, 3, igDragInt3);
|
||||
impl_drag_intn!(DragInt4, 4, igDragInt4);
|
||||
|
||||
|
||||
|
||||
#[must_use]
|
||||
pub struct DragIntRange2<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
|
||||
140
src/fonts.rs
140
src/fonts.rs
@ -6,7 +6,13 @@ use sys;
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
|
||||
enum FontGlyphRangeData {
|
||||
Chinese, Cyrillic, Default, Japanese, Korean, Thai, Custom(*const sys::ImWchar),
|
||||
Chinese,
|
||||
Cyrillic,
|
||||
Default,
|
||||
Japanese,
|
||||
Korean,
|
||||
Thai,
|
||||
Custom(*const sys::ImWchar),
|
||||
}
|
||||
|
||||
/// A set of 16-bit Unicode codepoints
|
||||
@ -51,27 +57,49 @@ impl FontGlyphRange {
|
||||
///
|
||||
/// This function will panic if the given slice is not a valid font range.
|
||||
pub fn from_slice(slice: &'static [sys::ImWchar]) -> FontGlyphRange {
|
||||
assert_eq!(slice.len() % 2, 1, "The length of a glyph range must be odd.");
|
||||
assert_eq!(slice.last(), Some(&0), "A glyph range must be zero-terminated.");
|
||||
assert_eq!(
|
||||
slice.len() % 2,
|
||||
1,
|
||||
"The length of a glyph range must be odd."
|
||||
);
|
||||
assert_eq!(
|
||||
slice.last(),
|
||||
Some(&0),
|
||||
"A glyph range must be zero-terminated."
|
||||
);
|
||||
|
||||
for i in 0..slice.len()-1 {
|
||||
assert_ne!(slice[i], 0, "A glyph in a range cannot be zero. \
|
||||
(Glyph is zero at index {})", i)
|
||||
for i in 0..slice.len() - 1 {
|
||||
assert_ne!(
|
||||
slice[i], 0,
|
||||
"A glyph in a range cannot be zero. \
|
||||
(Glyph is zero at index {})",
|
||||
i
|
||||
)
|
||||
}
|
||||
|
||||
let mut ranges = Vec::new();
|
||||
for i in 0..slice.len()/2 {
|
||||
for i in 0..slice.len() / 2 {
|
||||
let (start, end) = (slice[i * 2], slice[i * 2 + 1]);
|
||||
assert!(start <= end, "The start of a range cannot be larger than its end. \
|
||||
(At index {}, {} > {})", i * 2, start, end);
|
||||
assert!(
|
||||
start <= end,
|
||||
"The start of a range cannot be larger than its end. \
|
||||
(At index {}, {} > {})",
|
||||
i * 2,
|
||||
start,
|
||||
end
|
||||
);
|
||||
ranges.push((start, end));
|
||||
}
|
||||
ranges.sort_unstable_by_key(|x| x.0);
|
||||
for i in 0..ranges.len()-1 {
|
||||
for i in 0..ranges.len() - 1 {
|
||||
let (range_a, range_b) = (ranges[i], ranges[i + 1]);
|
||||
if range_a.1 >= range_b.0 {
|
||||
panic!("The glyph ranges {:?} and {:?} overlap between {:?}.",
|
||||
range_a, range_b, (range_a.1, range_b.0));
|
||||
panic!(
|
||||
"The glyph ranges {:?} and {:?} overlap between {:?}.",
|
||||
range_a,
|
||||
range_b,
|
||||
(range_a.1, range_b.0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,12 +122,12 @@ impl FontGlyphRange {
|
||||
|
||||
unsafe fn to_ptr(&self, atlas: *mut sys::ImFontAtlas) -> *const sys::ImWchar {
|
||||
match &self.0 {
|
||||
&FontGlyphRangeData::Chinese => sys::ImFontAtlas_GetGlyphRangesChinese(atlas),
|
||||
&FontGlyphRangeData::Chinese => sys::ImFontAtlas_GetGlyphRangesChinese(atlas),
|
||||
&FontGlyphRangeData::Cyrillic => sys::ImFontAtlas_GetGlyphRangesCyrillic(atlas),
|
||||
&FontGlyphRangeData::Default => sys::ImFontAtlas_GetGlyphRangesDefault(atlas),
|
||||
&FontGlyphRangeData::Default => sys::ImFontAtlas_GetGlyphRangesDefault(atlas),
|
||||
&FontGlyphRangeData::Japanese => sys::ImFontAtlas_GetGlyphRangesJapanese(atlas),
|
||||
&FontGlyphRangeData::Korean => sys::ImFontAtlas_GetGlyphRangesKorean(atlas),
|
||||
&FontGlyphRangeData::Thai => sys::ImFontAtlas_GetGlyphRangesThai(atlas),
|
||||
&FontGlyphRangeData::Korean => sys::ImFontAtlas_GetGlyphRangesKorean(atlas),
|
||||
&FontGlyphRangeData::Thai => sys::ImFontAtlas_GetGlyphRangesThai(atlas),
|
||||
|
||||
&FontGlyphRangeData::Custom(ptr) => ptr,
|
||||
}
|
||||
@ -109,16 +137,26 @@ impl FontGlyphRange {
|
||||
/// A builder for the configuration for a font.
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub struct ImFontConfig {
|
||||
size_pixels: f32, oversample_h: u32, oversample_v: u32, pixel_snap_h: bool,
|
||||
glyph_extra_spacing: sys::ImVec2, glyph_offset: sys::ImVec2, merge_mode: bool,
|
||||
size_pixels: f32,
|
||||
oversample_h: u32,
|
||||
oversample_v: u32,
|
||||
pixel_snap_h: bool,
|
||||
glyph_extra_spacing: sys::ImVec2,
|
||||
glyph_offset: sys::ImVec2,
|
||||
merge_mode: bool,
|
||||
rasterizer_multiply: f32,
|
||||
}
|
||||
impl ImFontConfig {
|
||||
pub fn new() -> ImFontConfig {
|
||||
ImFontConfig {
|
||||
size_pixels: 0.0, oversample_h: 3, oversample_v: 1, pixel_snap_h: false,
|
||||
glyph_extra_spacing: sys::ImVec2::zero(), glyph_offset: sys::ImVec2::zero(),
|
||||
merge_mode: false, rasterizer_multiply: 1.0,
|
||||
size_pixels: 0.0,
|
||||
oversample_h: 3,
|
||||
oversample_v: 1,
|
||||
pixel_snap_h: false,
|
||||
glyph_extra_spacing: sys::ImVec2::zero(),
|
||||
glyph_offset: sys::ImVec2::zero(),
|
||||
merge_mode: false,
|
||||
rasterizer_multiply: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,8 +217,12 @@ impl ImFontConfig {
|
||||
/// ======
|
||||
///
|
||||
/// If no font size is set for the configuration.
|
||||
pub fn add_font<'a>(self, atlas: &'a mut ImFontAtlas<'a>, data: &[u8],
|
||||
range: &FontGlyphRange) -> ImFont<'a> {
|
||||
pub fn add_font<'a>(
|
||||
self,
|
||||
atlas: &'a mut ImFontAtlas<'a>,
|
||||
data: &[u8],
|
||||
range: &FontGlyphRange,
|
||||
) -> ImFont<'a> {
|
||||
atlas.add_font_with_config(data, self, range)
|
||||
}
|
||||
|
||||
@ -197,15 +239,22 @@ impl Default for ImFontConfig {
|
||||
|
||||
/// A handle to an imgui font.
|
||||
pub struct ImFont<'a> {
|
||||
font: *mut sys::ImFont, _phantom: PhantomData<&'a mut sys::ImFont>,
|
||||
font: *mut sys::ImFont,
|
||||
_phantom: PhantomData<&'a mut sys::ImFont>,
|
||||
}
|
||||
impl <'a> ImFont<'a> {
|
||||
impl<'a> ImFont<'a> {
|
||||
unsafe fn from_ptr(font: *mut sys::ImFont) -> ImFont<'a> {
|
||||
ImFont { font, _phantom: PhantomData }
|
||||
ImFont {
|
||||
font,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
fn chain(&mut self) -> ImFont {
|
||||
ImFont { font: self.font, _phantom: PhantomData }
|
||||
ImFont {
|
||||
font: self.font,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn font_size(&self) -> f32 {
|
||||
@ -234,11 +283,15 @@ impl <'a> ImFont<'a> {
|
||||
/// A handle to imgui's font manager.
|
||||
#[repr(C)]
|
||||
pub struct ImFontAtlas<'a> {
|
||||
atlas: *mut sys::ImFontAtlas, _phantom: PhantomData<&'a mut sys::ImFontAtlas>,
|
||||
atlas: *mut sys::ImFontAtlas,
|
||||
_phantom: PhantomData<&'a mut sys::ImFontAtlas>,
|
||||
}
|
||||
impl <'a> ImFontAtlas<'a> {
|
||||
impl<'a> ImFontAtlas<'a> {
|
||||
pub(crate) unsafe fn from_ptr(atlas: *mut sys::ImFontAtlas) -> ImFontAtlas<'a> {
|
||||
ImFontAtlas { atlas, _phantom: PhantomData }
|
||||
ImFontAtlas {
|
||||
atlas,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds the default font to the font set.
|
||||
@ -252,9 +305,16 @@ impl <'a> ImFontAtlas<'a> {
|
||||
unsafe { ImFont::from_ptr(sys::ImFontAtlas_AddFontDefault(self.atlas, &config)) }
|
||||
}
|
||||
|
||||
fn raw_add_font(&mut self, data: &[u8], config: ImFontConfig,
|
||||
range: &FontGlyphRange) -> ImFont {
|
||||
assert!((data.len() as u64) < (c_int::max_value() as u64), "Font data is too long.");
|
||||
fn raw_add_font(
|
||||
&mut self,
|
||||
data: &[u8],
|
||||
config: ImFontConfig,
|
||||
range: &FontGlyphRange,
|
||||
) -> ImFont {
|
||||
assert!(
|
||||
(data.len() as u64) < (c_int::max_value() as u64),
|
||||
"Font data is too long."
|
||||
);
|
||||
unsafe {
|
||||
let mut config = config.make_config();
|
||||
assert!(config.size_pixels > 0.0, "Font size cannot be zero.");
|
||||
@ -279,8 +339,12 @@ impl <'a> ImFontAtlas<'a> {
|
||||
/// ======
|
||||
///
|
||||
/// If no font size is set for the configuration.
|
||||
pub fn add_font_with_config(&mut self, data: &[u8], config: ImFontConfig,
|
||||
range: &FontGlyphRange) -> ImFont {
|
||||
pub fn add_font_with_config(
|
||||
&mut self,
|
||||
data: &[u8],
|
||||
config: ImFontConfig,
|
||||
range: &FontGlyphRange,
|
||||
) -> ImFont {
|
||||
self.raw_add_font(data, config, range)
|
||||
}
|
||||
|
||||
@ -309,6 +373,8 @@ impl <'a> ImFontAtlas<'a> {
|
||||
unsafe { (*self.atlas).tex_id as usize }
|
||||
}
|
||||
pub fn set_texture_id(&mut self, value: usize) {
|
||||
unsafe { (*self.atlas).tex_id = value as *mut c_void; }
|
||||
unsafe {
|
||||
(*self.atlas).tex_id = value as *mut c_void;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
31
src/input.rs
31
src/input.rs
@ -1,6 +1,6 @@
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
use sys;
|
||||
|
||||
use super::{ImGuiInputTextFlags, ImStr, ImString, Ui};
|
||||
|
||||
@ -213,7 +213,6 @@ impl<'ui, 'p> InputTextMultiline<'ui, 'p> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[must_use]
|
||||
pub struct InputInt<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
@ -299,20 +298,20 @@ macro_rules! impl_input_floatn {
|
||||
#[must_use]
|
||||
pub struct $InputFloatN<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32;$N],
|
||||
value: &'p mut [f32; $N],
|
||||
decimal_precision: i32,
|
||||
flags: ImGuiInputTextFlags,
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
|
||||
impl<'ui, 'p> $InputFloatN<'ui, 'p> {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32;$N]) -> Self {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N]) -> Self {
|
||||
$InputFloatN {
|
||||
label: label,
|
||||
value: value,
|
||||
decimal_precision: -1,
|
||||
flags: ImGuiInputTextFlags::empty(),
|
||||
_phantom: PhantomData
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,14 +321,15 @@ macro_rules! impl_input_floatn {
|
||||
self.label.as_ptr(),
|
||||
self.value.as_mut_ptr(),
|
||||
self.decimal_precision,
|
||||
self.flags)
|
||||
self.flags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl_precision_params!($InputFloatN);
|
||||
impl_text_flags!($InputFloatN);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_input_floatn!(InputFloat2, 2, igInputFloat2);
|
||||
@ -341,33 +341,30 @@ macro_rules! impl_input_intn {
|
||||
#[must_use]
|
||||
pub struct $InputIntN<'ui, 'p> {
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32;$N],
|
||||
value: &'p mut [i32; $N],
|
||||
flags: ImGuiInputTextFlags,
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>
|
||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||
}
|
||||
|
||||
impl<'ui, 'p> $InputIntN<'ui, 'p> {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32;$N]) -> Self {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N]) -> Self {
|
||||
$InputIntN {
|
||||
label: label,
|
||||
value: value,
|
||||
flags: ImGuiInputTextFlags::empty(),
|
||||
_phantom: PhantomData
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(self) -> bool {
|
||||
unsafe {
|
||||
sys::$igInputIntN(
|
||||
self.label.as_ptr(),
|
||||
self.value.as_mut_ptr(),
|
||||
self.flags)
|
||||
sys::$igInputIntN(self.label.as_ptr(), self.value.as_mut_ptr(), self.flags)
|
||||
}
|
||||
}
|
||||
|
||||
impl_text_flags!($InputIntN);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_input_intn!(InputInt2, 2, igInputInt2);
|
||||
|
||||
261
src/lib.rs
261
src/lib.rs
@ -8,28 +8,38 @@ use std::slice;
|
||||
use std::str;
|
||||
use sys::ImGuiStyleVar;
|
||||
|
||||
pub use sys::{ImDrawIdx, ImDrawVert, ImGuiColorEditFlags, ImGuiHoveredFlags, ImGuiInputTextFlags,
|
||||
ImGuiKey, ImGuiMouseCursor, ImGuiSelectableFlags, ImGuiCond, ImGuiCol, ImGuiStyle,
|
||||
ImGuiTreeNodeFlags, ImGuiWindowFlags, ImVec2, ImVec4};
|
||||
pub use child_frame::ChildFrame;
|
||||
pub use color_editors::{ColorButton, ColorEdit, ColorEditMode, ColorFormat, ColorPicker,
|
||||
ColorPickerMode, ColorPreview, EditableColor};
|
||||
pub use drag::{DragFloat, DragFloat2, DragFloat3, DragFloat4, DragInt, DragInt2, DragInt3,
|
||||
DragInt4, DragFloatRange2, DragIntRange2};
|
||||
pub use fonts::{FontGlyphRange, ImFontAtlas, ImFont, ImFontConfig};
|
||||
pub use input::{InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputInt2, InputInt3,
|
||||
InputInt4, InputText, InputTextMultiline};
|
||||
pub use color_editors::{
|
||||
ColorButton, ColorEdit, ColorEditMode, ColorFormat, ColorPicker, ColorPickerMode, ColorPreview,
|
||||
EditableColor,
|
||||
};
|
||||
pub use drag::{
|
||||
DragFloat, DragFloat2, DragFloat3, DragFloat4, DragFloatRange2, DragInt, DragInt2, DragInt3,
|
||||
DragInt4, DragIntRange2,
|
||||
};
|
||||
pub use fonts::{FontGlyphRange, ImFont, ImFontAtlas, ImFontConfig};
|
||||
pub use input::{
|
||||
InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputInt2, InputInt3, InputInt4,
|
||||
InputText, InputTextMultiline,
|
||||
};
|
||||
pub use menus::{Menu, MenuItem};
|
||||
pub use plothistogram::PlotHistogram;
|
||||
pub use plotlines::PlotLines;
|
||||
pub use progressbar::ProgressBar;
|
||||
pub use sliders::{SliderFloat, SliderFloat2, SliderFloat3, SliderFloat4, SliderInt, SliderInt2,
|
||||
SliderInt3, SliderInt4};
|
||||
pub use sliders::{
|
||||
SliderFloat, SliderFloat2, SliderFloat3, SliderFloat4, SliderInt, SliderInt2, SliderInt3,
|
||||
SliderInt4,
|
||||
};
|
||||
pub use string::{ImStr, ImString};
|
||||
pub use style::StyleVar;
|
||||
pub use sys::{
|
||||
ImDrawIdx, ImDrawVert, ImGuiCol, ImGuiColorEditFlags, ImGuiCond, ImGuiHoveredFlags,
|
||||
ImGuiInputTextFlags, ImGuiKey, ImGuiMouseCursor, ImGuiSelectableFlags, ImGuiStyle,
|
||||
ImGuiTreeNodeFlags, ImGuiWindowFlags, ImVec2, ImVec4,
|
||||
};
|
||||
pub use trees::{CollapsingHeader, TreeNode};
|
||||
pub use window::Window;
|
||||
pub use window_draw_list::{ImColor, WindowDrawList, ChannelsSplit};
|
||||
pub use window_draw_list::{ChannelsSplit, ImColor, WindowDrawList};
|
||||
|
||||
mod child_frame;
|
||||
mod color_editors;
|
||||
@ -112,11 +122,21 @@ impl ImGui {
|
||||
log_filename: None,
|
||||
}
|
||||
}
|
||||
fn io(&self) -> &sys::ImGuiIO { unsafe { &*sys::igGetIO() } }
|
||||
fn io_mut(&mut self) -> &mut sys::ImGuiIO { unsafe { &mut *sys::igGetIO() } }
|
||||
pub fn style(&self) -> &ImGuiStyle { unsafe { &*sys::igGetStyle() } }
|
||||
pub fn style_mut(&mut self) -> &mut ImGuiStyle { unsafe { &mut *sys::igGetStyle() } }
|
||||
pub fn fonts(&mut self) -> ImFontAtlas { unsafe { ImFontAtlas::from_ptr(self.io_mut().fonts) } }
|
||||
fn io(&self) -> &sys::ImGuiIO {
|
||||
unsafe { &*sys::igGetIO() }
|
||||
}
|
||||
fn io_mut(&mut self) -> &mut sys::ImGuiIO {
|
||||
unsafe { &mut *sys::igGetIO() }
|
||||
}
|
||||
pub fn style(&self) -> &ImGuiStyle {
|
||||
unsafe { &*sys::igGetStyle() }
|
||||
}
|
||||
pub fn style_mut(&mut self) -> &mut ImGuiStyle {
|
||||
unsafe { &mut *sys::igGetStyle() }
|
||||
}
|
||||
pub fn fonts(&mut self) -> ImFontAtlas {
|
||||
unsafe { ImFontAtlas::from_ptr(self.io_mut().fonts) }
|
||||
}
|
||||
pub fn prepare_texture<'a, F, T>(&mut self, f: F) -> T
|
||||
where
|
||||
F: FnOnce(TextureHandle<'a>) -> T,
|
||||
@ -251,40 +271,28 @@ impl ImGui {
|
||||
}
|
||||
/// Get currently displayed cursor.
|
||||
pub fn mouse_cursor(&self) -> ImGuiMouseCursor {
|
||||
unsafe {
|
||||
sys::igGetMouseCursor()
|
||||
}
|
||||
unsafe { sys::igGetMouseCursor() }
|
||||
}
|
||||
/// Returns `true` if mouse is currently dragging with the `button` provided
|
||||
/// as argument.
|
||||
pub fn is_mouse_dragging(&self, button: ImMouseButton) -> bool {
|
||||
unsafe {
|
||||
sys::igIsMouseDragging(button as c_int, -1.0)
|
||||
}
|
||||
unsafe { sys::igIsMouseDragging(button as c_int, -1.0) }
|
||||
}
|
||||
/// Returns `true` if the `button` provided as argument is currently down.
|
||||
pub fn is_mouse_down(&self, button: ImMouseButton) -> bool {
|
||||
unsafe {
|
||||
sys::igIsMouseDown(button as c_int)
|
||||
}
|
||||
unsafe { sys::igIsMouseDown(button as c_int) }
|
||||
}
|
||||
/// Returns `true` if the `button` provided as argument is being clicked.
|
||||
pub fn is_mouse_clicked(&self, button: ImMouseButton) -> bool {
|
||||
unsafe {
|
||||
sys::igIsMouseClicked(button as c_int, false)
|
||||
}
|
||||
unsafe { sys::igIsMouseClicked(button as c_int, false) }
|
||||
}
|
||||
/// Returns `true` if the `button` provided as argument is being double-clicked.
|
||||
pub fn is_mouse_double_clicked(&self, button: ImMouseButton) -> bool {
|
||||
unsafe {
|
||||
sys::igIsMouseDoubleClicked(button as c_int)
|
||||
}
|
||||
unsafe { sys::igIsMouseDoubleClicked(button as c_int) }
|
||||
}
|
||||
/// Returns `true` if the `button` provided as argument was released
|
||||
pub fn is_mouse_released(&self, button: ImMouseButton) -> bool {
|
||||
unsafe {
|
||||
sys::igIsMouseReleased(button as c_int)
|
||||
}
|
||||
unsafe { sys::igIsMouseReleased(button as c_int) }
|
||||
}
|
||||
pub fn key_ctrl(&self) -> bool {
|
||||
let io = self.io();
|
||||
@ -358,14 +366,16 @@ impl ImGui {
|
||||
sys::ImGuiIO_AddInputCharactersUTF8(buf.as_ptr() as *const _);
|
||||
}
|
||||
}
|
||||
pub fn get_time(&self) -> f32 { unsafe { sys::igGetTime() } }
|
||||
pub fn get_frame_count(&self) -> i32 { unsafe { sys::igGetFrameCount() } }
|
||||
pub fn get_frame_rate(&self) -> f32 { self.io().framerate }
|
||||
pub fn frame<'ui, 'a: 'ui>(
|
||||
&'a mut self,
|
||||
frame_size: FrameSize,
|
||||
delta_time: f32,
|
||||
) -> Ui<'ui> {
|
||||
pub fn get_time(&self) -> f32 {
|
||||
unsafe { sys::igGetTime() }
|
||||
}
|
||||
pub fn get_frame_count(&self) -> i32 {
|
||||
unsafe { sys::igGetFrameCount() }
|
||||
}
|
||||
pub fn get_frame_rate(&self) -> f32 {
|
||||
self.io().framerate
|
||||
}
|
||||
pub fn frame<'ui, 'a: 'ui>(&'a mut self, frame_size: FrameSize, delta_time: f32) -> Ui<'ui> {
|
||||
{
|
||||
let io = self.io_mut();
|
||||
io.display_size.x = frame_size.logical_size.0 as c_float;
|
||||
@ -376,9 +386,15 @@ impl ImGui {
|
||||
}
|
||||
unsafe {
|
||||
sys::igNewFrame();
|
||||
CURRENT_UI = Some(Ui { imgui: mem::transmute(self as &'a ImGui), frame_size });
|
||||
CURRENT_UI = Some(Ui {
|
||||
imgui: mem::transmute(self as &'a ImGui),
|
||||
frame_size,
|
||||
});
|
||||
}
|
||||
Ui {
|
||||
imgui: self,
|
||||
frame_size,
|
||||
}
|
||||
Ui { imgui: self, frame_size }
|
||||
}
|
||||
}
|
||||
|
||||
@ -443,13 +459,11 @@ impl<'a> Iterator for DrawListIterator<'a> {
|
||||
type Item = DrawList<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next().map(|&ptr| {
|
||||
unsafe {
|
||||
DrawList {
|
||||
cmd_buffer: (*ptr).cmd_buffer.as_slice(),
|
||||
idx_buffer: (*ptr).idx_buffer.as_slice(),
|
||||
vtx_buffer: (*ptr).vtx_buffer.as_slice(),
|
||||
}
|
||||
self.iter.next().map(|&ptr| unsafe {
|
||||
DrawList {
|
||||
cmd_buffer: (*ptr).cmd_buffer.as_slice(),
|
||||
idx_buffer: (*ptr).idx_buffer.as_slice(),
|
||||
vtx_buffer: (*ptr).vtx_buffer.as_slice(),
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -468,13 +482,17 @@ pub struct Ui<'ui> {
|
||||
|
||||
static FMT: &'static [u8] = b"%s\0";
|
||||
|
||||
fn fmt_ptr() -> *const c_char { FMT.as_ptr() as *const c_char }
|
||||
fn fmt_ptr() -> *const c_char {
|
||||
FMT.as_ptr() as *const c_char
|
||||
}
|
||||
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn frame_size(&self) -> FrameSize {
|
||||
self.frame_size
|
||||
}
|
||||
pub fn imgui(&self) -> &ImGui { self.imgui }
|
||||
pub fn imgui(&self) -> &ImGui {
|
||||
self.imgui
|
||||
}
|
||||
pub fn want_capture_mouse(&self) -> bool {
|
||||
let io = self.imgui.io();
|
||||
io.want_capture_mouse
|
||||
@ -518,8 +536,12 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn show_user_guide(&self) { unsafe { sys::igShowUserGuide() }; }
|
||||
pub fn show_default_style_editor(&self) { unsafe { sys::igShowStyleEditor(ptr::null_mut()) }; }
|
||||
pub fn show_user_guide(&self) {
|
||||
unsafe { sys::igShowUserGuide() };
|
||||
}
|
||||
pub fn show_default_style_editor(&self) {
|
||||
unsafe { sys::igShowStyleEditor(ptr::null_mut()) };
|
||||
}
|
||||
pub fn show_style_editor<'p>(&self, style: &'p mut ImGuiStyle) {
|
||||
unsafe {
|
||||
sys::igShowStyleEditor(style as *mut ImGuiStyle);
|
||||
@ -542,12 +564,16 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
|
||||
impl<'a> Ui<'a> {
|
||||
pub unsafe fn current_ui() -> Option<&'a Ui<'a>> { CURRENT_UI.as_ref() }
|
||||
pub unsafe fn current_ui() -> Option<&'a Ui<'a>> {
|
||||
CURRENT_UI.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
// Window
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn window<'p>(&self, name: &'p ImStr) -> Window<'ui, 'p> { Window::new(self, name) }
|
||||
pub fn window<'p>(&self, name: &'p ImStr) -> Window<'ui, 'p> {
|
||||
Window::new(self, name)
|
||||
}
|
||||
/// Get current window's size in pixels
|
||||
pub fn get_window_size(&self) -> (f32, f32) {
|
||||
let mut out = ImVec2::new(0.0, 0.0);
|
||||
@ -561,13 +587,17 @@ impl<'ui> Ui<'ui> {
|
||||
// Layout
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Pushes a value to the item width stack.
|
||||
pub fn push_item_width(&self, width: f32) { unsafe { sys::igPushItemWidth(width) } }
|
||||
pub fn push_item_width(&self, width: f32) {
|
||||
unsafe { sys::igPushItemWidth(width) }
|
||||
}
|
||||
|
||||
/// Pops a value from the item width stack.
|
||||
///
|
||||
/// # Aborts
|
||||
/// The current process is aborted if the item width stack is empty.
|
||||
pub fn pop_item_width(&self) { unsafe { sys::igPopItemWidth() } }
|
||||
pub fn pop_item_width(&self) {
|
||||
unsafe { sys::igPopItemWidth() }
|
||||
}
|
||||
|
||||
/// Runs a function after temporarily pushing a value to the item width stack.
|
||||
pub fn with_item_width<F>(&self, width: f32, f: F)
|
||||
@ -579,21 +609,33 @@ impl<'ui> Ui<'ui> {
|
||||
self.pop_item_width();
|
||||
}
|
||||
|
||||
pub fn separator(&self) { unsafe { sys::igSeparator() }; }
|
||||
pub fn new_line(&self) { unsafe { sys::igNewLine() } }
|
||||
pub fn same_line(&self, pos_x: f32) { unsafe { sys::igSameLine(pos_x, -1.0f32) } }
|
||||
pub fn separator(&self) {
|
||||
unsafe { sys::igSeparator() };
|
||||
}
|
||||
pub fn new_line(&self) {
|
||||
unsafe { sys::igNewLine() }
|
||||
}
|
||||
pub fn same_line(&self, pos_x: f32) {
|
||||
unsafe { sys::igSameLine(pos_x, -1.0f32) }
|
||||
}
|
||||
pub fn same_line_spacing(&self, pos_x: f32, spacing_w: f32) {
|
||||
unsafe { sys::igSameLine(pos_x, spacing_w) }
|
||||
}
|
||||
pub fn spacing(&self) { unsafe { sys::igSpacing() }; }
|
||||
pub fn spacing(&self) {
|
||||
unsafe { sys::igSpacing() };
|
||||
}
|
||||
|
||||
pub fn columns<'p>(&self, count: i32, id: &'p ImStr, border: bool) {
|
||||
unsafe { sys::igColumns(count, id.as_ptr(), border) }
|
||||
}
|
||||
|
||||
pub fn next_column(&self) { unsafe { sys::igNextColumn() } }
|
||||
pub fn next_column(&self) {
|
||||
unsafe { sys::igNextColumn() }
|
||||
}
|
||||
|
||||
pub fn get_column_index(&self) -> i32 { unsafe { sys::igGetColumnIndex() } }
|
||||
pub fn get_column_index(&self) -> i32 {
|
||||
unsafe { sys::igGetColumnIndex() }
|
||||
}
|
||||
|
||||
pub fn get_column_offset(&self, column_index: i32) -> f32 {
|
||||
unsafe { sys::igGetColumnOffset(column_index) }
|
||||
@ -607,7 +649,9 @@ impl<'ui> Ui<'ui> {
|
||||
unsafe { sys::igGetColumnWidth(column_index) }
|
||||
}
|
||||
|
||||
pub fn get_columns_count(&self) -> i32 { unsafe { sys::igGetColumnsCount() } }
|
||||
pub fn get_columns_count(&self) -> i32 {
|
||||
unsafe { sys::igGetColumnsCount() }
|
||||
}
|
||||
|
||||
/// Fill a space of `size` in pixels with nothing on the current window.
|
||||
/// Can be used to move the cursor on the window.
|
||||
@ -668,19 +712,27 @@ pub enum ImId<'a> {
|
||||
}
|
||||
|
||||
impl From<i32> for ImId<'static> {
|
||||
fn from(i: i32) -> Self { ImId::Int(i) }
|
||||
fn from(i: i32) -> Self {
|
||||
ImId::Int(i)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized + AsRef<str>> From<&'a T> for ImId<'a> {
|
||||
fn from(s: &'a T) -> Self { ImId::Str(s.as_ref()) }
|
||||
fn from(s: &'a T) -> Self {
|
||||
ImId::Str(s.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<*const T> for ImId<'static> {
|
||||
fn from(p: *const T) -> Self { ImId::Ptr(p as *const c_void) }
|
||||
fn from(p: *const T) -> Self {
|
||||
ImId::Ptr(p as *const c_void)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<*mut T> for ImId<'static> {
|
||||
fn from(p: *mut T) -> Self { ImId::Ptr(p as *const T as *const c_void) }
|
||||
fn from(p: *mut T) -> Self {
|
||||
ImId::Ptr(p as *const T as *const c_void)
|
||||
}
|
||||
}
|
||||
|
||||
// ID scopes
|
||||
@ -710,7 +762,9 @@ impl<'ui> Ui<'ui> {
|
||||
///
|
||||
/// # Aborts
|
||||
/// The current process is aborted if the ID stack is empty.
|
||||
pub fn pop_id(&self) { unsafe { sys::igPopID() }; }
|
||||
pub fn pop_id(&self) {
|
||||
unsafe { sys::igPopID() };
|
||||
}
|
||||
|
||||
/// Runs a function after temporarily pushing a value to the ID stack.
|
||||
pub fn with_id<'a, F, I>(&self, id: I, f: F)
|
||||
@ -788,7 +842,12 @@ impl<'ui> Ui<'ui> {
|
||||
pub fn input_text<'p>(&self, label: &'p ImStr, buf: &'p mut ImString) -> InputText<'ui, 'p> {
|
||||
InputText::new(self, label, buf)
|
||||
}
|
||||
pub fn input_text_multiline<'p, S: Into<ImVec2>>(&self, label: &'p ImStr, buf: &'p mut ImString, size: S) -> InputTextMultiline<'ui, 'p> {
|
||||
pub fn input_text_multiline<'p, S: Into<ImVec2>>(
|
||||
&self,
|
||||
label: &'p ImStr,
|
||||
buf: &'p mut ImString,
|
||||
size: S,
|
||||
) -> InputTextMultiline<'ui, 'p> {
|
||||
InputTextMultiline::new(self, label, buf, size.into())
|
||||
}
|
||||
pub fn input_float<'p>(&self, label: &'p ImStr, value: &'p mut f32) -> InputFloat<'ui, 'p> {
|
||||
@ -999,7 +1058,9 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
// Widgets: Trees
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn tree_node<'p>(&self, id: &'p ImStr) -> TreeNode<'ui, 'p> { TreeNode::new(self, id) }
|
||||
pub fn tree_node<'p>(&self, id: &'p ImStr) -> TreeNode<'ui, 'p> {
|
||||
TreeNode::new(self, id)
|
||||
}
|
||||
pub fn collapsing_header<'p>(&self, label: &'p ImStr) -> CollapsingHeader<'ui, 'p> {
|
||||
CollapsingHeader::new(self, label)
|
||||
}
|
||||
@ -1063,7 +1124,9 @@ impl<'ui> Ui<'ui> {
|
||||
/// # fn main() {
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn tooltip_text<T: AsRef<str>>(&self, text: T) { self.tooltip(|| self.text(text)); }
|
||||
pub fn tooltip_text<T: AsRef<str>>(&self, text: T) {
|
||||
self.tooltip(|| self.text(text));
|
||||
}
|
||||
}
|
||||
|
||||
// Widgets: Menus
|
||||
@ -1088,7 +1151,9 @@ impl<'ui> Ui<'ui> {
|
||||
unsafe { sys::igEndMenuBar() };
|
||||
}
|
||||
}
|
||||
pub fn menu<'p>(&self, label: &'p ImStr) -> Menu<'ui, 'p> { Menu::new(self, label) }
|
||||
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)
|
||||
}
|
||||
@ -1109,7 +1174,9 @@ impl<'ui> Ui<'ui> {
|
||||
unsafe { sys::igEndPopup() };
|
||||
}
|
||||
}
|
||||
pub fn close_current_popup(&self) { unsafe { sys::igCloseCurrentPopup() }; }
|
||||
pub fn close_current_popup(&self) {
|
||||
unsafe { sys::igCloseCurrentPopup() };
|
||||
}
|
||||
}
|
||||
|
||||
// Widgets: Combos
|
||||
@ -1247,7 +1314,9 @@ impl<'ui> Ui<'ui> {
|
||||
/// Get previously drawn item's size
|
||||
pub fn get_item_rect_size(&self) -> (f32, f32) {
|
||||
let mut out = ImVec2::new(0.0, 0.0);
|
||||
unsafe { sys::igGetItemRectSize(&mut out); }
|
||||
unsafe {
|
||||
sys::igGetItemRectSize(&mut out);
|
||||
}
|
||||
(out.x, out.y)
|
||||
}
|
||||
}
|
||||
@ -1344,31 +1413,21 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
#[inline]
|
||||
fn push_style_var(&self, style_var: StyleVar) {
|
||||
use StyleVar::*;
|
||||
use sys::{igPushStyleVar, igPushStyleVarVec};
|
||||
use StyleVar::*;
|
||||
match style_var {
|
||||
Alpha(v) => unsafe { igPushStyleVar(ImGuiStyleVar::Alpha, v) },
|
||||
WindowPadding(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::WindowPadding, v) },
|
||||
WindowRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::WindowRounding, v) },
|
||||
WindowBorderSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::WindowBorderSize, v) },
|
||||
WindowMinSize(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::WindowMinSize, v) },
|
||||
ChildRounding(v) => unsafe {
|
||||
igPushStyleVar(ImGuiStyleVar::ChildRounding, v)
|
||||
},
|
||||
ChildBorderSize(v) => unsafe {
|
||||
igPushStyleVar(ImGuiStyleVar::ChildBorderSize, v)
|
||||
},
|
||||
PopupRounding(v) => unsafe {
|
||||
igPushStyleVar(ImGuiStyleVar::PopupRounding, v)
|
||||
},
|
||||
PopupBorderSize(v) => unsafe {
|
||||
igPushStyleVar(ImGuiStyleVar::PopupBorderSize, v)
|
||||
},
|
||||
ChildRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::ChildRounding, v) },
|
||||
ChildBorderSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::ChildBorderSize, v) },
|
||||
PopupRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::PopupRounding, v) },
|
||||
PopupBorderSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::PopupBorderSize, v) },
|
||||
FramePadding(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::FramePadding, v) },
|
||||
FrameRounding(v) => unsafe { igPushStyleVar(ImGuiStyleVar::FrameRounding, v) },
|
||||
FrameBorderSize(v) => unsafe {
|
||||
igPushStyleVar(ImGuiStyleVar::FrameBorderSize, v)
|
||||
},
|
||||
FrameBorderSize(v) => unsafe { igPushStyleVar(ImGuiStyleVar::FrameBorderSize, v) },
|
||||
ItemSpacing(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ItemSpacing, v) },
|
||||
ItemInnerSpacing(v) => unsafe { igPushStyleVarVec(ImGuiStyleVar::ItemInnerSpacing, v) },
|
||||
IndentSpacing(v) => unsafe { igPushStyleVar(ImGuiStyleVar::IndentSpacing, v) },
|
||||
@ -1479,18 +1538,20 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
/// Returns `true` if the last item is being active.
|
||||
pub fn is_item_active(&self) -> bool {
|
||||
unsafe {
|
||||
sys::igIsItemActive()
|
||||
}
|
||||
unsafe { sys::igIsItemActive() }
|
||||
}
|
||||
|
||||
/// Group items together as a single item.
|
||||
///
|
||||
/// May be useful to handle the same mouse event on a group of items, for example.
|
||||
pub fn group<F: FnOnce()>(&self, f: F) {
|
||||
unsafe { sys::igBeginGroup(); }
|
||||
unsafe {
|
||||
sys::igBeginGroup();
|
||||
}
|
||||
f();
|
||||
unsafe { sys::igEndGroup(); }
|
||||
unsafe {
|
||||
sys::igEndGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
use sys;
|
||||
|
||||
use super::{ImStr, Ui};
|
||||
|
||||
@ -70,9 +70,10 @@ 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 { sys::igMenuItemPtr(label, shortcut, selected, enabled) }
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use sys;
|
||||
use std::{f32, mem, ptr};
|
||||
use std::marker::PhantomData;
|
||||
use std::os::raw::c_float;
|
||||
use std::{f32, mem, ptr};
|
||||
use sys;
|
||||
|
||||
use super::{ImStr, ImVec2, Ui};
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use sys;
|
||||
use std::{f32, mem, ptr};
|
||||
use std::marker::PhantomData;
|
||||
use std::os::raw::c_float;
|
||||
use std::{f32, mem, ptr};
|
||||
use sys;
|
||||
|
||||
use super::{ImStr, ImVec2, Ui};
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#![warn(missing_docs)]
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
use sys;
|
||||
|
||||
use super::{ImStr, ImVec2, Ui};
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use sys;
|
||||
|
||||
use super::{ImStr, Ui};
|
||||
|
||||
@ -57,7 +57,13 @@ macro_rules! impl_slider_intn {
|
||||
}
|
||||
|
||||
impl<'ui, 'p> $SliderIntN<'ui, 'p> {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N], min: i32, max: i32) -> Self {
|
||||
pub fn new(
|
||||
_: &Ui<'ui>,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [i32; $N],
|
||||
min: i32,
|
||||
max: i32,
|
||||
) -> Self {
|
||||
$SliderIntN {
|
||||
label: label,
|
||||
value: value,
|
||||
@ -79,11 +85,12 @@ macro_rules! impl_slider_intn {
|
||||
self.value.as_mut_ptr(),
|
||||
self.min,
|
||||
self.max,
|
||||
self.display_format.as_ptr())
|
||||
self.display_format.as_ptr(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_slider_intn!(SliderInt2, 2, igSliderInt2);
|
||||
@ -151,7 +158,13 @@ macro_rules! impl_slider_floatn {
|
||||
}
|
||||
|
||||
impl<'ui, 'p> $SliderFloatN<'ui, 'p> {
|
||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N], min: f32, max: f32) -> Self {
|
||||
pub fn new(
|
||||
_: &Ui<'ui>,
|
||||
label: &'p ImStr,
|
||||
value: &'p mut [f32; $N],
|
||||
min: f32,
|
||||
max: f32,
|
||||
) -> Self {
|
||||
$SliderFloatN {
|
||||
label: label,
|
||||
value: value,
|
||||
@ -180,11 +193,12 @@ macro_rules! impl_slider_floatn {
|
||||
self.min,
|
||||
self.max,
|
||||
self.display_format.as_ptr(),
|
||||
self.power)
|
||||
self.power,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_slider_floatn!(SliderFloat2, 2, igSliderFloat2);
|
||||
|
||||
100
src/string.rs
100
src/string.rs
@ -22,7 +22,9 @@ 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');
|
||||
@ -36,12 +38,24 @@ impl ImString {
|
||||
self.0.extend_from_slice(string.as_bytes());
|
||||
self.0.push(b'\0');
|
||||
}
|
||||
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 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 _ }
|
||||
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 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 _
|
||||
}
|
||||
|
||||
/// Updates the buffer length based on the current contents.
|
||||
///
|
||||
@ -57,40 +71,58 @@ impl ImString {
|
||||
}
|
||||
|
||||
impl<'a> Default for ImString {
|
||||
fn default() -> ImString { unsafe { ImString::from_utf8_with_nul_unchecked(vec![0]) } }
|
||||
fn default() -> ImString {
|
||||
unsafe { ImString::from_utf8_with_nul_unchecked(vec![0]) }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for ImString {
|
||||
fn from(s: String) -> ImString { ImString::new(s) }
|
||||
fn from(s: String) -> ImString {
|
||||
ImString::new(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized + AsRef<ImStr>> From<&'a T> for ImString {
|
||||
fn from(s: &'a T) -> ImString { s.as_ref().to_owned() }
|
||||
fn from(s: &'a T) -> ImString {
|
||||
s.as_ref().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<ImStr> for ImString {
|
||||
fn as_ref(&self) -> &ImStr { self }
|
||||
fn as_ref(&self) -> &ImStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Borrow<ImStr> for ImString {
|
||||
fn borrow(&self) -> &ImStr { self }
|
||||
fn borrow(&self) -> &ImStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for ImString {
|
||||
fn as_ref(&self) -> &str { self.to_str() }
|
||||
fn as_ref(&self) -> &str {
|
||||
self.to_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl Borrow<str> for ImString {
|
||||
fn borrow(&self) -> &str { self.to_str() }
|
||||
fn borrow(&self) -> &str {
|
||||
self.to_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<RangeFull> for ImString {
|
||||
type Output = ImStr;
|
||||
fn index(&self, _index: RangeFull) -> &ImStr { self }
|
||||
fn index(&self, _index: RangeFull) -> &ImStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ImString {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(self.to_str(), f) }
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Debug::fmt(self.to_str(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ImString {
|
||||
@ -113,29 +145,47 @@ 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 fn new<S: AsRef<ImStr> + ?Sized>(s: &S) -> &ImStr { s.as_ref() }
|
||||
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 new<S: AsRef<ImStr> + ?Sized>(s: &S) -> &ImStr {
|
||||
s.as_ref()
|
||||
}
|
||||
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()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<CStr> for ImStr {
|
||||
fn as_ref(&self) -> &CStr { &self.0 }
|
||||
fn as_ref(&self) -> &CStr {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<ImStr> for ImStr {
|
||||
fn as_ref(&self) -> &ImStr { self }
|
||||
fn as_ref(&self) -> &ImStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for ImStr {
|
||||
fn as_ref(&self) -> &str { self.to_str() }
|
||||
fn as_ref(&self) -> &str {
|
||||
self.to_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToOwned for ImStr {
|
||||
type Owned = ImString;
|
||||
fn to_owned(&self) -> ImString { ImString(self.0.to_owned().into_bytes()) }
|
||||
fn to_owned(&self) -> ImString {
|
||||
ImString(self.0.to_owned().into_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use sys;
|
||||
|
||||
use super::{ImGuiCond, ImGuiTreeNodeFlags, ImStr, Ui};
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use sys;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
use sys;
|
||||
|
||||
use super::{ImGuiCond, ImGuiStyleVar, ImGuiWindowFlags, ImStr, ImVec2, Ui};
|
||||
|
||||
@ -122,34 +122,26 @@ impl<'ui, 'p> Window<'ui, 'p> {
|
||||
}
|
||||
#[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) {
|
||||
@ -165,9 +157,9 @@ impl<'ui, 'p> Window<'ui, 'p> {
|
||||
}
|
||||
sys::igBegin(
|
||||
self.name.as_ptr(),
|
||||
self.opened.map(|x| x as *mut bool).unwrap_or(
|
||||
ptr::null_mut(),
|
||||
),
|
||||
self.opened
|
||||
.map(|x| x as *mut bool)
|
||||
.unwrap_or(ptr::null_mut()),
|
||||
self.flags,
|
||||
)
|
||||
};
|
||||
|
||||
@ -16,19 +16,27 @@ use std::marker::PhantomData;
|
||||
pub struct ImColor(ImU32);
|
||||
|
||||
impl From<ImColor> for ImU32 {
|
||||
fn from(color: ImColor) -> Self { color.0 }
|
||||
fn from(color: ImColor) -> Self {
|
||||
color.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ImU32> for ImColor {
|
||||
fn from(color: ImU32) -> Self { ImColor(color) }
|
||||
fn from(color: ImU32) -> Self {
|
||||
ImColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ImVec4> for ImColor {
|
||||
fn from(v: ImVec4) -> Self { ImColor(unsafe { sys::igColorConvertFloat4ToU32(v) }) }
|
||||
fn from(v: ImVec4) -> Self {
|
||||
ImColor(unsafe { sys::igColorConvertFloat4ToU32(v) })
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[f32; 4]> for ImColor {
|
||||
fn from(v: [f32; 4]) -> Self { ImColor(unsafe { sys::igColorConvertFloat4ToU32(v.into()) }) }
|
||||
fn from(v: [f32; 4]) -> Self {
|
||||
ImColor(unsafe { sys::igColorConvertFloat4ToU32(v.into()) })
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(f32, f32, f32, f32)> for ImColor {
|
||||
@ -38,11 +46,15 @@ impl From<(f32, f32, f32, f32)> for ImColor {
|
||||
}
|
||||
|
||||
impl From<[f32; 3]> for ImColor {
|
||||
fn from(v: [f32; 3]) -> Self { [v[0], v[1], v[2], 1.0].into() }
|
||||
fn from(v: [f32; 3]) -> Self {
|
||||
[v[0], v[1], v[2], 1.0].into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(f32, f32, f32)> for ImColor {
|
||||
fn from(v: (f32, f32, f32)) -> Self { [v.0, v.1, v.2, 1.0].into() }
|
||||
fn from(v: (f32, f32, f32)) -> Self {
|
||||
[v.0, v.1, v.2, 1.0].into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Object implementing the custom draw API.
|
||||
@ -59,7 +71,9 @@ static mut WINDOW_DRAW_LIST_LOADED: bool = false;
|
||||
|
||||
impl<'ui> Drop for WindowDrawList<'ui> {
|
||||
fn drop(&mut self) {
|
||||
unsafe { WINDOW_DRAW_LIST_LOADED = false; }
|
||||
unsafe {
|
||||
WINDOW_DRAW_LIST_LOADED = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user