From 00d818067110bd3b5bf772e3bfb4a31f066cbda1 Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 10 Feb 2021 14:56:26 +1100 Subject: [PATCH 01/24] Add `DrawListMut::add_image` and friends --- imgui-examples/examples/custom_textures.rs | 85 +++++- imgui/src/draw_list.rs | 323 +++++++++++++++++++++ 2 files changed, 407 insertions(+), 1 deletion(-) diff --git a/imgui-examples/examples/custom_textures.rs b/imgui-examples/examples/custom_textures.rs index 5080ffa..2593a9d 100644 --- a/imgui-examples/examples/custom_textures.rs +++ b/imgui-examples/examples/custom_textures.rs @@ -79,7 +79,7 @@ impl CustomTexturesApp { fn show_textures(&self, ui: &Ui) { Window::new(im_str!("Hello textures")) - .size([400.0, 600.0], Condition::FirstUseEver) + .size([400.0, 400.0], Condition::FirstUseEver) .build(ui, || { ui.text(im_str!("Hello textures!")); if let Some(my_texture_id) = self.my_texture_id { @@ -91,6 +91,89 @@ impl CustomTexturesApp { ui.text("Say hello to Lenna.jpg"); lenna.show(ui); } + + // Example of using custom textures on a button + if let Some(lenna) = &self.lenna { + ui.text("The Lenna buttons"); + + { + let _is_clicked = + ui.invisible_button(im_str!("Boring Button"), [100.0, 100.0]); + // See also `imgui::Ui::style_color` + let tint_none = [1.0, 1.0, 1.0, 1.0]; + let tint_green = [0.5, 1.0, 0.5, 1.0]; + let tint_red = [1.0, 0.5, 0.5, 1.0]; + + let tint = match ( + ui.is_item_hovered(), + ui.is_mouse_down(imgui::MouseButton::Left), + ) { + (false, false) => tint_none, + (false, true) => tint_none, + (true, false) => tint_green, + (true, true) => tint_red, + }; + + let draw_list = ui.get_window_draw_list(); + draw_list + .add_image(lenna.texture_id, ui.item_rect_min(), ui.item_rect_max()) + .col(tint) + .build(); + } + + { + ui.same_line(0.0); + + // Button using quad positioned image + let is_clicked = + ui.invisible_button(im_str!("Exciting Button"), [100.0, 100.0]); + + // Button bounds + let min = ui.item_rect_min(); + let max = ui.item_rect_max(); + + // get corner coordinates + let tl = [ + min[0], + min[1] + (ui.frame_count() as f32 / 10.0).cos() * 10.0, + ]; + let tr = [ + max[0], + min[1] + (ui.frame_count() as f32 / 10.0).sin() * 10.0, + ]; + let bl = [min[0], max[1]]; + let br = max; + + let draw_list = ui.get_window_draw_list(); + draw_list + .add_image_quad(lenna.texture_id, tl, tr, br, bl) + .build(); + } + + // Rounded image + { + ui.same_line(0.0); + let is_clicked = + ui.invisible_button(im_str!("Smooth Button"), [100.0, 100.0]); + + let draw_list = ui.get_window_draw_list(); + draw_list + .add_image_rounded( + lenna.texture_id, + ui.item_rect_min(), + ui.item_rect_max(), + 16.0, + ) + // Tint brighter for visiblity of corners + .col([2.0, 0.5, 0.5, 1.0]) + // Rounding on each corner can be changed separately + .round_top_left((ui.frame_count()+0) / 60 % 4 == 0) + .round_top_right((ui.frame_count()+1) / 60 % 4 == 1) + .round_bot_right((ui.frame_count()+3) / 60 % 4 == 2) + .round_bot_left((ui.frame_count()+2) / 60 % 4 == 3) + .build(); + } + } }); } } diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index b117dc7..8626fcb 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -3,6 +3,7 @@ use sys::ImDrawList; use super::Ui; use crate::legacy::ImDrawCornerFlags; +use crate::render::renderer::TextureId; use std::marker::PhantomData; @@ -251,6 +252,66 @@ impl<'ui> DrawListMut<'ui> { } } +/// # Images +impl<'ui> DrawListMut<'ui> { + /// Draw the specified image in the rect specified by `p_min` to + /// `p_max`. + /// + /// # Examples + /// + /// ``` + /// # use imgui::*; + /// fn custom_button(ui: &Ui, img_id: TextureId) { + /// // Tint image red + /// + /// // Invisible button is good widget to customise with custom image + /// ui.invisible_button(im_str!("custom_button"), [100.0, 20.0]); + /// + /// // Red tint when button is hovered, no tint otherwise + /// let overlay_color = if ui.is_item_hovered() { + /// [1.0, 0.6, 0.6, 1.0] + /// } else { + /// [1.0, 1.0, 1.0, 1.0] + /// }; + /// + /// // Get draw list and draw image over invisible button + /// let draw_list = ui.get_window_draw_list(); + /// draw_list + /// .add_image(img_id, ui.item_rect_min(), ui.item_rect_max()) + /// .col(overlay_color) + /// .build(); + /// } + /// ``` + pub fn add_image(&'ui self, texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2]) -> Image { + Image::new(self, texture_id, p_min, p_max) + } + + /// Draw the specified image to a quad with the specified + /// coordinates. Similar to [`DrawListMut::add_image`] but this + /// method is able to draw non-rectangle images. + pub fn add_image_quad( + &'ui self, + texture_id: TextureId, + p1: [f32; 2], + p2: [f32; 2], + p3: [f32; 2], + p4: [f32; 2], + ) -> ImageQuad { + ImageQuad::new(self, texture_id, p1, p2, p3, p4) + } + + /// Draw the speciied image, with rounded corners + pub fn add_image_rounded( + &'ui self, + texture_id: TextureId, + p_min: [f32; 2], + p_max: [f32; 2], + rounding: f32, + ) -> ImageRounded { + ImageRounded::new(self, texture_id, p_min, p_max, rounding) + } +} + /// Represents a line about to be drawn #[must_use = "should call .build() to draw the object"] pub struct Line<'ui> { @@ -605,3 +666,265 @@ impl<'ui> BezierCurve<'ui> { } } } + +/// Represents a image about to be drawn +#[must_use = "should call .build() to draw the object"] +pub struct Image<'ui> { + texture_id: TextureId, + p_min: [f32; 2], + p_max: [f32; 2], + uv_min: [f32; 2], + uv_max: [f32; 2], + col: ImColor32, + draw_list: &'ui DrawListMut<'ui>, +} + +impl<'ui> Image<'ui> { + fn new( + draw_list: &'ui DrawListMut, + texture_id: TextureId, + p_min: [f32; 2], + p_max: [f32; 2], + ) -> Self { + Self { + texture_id, + p_min, + p_max, + uv_min: [0.0, 0.0], + uv_max: [1.0, 1.0], + col: [1.0, 1.0, 1.0, 1.0].into(), + draw_list, + } + } + + /// Set uv_min (default `[0.0, 0.0]`) + pub fn uv_min(mut self, uv_min: [f32; 2]) -> Self { + self.uv_min = uv_min; + self + } + /// Set uv_max (default `[1.0, 1.0]`) + pub fn uv_max(mut self, uv_max: [f32; 2]) -> Self { + self.uv_max = uv_max; + self + } + + /// Set color tint (default: no tint/white `[1.0, 1.0, 1.0, 1.0]`) + pub fn col(mut self, col: C) -> Self + where + C: Into, + { + self.col = col.into(); + self + } + + /// Draw the image on the window. + pub fn build(self) { + use std::os::raw::c_void; + + unsafe { + sys::ImDrawList_AddImage( + self.draw_list.draw_list, + self.texture_id.id() as *mut c_void, + self.p_min.into(), + self.p_max.into(), + self.uv_min.into(), + self.uv_max.into(), + self.col.into(), + ); + } + } +} + +/// Represents a image about to be drawn +#[must_use = "should call .build() to draw the object"] +pub struct ImageQuad<'ui> { + texture_id: TextureId, + p1: [f32; 2], + p2: [f32; 2], + p3: [f32; 2], + p4: [f32; 2], + uv1: [f32; 2], + uv2: [f32; 2], + uv3: [f32; 2], + uv4: [f32; 2], + col: ImColor32, + draw_list: &'ui DrawListMut<'ui>, +} + +impl<'ui> ImageQuad<'ui> { + fn new( + draw_list: &'ui DrawListMut, + texture_id: TextureId, + p1: [f32; 2], + p2: [f32; 2], + p3: [f32; 2], + p4: [f32; 2], + ) -> Self { + Self { + texture_id, + p1, + p2, + p3, + p4, + uv1: [0.0, 0.0], + uv2: [1.0, 0.0], + uv3: [1.0, 1.0], + uv4: [0.0, 1.0], + col: [1.0, 1.0, 1.0, 1.0].into(), + draw_list, + } + } + + /// Set uv coordinates of each point of the quad. If not called, defaults are: + /// + /// ``` + /// uv1: [0, 0], + /// uv2: [1, 0], + /// uv3: [1, 1], + /// uv4: [0, 1], + /// ``` + pub fn uv(mut self, uv1: [f32; 2], uv2: [f32; 2], uv3: [f32; 2], uv4: [f32; 2]) -> Self { + self.uv1 = uv1; + self.uv2 = uv2; + self.uv3 = uv3; + self.uv4 = uv4; + self + } + + /// Set color tint (default: no tint/white `[1.0, 1.0, 1.0, 1.0]`) + pub fn col(mut self, col: C) -> Self + where + C: Into, + { + self.col = col.into(); + self + } + + /// Draw the image on the window. + pub fn build(self) { + use std::os::raw::c_void; + + unsafe { + sys::ImDrawList_AddImageQuad( + self.draw_list.draw_list, + self.texture_id.id() as *mut c_void, + self.p1.into(), + self.p2.into(), + self.p3.into(), + self.p4.into(), + self.uv1.into(), + self.uv2.into(), + self.uv3.into(), + self.uv4.into(), + self.col.into(), + ); + } + } +} + +/// Represents a image about to be drawn +#[must_use = "should call .build() to draw the object"] +pub struct ImageRounded<'ui> { + texture_id: TextureId, + p_min: [f32; 2], + p_max: [f32; 2], + uv_min: [f32; 2], + uv_max: [f32; 2], + col: ImColor32, + rounding: f32, + rounding_corners: ImDrawCornerFlags, + draw_list: &'ui DrawListMut<'ui>, +} + +impl<'ui> ImageRounded<'ui> { + fn new( + draw_list: &'ui DrawListMut, + texture_id: TextureId, + p_min: [f32; 2], + p_max: [f32; 2], + rounding: f32, + ) -> Self { + Self { + texture_id, + p_min, + p_max, + uv_min: [0.0, 0.0], + uv_max: [1.0, 1.0], + col: [1.0, 1.0, 1.0, 1.0].into(), + rounding, + rounding_corners: ImDrawCornerFlags::All, + draw_list, + } + } + + /// Set uv_min (default `[0.0, 0.0]`) + pub fn uv_min(mut self, uv_min: [f32; 2]) -> Self { + self.uv_min = uv_min; + self + } + /// Set uv_max (default `[1.0, 1.0]`) + pub fn uv_max(mut self, uv_max: [f32; 2]) -> Self { + self.uv_max = uv_max; + self + } + + /// Set color tint (default: no tint/white `[1.0, 1.0, 1.0, 1.0]`) + pub fn col(mut self, col: C) -> Self + where + C: Into, + { + self.col = col.into(); + self + } + + /// Set flag to indicate rounding on all all corners. + pub fn round_all(mut self, value: bool) -> Self { + self.rounding_corners.set(ImDrawCornerFlags::All, value); + self + } + + /// Set flag to indicate if image's top-left corner will be rounded. + pub fn round_top_left(mut self, value: bool) -> Self { + self.rounding_corners.set(ImDrawCornerFlags::TopLeft, value); + self + } + + /// Set flag to indicate if image's top-right corner will be rounded. + pub fn round_top_right(mut self, value: bool) -> Self { + self.rounding_corners + .set(ImDrawCornerFlags::TopRight, value); + self + } + + /// Set flag to indicate if image's bottom-left corner will be rounded. + pub fn round_bot_left(mut self, value: bool) -> Self { + self.rounding_corners.set(ImDrawCornerFlags::BotLeft, value); + self + } + + /// Set flag to indicate if image's bottom-right corner will be rounded. + pub fn round_bot_right(mut self, value: bool) -> Self { + self.rounding_corners + .set(ImDrawCornerFlags::BotRight, value); + self + } + + /// Draw the image on the window. + pub fn build(self) { + use std::os::raw::c_void; + + unsafe { + sys::ImDrawList_AddImageRounded( + self.draw_list.draw_list, + self.texture_id.id() as *mut c_void, + self.p_min.into(), + self.p_max.into(), + self.uv_min.into(), + self.uv_max.into(), + self.col.into(), + self.rounding.into(), + self.rounding_corners.bits(), + ); + } + } +} From eccc537abe8d4e6ca4c06b8f0aa60eb15c511ec2 Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 10 Feb 2021 14:56:37 +1100 Subject: [PATCH 02/24] Update link in docs --- imgui/src/fonts/glyph_ranges.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui/src/fonts/glyph_ranges.rs b/imgui/src/fonts/glyph_ranges.rs index 4ba7c45..dcadeb0 100644 --- a/imgui/src/fonts/glyph_ranges.rs +++ b/imgui/src/fonts/glyph_ranges.rs @@ -113,7 +113,7 @@ impl FontGlyphRanges { /// Creates a glyph range from a static slice without checking its validity. /// - /// See [`FontRangeGlyph::from_slice`] for more information. + /// See [`FontGlyphRanges::from_slice`] for more information. /// /// # Safety /// From 028ebf538f51b95efaeb2efd211d8a7e71b491da Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 10 Feb 2021 17:49:14 +1100 Subject: [PATCH 03/24] Make DrawListMut::add_image doc example more concise Longer example code in 'imgui-examples/examples/custom_textures.rs' shows more detailed usage --- imgui/src/draw_list.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index 8626fcb..b3a1637 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -262,23 +262,13 @@ impl<'ui> DrawListMut<'ui> { /// ``` /// # use imgui::*; /// fn custom_button(ui: &Ui, img_id: TextureId) { - /// // Tint image red - /// - /// // Invisible button is good widget to customise with custom image + /// // Invisible button is good widget to customise with image /// ui.invisible_button(im_str!("custom_button"), [100.0, 20.0]); /// - /// // Red tint when button is hovered, no tint otherwise - /// let overlay_color = if ui.is_item_hovered() { - /// [1.0, 0.6, 0.6, 1.0] - /// } else { - /// [1.0, 1.0, 1.0, 1.0] - /// }; - /// /// // Get draw list and draw image over invisible button /// let draw_list = ui.get_window_draw_list(); /// draw_list /// .add_image(img_id, ui.item_rect_min(), ui.item_rect_max()) - /// .col(overlay_color) /// .build(); /// } /// ``` From e83f71bf82d2a5ddda78b42f42906d469b11dbcf Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 10 Feb 2021 18:24:35 +1100 Subject: [PATCH 04/24] Fix clippy lint about redundant .into() --- imgui/src/draw_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index b3a1637..e59075e 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -912,7 +912,7 @@ impl<'ui> ImageRounded<'ui> { self.uv_min.into(), self.uv_max.into(), self.col.into(), - self.rounding.into(), + self.rounding, self.rounding_corners.bits(), ); } From 0521a8fa9fb7a480be004f5d615113e35abfe0ed Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 10 Feb 2021 18:25:07 +1100 Subject: [PATCH 05/24] cargo fmt custom_textures.rs example --- imgui-examples/examples/custom_textures.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui-examples/examples/custom_textures.rs b/imgui-examples/examples/custom_textures.rs index 2593a9d..c34bc9b 100644 --- a/imgui-examples/examples/custom_textures.rs +++ b/imgui-examples/examples/custom_textures.rs @@ -167,10 +167,10 @@ impl CustomTexturesApp { // Tint brighter for visiblity of corners .col([2.0, 0.5, 0.5, 1.0]) // Rounding on each corner can be changed separately - .round_top_left((ui.frame_count()+0) / 60 % 4 == 0) - .round_top_right((ui.frame_count()+1) / 60 % 4 == 1) - .round_bot_right((ui.frame_count()+3) / 60 % 4 == 2) - .round_bot_left((ui.frame_count()+2) / 60 % 4 == 3) + .round_top_left((ui.frame_count() + 0) / 60 % 4 == 0) + .round_top_right((ui.frame_count() + 1) / 60 % 4 == 1) + .round_bot_right((ui.frame_count() + 3) / 60 % 4 == 2) + .round_bot_left((ui.frame_count() + 2) / 60 % 4 == 3) .build(); } } From daa08eb90b7dd415d8c368a4e5e1889b0baca3be Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 10 Feb 2021 21:01:38 +1100 Subject: [PATCH 06/24] Remove unused variable in example to apease clippy --- imgui-examples/examples/custom_textures.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/imgui-examples/examples/custom_textures.rs b/imgui-examples/examples/custom_textures.rs index c34bc9b..8db0867 100644 --- a/imgui-examples/examples/custom_textures.rs +++ b/imgui-examples/examples/custom_textures.rs @@ -97,8 +97,7 @@ impl CustomTexturesApp { ui.text("The Lenna buttons"); { - let _is_clicked = - ui.invisible_button(im_str!("Boring Button"), [100.0, 100.0]); + ui.invisible_button(im_str!("Boring Button"), [100.0, 100.0]); // See also `imgui::Ui::style_color` let tint_none = [1.0, 1.0, 1.0, 1.0]; let tint_green = [0.5, 1.0, 0.5, 1.0]; @@ -125,8 +124,7 @@ impl CustomTexturesApp { ui.same_line(0.0); // Button using quad positioned image - let is_clicked = - ui.invisible_button(im_str!("Exciting Button"), [100.0, 100.0]); + ui.invisible_button(im_str!("Exciting Button"), [100.0, 100.0]); // Button bounds let min = ui.item_rect_min(); @@ -153,8 +151,7 @@ impl CustomTexturesApp { // Rounded image { ui.same_line(0.0); - let is_clicked = - ui.invisible_button(im_str!("Smooth Button"), [100.0, 100.0]); + ui.invisible_button(im_str!("Smooth Button"), [100.0, 100.0]); let draw_list = ui.get_window_draw_list(); draw_list From 3c37e6797290bd6c5c7c62cdef311af7d56fd341 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 11 Feb 2021 10:40:34 +1100 Subject: [PATCH 07/24] Address another clippy lint --- imgui-examples/examples/custom_textures.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui-examples/examples/custom_textures.rs b/imgui-examples/examples/custom_textures.rs index 8db0867..2dc6acf 100644 --- a/imgui-examples/examples/custom_textures.rs +++ b/imgui-examples/examples/custom_textures.rs @@ -164,7 +164,7 @@ impl CustomTexturesApp { // Tint brighter for visiblity of corners .col([2.0, 0.5, 0.5, 1.0]) // Rounding on each corner can be changed separately - .round_top_left((ui.frame_count() + 0) / 60 % 4 == 0) + .round_top_left(ui.frame_count() / 60 % 4 == 0) .round_top_right((ui.frame_count() + 1) / 60 % 4 == 1) .round_bot_right((ui.frame_count() + 3) / 60 % 4 == 2) .round_bot_left((ui.frame_count() + 2) / 60 % 4 == 3) From 74ba0bec360cc64ac466712a42b25b851b53acdb Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 11 Feb 2021 13:46:26 +1100 Subject: [PATCH 08/24] imgui::legacy::ImGuiDragDropFlags has already been modernised Has been available at imgui::drag_drop::DragDropFlags since implemented --- imgui/src/legacy.rs | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/imgui/src/legacy.rs b/imgui/src/legacy.rs index 0b34f47..79c6bf7 100644 --- a/imgui/src/legacy.rs +++ b/imgui/src/legacy.rs @@ -4,45 +4,6 @@ use std::os::raw::c_int; use crate::widget::tree::TreeNodeFlags; -bitflags!( - /// Flags for igBeginDragDropSource(), igAcceptDragDropPayload() - #[repr(C)] - pub struct ImGuiDragDropFlags: c_int { - /// By default, a successful call to igBeginDragDropSource opens a tooltip so you can - /// display a preview or description of the source contents. This flag disable this - /// behavior. - const SourceNoPreviewTooltip = 1; - /// By default, when dragging we clear data so that igIsItemHovered() will return false, to - /// avoid subsequent user code submitting tooltips. This flag disable this behavior so you - /// can still call igIsItemHovered() on the source item. - const SourceNoDisableHover = 1 << 1; - /// Disable the behavior that allows to open tree nodes and collapsing header by holding - /// over them while dragging a source item. - const SourceNoHoldToOpenOthers = 1 << 2; - /// Allow items such as igText(), igImage() that have no unique identifier to be used as - /// drag source, by manufacturing a temporary identifier based on their window-relative - /// position. This is extremely unusual within the dear imgui ecosystem and so we made it - /// explicit. - const SourceAllowNullID = 1 << 3; - /// External source (from outside of imgui), won't attempt to read current item/window - /// info. Will always return true. Only one Extern source can be active simultaneously. - const SourceExtern = 1 << 4; - /// Automatically expire the payload if the source cease to be submitted (otherwise - /// payloads are persisting while being dragged) - const SourceAutoExpirePayload = 1 << 5; - /// igAcceptDragDropPayload() will returns true even before the mouse button is released. - /// You can then call igIsDelivery() to test if the payload needs to be delivered. - const AcceptBeforeDelivery = 1 << 10; - /// Do not draw the default highlight rectangle when hovering over target. - const AcceptNoDrawDefaultRect = 1 << 11; - /// Request hiding the igBeginDragDropSource tooltip from the igBeginDragDropTarget site. - const AcceptNoPreviewTooltip = 1 << 12; - /// For peeking ahead and inspecting the payload before delivery. - const AcceptPeekOnly = ImGuiDragDropFlags::AcceptBeforeDelivery.bits - | ImGuiDragDropFlags::AcceptNoDrawDefaultRect.bits; - } -); - bitflags!( /// Flags for indictating which corner of a rectangle should be rounded #[repr(C)] From 714710c6816031188a4ddbfcdcb5a69207fc444d Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 11 Feb 2021 14:16:00 +1100 Subject: [PATCH 09/24] Move ImDrawCornerFlags out of legacy.rs as per #445 Becomes draw_list::CornerFlags with Rust-style casing and documentation as necessary --- imgui/src/draw_list.rs | 73 +++++++++++++++++++++++++++++++----------- imgui/src/legacy.rs | 31 ------------------ 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index e59075e..1f8ad31 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -1,12 +1,49 @@ +use bitflags::bitflags; + use crate::ImColor32; use sys::ImDrawList; use super::Ui; -use crate::legacy::ImDrawCornerFlags; use crate::render::renderer::TextureId; use std::marker::PhantomData; +bitflags!( + /// Flags for indictating which corner of a rectangle should be rounded + #[repr(C)] + pub struct CornerFlags: u32 { + const NONE = sys::ImDrawCornerFlags_None; + const TOP_LEFT = sys::ImDrawCornerFlags_TopLeft; + const TOP_RIGHT = sys::ImDrawCornerFlags_TopRight; + const BOT_LEFT = sys::ImDrawCornerFlags_BotLeft; + const BOT_RIGHT = sys::ImDrawCornerFlags_BotRight; + const TOP = sys::ImDrawCornerFlags_Top; + const BOT = sys::ImDrawCornerFlags_Bot; + const LEFT = sys::ImDrawCornerFlags_Left; + const RIGHT = sys::ImDrawCornerFlags_Right; + const ALL = sys::ImDrawCornerFlags_All; + } +); + +bitflags!( + /// Draw list flags + #[repr(C)] + pub struct DrawListFlags: u32 { + const NONE = sys::ImDrawListFlags_None; + /// Enable anti-aliased lines/borders (*2 the number of triangles for 1.0f wide line or lines + /// thin enough to be drawn using textures, otherwise *3 the number of triangles) + const ANTI_ALIASED_LINES = sys::ImDrawListFlags_AntiAliasedLines; + /// Enable anti-aliased lines/borders using textures when possible. Require backend to render + /// with bilinear filtering. + const ANTI_ALIASED_LINES_USE_TEX = sys::ImDrawListFlags_AntiAliasedLinesUseTex; + /// Enable anti-aliased edge around filled shapes (rounded rectangles, circles). + const ANTI_ALIASED_FILL = sys::ImDrawListFlags_AntiAliasedFill; + /// Can emit 'VtxOffset > 0' to allow large meshes. Set when + /// [`BackendFlags::RENDERER_HAS_VTX_OFFSET`] is enabled. + const ALLOW_VTX_OFFSET = sys::ImDrawListFlags_AllowVtxOffset; + } +); + /// Object implementing the custom draw API. /// /// Called from [`Ui::get_window_draw_list`], [`Ui::get_background_draw_list`] or [`Ui::get_foreground_draw_list`]. @@ -353,7 +390,7 @@ pub struct Rect<'ui> { p2: [f32; 2], color: ImColor32, rounding: f32, - flags: ImDrawCornerFlags, + flags: CornerFlags, thickness: f32, filled: bool, draw_list: &'ui DrawListMut<'ui>, @@ -369,7 +406,7 @@ impl<'ui> Rect<'ui> { p2, color: c.into(), rounding: 0.0, - flags: ImDrawCornerFlags::All, + flags: CornerFlags::ALL, thickness: 1.0, filled: false, draw_list, @@ -385,25 +422,25 @@ impl<'ui> Rect<'ui> { /// Set flag to indicate if rectangle's top-left corner will be rounded. pub fn round_top_left(mut self, value: bool) -> Self { - self.flags.set(ImDrawCornerFlags::TopLeft, value); + self.flags.set(CornerFlags::TOP_LEFT, value); self } /// Set flag to indicate if rectangle's top-right corner will be rounded. pub fn round_top_right(mut self, value: bool) -> Self { - self.flags.set(ImDrawCornerFlags::TopRight, value); + self.flags.set(CornerFlags::TOP_RIGHT, value); self } /// Set flag to indicate if rectangle's bottom-left corner will be rounded. pub fn round_bot_left(mut self, value: bool) -> Self { - self.flags.set(ImDrawCornerFlags::BotLeft, value); + self.flags.set(CornerFlags::BOT_LEFT, value); self } /// Set flag to indicate if rectangle's bottom-right corner will be rounded. pub fn round_bot_right(mut self, value: bool) -> Self { - self.flags.set(ImDrawCornerFlags::BotRight, value); + self.flags.set(CornerFlags::BOT_RIGHT, value); self } @@ -429,7 +466,7 @@ impl<'ui> Rect<'ui> { self.p2.into(), self.color.into(), self.rounding, - self.flags.bits(), + self.flags.bits() as i32, ); } } else { @@ -440,7 +477,7 @@ impl<'ui> Rect<'ui> { self.p2.into(), self.color.into(), self.rounding, - self.flags.bits(), + self.flags.bits() as i32, self.thickness, ); } @@ -822,7 +859,7 @@ pub struct ImageRounded<'ui> { uv_max: [f32; 2], col: ImColor32, rounding: f32, - rounding_corners: ImDrawCornerFlags, + rounding_corners: CornerFlags, draw_list: &'ui DrawListMut<'ui>, } @@ -842,7 +879,7 @@ impl<'ui> ImageRounded<'ui> { uv_max: [1.0, 1.0], col: [1.0, 1.0, 1.0, 1.0].into(), rounding, - rounding_corners: ImDrawCornerFlags::All, + rounding_corners: CornerFlags::ALL, draw_list, } } @@ -869,33 +906,31 @@ impl<'ui> ImageRounded<'ui> { /// Set flag to indicate rounding on all all corners. pub fn round_all(mut self, value: bool) -> Self { - self.rounding_corners.set(ImDrawCornerFlags::All, value); + self.rounding_corners.set(CornerFlags::ALL, value); self } /// Set flag to indicate if image's top-left corner will be rounded. pub fn round_top_left(mut self, value: bool) -> Self { - self.rounding_corners.set(ImDrawCornerFlags::TopLeft, value); + self.rounding_corners.set(CornerFlags::TOP_LEFT, value); self } /// Set flag to indicate if image's top-right corner will be rounded. pub fn round_top_right(mut self, value: bool) -> Self { - self.rounding_corners - .set(ImDrawCornerFlags::TopRight, value); + self.rounding_corners.set(CornerFlags::TOP_RIGHT, value); self } /// Set flag to indicate if image's bottom-left corner will be rounded. pub fn round_bot_left(mut self, value: bool) -> Self { - self.rounding_corners.set(ImDrawCornerFlags::BotLeft, value); + self.rounding_corners.set(CornerFlags::BOT_LEFT, value); self } /// Set flag to indicate if image's bottom-right corner will be rounded. pub fn round_bot_right(mut self, value: bool) -> Self { - self.rounding_corners - .set(ImDrawCornerFlags::BotRight, value); + self.rounding_corners.set(CornerFlags::BOT_RIGHT, value); self } @@ -913,7 +948,7 @@ impl<'ui> ImageRounded<'ui> { self.uv_max.into(), self.col.into(), self.rounding, - self.rounding_corners.bits(), + self.rounding_corners.bits() as i32, ); } } diff --git a/imgui/src/legacy.rs b/imgui/src/legacy.rs index 79c6bf7..58d3f0a 100644 --- a/imgui/src/legacy.rs +++ b/imgui/src/legacy.rs @@ -4,37 +4,6 @@ use std::os::raw::c_int; use crate::widget::tree::TreeNodeFlags; -bitflags!( - /// Flags for indictating which corner of a rectangle should be rounded - #[repr(C)] - pub struct ImDrawCornerFlags: c_int { - const TopLeft = 1; - const TopRight = 1 << 1; - const BotLeft = 1 << 2; - const BotRight = 1 << 3; - const Top = ImDrawCornerFlags::TopLeft.bits - | ImDrawCornerFlags::TopRight.bits; - const Bot = ImDrawCornerFlags::BotLeft.bits - | ImDrawCornerFlags::BotRight.bits; - const Left = ImDrawCornerFlags::TopLeft.bits - | ImDrawCornerFlags::BotLeft.bits; - const Right = ImDrawCornerFlags::TopRight.bits - | ImDrawCornerFlags::BotRight.bits; - const All = 0xF; - } -); - -bitflags!( - /// Draw list flags - #[repr(C)] - pub struct ImDrawListFlags: c_int { - const AntiAliasedLines = 1; - const AntiAliasedLinesUseTex = 1 << 1; - const AntiAliasedFill = 1 << 2; - const AllowVtxOffset = 1 << 3; - } -); - bitflags!( /// Flags for text inputs #[repr(C)] From f72e78ddf4b16bd73540c3e095af225dc4210ed5 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 11 Feb 2021 14:30:46 +1100 Subject: [PATCH 10/24] Also move ImGuiInputTextFlags out of legacy.rs as per #445 Becomes input_widget::InputTextFlags with Rust-style casing --- imgui/src/input_widget.rs | 126 ++++++++++++++++++++++++++------------ imgui/src/legacy.rs | 49 --------------- 2 files changed, 86 insertions(+), 89 deletions(-) diff --git a/imgui/src/input_widget.rs b/imgui/src/input_widget.rs index d39d350..118e49f 100644 --- a/imgui/src/input_widget.rs +++ b/imgui/src/input_widget.rs @@ -1,121 +1,167 @@ use std::marker::PhantomData; use std::os::raw::{c_int, c_void}; use std::ptr; +use bitflags::bitflags; -use crate::legacy::ImGuiInputTextFlags; use crate::sys; use crate::{ImStr, ImString, Ui}; +bitflags!( + /// Flags for text inputs + #[repr(C)] + pub struct InputTextFlags: u32 { + /// Allow 0123456789.+-*/ + const CHARS_DECIMAL = sys::ImGuiInputTextFlags_CharsDecimal; + /// Allow 0123456789ABCDEFabcdef + const CHARS_HEXADECIMAL = sys::ImGuiInputTextFlags_CharsHexadecimal; + /// Turn a..z into A..Z + const CHARS_UPPERCASE = sys::ImGuiInputTextFlags_CharsUppercase; + /// Filter out spaces, tabs + const CHARS_NO_BLANK = sys::ImGuiInputTextFlags_CharsNoBlank; + /// Select entire text when first taking mouse focus + const AUTO_SELECT_ALL = sys::ImGuiInputTextFlags_AutoSelectAll; + /// Return 'true' when Enter is pressed (as opposed to when the value was modified) + const ENTER_RETURNS_TRUE = sys::ImGuiInputTextFlags_EnterReturnsTrue; + /// Call user function on pressing TAB (for completion handling) + const CALLBACK_COMPLETION = sys::ImGuiInputTextFlags_CallbackCompletion; + /// Call user function on pressing Up/Down arrows (for history handling) + const CALLBACK_HISTORY = sys::ImGuiInputTextFlags_CallbackHistory; + /// Call user function every time. User code may query cursor position, modify text buffer. + const CALLBACK_ALWAYS = sys::ImGuiInputTextFlags_CallbackAlways; + /// Call user function to filter character. + const CALLBACK_CHAR_FILTER = sys::ImGuiInputTextFlags_CallbackCharFilter; + /// Pressing TAB input a '\t' character into the text field + const ALLOW_TAB_INPUT = sys::ImGuiInputTextFlags_AllowTabInput; + /// In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is + /// opposite: unfocus with Ctrl+Enter, add line with Enter). + const CTRL_ENTER_FOR_NEW_LINE = sys::ImGuiInputTextFlags_CtrlEnterForNewLine; + /// Disable following the cursor horizontally + const NO_HORIZONTAL_SCROLL = sys::ImGuiInputTextFlags_NoHorizontalScroll; + /// Insert mode + const ALWAYS_INSERT_MODE = sys::ImGuiInputTextFlags_AlwaysInsertMode; + /// Read-only mode + const READ_ONLY = sys::ImGuiInputTextFlags_ReadOnly; + /// Password mode, display all characters as '*' + const PASSWORD = sys::ImGuiInputTextFlags_Password; + /// Disable undo/redo. + const NO_UNDO_REDO = sys::ImGuiInputTextFlags_NoUndoRedo; + /// Allow 0123456789.+-*/eE (Scientific notation input) + const CHARS_SCIENTIFIC = sys::ImGuiInputTextFlags_CharsScientific; + /// Allow buffer capacity resize + notify when the string wants to be resized + const CALLBACK_RESIZE = sys::ImGuiInputTextFlags_CallbackResize; + } +); + macro_rules! impl_text_flags { ($InputType:ident) => { #[inline] - pub fn flags(mut self, flags: ImGuiInputTextFlags) -> Self { + pub fn flags(mut self, flags: InputTextFlags) -> Self { self.flags = flags; self } #[inline] pub fn chars_decimal(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::CharsDecimal, value); + self.flags.set(InputTextFlags::CHARS_DECIMAL, value); self } #[inline] pub fn chars_hexadecimal(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::CharsHexadecimal, value); + self.flags.set(InputTextFlags::CHARS_HEXADECIMAL, value); self } #[inline] pub fn chars_uppercase(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::CharsUppercase, value); + self.flags.set(InputTextFlags::CHARS_UPPERCASE, value); self } #[inline] pub fn chars_noblank(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::CharsNoBlank, value); + self.flags.set(InputTextFlags::CHARS_NO_BLANK, value); self } #[inline] pub fn auto_select_all(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::AutoSelectAll, value); + self.flags.set(InputTextFlags::AUTO_SELECT_ALL, value); self } #[inline] pub fn enter_returns_true(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::EnterReturnsTrue, value); + self.flags.set(InputTextFlags::ENTER_RETURNS_TRUE, value); self } #[inline] pub fn callback_completion(mut self, value: bool) -> Self { self.flags - .set(ImGuiInputTextFlags::CallbackCompletion, value); + .set(InputTextFlags::CALLBACK_COMPLETION, value); self } #[inline] pub fn callback_history(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::CallbackHistory, value); + self.flags.set(InputTextFlags::CALLBACK_HISTORY, value); self } #[inline] pub fn callback_always(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::CallbackAlways, value); + self.flags.set(InputTextFlags::CALLBACK_ALWAYS, value); self } #[inline] pub fn callback_char_filter(mut self, value: bool) -> Self { self.flags - .set(ImGuiInputTextFlags::CallbackCharFilter, value); + .set(InputTextFlags::CALLBACK_CHAR_FILTER, value); self } #[inline] pub fn resize_buffer(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::CallbackResize, value); + self.flags.set(InputTextFlags::CALLBACK_RESIZE, value); self } #[inline] pub fn allow_tab_input(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::AllowTabInput, value); + self.flags.set(InputTextFlags::ALLOW_TAB_INPUT, value); self } #[inline] pub fn no_horizontal_scroll(mut self, value: bool) -> Self { self.flags - .set(ImGuiInputTextFlags::NoHorizontalScroll, value); + .set(InputTextFlags::NO_HORIZONTAL_SCROLL, value); self } #[inline] pub fn always_insert_mode(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::AlwaysInsertMode, value); + self.flags.set(InputTextFlags::ALWAYS_INSERT_MODE, value); self } #[inline] pub fn read_only(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::ReadOnly, value); + self.flags.set(InputTextFlags::READ_ONLY, value); self } #[inline] pub fn password(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::Password, value); + self.flags.set(InputTextFlags::PASSWORD, value); self } #[inline] pub fn no_undo_redo(mut self, value: bool) -> Self { - self.flags.set(ImGuiInputTextFlags::NoUndoRedo, value); + self.flags.set(InputTextFlags::NO_UNDO_REDO, value); self } }; @@ -139,7 +185,7 @@ macro_rules! impl_step_params { extern "C" fn resize_callback(data: *mut sys::ImGuiInputTextCallbackData) -> c_int { unsafe { - if (*data).EventFlag == ImGuiInputTextFlags::CallbackResize.bits() { + if (*data).EventFlag == InputTextFlags::CALLBACK_RESIZE.bits() as i32 { if let Some(buffer) = ((*data).UserData as *mut ImString).as_mut() { let requested_size = (*data).BufSize as usize; if requested_size > buffer.capacity_with_nul() { @@ -160,7 +206,7 @@ extern "C" fn resize_callback(data: *mut sys::ImGuiInputTextCallbackData) -> c_i pub struct InputText<'ui, 'p> { label: &'p ImStr, buf: &'p mut ImString, - flags: ImGuiInputTextFlags, + flags: InputTextFlags, _phantom: PhantomData<&'ui Ui<'ui>>, } @@ -169,7 +215,7 @@ impl<'ui, 'p> InputText<'ui, 'p> { InputText { label, buf, - flags: ImGuiInputTextFlags::empty(), + flags: InputTextFlags::empty(), _phantom: PhantomData, } } @@ -182,7 +228,7 @@ impl<'ui, 'p> InputText<'ui, 'p> { pub fn build(self) -> bool { let (ptr, capacity) = (self.buf.as_mut_ptr(), self.buf.capacity_with_nul()); let (callback, data): (sys::ImGuiInputTextCallback, _) = { - if self.flags.contains(ImGuiInputTextFlags::CallbackResize) { + if self.flags.contains(InputTextFlags::CALLBACK_RESIZE) { (Some(resize_callback), self.buf as *mut _ as *mut c_void) } else { (None, ptr::null_mut()) @@ -194,7 +240,7 @@ impl<'ui, 'p> InputText<'ui, 'p> { self.label.as_ptr(), ptr, capacity, - self.flags.bits(), + self.flags.bits() as i32, callback, data, ); @@ -208,7 +254,7 @@ impl<'ui, 'p> InputText<'ui, 'p> { pub struct InputTextMultiline<'ui, 'p> { label: &'p ImStr, buf: &'p mut ImString, - flags: ImGuiInputTextFlags, + flags: InputTextFlags, size: [f32; 2], _phantom: PhantomData<&'ui Ui<'ui>>, } @@ -218,7 +264,7 @@ impl<'ui, 'p> InputTextMultiline<'ui, 'p> { InputTextMultiline { label, buf, - flags: ImGuiInputTextFlags::empty(), + flags: InputTextFlags::empty(), size, _phantom: PhantomData, } @@ -232,7 +278,7 @@ impl<'ui, 'p> InputTextMultiline<'ui, 'p> { pub fn build(self) -> bool { let (ptr, capacity) = (self.buf.as_mut_ptr(), self.buf.capacity_with_nul()); let (callback, data): (sys::ImGuiInputTextCallback, _) = { - if self.flags.contains(ImGuiInputTextFlags::CallbackResize) { + if self.flags.contains(InputTextFlags::CALLBACK_RESIZE) { (Some(resize_callback), self.buf as *mut _ as *mut c_void) } else { (None, ptr::null_mut()) @@ -245,7 +291,7 @@ impl<'ui, 'p> InputTextMultiline<'ui, 'p> { ptr, capacity, self.size.into(), - self.flags.bits(), + self.flags.bits() as i32, callback, data, ); @@ -261,7 +307,7 @@ pub struct InputInt<'ui, 'p> { value: &'p mut i32, step: i32, step_fast: i32, - flags: ImGuiInputTextFlags, + flags: InputTextFlags, _phantom: PhantomData<&'ui Ui<'ui>>, } @@ -272,7 +318,7 @@ impl<'ui, 'p> InputInt<'ui, 'p> { value, step: 1, step_fast: 100, - flags: ImGuiInputTextFlags::empty(), + flags: InputTextFlags::empty(), _phantom: PhantomData, } } @@ -284,7 +330,7 @@ impl<'ui, 'p> InputInt<'ui, 'p> { self.value as *mut i32, self.step, self.step_fast, - self.flags.bits(), + self.flags.bits() as i32, ) } } @@ -299,7 +345,7 @@ pub struct InputFloat<'ui, 'p> { value: &'p mut f32, step: f32, step_fast: f32, - flags: ImGuiInputTextFlags, + flags: InputTextFlags, _phantom: PhantomData<&'ui Ui<'ui>>, } @@ -310,7 +356,7 @@ impl<'ui, 'p> InputFloat<'ui, 'p> { value, step: 0.0, step_fast: 0.0, - flags: ImGuiInputTextFlags::empty(), + flags: InputTextFlags::empty(), _phantom: PhantomData, } } @@ -323,7 +369,7 @@ impl<'ui, 'p> InputFloat<'ui, 'p> { self.step, self.step_fast, b"%.3f\0".as_ptr() as *const _, - self.flags.bits(), + self.flags.bits() as i32, ) } } @@ -338,7 +384,7 @@ macro_rules! impl_input_floatn { pub struct $InputFloatN<'ui, 'p> { label: &'p ImStr, value: &'p mut [f32; $N], - flags: ImGuiInputTextFlags, + flags: InputTextFlags, _phantom: PhantomData<&'ui Ui<'ui>>, } @@ -347,7 +393,7 @@ macro_rules! impl_input_floatn { $InputFloatN { label, value, - flags: ImGuiInputTextFlags::empty(), + flags: InputTextFlags::empty(), _phantom: PhantomData, } } @@ -358,7 +404,7 @@ macro_rules! impl_input_floatn { self.label.as_ptr(), self.value.as_mut_ptr(), b"%.3f\0".as_ptr() as *const _, - self.flags.bits(), + self.flags.bits() as i32, ) } } @@ -378,7 +424,7 @@ macro_rules! impl_input_intn { pub struct $InputIntN<'ui, 'p> { label: &'p ImStr, value: &'p mut [i32; $N], - flags: ImGuiInputTextFlags, + flags: InputTextFlags, _phantom: PhantomData<&'ui Ui<'ui>>, } @@ -387,7 +433,7 @@ macro_rules! impl_input_intn { $InputIntN { label, value, - flags: ImGuiInputTextFlags::empty(), + flags: InputTextFlags::empty(), _phantom: PhantomData, } } @@ -397,7 +443,7 @@ macro_rules! impl_input_intn { sys::$igInputIntN( self.label.as_ptr(), self.value.as_mut_ptr(), - self.flags.bits(), + self.flags.bits() as i32, ) } } diff --git a/imgui/src/legacy.rs b/imgui/src/legacy.rs index 58d3f0a..e98d907 100644 --- a/imgui/src/legacy.rs +++ b/imgui/src/legacy.rs @@ -1,53 +1,4 @@ #![allow(non_upper_case_globals)] -use bitflags::bitflags; -use std::os::raw::c_int; - use crate::widget::tree::TreeNodeFlags; -bitflags!( - /// Flags for text inputs - #[repr(C)] - pub struct ImGuiInputTextFlags: c_int { - /// Allow 0123456789.+-*/ - const CharsDecimal = 1; - /// Allow 0123456789ABCDEFabcdef - const CharsHexadecimal = 1 << 1; - /// Turn a..z into A..Z - const CharsUppercase = 1 << 2; - /// Filter out spaces, tabs - const CharsNoBlank = 1 << 3; - /// Select entire text when first taking mouse focus - const AutoSelectAll = 1 << 4; - /// Return 'true' when Enter is pressed (as opposed to when the value was modified) - const EnterReturnsTrue = 1 << 5; - /// Call user function on pressing TAB (for completion handling) - const CallbackCompletion = 1 << 6; - /// Call user function on pressing Up/Down arrows (for history handling) - const CallbackHistory = 1 << 7; - /// Call user function every time. User code may query cursor position, modify text buffer. - const CallbackAlways = 1 << 8; - /// Call user function to filter character. - const CallbackCharFilter = 1 << 9; - /// Pressing TAB input a '\t' character into the text field - const AllowTabInput = 1 << 10; - /// In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is - /// opposite: unfocus with Ctrl+Enter, add line with Enter). - const CtrlEnterForNewLine = 1 << 11; - /// Disable following the cursor horizontally - const NoHorizontalScroll = 1 << 12; - /// Insert mode - const AlwaysInsertMode = 1 << 13; - /// Read-only mode - const ReadOnly = 1 << 14; - /// Password mode, display all characters as '*' - const Password = 1 << 15; - /// Disable undo/redo. - const NoUndoRedo = 1 << 16; - /// Allow 0123456789.+-*/eE (Scientific notation input) - const CharsScientific = 1 << 17; - /// Allow buffer capacity resize + notify when the string wants to be resized - const CallbackResize = 1 << 18; - } -); - pub type ImGuiTreeNodeFlags = TreeNodeFlags; From b3a50e69286eef6b00610c392dfc4b6656fec585 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 11 Feb 2021 14:33:10 +1100 Subject: [PATCH 11/24] Finally, remove legacy.rs Any use of imgui::ImGuiTreeNodeFlags should be updated to imgui::TreeNodeFlags --- imgui/src/legacy.rs | 4 ---- imgui/src/lib.rs | 2 -- 2 files changed, 6 deletions(-) delete mode 100644 imgui/src/legacy.rs diff --git a/imgui/src/legacy.rs b/imgui/src/legacy.rs deleted file mode 100644 index e98d907..0000000 --- a/imgui/src/legacy.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![allow(non_upper_case_globals)] -use crate::widget::tree::TreeNodeFlags; - -pub type ImGuiTreeNodeFlags = TreeNodeFlags; diff --git a/imgui/src/lib.rs b/imgui/src/lib.rs index f497fd3..f490bc8 100644 --- a/imgui/src/lib.rs +++ b/imgui/src/lib.rs @@ -25,7 +25,6 @@ pub use self::input_widget::{ }; pub use self::io::*; pub use self::layout::*; -pub use self::legacy::*; pub use self::list_clipper::ListClipper; pub use self::plothistogram::PlotHistogram; pub use self::plotlines::PlotLines; @@ -66,7 +65,6 @@ mod input_widget; pub mod internal; mod io; mod layout; -mod legacy; mod list_clipper; mod plothistogram; mod plotlines; From 1a55b4ae24c627bb455eb70b19da7f2f1b7da5ba Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 20 Feb 2021 20:00:25 +1100 Subject: [PATCH 12/24] Add "DrawList" prefix to Image/ImageQuad/ImageRounded Also make their constructions public just in case it leads to neater code in some circumstances --- imgui/src/draw_list.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index 1f8ad31..91cb60d 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -309,8 +309,8 @@ impl<'ui> DrawListMut<'ui> { /// .build(); /// } /// ``` - pub fn add_image(&'ui self, texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2]) -> Image { - Image::new(self, texture_id, p_min, p_max) + pub fn add_image(&'ui self, texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2]) -> DrawListImage { + DrawListImage::new(self, texture_id, p_min, p_max) } /// Draw the specified image to a quad with the specified @@ -323,8 +323,8 @@ impl<'ui> DrawListMut<'ui> { p2: [f32; 2], p3: [f32; 2], p4: [f32; 2], - ) -> ImageQuad { - ImageQuad::new(self, texture_id, p1, p2, p3, p4) + ) -> DrawListImageQuad { + DrawListImageQuad::new(self, texture_id, p1, p2, p3, p4) } /// Draw the speciied image, with rounded corners @@ -334,8 +334,8 @@ impl<'ui> DrawListMut<'ui> { p_min: [f32; 2], p_max: [f32; 2], rounding: f32, - ) -> ImageRounded { - ImageRounded::new(self, texture_id, p_min, p_max, rounding) + ) -> DrawListImageRounded { + DrawListImageRounded::new(self, texture_id, p_min, p_max, rounding) } } @@ -696,7 +696,7 @@ impl<'ui> BezierCurve<'ui> { /// Represents a image about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct Image<'ui> { +pub struct DrawListImage<'ui> { texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2], @@ -706,8 +706,9 @@ pub struct Image<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> Image<'ui> { - fn new( +impl<'ui> DrawListImage<'ui> { + /// Typically constructed by [`DrawListMut::add_image`] + pub fn new( draw_list: &'ui DrawListMut, texture_id: TextureId, p_min: [f32; 2], @@ -764,7 +765,7 @@ impl<'ui> Image<'ui> { /// Represents a image about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct ImageQuad<'ui> { +pub struct DrawListImageQuad<'ui> { texture_id: TextureId, p1: [f32; 2], p2: [f32; 2], @@ -778,8 +779,9 @@ pub struct ImageQuad<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> ImageQuad<'ui> { - fn new( +impl<'ui> DrawListImageQuad<'ui> { + /// Typically constructed by [`DrawListMut::add_image_quad`] + pub fn new( draw_list: &'ui DrawListMut, texture_id: TextureId, p1: [f32; 2], @@ -849,9 +851,10 @@ impl<'ui> ImageQuad<'ui> { } } -/// Represents a image about to be drawn +/// Represents a image about to be drawn. Similar to [`DrawListImage`] but +/// with corners rounded with a given radius #[must_use = "should call .build() to draw the object"] -pub struct ImageRounded<'ui> { +pub struct DrawListImageRounded<'ui> { texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2], @@ -863,8 +866,9 @@ pub struct ImageRounded<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> ImageRounded<'ui> { - fn new( +impl<'ui> DrawListImageRounded<'ui> { + /// Typically constructed by [`DrawListMut::add_image_rounded`] + pub fn new( draw_list: &'ui DrawListMut, texture_id: TextureId, p_min: [f32; 2], From a90989db58674f4fe07c5c5184d57630fc8c358f Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 20 Feb 2021 20:01:26 +1100 Subject: [PATCH 13/24] Make draw_list module public --- imgui/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui/src/lib.rs b/imgui/src/lib.rs index f490bc8..07c71d3 100644 --- a/imgui/src/lib.rs +++ b/imgui/src/lib.rs @@ -58,7 +58,7 @@ pub mod color; mod columns; mod context; pub mod drag_drop; -mod draw_list; +pub mod draw_list; mod fonts; mod input; mod input_widget; From 20864b53de7d44a3ae1ab2e965b459e3ed09ebdb Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 20 Feb 2021 20:03:13 +1100 Subject: [PATCH 14/24] Add "DrawList" prefix Line, Rect, Triangle, Circle, BezierCurve Also make their constructers public For consistency with newly added DrawListImage (which was ambiguous with the Image widget) --- imgui/src/draw_list.rs | 44 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index 91cb60d..87143c6 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -158,20 +158,20 @@ impl<'ui> ChannelsSplit<'ui> { /// Drawing functions impl<'ui> DrawListMut<'ui> { /// Returns a line from point `p1` to `p2` with color `c`. - pub fn add_line(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Line<'ui> + pub fn add_line(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> DrawListLine<'ui> where C: Into, { - Line::new(self, p1, p2, c) + DrawListLine::new(self, p1, p2, c) } /// 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(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Rect<'ui> + pub fn add_rect(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> DrawListRect<'ui> where C: Into, { - Rect::new(self, p1, p2, c) + DrawListRect::new(self, p1, p2, c) } /// Draw a rectangle whose upper-left corner is at point `p1` @@ -214,19 +214,19 @@ impl<'ui> DrawListMut<'ui> { p2: [f32; 2], p3: [f32; 2], c: C, - ) -> Triangle<'ui> + ) -> DrawListTriangle<'ui> where C: Into, { - Triangle::new(self, p1, p2, p3, c) + DrawListTriangle::new(self, p1, p2, p3, c) } /// Returns a circle with the given `center`, `radius` and `color`. - pub fn add_circle(&'ui self, center: [f32; 2], radius: f32, color: C) -> Circle<'ui> + pub fn add_circle(&'ui self, center: [f32; 2], radius: f32, color: C) -> DrawListCircle<'ui> where C: Into, { - Circle::new(self, center, radius, color) + DrawListCircle::new(self, center, radius, color) } /// Draw a text whose upper-left corner is at point `pos`. @@ -254,11 +254,11 @@ impl<'ui> DrawListMut<'ui> { cp1: [f32; 2], pos1: [f32; 2], color: C, - ) -> BezierCurve<'ui> + ) -> DrawListBezierCurve<'ui> where C: Into, { - BezierCurve::new(self, pos0, cp0, cp1, pos1, color) + DrawListBezierCurve::new(self, pos0, cp0, cp1, pos1, color) } /// Push a clipping rectangle on the stack, run `f` and pop it. @@ -341,7 +341,7 @@ impl<'ui> DrawListMut<'ui> { /// Represents a line about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct Line<'ui> { +pub struct DrawListLine<'ui> { p1: [f32; 2], p2: [f32; 2], color: ImColor32, @@ -349,7 +349,7 @@ pub struct Line<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> Line<'ui> { +impl<'ui> DrawListLine<'ui> { fn new(draw_list: &'ui DrawListMut, p1: [f32; 2], p2: [f32; 2], c: C) -> Self where C: Into, @@ -385,7 +385,7 @@ impl<'ui> Line<'ui> { /// Represents a rectangle about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct Rect<'ui> { +pub struct DrawListRect<'ui> { p1: [f32; 2], p2: [f32; 2], color: ImColor32, @@ -396,7 +396,7 @@ pub struct Rect<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> Rect<'ui> { +impl<'ui> DrawListRect<'ui> { fn new(draw_list: &'ui DrawListMut, p1: [f32; 2], p2: [f32; 2], c: C) -> Self where C: Into, @@ -487,7 +487,7 @@ 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> { +pub struct DrawListTriangle<'ui> { p1: [f32; 2], p2: [f32; 2], p3: [f32; 2], @@ -497,7 +497,7 @@ pub struct Triangle<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> Triangle<'ui> { +impl<'ui> DrawListTriangle<'ui> { fn new(draw_list: &'ui DrawListMut, p1: [f32; 2], p2: [f32; 2], p3: [f32; 2], c: C) -> Self where C: Into, @@ -554,7 +554,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> { +pub struct DrawListCircle<'ui> { center: [f32; 2], radius: f32, color: ImColor32, @@ -564,7 +564,8 @@ pub struct Circle<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> Circle<'ui> { +impl<'ui> DrawListCircle<'ui> { + /// Typically constructed by [`DrawListMut::add_circle`] pub fn new(draw_list: &'ui DrawListMut, center: [f32; 2], radius: f32, color: C) -> Self where C: Into, @@ -628,7 +629,7 @@ 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> { +pub struct DrawListBezierCurve<'ui> { pos0: [f32; 2], cp0: [f32; 2], pos1: [f32; 2], @@ -640,8 +641,9 @@ pub struct BezierCurve<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> BezierCurve<'ui> { - fn new( +impl<'ui> DrawListBezierCurve<'ui> { + /// Typically constructed by [`DrawListMut::add_bezier_curve`] + pub fn new( draw_list: &'ui DrawListMut, pos0: [f32; 2], cp0: [f32; 2], From 68867ea580a57de920ef3c2c2db18fb44f4d80ea Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 20 Feb 2021 20:19:55 +1100 Subject: [PATCH 15/24] Basic doc onimgui::draw_list module --- imgui/src/draw_list.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index 87143c6..9f240a9 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -1,3 +1,18 @@ +//! The draw list lets you create custom graphics with a window. +//! +//! Each dear imgui window contains its own draw list. You can use +//! [`Ui::get_window_draw_list`] to access the current window draw +//! list and draw custom primitives. You can interleave normal widget +//! calls and adding primitives to the current draw list. +//! +//! Interaction is mostly through the mtehods [`DrawListMut`] struct, +//! such as [`DrawListMut::add_line`], however you can also construct +//! structs like [`DrawListLine`] directly, then call +//! `DrawListLine::build` with a reference to your draw list +//! +//! There are examples such as `draw_list.rs` and `custom_textures.rs` +//! within the `imgui-examples` directory + use bitflags::bitflags; use crate::ImColor32; From 6bf75335ed2cf30a22a88d0552e04b2c559c4a51 Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 20 Feb 2021 20:21:26 +1100 Subject: [PATCH 16/24] cargo fmt --- imgui/src/draw_list.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index 9f240a9..67e500a 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -324,7 +324,12 @@ impl<'ui> DrawListMut<'ui> { /// .build(); /// } /// ``` - pub fn add_image(&'ui self, texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2]) -> DrawListImage { + pub fn add_image( + &'ui self, + texture_id: TextureId, + p_min: [f32; 2], + p_max: [f32; 2], + ) -> DrawListImage { DrawListImage::new(self, texture_id, p_min, p_max) } From cb742c8a4d81eedeeaf83bd3ff6965487874d757 Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 20 Feb 2021 20:21:50 +1100 Subject: [PATCH 17/24] Additional cargo fmt --- imgui/src/input_widget.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/imgui/src/input_widget.rs b/imgui/src/input_widget.rs index 118e49f..fa952c8 100644 --- a/imgui/src/input_widget.rs +++ b/imgui/src/input_widget.rs @@ -1,7 +1,7 @@ +use bitflags::bitflags; use std::marker::PhantomData; use std::os::raw::{c_int, c_void}; use std::ptr; -use bitflags::bitflags; use crate::sys; use crate::{ImStr, ImString, Ui}; @@ -98,8 +98,7 @@ macro_rules! impl_text_flags { #[inline] pub fn callback_completion(mut self, value: bool) -> Self { - self.flags - .set(InputTextFlags::CALLBACK_COMPLETION, value); + self.flags.set(InputTextFlags::CALLBACK_COMPLETION, value); self } @@ -117,8 +116,7 @@ macro_rules! impl_text_flags { #[inline] pub fn callback_char_filter(mut self, value: bool) -> Self { - self.flags - .set(InputTextFlags::CALLBACK_CHAR_FILTER, value); + self.flags.set(InputTextFlags::CALLBACK_CHAR_FILTER, value); self } @@ -136,8 +134,7 @@ macro_rules! impl_text_flags { #[inline] pub fn no_horizontal_scroll(mut self, value: bool) -> Self { - self.flags - .set(InputTextFlags::NO_HORIZONTAL_SCROLL, value); + self.flags.set(InputTextFlags::NO_HORIZONTAL_SCROLL, value); self } From 759ed18202c32d8d0470c2da246b29e0691ba895 Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 24 Feb 2021 20:06:36 +1100 Subject: [PATCH 18/24] Remove DrawList prefix from widgets The prefix makes things too cluttered and only helps in fairly specific circumstances --- imgui/src/draw_list.rs | 65 +++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index 67e500a..f12cf0c 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -7,8 +7,8 @@ //! //! Interaction is mostly through the mtehods [`DrawListMut`] struct, //! such as [`DrawListMut::add_line`], however you can also construct -//! structs like [`DrawListLine`] directly, then call -//! `DrawListLine::build` with a reference to your draw list +//! structs like [`Line`] directly, then call +//! `Line::build` with a reference to your draw list //! //! There are examples such as `draw_list.rs` and `custom_textures.rs` //! within the `imgui-examples` directory @@ -173,20 +173,20 @@ impl<'ui> ChannelsSplit<'ui> { /// Drawing functions impl<'ui> DrawListMut<'ui> { /// Returns a line from point `p1` to `p2` with color `c`. - pub fn add_line(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> DrawListLine<'ui> + pub fn add_line(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Line<'ui> where C: Into, { - DrawListLine::new(self, p1, p2, c) + Line::new(self, p1, p2, c) } /// 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(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> DrawListRect<'ui> + pub fn add_rect(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Rect<'ui> where C: Into, { - DrawListRect::new(self, p1, p2, c) + Rect::new(self, p1, p2, c) } /// Draw a rectangle whose upper-left corner is at point `p1` @@ -237,11 +237,11 @@ impl<'ui> DrawListMut<'ui> { } /// Returns a circle with the given `center`, `radius` and `color`. - pub fn add_circle(&'ui self, center: [f32; 2], radius: f32, color: C) -> DrawListCircle<'ui> + pub fn add_circle(&'ui self, center: [f32; 2], radius: f32, color: C) -> Circle<'ui> where C: Into, { - DrawListCircle::new(self, center, radius, color) + Circle::new(self, center, radius, color) } /// Draw a text whose upper-left corner is at point `pos`. @@ -269,11 +269,11 @@ impl<'ui> DrawListMut<'ui> { cp1: [f32; 2], pos1: [f32; 2], color: C, - ) -> DrawListBezierCurve<'ui> + ) -> BezierCurve<'ui> where C: Into, { - DrawListBezierCurve::new(self, pos0, cp0, cp1, pos1, color) + BezierCurve::new(self, pos0, cp0, cp1, pos1, color) } /// Push a clipping rectangle on the stack, run `f` and pop it. @@ -329,8 +329,8 @@ impl<'ui> DrawListMut<'ui> { texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2], - ) -> DrawListImage { - DrawListImage::new(self, texture_id, p_min, p_max) + ) -> Image { + Image::new(self, texture_id, p_min, p_max) } /// Draw the specified image to a quad with the specified @@ -343,8 +343,8 @@ impl<'ui> DrawListMut<'ui> { p2: [f32; 2], p3: [f32; 2], p4: [f32; 2], - ) -> DrawListImageQuad { - DrawListImageQuad::new(self, texture_id, p1, p2, p3, p4) + ) -> ImageQuad { + ImageQuad::new(self, texture_id, p1, p2, p3, p4) } /// Draw the speciied image, with rounded corners @@ -354,14 +354,14 @@ impl<'ui> DrawListMut<'ui> { p_min: [f32; 2], p_max: [f32; 2], rounding: f32, - ) -> DrawListImageRounded { - DrawListImageRounded::new(self, texture_id, p_min, p_max, rounding) + ) -> ImageRounded { + ImageRounded::new(self, texture_id, p_min, p_max, rounding) } } /// Represents a line about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct DrawListLine<'ui> { +pub struct Line<'ui> { p1: [f32; 2], p2: [f32; 2], color: ImColor32, @@ -369,7 +369,7 @@ pub struct DrawListLine<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> DrawListLine<'ui> { +impl<'ui> Line<'ui> { fn new(draw_list: &'ui DrawListMut, p1: [f32; 2], p2: [f32; 2], c: C) -> Self where C: Into, @@ -405,7 +405,7 @@ impl<'ui> DrawListLine<'ui> { /// Represents a rectangle about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct DrawListRect<'ui> { +pub struct Rect<'ui> { p1: [f32; 2], p2: [f32; 2], color: ImColor32, @@ -416,7 +416,7 @@ pub struct DrawListRect<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> DrawListRect<'ui> { +impl<'ui> Rect<'ui> { fn new(draw_list: &'ui DrawListMut, p1: [f32; 2], p2: [f32; 2], c: C) -> Self where C: Into, @@ -574,7 +574,7 @@ impl<'ui> DrawListTriangle<'ui> { /// Represents a circle about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct DrawListCircle<'ui> { +pub struct Circle<'ui> { center: [f32; 2], radius: f32, color: ImColor32, @@ -584,7 +584,7 @@ pub struct DrawListCircle<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> DrawListCircle<'ui> { +impl<'ui> Circle<'ui> { /// Typically constructed by [`DrawListMut::add_circle`] pub fn new(draw_list: &'ui DrawListMut, center: [f32; 2], radius: f32, color: C) -> Self where @@ -649,7 +649,7 @@ impl<'ui> DrawListCircle<'ui> { /// Represents a Bezier curve about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct DrawListBezierCurve<'ui> { +pub struct BezierCurve<'ui> { pos0: [f32; 2], cp0: [f32; 2], pos1: [f32; 2], @@ -661,7 +661,7 @@ pub struct DrawListBezierCurve<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> DrawListBezierCurve<'ui> { +impl<'ui> BezierCurve<'ui> { /// Typically constructed by [`DrawListMut::add_bezier_curve`] pub fn new( draw_list: &'ui DrawListMut, @@ -716,9 +716,10 @@ impl<'ui> DrawListBezierCurve<'ui> { } } -/// Represents a image about to be drawn +/// Image draw list primitive, not to be confused with the widget +/// [`imgui::widgets::image::Image`]. See [`DrawListMut::add_image`] #[must_use = "should call .build() to draw the object"] -pub struct DrawListImage<'ui> { +pub struct Image<'ui> { texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2], @@ -728,7 +729,7 @@ pub struct DrawListImage<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> DrawListImage<'ui> { +impl<'ui> Image<'ui> { /// Typically constructed by [`DrawListMut::add_image`] pub fn new( draw_list: &'ui DrawListMut, @@ -787,7 +788,7 @@ impl<'ui> DrawListImage<'ui> { /// Represents a image about to be drawn #[must_use = "should call .build() to draw the object"] -pub struct DrawListImageQuad<'ui> { +pub struct ImageQuad<'ui> { texture_id: TextureId, p1: [f32; 2], p2: [f32; 2], @@ -801,7 +802,7 @@ pub struct DrawListImageQuad<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> DrawListImageQuad<'ui> { +impl<'ui> ImageQuad<'ui> { /// Typically constructed by [`DrawListMut::add_image_quad`] pub fn new( draw_list: &'ui DrawListMut, @@ -873,10 +874,10 @@ impl<'ui> DrawListImageQuad<'ui> { } } -/// Represents a image about to be drawn. Similar to [`DrawListImage`] but +/// Represents a image about to be drawn. Similar to [`Image`] but /// with corners rounded with a given radius #[must_use = "should call .build() to draw the object"] -pub struct DrawListImageRounded<'ui> { +pub struct ImageRounded<'ui> { texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2], @@ -888,7 +889,7 @@ pub struct DrawListImageRounded<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> DrawListImageRounded<'ui> { +impl<'ui> ImageRounded<'ui> { /// Typically constructed by [`DrawListMut::add_image_rounded`] pub fn new( draw_list: &'ui DrawListMut, From a4f74624e19e642ee9bde126d707e23d19d2a494 Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 24 Feb 2021 20:07:05 +1100 Subject: [PATCH 19/24] Fix wording in imgui::draw_list docs --- imgui/src/draw_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index f12cf0c..ea0cd2f 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -1,4 +1,4 @@ -//! The draw list lets you create custom graphics with a window. +//! The draw list lets you create custom graphics within a window. //! //! Each dear imgui window contains its own draw list. You can use //! [`Ui::get_window_draw_list`] to access the current window draw From caf8c8d95a6f08f9cc854cb453a5d2c4962cfd4b Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 24 Feb 2021 20:13:07 +1100 Subject: [PATCH 20/24] Fix doc link to `imgui::Image` Unsure why but [`imgui::Image`] doesn't work while [`crate::Image`] does --- imgui/src/draw_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index ea0cd2f..f462f3d 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -717,7 +717,7 @@ impl<'ui> BezierCurve<'ui> { } /// Image draw list primitive, not to be confused with the widget -/// [`imgui::widgets::image::Image`]. See [`DrawListMut::add_image`] +/// [`imgui::Image`](crate::Image). #[must_use = "should call .build() to draw the object"] pub struct Image<'ui> { texture_id: TextureId, From d98e004454ee55166efc303bc0f57ded9239c8c4 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 25 Feb 2021 21:03:52 +1100 Subject: [PATCH 21/24] cargo fmt --- imgui/src/draw_list.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index f462f3d..c5b6aa2 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -324,12 +324,7 @@ impl<'ui> DrawListMut<'ui> { /// .build(); /// } /// ``` - pub fn add_image( - &'ui self, - texture_id: TextureId, - p_min: [f32; 2], - p_max: [f32; 2], - ) -> Image { + pub fn add_image(&'ui self, texture_id: TextureId, p_min: [f32; 2], p_max: [f32; 2]) -> Image { Image::new(self, texture_id, p_min, p_max) } From 6b735e9aaba2f3d6d62380753bdc1c0df5de9e3d Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 25 Feb 2021 23:08:15 +1100 Subject: [PATCH 22/24] Somehow missed reverting the DrawList prefix from Triangle --- imgui/src/draw_list.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index c5b6aa2..2d482c8 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -229,11 +229,11 @@ impl<'ui> DrawListMut<'ui> { p2: [f32; 2], p3: [f32; 2], c: C, - ) -> DrawListTriangle<'ui> + ) -> Triangle<'ui> where C: Into, { - DrawListTriangle::new(self, p1, p2, p3, c) + Triangle::new(self, p1, p2, p3, c) } /// Returns a circle with the given `center`, `radius` and `color`. @@ -502,7 +502,7 @@ 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 DrawListTriangle<'ui> { +pub struct Triangle<'ui> { p1: [f32; 2], p2: [f32; 2], p3: [f32; 2], @@ -512,7 +512,7 @@ pub struct DrawListTriangle<'ui> { draw_list: &'ui DrawListMut<'ui>, } -impl<'ui> DrawListTriangle<'ui> { +impl<'ui> Triangle<'ui> { fn new(draw_list: &'ui DrawListMut, p1: [f32; 2], p2: [f32; 2], p3: [f32; 2], c: C) -> Self where C: Into, From e7001104dd4dfe8c6be7ca39d13a1cdb473bd74b Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 25 Feb 2021 23:08:50 +1100 Subject: [PATCH 23/24] Updated changelog for DrawListMut::add_image and legacy removal --- CHANGELOG.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 3e6d013..151da71 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -4,6 +4,16 @@ - Removed legacy `ImGuiDragDropFlags` from `legacy.rs`, which were accidentally not cleared when they were remade in `drag_drop.rs` in v0.7.0. +- The remaining flags in `imgui::legacy` have been updated to be consistent with other flags in the project. + - `imgui::legacy::ImGuiInputTextFlags` is now `imgui::input_widgets::InputTextFlags` + - `imgui::legacy::ImGuiTreeNodeFlags` is now `imgui::widget::tree::TreeNodeFlags` + - `imgui::legacy::ImDrawListFlags` is now `imgui::draw_list::DrawListFlags` + +- `DrawListMut` has new methods to draw images + - The methods are `add_image`, `add_image_quad`, and `add_image_rounded`. The `imgui-examples/examples/custom_textures.rs` has been updated to show their usage. + - Additionally the `imgui::draw_list` module is now public, which contains the various draw list objects. While the `add_*` methods are preferred, `imgui::draw_list::Circle::new(&draw_list_mut, ...).build()` is equivalent + + ## [0.7.0] - 2021-02-04 - Upgrade to [Dear ImGui v1.80](https://github.com/ocornut/imgui/releases/tag/v1.80). (Note that the new table functionality is not yet supported, however) From 107133c799c3fab10d8bfe18495b67dc28638fdd Mon Sep 17 00:00:00 2001 From: dbr Date: Tue, 9 Mar 2021 10:37:32 +1100 Subject: [PATCH 24/24] Fix functional conflicts - `ui.same_line()` no longer needs the default value specified \o/ - Doctests now actually being run, need to mark a code block as not-Rust --- imgui-examples/examples/custom_textures.rs | 4 ++-- imgui/src/draw_list.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui-examples/examples/custom_textures.rs b/imgui-examples/examples/custom_textures.rs index 2dc6acf..c1cce95 100644 --- a/imgui-examples/examples/custom_textures.rs +++ b/imgui-examples/examples/custom_textures.rs @@ -121,7 +121,7 @@ impl CustomTexturesApp { } { - ui.same_line(0.0); + ui.same_line(); // Button using quad positioned image ui.invisible_button(im_str!("Exciting Button"), [100.0, 100.0]); @@ -150,7 +150,7 @@ impl CustomTexturesApp { // Rounded image { - ui.same_line(0.0); + ui.same_line(); ui.invisible_button(im_str!("Smooth Button"), [100.0, 100.0]); let draw_list = ui.get_window_draw_list(); diff --git a/imgui/src/draw_list.rs b/imgui/src/draw_list.rs index c742d56..43f4458 100644 --- a/imgui/src/draw_list.rs +++ b/imgui/src/draw_list.rs @@ -838,8 +838,8 @@ impl<'ui> ImageQuad<'ui> { /// Set uv coordinates of each point of the quad. If not called, defaults are: /// - /// ``` - /// uv1: [0, 0], + /// ```text + /// uv1: [0.0, 0.0], /// uv2: [1, 0], /// uv3: [1, 1], /// uv4: [0, 1],