Abolish ImVec2/ImVec4 from safe APIs

[f32; 2] and [f32; 4] are now the canonical types
This commit is contained in:
Joonas Javanainen 2019-06-28 00:05:10 +03:00
parent 21cc1af4ce
commit 109e232422
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
20 changed files with 329 additions and 399 deletions

View File

@ -14,14 +14,14 @@ Wrapped Dear ImGui version: 1.66b
```rust
ui.window(im_str!("Hello world"))
.size((300.0, 100.0), ImGuiCond::FirstUseEver)
.size([300.0, 100.0], Condition::FirstUseEver)
.build(|| {
ui.text(im_str!("Hello world!"));
ui.text(im_str!("こんにちは世界!"));
ui.text(im_str!("This...is...imgui-rs!"));
ui.separator();
let mouse_pos = ui.imgui().mouse_pos();
ui.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1));
ui.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos[0], mouse_pos[1]));
})
```

View File

@ -375,46 +375,46 @@ dependencies = [
[[package]]
name = "imgui"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glium 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui-sys 0.0.24-pre",
"imgui-sys 0.1.0-pre",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "imgui-examples"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"glium 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui 0.0.24-pre",
"imgui-glium-renderer 0.0.24-pre",
"imgui-winit-support 0.0.24-pre",
"imgui 0.1.0-pre",
"imgui-glium-renderer 0.1.0-pre",
"imgui-winit-support 0.1.0-pre",
]
[[package]]
name = "imgui-glium-renderer"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"glium 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui 0.0.24-pre",
"imgui 0.1.0-pre",
]
[[package]]
name = "imgui-sys"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "imgui-winit-support"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"imgui 0.0.24-pre",
"imgui 0.1.0-pre",
"winit 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -39,8 +39,8 @@ fn main() {
fn example_selector(state: &mut State, ui: &Ui) {
ui.window(im_str!("Color button examples"))
.position((20.0, 20.0), Condition::Appearing)
.size((700.0, 80.0), Condition::Appearing)
.position([20.0, 20.0], Condition::Appearing)
.size([700.0, 80.0], Condition::Appearing)
.resizable(false)
.build(|| {
let ex1 = ui.radio_button(im_str!("Example 1: Basics"), &mut state.example, 1);
@ -53,8 +53,8 @@ fn example_selector(state: &mut State, ui: &Ui) {
fn example_1(state: &mut State, ui: &Ui) {
ui.window(im_str!("Example 1: Basics"))
.size((700.0, 300.0), Condition::Appearing)
.position((20.0, 120.0), Condition::Appearing)
.size([700.0, 300.0], Condition::Appearing)
.position([20.0, 120.0], Condition::Appearing)
.build(|| {
ui.text_wrapped(im_str!(
"Color button is a widget that displays a color value as a clickable rectangle. \
@ -65,7 +65,7 @@ fn example_1(state: &mut State, ui: &Ui) {
ui.text("This button is black:");
if ui
.color_button(im_str!("Black color"), (0.0, 0.0, 0.0, 1.0))
.color_button(im_str!("Black color"), [0.0, 0.0, 0.0, 1.0])
.build()
{
state.notify_text = "*** Black button was clicked";
@ -73,7 +73,7 @@ fn example_1(state: &mut State, ui: &Ui) {
ui.text("This button is red:");
if ui
.color_button(im_str!("Red color"), (1.0, 0.0, 0.0, 1.0))
.color_button(im_str!("Red color"), [1.0, 0.0, 0.0, 1.0])
.build()
{
state.notify_text = "*** Red button was clicked";
@ -81,8 +81,8 @@ fn example_1(state: &mut State, ui: &Ui) {
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))
.size((100.0, 50.0))
.color_button(im_str!("Green color"), [0.0, 1.0, 0.0, 1.0])
.size([100.0, 50.0])
.build()
{
state.notify_text = "*** BIG button was clicked";
@ -90,7 +90,7 @@ 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))
.color_button(im_str!("No tooltip"), [0.0, 0.0, 1.0, 1.0])
.tooltip(false)
.build()
{
@ -101,8 +101,8 @@ fn example_1(state: &mut State, ui: &Ui) {
fn example_2(ui: &Ui) {
ui.window(im_str!("Example 2: Alpha component"))
.size((700.0, 320.0), Condition::Appearing)
.position((20.0, 140.0), Condition::Appearing)
.size([700.0, 320.0], Condition::Appearing)
.position([20.0, 140.0], Condition::Appearing)
.build(|| {
ui.text_wrapped(im_str!(
"The displayed color is passed to the button as four float values between \
@ -111,7 +111,7 @@ fn example_2(ui: &Ui) {
));
ui.text("This button ignores the alpha component:");
ui.color_button(im_str!("Red color"), (1.0, 0.0, 0.0, 0.5))
ui.color_button(im_str!("Red color"), [1.0, 0.0, 0.0, 0.5])
.alpha(false)
.build();
@ -127,7 +127,7 @@ fn example_2(ui: &Ui) {
ui.text_wrapped(im_str!(
"ColorPreview::Opaque (default) doesn't show the alpha component at all"
));
ui.color_button(im_str!("Red + ColorPreview::Opaque"), (1.0, 0.0, 0.0, 0.5))
ui.color_button(im_str!("Red + ColorPreview::Opaque"), [1.0, 0.0, 0.0, 0.5])
.preview(ColorPreview::Opaque)
.build();
@ -138,7 +138,7 @@ fn example_2(ui: &Ui) {
));
ui.color_button(
im_str!("Red + ColorPreview::HalfAlpha"),
(1.0, 0.0, 0.0, 0.5),
[1.0, 0.0, 0.0, 0.5],
)
.preview(ColorPreview::HalfAlpha)
.build();
@ -148,7 +148,7 @@ fn example_2(ui: &Ui) {
"ColorPreview::Alpha uses a checkerboard pattern in the entire color area to \
illustrate the alpha component"
));
ui.color_button(im_str!("Red + ColorPreview::Alpha"), (1.0, 0.0, 0.0, 0.5))
ui.color_button(im_str!("Red + ColorPreview::Alpha"), [1.0, 0.0, 0.0, 0.5])
.preview(ColorPreview::Alpha)
.build();
});

View File

@ -24,7 +24,7 @@ struct CustomTexturesApp {
struct Lenna {
texture_id: TextureId,
size: (f32, f32),
size: [f32; 2],
}
impl CustomTexturesApp {
@ -72,12 +72,12 @@ impl CustomTexturesApp {
fn show_textures(&self, ui: &Ui) {
ui.window(im_str!("Hello textures"))
.size((400.0, 600.0), Condition::FirstUseEver)
.size([400.0, 600.0], Condition::FirstUseEver)
.build(|| {
ui.text(im_str!("Hello textures!"));
if let Some(my_texture_id) = self.my_texture_id {
ui.text("Some generated texture");
ui.image(my_texture_id, (100.0, 100.0)).build();
ui.image(my_texture_id, [100.0, 100.0]).build();
}
if let Some(lenna) = &self.lenna {
@ -109,7 +109,7 @@ impl Lenna {
let texture_id = textures.insert(Rc::new(gl_texture));
Ok(Lenna {
texture_id,
size: (width as f32, height as f32),
size: [width as f32, height as f32],
})
}

View File

@ -12,7 +12,7 @@ fn main() {
fn hello_world<'a>(ui: &Ui<'a>) -> bool {
ui.window(im_str!("Hello world"))
.size((300.0, 100.0), Condition::FirstUseEver)
.size([300.0, 100.0], Condition::FirstUseEver)
.build(|| {
ui.text(im_str!("Hello world!"));
ui.text(im_str!("こんにちは世界!"));

View File

@ -2,7 +2,7 @@ use glium::{
backend::{Context, Facade},
Texture2d,
};
use imgui::{FontGlyphRange, ImFontConfig, self, Ui};
use imgui::{self, FontGlyphRange, ImFontConfig, Ui};
use imgui_winit_support::{HiDpiMode, WinitPlatform};
use std::rc::Rc;
use std::time::Instant;
@ -55,7 +55,8 @@ where
imgui.io_mut().font_global_scale = (1.0 / hidpi_factor) as f32;
let mut renderer = GliumRenderer::init(&mut imgui, &display).expect("Failed to initialize renderer");
let mut renderer =
GliumRenderer::init(&mut imgui, &display).expect("Failed to initialize renderer");
let mut last_frame = Instant::now();
let mut quit = false;

View File

@ -23,14 +23,14 @@ fn main() {
draw_list
.add_line(
canvas_pos,
[canvas_pos.0 + RADIUS, canvas_pos.1 + RADIUS],
[canvas_pos[0] + RADIUS, canvas_pos[1] + RADIUS],
RED,
)
.thickness(5.0)
.build();
channels.set_current(0);
let center = (canvas_pos.0 + RADIUS, canvas_pos.1 + RADIUS);
let center = [canvas_pos[0] + RADIUS, canvas_pos[1] + RADIUS];
draw_list
.add_circle(center, RADIUS, WHITE)
.thickness(10.0)

View File

@ -167,7 +167,7 @@ impl Default for AutoResizeState {
struct CustomRenderingState {
sz: f32,
col: [f32; 3],
points: Vec<(f32, f32)>,
points: Vec<[f32; 2]>,
adding_line: bool,
}
@ -284,7 +284,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
.scroll_bar(!state.no_scrollbar)
.collapsible(!state.no_collapse)
.menu_bar(!state.no_menu)
.size((550.0, 680.0), Condition::FirstUseEver);
.size([550.0, 680.0], Condition::FirstUseEver);
if !state.no_close {
window = window.opened(opened)
}
@ -390,8 +390,8 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
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_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"));
});
@ -399,7 +399,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
ui.input_text_multiline(
im_str!("multiline"),
&mut state.text_multiline,
(300., 100.),
[300., 100.],
).build();
});
@ -636,7 +636,7 @@ CTRL+click on individual component to input value.\n",
name,
false,
ImGuiSelectableFlags::empty(),
ImVec2::new(0.0, 0.0),
[0.0, 0.0]
) {
state.selected_fish = Some(index);
}
@ -650,7 +650,7 @@ CTRL+click on individual component to input value.\n",
them by clicking outside the window."
));
if ui.button(im_str!("Delete.."), (0.0, 0.0)) {
if ui.button(im_str!("Delete.."), [0.0, 0.0]) {
ui.open_popup(im_str!("Delete?"));
}
ui.popup_modal(im_str!("Delete?")).always_auto_resize(true).build(|| {
@ -659,17 +659,17 @@ CTRL+click on individual component to input value.\n",
ui.with_style_var(StyleVar::FramePadding([0.0, 0.0]), || {
ui.checkbox(im_str!("Don't ask me next time"), &mut state.dont_ask_me_next_time);
if ui.button(im_str!("OK"), (120.0, 0.0)) {
if ui.button(im_str!("OK"), [120.0, 0.0]) {
ui.close_current_popup();
}
ui.same_line(0.0);
if ui.button(im_str!("Cancel"), (120.0, 0.0)) {
if ui.button(im_str!("Cancel"), [120.0, 0.0]) {
ui.close_current_popup();
}
});
});
if ui.button(im_str!("Stacked modals.."), (0.0, 0.0)) {
if ui.button(im_str!("Stacked modals.."), [0.0, 0.0]) {
ui.open_popup(im_str!("Stacked 1"));
}
ui.popup_modal(im_str!("Stacked 1")).build(|| {
@ -683,17 +683,17 @@ CTRL+click on individual component to input value.\n",
ui.color_edit(im_str!("color"), &mut state.stacked_modals_color).build();
if ui.button(im_str!("Add another modal.."), (0.0, 0.0)) {
if ui.button(im_str!("Add another modal.."), [0.0, 0.0]) {
ui.open_popup(im_str!("Stacked 2")) ;
}
ui.popup_modal(im_str!("Stacked 2")).build(|| {
ui.text("Hello from Stacked The Second");
if ui.button(im_str!("Close"), (0.0, 0.0)) {
if ui.button(im_str!("Close"), [0.0, 0.0]) {
ui.close_current_popup();
}
});
if ui.button(im_str!("Close"), (0.0, 0.0)) {
if ui.button(im_str!("Close"), [0.0, 0.0]) {
ui.close_current_popup();
}
});
@ -756,7 +756,7 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
ui.menu_item(im_str!("Enabled"))
.selected(&mut state.enabled)
.build();
ui.child_frame(im_str!("child"), (0.0, 60.0))
ui.child_frame(im_str!("child"), [0.0, 60.0])
.show_borders(true)
.build(|| {
for i in 0..10 {
@ -806,7 +806,7 @@ output your content because that would create a feedback loop.",
fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) {
const DISTANCE: f32 = 10.0;
let window_pos = (DISTANCE, DISTANCE);
let window_pos = [DISTANCE, DISTANCE];
ui.with_color_var(StyleColor::WindowBg, [0.0, 0.0, 0.0, 0.3], || {
ui.window(im_str!("Example: Fixed Overlay"))
.opened(opened)
@ -830,7 +830,7 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) {
fn show_example_app_manipulating_window_title(ui: &Ui) {
ui.window(im_str!("Same title as another window##1"))
.position((100.0, 100.0), Condition::FirstUseEver)
.position([100.0, 100.0], Condition::FirstUseEver)
.build(|| {
ui.text(
"This is window 1.
@ -838,7 +838,7 @@ My title is the same as window 2, but my identifier is unique.",
);
});
ui.window(im_str!("Same title as another window##2"))
.position((100.0, 200.0), Condition::FirstUseEver)
.position([100.0, 200.0], Condition::FirstUseEver)
.build(|| {
ui.text(
"This is window 2.
@ -850,13 +850,13 @@ My title is the same as window 1, but my identifier is unique.",
let num = ui.get_frame_count(); // The C++ version uses rand() here
let title = im_str!("Animated title {} {}###AnimatedTitle", chars[ch_idx], num);
ui.window(&title)
.position((100.0, 300.0), Condition::FirstUseEver)
.position([100.0, 300.0], Condition::FirstUseEver)
.build(|| ui.text("This window has a changing title"));
}
fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, opened: &mut bool) {
ui.window(im_str!("Example: Custom rendering"))
.size((350.0, 560.0), Condition::FirstUseEver)
.size([350.0, 560.0], Condition::FirstUseEver)
.opened(opened)
.build(|| {
ui.text("Primitives");
@ -865,13 +865,13 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
let draw_list = ui.get_window_draw_list();
let p = ui.get_cursor_screen_pos();
let spacing = 8.0;
let mut y = p.1 + 4.0;
let mut y = p[1] + 4.0;
for n in 0..2 {
let mut x = p.0 + 4.0;
let mut x = p[0] + 4.0;
let thickness = if n == 0 { 1.0 } else { 4.0 };
draw_list
.add_circle(
(x + state.sz * 0.5, y + state.sz * 0.5),
[x + state.sz * 0.5, y + state.sz * 0.5],
state.sz * 0.5,
state.col,
)
@ -880,18 +880,18 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
.build();
x += state.sz + spacing;
draw_list
.add_rect((x, y), (x + state.sz, y + state.sz), state.col)
.add_rect([x, y], [x + state.sz, y + state.sz], state.col)
.thickness(thickness)
.build();
x += state.sz + spacing;
draw_list
.add_rect((x, y), (x + state.sz, y + state.sz), state.col)
.add_rect([x, y], [x + state.sz, y + state.sz], state.col)
.thickness(thickness)
.rounding(10.0)
.build();
x += state.sz + spacing;
draw_list
.add_rect((x, y), (x + state.sz, y + state.sz), state.col)
.add_rect([x, y], [x + state.sz, y + state.sz], state.col)
.thickness(thickness)
.rounding(10.0)
.round_top_right(false)
@ -900,45 +900,45 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
x += state.sz + spacing;
draw_list
.add_triangle(
(x + state.sz * 0.5, y),
(x + state.sz, y + state.sz - 0.5),
(x, y + state.sz - 0.5),
[x + state.sz * 0.5, y],
[x + state.sz, y + state.sz - 0.5],
[x, y + state.sz - 0.5],
state.col,
)
.thickness(thickness)
.build();
x += state.sz + spacing;
draw_list
.add_line((x, y), (x + state.sz, y), state.col)
.add_line([x, y], [x + state.sz, y], state.col)
.thickness(thickness)
.build();
x += state.sz + spacing;
draw_list
.add_line((x, y), (x + state.sz, y + state.sz), state.col)
.add_line([x, y], [x + state.sz, y + state.sz], state.col)
.thickness(thickness)
.build();
x += state.sz + spacing;
draw_list
.add_line((x, y), (x, y + state.sz), state.col)
.add_line([x, y], [x, y + state.sz], state.col)
.thickness(thickness)
.build();
x += spacing;
draw_list
.add_bezier_curve(
(x, y),
(x + state.sz * 1.3, y + state.sz * 0.3),
(x + state.sz - state.sz * 1.3, y + state.sz - state.sz * 0.3),
(x + state.sz, y + state.sz),
[x, y],
[x + state.sz * 1.3, y + state.sz * 0.3],
[x + state.sz - state.sz * 1.3, y + state.sz - state.sz * 0.3],
[x + state.sz, y + state.sz],
state.col,
)
.thickness(thickness)
.build();
y += state.sz + spacing;
}
let mut x = p.0 + 4.0;
let mut x = p[0] + 4.0;
draw_list
.add_circle(
(x + state.sz * 0.5, y + state.sz * 0.5),
[x + state.sz * 0.5, y + state.sz * 0.5],
state.sz * 0.5,
state.col,
)
@ -947,18 +947,18 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
.build();
x += state.sz + spacing;
draw_list
.add_rect((x, y), (x + state.sz, y + state.sz), state.col)
.add_rect([x, y], [x + state.sz, y + state.sz], state.col)
.filled(true)
.build();
x += state.sz + spacing;
draw_list
.add_rect((x, y), (x + state.sz, y + state.sz), state.col)
.add_rect([x, y], [x + state.sz, y + state.sz], state.col)
.filled(true)
.rounding(10.0)
.build();
x += state.sz + spacing;
draw_list
.add_rect((x, y), (x + state.sz, y + state.sz), state.col)
.add_rect([x, y], [x + state.sz, y + state.sz], state.col)
.filled(true)
.rounding(10.0)
.round_top_right(false)
@ -967,9 +967,9 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
x += state.sz + spacing;
draw_list
.add_triangle(
(x + state.sz * 0.5, y),
(x + state.sz, y + state.sz - 0.5),
(x, y + state.sz - 0.5),
[x + state.sz * 0.5, y],
[x + state.sz, y + state.sz - 0.5],
[x, y + state.sz - 0.5],
state.col,
)
.filled(true)
@ -980,23 +980,23 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
const MULTICOLOR_RECT_CORNER_COLOR3: [f32; 3] = [1.0, 1.0, 0.0];
const MULTICOLOR_RECT_CORNER_COLOR4: [f32; 3] = [0.0, 1.0, 0.0];
draw_list.add_rect_filled_multicolor(
(x, y),
(x + state.sz, y + state.sz),
[x, y],
[x + state.sz, y + state.sz],
MULTICOLOR_RECT_CORNER_COLOR1,
MULTICOLOR_RECT_CORNER_COLOR2,
MULTICOLOR_RECT_CORNER_COLOR3,
MULTICOLOR_RECT_CORNER_COLOR4,
);
ui.dummy(((state.sz + spacing) * 8.0, (state.sz + spacing) * 3.0));
ui.dummy([(state.sz + spacing) * 8.0, (state.sz + spacing) * 3.0]);
ui.separator();
ui.text(im_str!("Canvas example"));
if ui.button(im_str!("Clear"), (0.0, 0.0)) {
if ui.button(im_str!("Clear"), [0.0, 0.0]) {
state.points.clear();
}
if state.points.len() >= 2 {
ui.same_line(0.0);
if ui.button(im_str!("Undo"), (0.0, 0.0)) {
if ui.button(im_str!("Undo"), [0.0, 0.0]) {
state.points.pop();
state.points.pop();
}
@ -1017,11 +1017,11 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
let canvas_pos = ui.get_cursor_screen_pos();
// Resize canvas to what's available
let mut canvas_size = ui.get_content_region_avail();
if canvas_size.0 < 50.0 {
canvas_size.0 = 50.0;
if canvas_size[0] < 50.0 {
canvas_size[0] = 50.0;
}
if canvas_size.1 < 50.0 {
canvas_size.1 = 50.0;
if canvas_size[1] < 50.0 {
canvas_size[1] = 50.0;
}
const CANVAS_CORNER_COLOR1: [f32; 3] = [0.2, 0.2, 0.2];
const CANVAS_CORNER_COLOR2: [f32; 3] = [0.2, 0.2, 0.24];
@ -1029,7 +1029,10 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
const CANVAS_CORNER_COLOR4: [f32; 3] = [0.2, 0.2, 0.24];
draw_list.add_rect_filled_multicolor(
canvas_pos,
(canvas_pos.0 + canvas_size.0, canvas_pos.1 + canvas_size.1),
[
canvas_pos[0] + canvas_size[0],
canvas_pos[1] + canvas_size[1],
],
CANVAS_CORNER_COLOR1,
CANVAS_CORNER_COLOR2,
CANVAS_CORNER_COLOR3,
@ -1039,7 +1042,10 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
draw_list
.add_rect(
canvas_pos,
(canvas_pos.0 + canvas_size.0, canvas_pos.1 + canvas_size.1),
[
canvas_pos[0] + canvas_size[0],
canvas_pos[1] + canvas_size[1],
],
CANVAS_BORDER_COLOR,
)
.build();
@ -1047,7 +1053,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
let mut adding_preview = false;
ui.invisible_button(im_str!("canvas"), canvas_size);
let mouse_pos = ui.io().mouse_pos;
let mouse_pos_in_canvas = (mouse_pos[0] - canvas_pos.0, mouse_pos[1] - canvas_pos.1);
let mouse_pos_in_canvas = [mouse_pos[0] - canvas_pos[0], mouse_pos[1] - canvas_pos[1]];
if state.adding_line {
adding_preview = true;
state.points.push(mouse_pos_in_canvas);
@ -1070,7 +1076,10 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
}
draw_list.with_clip_rect_intersect(
canvas_pos,
(canvas_pos.0 + canvas_size.0, canvas_pos.1 + canvas_size.1),
[
canvas_pos[0] + canvas_size[0],
canvas_pos[1] + canvas_size[1],
],
|| {
const LINE_COLOR: [f32; 3] = [1.0, 1.0, 0.0];
for line in state.points.chunks(2) {
@ -1080,8 +1089,8 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState,
let (p1, p2) = (line[0], line[1]);
draw_list
.add_line(
(canvas_pos.0 + p1.0, canvas_pos.1 + p1.1),
(canvas_pos.0 + p2.0, canvas_pos.1 + p2.1),
[canvas_pos[0] + p1[0], canvas_pos[1] + p1[1]],
[canvas_pos[0] + p2[0], canvas_pos[1] + p2[1]],
LINE_COLOR,
)
.thickness(2.0)

View File

@ -347,49 +347,49 @@ dependencies = [
[[package]]
name = "imgui"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui-sys 0.0.24-pre",
"imgui-sys 0.1.0-pre",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "imgui-gfx-examples"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"gfx 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_window_dxgi 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_window_glutin 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui 0.0.24-pre",
"imgui-gfx-renderer 0.0.24-pre",
"imgui-winit-support 0.0.24-pre",
"imgui 0.1.0-pre",
"imgui-gfx-renderer 0.1.0-pre",
"imgui-winit-support 0.1.0-pre",
]
[[package]]
name = "imgui-gfx-renderer"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"gfx 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui 0.0.24-pre",
"imgui 0.1.0-pre",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "imgui-sys"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "imgui-winit-support"
version = "0.0.24-pre"
version = "0.1.0-pre"
dependencies = [
"imgui 0.0.24-pre",
"imgui 0.1.0-pre",
"winit 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -16,7 +16,7 @@ fn hello_world<'a>(ui: &Ui<'a>) -> bool {
let window_title = im_str!("Hello world (DirectX)");
ui.window(window_title)
.size((300.0, 100.0), Condition::FirstUseEver)
.size([300.0, 100.0], Condition::FirstUseEver)
.build(|| {
ui.text(im_str!("Hello world!"));
ui.text(im_str!("こんにちは世界!"));

View File

@ -2,19 +2,19 @@ use std::marker::PhantomData;
use crate::legacy::ImGuiWindowFlags;
use crate::sys;
use crate::{ImStr, ImVec2, Ui};
use crate::{ImStr, Ui};
#[must_use]
pub struct ChildFrame<'ui, 'p> {
name: &'p ImStr,
size: ImVec2,
size: [f32; 2],
border: bool,
flags: ImGuiWindowFlags,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui, 'p> ChildFrame<'ui, 'p> {
pub fn new<S: Into<ImVec2>>(_: &Ui<'ui>, name: &'p ImStr, size: S) -> ChildFrame<'ui, 'p> {
pub fn new(_: &Ui<'ui>, name: &'p ImStr, size: [f32; 2]) -> ChildFrame<'ui, 'p> {
ChildFrame {
name,
size: size.into(),
@ -101,7 +101,7 @@ impl<'ui, 'p> ChildFrame<'ui, 'p> {
let render_child_frame = unsafe {
sys::igBeginChild(
self.name.as_ptr(),
self.size,
self.size.into(),
self.border,
self.flags.bits(),
)

View File

@ -4,7 +4,7 @@ use std::ptr;
use crate::legacy::ImGuiColorEditFlags;
use crate::sys;
use crate::{ImStr, ImVec2, ImVec4, Ui};
use crate::{ImStr, Ui};
/// Mutable reference to an editable color value.
#[derive(Debug)]
@ -356,20 +356,20 @@ impl<'ui, 'p> ColorPicker<'ui, 'p> {
#[must_use]
pub struct ColorButton<'ui, 'p> {
desc_id: &'p ImStr,
color: ImVec4,
color: [f32; 4],
flags: ImGuiColorEditFlags,
size: ImVec2,
size: [f32; 2],
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui, 'p> ColorButton<'ui, 'p> {
/// Constructs a new color button builder.
pub fn new(_: &Ui<'ui>, desc_id: &'p ImStr, color: ImVec4) -> Self {
pub fn new(_: &Ui<'ui>, desc_id: &'p ImStr, color: [f32; 4]) -> Self {
ColorButton {
desc_id,
color,
flags: ImGuiColorEditFlags::empty(),
size: ImVec2::zero(),
size: [0.0, 0.0],
_phantom: PhantomData,
}
}
@ -408,7 +408,7 @@ impl<'ui, 'p> ColorButton<'ui, 'p> {
///
/// Use 0.0 for width and/or height to use the default size.
#[inline]
pub fn size<S: Into<ImVec2>>(mut self, size: S) -> Self {
pub fn size(mut self, size: [f32; 2]) -> Self {
self.size = size.into();
self
}
@ -417,9 +417,9 @@ impl<'ui, 'p> ColorButton<'ui, 'p> {
unsafe {
sys::igColorButton(
self.desc_id.as_ptr(),
self.color,
self.color.into(),
self.flags.bits(),
self.size,
self.size.into(),
)
}
}

View File

@ -3,7 +3,7 @@ use std::os::raw::c_void;
use crate::render::renderer::TextureId;
use crate::sys;
use crate::{ImVec2, ImVec4, Ui};
use crate::Ui;
/// Represent an image about to be drawn.
/// See [`Ui::image`].
@ -12,36 +12,23 @@ use crate::{ImVec2, ImVec4, Ui};
#[must_use]
pub struct Image<'ui> {
texture_id: TextureId,
size: ImVec2,
uv0: ImVec2,
uv1: ImVec2,
tint_col: ImVec4,
border_col: ImVec4,
size: [f32; 2],
uv0: [f32; 2],
uv1: [f32; 2],
tint_col: [f32; 4],
border_col: [f32; 4],
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui> Image<'ui> {
pub fn new<S>(_: &Ui<'ui>, texture_id: TextureId, size: S) -> Self
where
S: Into<ImVec2>,
{
const DEFAULT_UV0: ImVec2 = ImVec2 { x: 0.0, y: 0.0 };
const DEFAULT_UV1: ImVec2 = ImVec2 { x: 1.0, y: 1.0 };
const DEFAULT_TINT_COL: ImVec4 = ImVec4 {
x: 1.0,
y: 1.0,
z: 1.0,
w: 1.0,
};
const DEFAULT_BORDER_COL: ImVec4 = ImVec4 {
x: 0.0,
y: 0.0,
z: 0.0,
w: 0.0,
};
pub fn new(_: &Ui<'ui>, texture_id: TextureId, size: [f32; 2]) -> Self {
const DEFAULT_UV0: [f32; 2] = [0.0, 0.0];
const DEFAULT_UV1: [f32; 2] = [1.0, 1.0];
const DEFAULT_TINT_COL: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
const DEFAULT_BORDER_COL: [f32; 4] = [0.0, 0.0, 0.0, 0.0];
Image {
texture_id,
size: size.into(),
size,
uv0: DEFAULT_UV0,
uv1: DEFAULT_UV1,
tint_col: DEFAULT_TINT_COL,
@ -50,28 +37,28 @@ impl<'ui> Image<'ui> {
}
}
/// Set size (default based on texture)
pub fn size<T: Into<ImVec2>>(mut self, size: T) -> Self {
self.size = size.into();
pub fn size(mut self, size: [f32; 2]) -> Self {
self.size = size;
self
}
/// Set uv0 (default `[0.0, 0.0]`)
pub fn uv0<T: Into<ImVec2>>(mut self, uv0: T) -> Self {
self.uv0 = uv0.into();
pub fn uv0(mut self, uv0: [f32; 2]) -> Self {
self.uv0 = uv0;
self
}
/// Set uv1 (default `[1.0, 1.0]`)
pub fn uv1<T: Into<ImVec2>>(mut self, uv1: T) -> Self {
self.uv1 = uv1.into();
pub fn uv1(mut self, uv1: [f32; 2]) -> Self {
self.uv1 = uv1;
self
}
/// Set tint color (default: no tint color)
pub fn tint_col<T: Into<ImVec4>>(mut self, tint_col: T) -> Self {
self.tint_col = tint_col.into();
pub fn tint_col(mut self, tint_col: [f32; 4]) -> Self {
self.tint_col = tint_col;
self
}
/// Set border color (default: no border)
pub fn border_col<T: Into<ImVec4>>(mut self, border_col: T) -> Self {
self.border_col = border_col.into();
pub fn border_col(mut self, border_col: [f32; 4]) -> Self {
self.border_col = border_col;
self
}
/// Draw image where the cursor currently is
@ -79,11 +66,11 @@ impl<'ui> Image<'ui> {
unsafe {
sys::igImage(
self.texture_id.id() as *mut c_void,
self.size,
self.uv0,
self.uv1,
self.tint_col,
self.border_col,
self.size.into(),
self.uv0.into(),
self.uv1.into(),
self.tint_col.into(),
self.border_col.into(),
);
}
}
@ -96,38 +83,25 @@ impl<'ui> Image<'ui> {
#[must_use]
pub struct ImageButton<'ui> {
texture_id: TextureId,
size: ImVec2,
uv0: ImVec2,
uv1: ImVec2,
size: [f32; 2],
uv0: [f32; 2],
uv1: [f32; 2],
frame_padding: i32,
bg_col: ImVec4,
tint_col: ImVec4,
bg_col: [f32; 4],
tint_col: [f32; 4],
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui> ImageButton<'ui> {
pub fn new<S>(_: &Ui<'ui>, texture_id: TextureId, size: S) -> Self
where
S: Into<ImVec2>,
{
const DEFAULT_UV0: ImVec2 = ImVec2 { x: 0.0, y: 0.0 };
const DEFAULT_UV1: ImVec2 = ImVec2 { x: 1.0, y: 1.0 };
pub fn new(_: &Ui<'ui>, texture_id: TextureId, size: [f32; 2]) -> Self {
const DEFAULT_UV0: [f32; 2] = [0.0, 0.0];
const DEFAULT_UV1: [f32; 2] = [1.0, 1.0];
const DEFAULT_FRAME_PADDING: i32 = -1;
const DEFAULT_BG_COL: ImVec4 = ImVec4 {
x: 0.0,
y: 0.0,
z: 0.0,
w: 0.0,
};
const DEFAULT_TINT_COL: ImVec4 = ImVec4 {
x: 1.0,
y: 1.0,
z: 1.0,
w: 1.0,
};
const DEFAULT_BG_COL: [f32; 4] = [0.0, 0.0, 0.0, 0.0];
const DEFAULT_TINT_COL: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
ImageButton {
texture_id,
size: size.into(),
size: size,
uv0: DEFAULT_UV0,
uv1: DEFAULT_UV1,
frame_padding: DEFAULT_FRAME_PADDING,
@ -137,18 +111,18 @@ impl<'ui> ImageButton<'ui> {
}
}
/// Set size (default based on texture)
pub fn size<T: Into<ImVec2>>(mut self, size: T) -> Self {
self.size = size.into();
pub fn size(mut self, size: [f32; 2]) -> Self {
self.size = size;
self
}
/// Set uv0 (default `[0.0, 0.0]`)
pub fn uv0<T: Into<ImVec2>>(mut self, uv0: T) -> Self {
self.uv0 = uv0.into();
pub fn uv0(mut self, uv0: [f32; 2]) -> Self {
self.uv0 = uv0;
self
}
/// Set uv1 (default `[1.0, 1.0]`)
pub fn uv1<T: Into<ImVec2>>(mut self, uv1: T) -> Self {
self.uv1 = uv1.into();
pub fn uv1(mut self, uv1: [f32; 2]) -> Self {
self.uv1 = uv1;
self
}
/// Set frame padding (default: uses frame padding from style).
@ -160,13 +134,13 @@ impl<'ui> ImageButton<'ui> {
self
}
/// Set tint color (default: no tint color)
pub fn tint_col<T: Into<ImVec4>>(mut self, tint_col: T) -> Self {
self.tint_col = tint_col.into();
pub fn tint_col(mut self, tint_col: [f32; 4]) -> Self {
self.tint_col = tint_col;
self
}
/// Set background color (default: no background color)
pub fn background_col<T: Into<ImVec4>>(mut self, bg_col: T) -> Self {
self.bg_col = bg_col.into();
pub fn background_col(mut self, bg_col: [f32; 4]) -> Self {
self.bg_col = bg_col;
self
}
/// Draw image button where the cursor currently is
@ -174,12 +148,12 @@ impl<'ui> ImageButton<'ui> {
unsafe {
sys::igImageButton(
self.texture_id.id() as *mut c_void,
self.size,
self.uv0,
self.uv1,
self.size.into(),
self.uv0.into(),
self.uv1.into(),
self.frame_padding,
self.bg_col,
self.tint_col,
self.bg_col.into(),
self.tint_col.into(),
)
}
}

View File

@ -208,12 +208,12 @@ pub struct InputTextMultiline<'ui, 'p> {
label: &'p ImStr,
buf: &'p mut ImString,
flags: ImGuiInputTextFlags,
size: sys::ImVec2,
size: [f32; 2],
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui, 'p> InputTextMultiline<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString, size: sys::ImVec2) -> Self {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString, size: [f32; 2]) -> Self {
InputTextMultiline {
label,
buf,
@ -243,7 +243,7 @@ impl<'ui, 'p> InputTextMultiline<'ui, 'p> {
self.label.as_ptr(),
ptr,
capacity,
self.size,
self.size.into(),
self.flags.bits(),
callback,
data,

View File

@ -42,7 +42,6 @@ pub use self::sliders::{
};
pub use self::string::{ImStr, ImString};
pub use self::style::*;
pub use self::sys::{ImVec2, ImVec4};
pub use self::trees::{CollapsingHeader, TreeNode};
pub use self::window::Window;
pub use self::window_draw_list::{ChannelsSplit, ImColor, WindowDrawList};
@ -209,22 +208,22 @@ impl<'ui> Ui<'ui> {
Window::new(self, name)
}
/// Get current window's size in pixels
pub fn get_window_size(&self) -> (f32, f32) {
pub fn get_window_size(&self) -> [f32; 2] {
let size = unsafe { sys::igGetWindowSize_nonUDT2() };
size.into()
}
/// Get current window's position in pixels
pub fn get_window_pos(&self) -> (f32, f32) {
pub fn get_window_pos(&self) -> [f32; 2] {
let size = unsafe { sys::igGetWindowPos_nonUDT2() };
size.into()
}
pub fn get_window_content_region_min(&self) -> (f32, f32) {
pub fn get_window_content_region_min(&self) -> [f32; 2] {
let size = unsafe { sys::igGetWindowContentRegionMin_nonUDT2() };
size.into()
}
pub fn get_window_content_region_max(&self) -> (f32, f32) {
pub fn get_window_content_region_max(&self) -> [f32; 2] {
let size = unsafe { sys::igGetWindowContentRegionMax_nonUDT2() };
size.into()
}
@ -301,7 +300,7 @@ impl<'ui> Ui<'ui> {
/// Fill a space of `size` in pixels with nothing on the current window.
/// Can be used to move the cursor on the window.
pub fn dummy<S: Into<ImVec2>>(&self, size: S) {
pub fn dummy(&self, size: [f32; 2]) {
unsafe { sys::igDummy(size.into()) }
}
@ -310,37 +309,37 @@ impl<'ui> Ui<'ui> {
///
/// This is especially useful for drawing, as the drawing API uses
/// screen coordiantes.
pub fn get_cursor_screen_pos(&self) -> (f32, f32) {
pub fn get_cursor_screen_pos(&self) -> [f32; 2] {
let size = unsafe { sys::igGetCursorScreenPos_nonUDT2() };
size.into()
}
/// Set cursor position on the screen, in screen coordinates.
/// This sets the point on which the next widget will be drawn.
pub fn set_cursor_screen_pos<P: Into<ImVec2>>(&self, pos: P) {
pub fn set_cursor_screen_pos(&self, pos: [f32; 2]) {
unsafe { sys::igSetCursorScreenPos(pos.into()) }
}
/// Get cursor position on the screen, in window coordinates.
pub fn get_cursor_pos(&self) -> (f32, f32) {
pub fn get_cursor_pos(&self) -> [f32; 2] {
let size = unsafe { sys::igGetCursorPos_nonUDT2() };
size.into()
}
/// Set cursor position on the screen, in window coordinates.
/// This sets the point on which the next widget will be drawn.
pub fn set_cursor_pos<P: Into<ImVec2>>(&self, pos: P) {
pub fn set_cursor_pos(&self, pos: [f32; 2]) {
unsafe { sys::igSetCursorPos(pos.into()) }
}
pub fn get_content_region_max(&self) -> (f32, f32) {
pub fn get_content_region_max(&self) -> [f32; 2] {
let size = unsafe { sys::igGetContentRegionMax_nonUDT2() };
size.into()
}
/// Get available space left between the cursor and the edges of the current
/// window.
pub fn get_content_region_avail(&self) -> (f32, f32) {
pub fn get_content_region_avail(&self) -> [f32; 2] {
let size = unsafe { sys::igGetContentRegionAvail_nonUDT2() };
size.into()
}
@ -429,10 +428,7 @@ impl<'ui> Ui<'ui> {
sys::igTextUnformatted(start as *const c_char, end as *const c_char);
}
}
pub fn text_colored<'p, A>(&self, col: A, text: &'p ImStr)
where
A: Into<ImVec4>,
{
pub fn text_colored<'p>(&self, col: [f32; 4], text: &'p ImStr) {
unsafe {
sys::igTextColored(col.into(), fmt_ptr(), text.as_ptr());
}
@ -475,7 +471,7 @@ impl<'ui> Ui<'ui> {
sys::igBulletText(fmt_ptr(), text.as_ptr());
}
}
pub fn button<'p, S: Into<ImVec2>>(&self, label: &'p ImStr, size: S) -> bool {
pub fn button(&self, label: &ImStr, size: [f32; 2]) -> bool {
unsafe { sys::igButton(label.as_ptr(), size.into()) }
}
pub fn small_button<'p>(&self, label: &'p ImStr) -> bool {
@ -483,7 +479,7 @@ impl<'ui> Ui<'ui> {
}
/// Make a invisible event. Can be used to conveniently catch events when
/// mouse hovers or click the area covered by this invisible button.
pub fn invisible_button<'p, S: Into<ImVec2>>(&self, label: &'p ImStr, size: S) -> bool {
pub fn invisible_button(&self, label: &ImStr, size: [f32; 2]) -> bool {
unsafe { sys::igInvisibleButton(label.as_ptr(), size.into()) }
}
pub fn checkbox<'p>(&self, label: &'p ImStr, value: &'p mut bool) -> bool {
@ -496,11 +492,11 @@ 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>>(
pub fn input_text_multiline<'p>(
&self,
label: &'p ImStr,
buf: &'p mut ImString,
size: S,
size: [f32; 2],
) -> InputTextMultiline<'ui, 'p> {
InputTextMultiline::new(self, label, buf, size.into())
}
@ -693,11 +689,7 @@ impl<'ui> Ui<'ui> {
ColorPicker::new(self, label, value.into())
}
/// Constructs a new color button builder.
pub fn color_button<'p, C: Into<ImVec4>>(
&self,
desc_id: &'p ImStr,
color: C,
) -> ColorButton<'ui, 'p> {
pub fn color_button<'p>(&self, desc_id: &'p ImStr, color: [f32; 4]) -> ColorButton<'ui, 'p> {
ColorButton::new(self, desc_id, color.into())
}
/// Initialize current options (generally on application startup) if you want to select a
@ -722,12 +714,12 @@ impl<'ui> Ui<'ui> {
// Widgets: Selectable / Lists
impl<'ui> Ui<'ui> {
pub fn selectable<'p, S: Into<ImVec2>>(
pub fn selectable(
&self,
label: &'p ImStr,
label: &ImStr,
selected: bool,
flags: ImGuiSelectableFlags,
size: S,
size: [f32; 2],
) -> bool {
unsafe { sys::igSelectable(label.as_ptr(), selected, flags.bits(), size.into()) }
}
@ -747,7 +739,7 @@ impl<'ui> Ui<'ui> {
/// ui.text("Hover over me");
/// if ui.is_item_hovered() {
/// ui.tooltip(|| {
/// ui.text_colored((1.0, 0.0, 0.0, 1.0), im_str!("I'm red!"));
/// ui.text_colored([1.0, 0.0, 0.0, 1.0], im_str!("I'm red!"));
/// });
/// }
/// }
@ -834,12 +826,12 @@ impl<'ui> Ui<'ui> {
/// # use imgui::*;
/// # let mut imgui = Context::create();
/// # let ui = imgui.frame();
/// if ui.button(im_str!("Show modal"), (0.0, 0.0)) {
/// if ui.button(im_str!("Show modal"), [0.0, 0.0]) {
/// ui.open_popup(im_str!("modal"));
/// }
/// ui.popup_modal(im_str!("modal")).build(|| {
/// ui.text("Content of my modal");
/// if ui.button(im_str!("OK"), (0.0, 0.0)) {
/// if ui.button(im_str!("OK"), [0.0, 0.0]) {
/// ui.close_current_popup();
/// }
/// });
@ -962,20 +954,14 @@ impl<'ui> Ui<'ui> {
// Image
impl<'ui> Ui<'ui> {
pub fn image<S>(&self, texture: TextureId, size: S) -> Image
where
S: Into<ImVec2>,
{
pub fn image(&self, texture: TextureId, size: [f32; 2]) -> Image {
Image::new(self, texture, size)
}
}
// ImageButton
impl<'ui> Ui<'ui> {
pub fn image_button<S>(&self, texture: TextureId, size: S) -> ImageButton
where
S: Into<ImVec2>,
{
pub fn image_button(&self, texture: TextureId, size: [f32; 2]) -> ImageButton {
ImageButton::new(self, texture, size)
}
}
@ -992,8 +978,8 @@ impl<'ui> Ui<'ui> {
text: &ImStr,
hide_text_after_double_hash: bool,
wrap_width: f32,
) -> ImVec2 {
let result: [f32; 2] = unsafe {
) -> [f32; 2] {
unsafe {
sys::igCalcTextSize_nonUDT2(
text.as_ptr(),
std::ptr::null(),
@ -1001,8 +987,7 @@ impl<'ui> Ui<'ui> {
wrap_width,
)
.into()
};
result.into()
}
}
}
@ -1012,7 +997,7 @@ impl<'ui> Ui<'ui> {
unsafe { sys::igGetTextLineHeightWithSpacing() }
}
/// Get previously drawn item's size
pub fn get_item_rect_size(&self) -> (f32, f32) {
pub fn get_item_rect_size(&self) -> [f32; 2] {
let size = unsafe { sys::igGetItemRectSize_nonUDT2() };
size.into()
}
@ -1027,7 +1012,7 @@ impl<'ui> Ui<'ui> {
/// # let mut imgui = Context::create();
/// # let ui = imgui.frame();
/// ui.progress_bar(0.6)
/// .size((100.0, 12.0))
/// .size([100.0, 12.0])
/// .overlay_text(im_str!("Progress!"))
/// .build();
/// ```
@ -1050,19 +1035,15 @@ impl<'ui> Ui<'ui> {
/// .build(|| {
/// ui.separator();
///
/// ui.child_frame(im_str!("child frame"), (400.0, 100.0))
/// ui.child_frame(im_str!("child frame"), [400.0, 100.0])
/// .show_borders(true)
/// .always_show_vertical_scroll_bar(true)
/// .build(|| {
/// ui.text_colored((1.0, 0.0, 0.0, 1.0), im_str!("hello mate!"));
/// ui.text_colored([1.0, 0.0, 0.0, 1.0], im_str!("hello mate!"));
/// });
/// });
pub fn child_frame<'p, S: Into<ImVec2>>(
&self,
name: &'p ImStr,
size: S,
) -> ChildFrame<'ui, 'p> {
ChildFrame::new(self, name, size.into())
pub fn child_frame<'p>(&self, name: &'p ImStr, size: [f32; 2]) -> ChildFrame<'ui, 'p> {
ChildFrame::new(self, name, size)
}
}
@ -1196,12 +1177,7 @@ impl<'ui> Ui<'ui> {
/// ui.text_wrapped(im_str!("AB"));
/// });
/// ```
pub fn with_color_var<F: FnOnce(), C: Into<ImVec4> + Copy>(
&self,
var: StyleColor,
color: C,
f: F,
) {
pub fn with_color_var<F: FnOnce()>(&self, var: StyleColor, color: [f32; 4], f: F) {
unsafe {
sys::igPushStyleColor(var as _, color.into());
}
@ -1225,11 +1201,7 @@ impl<'ui> Ui<'ui> {
/// ui.text_wrapped(im_str!("AB"));
/// });
/// ```
pub fn with_color_vars<F: FnOnce(), C: Into<ImVec4> + Copy>(
&self,
color_vars: &[(StyleColor, C)],
f: F,
) {
pub fn with_color_vars<F: FnOnce()>(&self, color_vars: &[(StyleColor, [f32; 4])], f: F) {
for &(color_var, color) in color_vars {
unsafe {
sys::igPushStyleColor(color_var as _, color.into());
@ -1243,14 +1215,13 @@ impl<'ui> Ui<'ui> {
impl<'ui> Ui<'ui> {
/// Runs a function after temporarily pushing an array of values to the
/// style and color stack.
pub fn with_style_and_color_vars<F, C>(
pub fn with_style_and_color_vars<F>(
&self,
style_vars: &[StyleVar],
color_vars: &[(StyleColor, C)],
color_vars: &[(StyleColor, [f32; 4])],
f: F,
) where
F: FnOnce(),
C: Into<ImVec4> + Copy,
{
self.with_style_vars(style_vars, || {
self.with_color_vars(color_vars, f);

View File

@ -3,7 +3,7 @@ use std::os::raw::c_float;
use std::{f32, mem, ptr};
use sys;
use super::{ImStr, ImVec2, Ui};
use super::{ImStr, Ui};
#[must_use]
pub struct PlotHistogram<'ui, 'p> {
@ -13,7 +13,7 @@ pub struct PlotHistogram<'ui, 'p> {
overlay_text: Option<&'p ImStr>,
scale_min: f32,
scale_max: f32,
graph_size: ImVec2,
graph_size: [f32; 2],
_phantom: PhantomData<&'ui Ui<'ui>>,
}
@ -26,7 +26,7 @@ impl<'ui, 'p> PlotHistogram<'ui, 'p> {
overlay_text: None,
scale_min: f32::MAX,
scale_max: f32::MAX,
graph_size: ImVec2::new(0.0f32, 0.0f32),
graph_size: [0.0, 0.0],
_phantom: PhantomData,
}
}
@ -56,8 +56,8 @@ impl<'ui, 'p> PlotHistogram<'ui, 'p> {
}
#[inline]
pub fn graph_size<S: Into<ImVec2>>(mut self, graph_size: S) -> Self {
self.graph_size = graph_size.into();
pub fn graph_size(mut self, graph_size: [f32; 2]) -> Self {
self.graph_size = graph_size;
self
}
@ -71,7 +71,7 @@ impl<'ui, 'p> PlotHistogram<'ui, 'p> {
self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()),
self.scale_min,
self.scale_max,
self.graph_size,
self.graph_size.into(),
mem::size_of::<f32>() as i32,
);
}

View File

@ -3,7 +3,7 @@ use std::os::raw::c_float;
use std::{f32, mem, ptr};
use sys;
use super::{ImStr, ImVec2, Ui};
use super::{ImStr, Ui};
#[must_use]
pub struct PlotLines<'ui, 'p> {
@ -13,7 +13,7 @@ pub struct PlotLines<'ui, 'p> {
overlay_text: Option<&'p ImStr>,
scale_min: f32,
scale_max: f32,
graph_size: ImVec2,
graph_size: [f32; 2],
_phantom: PhantomData<&'ui Ui<'ui>>,
}
@ -26,7 +26,7 @@ impl<'ui, 'p> PlotLines<'ui, 'p> {
overlay_text: None,
scale_min: f32::MAX,
scale_max: f32::MAX,
graph_size: ImVec2::new(0.0f32, 0.0f32),
graph_size: [0.0, 0.0],
_phantom: PhantomData,
}
}
@ -56,8 +56,8 @@ impl<'ui, 'p> PlotLines<'ui, 'p> {
}
#[inline]
pub fn graph_size<S: Into<ImVec2>>(mut self, graph_size: S) -> Self {
self.graph_size = graph_size.into();
pub fn graph_size(mut self, graph_size: [f32; 2]) -> Self {
self.graph_size = graph_size;
self
}
@ -71,7 +71,7 @@ impl<'ui, 'p> PlotLines<'ui, 'p> {
self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()),
self.scale_min,
self.scale_max,
self.graph_size,
self.graph_size.into(),
mem::size_of::<f32>() as i32,
);
}

View File

@ -3,13 +3,13 @@ use std::marker::PhantomData;
use std::ptr;
use sys;
use super::{ImStr, ImVec2, Ui};
use super::{ImStr, Ui};
/// Progress bar widget.
#[must_use]
pub struct ProgressBar<'ui, 'p> {
fraction: f32,
size: ImVec2,
size: [f32; 2],
overlay_text: Option<&'p ImStr>,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
@ -23,7 +23,7 @@ impl<'ui, 'p> ProgressBar<'ui, 'p> {
pub fn new(_: &Ui<'ui>, fraction: f32) -> Self {
ProgressBar {
fraction,
size: ImVec2::new(-1.0, 0.0),
size: [-1.0, 0.0],
overlay_text: None,
_phantom: PhantomData,
}
@ -40,8 +40,8 @@ impl<'ui, 'p> ProgressBar<'ui, 'p> {
/// align to the end of the axis, zero will let the progress bar choose a
/// size and positive values will use the given size.
#[inline]
pub fn size<S: Into<ImVec2>>(mut self, size: S) -> Self {
self.size = size.into();
pub fn size(mut self, size: [f32; 2]) -> Self {
self.size = size;
self
}
@ -51,7 +51,7 @@ impl<'ui, 'p> ProgressBar<'ui, 'p> {
unsafe {
sys::igProgressBar(
self.fraction,
self.size,
self.size.into(),
self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()),
);
}

View File

@ -7,10 +7,10 @@ use crate::{Condition, ImStr, Ui};
#[must_use]
pub struct Window<'ui, 'p> {
pos: (f32, f32),
pos: [f32; 2],
pos_cond: Condition,
pos_pivot: (f32, f32),
size: (f32, f32),
pos_pivot: [f32; 2],
size: [f32; 2],
size_cond: Condition,
name: &'p ImStr,
opened: Option<&'p mut bool>,
@ -21,10 +21,10 @@ pub struct Window<'ui, 'p> {
impl<'ui, 'p> Window<'ui, 'p> {
pub fn new(_: &Ui<'ui>, name: &'p ImStr) -> Window<'ui, 'p> {
Window {
pos: (0.0, 0.0),
pos: [0.0, 0.0],
pos_cond: Condition::Never,
pos_pivot: (0.0, 0.0),
size: (0.0, 0.0),
pos_pivot: [0.0, 0.0],
size: [0.0, 0.0],
size_cond: Condition::Never,
name,
opened: None,
@ -33,18 +33,18 @@ impl<'ui, 'p> Window<'ui, 'p> {
}
}
#[inline]
pub fn position(mut self, pos: (f32, f32), cond: Condition) -> Self {
pub fn position(mut self, pos: [f32; 2], cond: Condition) -> Self {
self.pos = pos;
self.pos_cond = cond;
self
}
#[inline]
pub fn position_pivot(mut self, pivot: (f32, f32)) -> Self {
pub fn position_pivot(mut self, pivot: [f32; 2]) -> Self {
self.pos_pivot = pivot;
self
}
#[inline]
pub fn size(mut self, size: (f32, f32), cond: Condition) -> Self {
pub fn size(mut self, size: [f32; 2], cond: Condition) -> Self {
self.size = size;
self.size_cond = cond;
self

View File

@ -1,7 +1,7 @@
use sys;
use sys::{ImDrawList, ImU32};
use super::{ImVec2, ImVec4, Ui};
use super::Ui;
use crate::legacy::ImDrawCornerFlags;
use std::marker::PhantomData;
@ -28,12 +28,6 @@ impl From<ImU32> for ImColor {
}
}
impl From<ImVec4> for ImColor {
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()) })
@ -149,10 +143,8 @@ impl<'ui> ChannelsSplit<'ui> {
/// Drawing functions
impl<'ui> WindowDrawList<'ui> {
/// Returns a line from point `p1` to `p2` with color `c`.
pub fn add_line<P1, P2, C>(&'ui self, p1: P1, p2: P2, c: C) -> Line<'ui>
pub fn add_line<C>(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Line<'ui>
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
C: Into<ImColor>,
{
Line::new(self, p1, p2, c)
@ -160,10 +152,8 @@ impl<'ui> WindowDrawList<'ui> {
/// Returns a rectangle whose upper-left corner is at point `p1`
/// and lower-right corner is at point `p2`, with color `c`.
pub fn add_rect<P1, P2, C>(&'ui self, p1: P1, p2: P2, c: C) -> Rect<'ui>
pub fn add_rect<C>(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Rect<'ui>
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
C: Into<ImColor>,
{
Rect::new(self, p1, p2, c)
@ -174,17 +164,15 @@ impl<'ui> WindowDrawList<'ui> {
/// The remains parameters are the respective color of the corners
/// in the counter-clockwise starting from the upper-left corner
/// first.
pub fn add_rect_filled_multicolor<P1, P2, C1, C2, C3, C4>(
pub fn add_rect_filled_multicolor<C1, C2, C3, C4>(
&self,
p1: P1,
p2: P2,
p1: [f32; 2],
p2: [f32; 2],
col_upr_left: C1,
col_upr_right: C2,
col_bot_right: C3,
col_bot_left: C4,
) where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
C1: Into<ImColor>,
C2: Into<ImColor>,
C3: Into<ImColor>,
@ -205,29 +193,30 @@ impl<'ui> WindowDrawList<'ui> {
/// Returns a triangle with the given 3 vertices `p1`, `p2` and `p3`
/// and color `c`.
pub fn add_triangle<P1, P2, P3, C>(&'ui self, p1: P1, p2: P2, p3: P3, c: C) -> Triangle<'ui>
pub fn add_triangle<C>(
&'ui self,
p1: [f32; 2],
p2: [f32; 2],
p3: [f32; 2],
c: C,
) -> Triangle<'ui>
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
P3: Into<ImVec2>,
C: Into<ImColor>,
{
Triangle::new(self, p1, p2, p3, c)
}
/// Returns a circle with the given `center`, `radius` and `color`.
pub fn add_circle<P, C>(&'ui self, center: P, radius: f32, color: C) -> Circle<'ui>
pub fn add_circle<C>(&'ui self, center: [f32; 2], radius: f32, color: C) -> Circle<'ui>
where
P: Into<ImVec2>,
C: Into<ImColor>,
{
Circle::new(self, center, radius, color)
}
/// Draw a text whose upper-left corner is at point `pos`.
pub fn add_text<P, C, T>(&self, pos: P, col: C, text: T)
pub fn add_text<C, T>(&self, pos: [f32; 2], col: C, text: T)
where
P: Into<ImVec2>,
C: Into<ImColor>,
T: AsRef<str>,
{
@ -243,19 +232,15 @@ impl<'ui> WindowDrawList<'ui> {
/// Returns a Bezier curve stretching from `pos0` to `pos1`, whose
/// curvature is defined by `cp0` and `cp1`.
pub fn add_bezier_curve<P1, P2, P3, P4, C>(
pub fn add_bezier_curve<C>(
&'ui self,
pos0: P1,
cp0: P2,
cp1: P3,
pos1: P4,
pos0: [f32; 2],
cp0: [f32; 2],
cp1: [f32; 2],
pos1: [f32; 2],
color: C,
) -> BezierCurve<'ui>
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
P3: Into<ImVec2>,
P4: Into<ImVec2>,
C: Into<ImColor>,
{
BezierCurve::new(self, pos0, cp0, cp1, pos1, color)
@ -265,10 +250,8 @@ impl<'ui> WindowDrawList<'ui> {
///
/// Clip all drawings done within the closure `f` in the given
/// rectangle.
pub fn with_clip_rect<P1, P2, F>(&self, min: P1, max: P2, f: F)
pub fn with_clip_rect<F>(&self, min: [f32; 2], max: [f32; 2], f: F)
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
F: FnOnce(),
{
unsafe { sys::ImDrawList_PushClipRect(self.draw_list, min.into(), max.into(), false) }
@ -281,10 +264,8 @@ impl<'ui> WindowDrawList<'ui> {
/// Clip all drawings done within the closure `f` in the given
/// rectangle. Intersect with all clipping rectangle previously on
/// the stack.
pub fn with_clip_rect_intersect<P1, P2, F>(&self, min: P1, max: P2, f: F)
pub fn with_clip_rect_intersect<F>(&self, min: [f32; 2], max: [f32; 2], f: F)
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
F: FnOnce(),
{
unsafe { sys::ImDrawList_PushClipRect(self.draw_list, min.into(), max.into(), true) }
@ -296,23 +277,21 @@ impl<'ui> WindowDrawList<'ui> {
/// Represents a line about to be drawn
#[must_use = "should call .build() to draw the object"]
pub struct Line<'ui> {
p1: ImVec2,
p2: ImVec2,
p1: [f32; 2],
p2: [f32; 2],
color: ImColor,
thickness: f32,
draw_list: &'ui WindowDrawList<'ui>,
}
impl<'ui> Line<'ui> {
fn new<P1, P2, C>(draw_list: &'ui WindowDrawList, p1: P1, p2: P2, c: C) -> Self
fn new<C>(draw_list: &'ui WindowDrawList, p1: [f32; 2], p2: [f32; 2], c: C) -> Self
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
C: Into<ImColor>,
{
Self {
p1: p1.into(),
p2: p2.into(),
p1,
p2,
color: c.into(),
thickness: 1.0,
draw_list,
@ -330,8 +309,8 @@ impl<'ui> Line<'ui> {
unsafe {
sys::ImDrawList_AddLine(
self.draw_list.draw_list,
self.p1,
self.p2,
self.p1.into(),
self.p2.into(),
self.color.into(),
self.thickness,
)
@ -342,8 +321,8 @@ impl<'ui> Line<'ui> {
/// Represents a rectangle about to be drawn
#[must_use = "should call .build() to draw the object"]
pub struct Rect<'ui> {
p1: ImVec2,
p2: ImVec2,
p1: [f32; 2],
p2: [f32; 2],
color: ImColor,
rounding: f32,
flags: ImDrawCornerFlags,
@ -353,15 +332,13 @@ pub struct Rect<'ui> {
}
impl<'ui> Rect<'ui> {
fn new<P1, P2, C>(draw_list: &'ui WindowDrawList, p1: P1, p2: P2, c: C) -> Self
fn new<C>(draw_list: &'ui WindowDrawList, p1: [f32; 2], p2: [f32; 2], c: C) -> Self
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
C: Into<ImColor>,
{
Self {
p1: p1.into(),
p2: p2.into(),
p1,
p2,
color: c.into(),
rounding: 0.0,
flags: ImDrawCornerFlags::All,
@ -420,8 +397,8 @@ impl<'ui> Rect<'ui> {
unsafe {
sys::ImDrawList_AddRectFilled(
self.draw_list.draw_list,
self.p1,
self.p2,
self.p1.into(),
self.p2.into(),
self.color.into(),
self.rounding,
self.flags.bits(),
@ -431,8 +408,8 @@ impl<'ui> Rect<'ui> {
unsafe {
sys::ImDrawList_AddRect(
self.draw_list.draw_list,
self.p1,
self.p2,
self.p1.into(),
self.p2.into(),
self.color.into(),
self.rounding,
self.flags.bits(),
@ -446,9 +423,9 @@ impl<'ui> Rect<'ui> {
/// Represents a triangle about to be drawn on the window
#[must_use = "should call .build() to draw the object"]
pub struct Triangle<'ui> {
p1: ImVec2,
p2: ImVec2,
p3: ImVec2,
p1: [f32; 2],
p2: [f32; 2],
p3: [f32; 2],
color: ImColor,
thickness: f32,
filled: bool,
@ -456,17 +433,20 @@ pub struct Triangle<'ui> {
}
impl<'ui> Triangle<'ui> {
fn new<P1, P2, P3, C>(draw_list: &'ui WindowDrawList, p1: P1, p2: P2, p3: P3, c: C) -> Self
fn new<C>(
draw_list: &'ui WindowDrawList,
p1: [f32; 2],
p2: [f32; 2],
p3: [f32; 2],
c: C,
) -> Self
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
P3: Into<ImVec2>,
C: Into<ImColor>,
{
Self {
p1: p1.into(),
p2: p2.into(),
p3: p3.into(),
p1,
p2,
p3,
color: c.into(),
thickness: 1.0,
filled: false,
@ -492,9 +472,9 @@ impl<'ui> Triangle<'ui> {
unsafe {
sys::ImDrawList_AddTriangleFilled(
self.draw_list.draw_list,
self.p1,
self.p2,
self.p3,
self.p1.into(),
self.p2.into(),
self.p3.into(),
self.color.into(),
)
}
@ -502,9 +482,9 @@ impl<'ui> Triangle<'ui> {
unsafe {
sys::ImDrawList_AddTriangle(
self.draw_list.draw_list,
self.p1,
self.p2,
self.p3,
self.p1.into(),
self.p2.into(),
self.p3.into(),
self.color.into(),
self.thickness,
)
@ -516,7 +496,7 @@ impl<'ui> Triangle<'ui> {
/// Represents a circle about to be drawn
#[must_use = "should call .build() to draw the object"]
pub struct Circle<'ui> {
center: ImVec2,
center: [f32; 2],
radius: f32,
color: ImColor,
num_segments: u32,
@ -526,13 +506,12 @@ pub struct Circle<'ui> {
}
impl<'ui> Circle<'ui> {
pub fn new<P, C>(draw_list: &'ui WindowDrawList, center: P, radius: f32, color: C) -> Self
pub fn new<C>(draw_list: &'ui WindowDrawList, center: [f32; 2], radius: f32, color: C) -> Self
where
P: Into<ImVec2>,
C: Into<ImColor>,
{
Self {
center: center.into(),
center,
radius,
color: color.into(),
num_segments: 12,
@ -567,7 +546,7 @@ impl<'ui> Circle<'ui> {
unsafe {
sys::ImDrawList_AddCircleFilled(
self.draw_list.draw_list,
self.center,
self.center.into(),
self.radius,
self.color.into(),
self.num_segments as i32,
@ -577,7 +556,7 @@ impl<'ui> Circle<'ui> {
unsafe {
sys::ImDrawList_AddCircle(
self.draw_list.draw_list,
self.center,
self.center.into(),
self.radius,
self.color.into(),
self.num_segments as i32,
@ -591,10 +570,10 @@ impl<'ui> Circle<'ui> {
/// Represents a Bezier curve about to be drawn
#[must_use = "should call .build() to draw the object"]
pub struct BezierCurve<'ui> {
pos0: ImVec2,
cp0: ImVec2,
pos1: ImVec2,
cp1: ImVec2,
pos0: [f32; 2],
cp0: [f32; 2],
pos1: [f32; 2],
cp1: [f32; 2],
color: ImColor,
thickness: f32,
/// If num_segments is not set, the bezier curve is auto-tessalated.
@ -603,26 +582,22 @@ pub struct BezierCurve<'ui> {
}
impl<'ui> BezierCurve<'ui> {
fn new<P1, P2, P3, P4, C>(
fn new<C>(
draw_list: &'ui WindowDrawList,
pos0: P1,
cp0: P2,
cp1: P3,
pos1: P4,
pos0: [f32; 2],
cp0: [f32; 2],
cp1: [f32; 2],
pos1: [f32; 2],
c: C,
) -> Self
where
P1: Into<ImVec2>,
P2: Into<ImVec2>,
P3: Into<ImVec2>,
P4: Into<ImVec2>,
C: Into<ImColor>,
{
Self {
pos0: pos0.into(),
cp0: cp0.into(),
pos1: pos1.into(),
cp1: cp1.into(),
pos0,
cp0,
cp1,
pos1,
color: c.into(),
thickness: 1.0,
num_segments: None,
@ -648,10 +623,10 @@ impl<'ui> BezierCurve<'ui> {
unsafe {
sys::ImDrawList_AddBezierCurve(
self.draw_list.draw_list,
self.pos0,
self.cp0,
self.cp1,
self.pos1,
self.pos0.into(),
self.cp0.into(),
self.cp1.into(),
self.pos1.into(),
self.color.into(),
self.thickness,
self.num_segments.unwrap_or(0) as i32,