mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 13:38:35 +00:00
Update to imgui 1.81
Changes: - No more ListBox::calculate_size(...) as this was deprecated upstream
This commit is contained in:
parent
2839f76cec
commit
507d5d5065
@ -515,7 +515,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
|
||||
im_str!("Tilefish"),
|
||||
];
|
||||
|
||||
ListBox::new(im_str!("selectables list")).calculate_size(8, 4).build(ui, || {
|
||||
ListBox::new(im_str!("selectables list")).build(ui, || {
|
||||
for (index, name) in names.iter().enumerate() {
|
||||
let selected = matches!(state.selected_fish2, Some(i) if i == index );
|
||||
if Selectable::new(name).selected(selected).build(ui) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
imgui-sys/third-party/cimgui
vendored
2
imgui-sys/third-party/cimgui
vendored
@ -1 +1 @@
|
||||
Subproject commit 6791a95f79d51d8ca9df2b32d2b87a0c17a3c093
|
||||
Subproject commit 25aa25bd835eaacdfabb9289fb33c21cd6e65987
|
||||
@ -50,7 +50,7 @@ impl<'ui> DrawListMut<'ui> {
|
||||
pub(crate) fn background(_: &Ui<'ui>) -> Self {
|
||||
Self::lock_draw_list();
|
||||
Self {
|
||||
draw_list: unsafe { sys::igGetBackgroundDrawList() },
|
||||
draw_list: unsafe { sys::igGetBackgroundDrawListNil() },
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
@ -58,7 +58,7 @@ impl<'ui> DrawListMut<'ui> {
|
||||
pub(crate) fn foreground(_: &Ui<'ui>) -> Self {
|
||||
Self::lock_draw_list();
|
||||
Self {
|
||||
draw_list: unsafe { sys::igGetForegroundDrawList() },
|
||||
draw_list: unsafe { sys::igGetForegroundDrawListNil() },
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +58,8 @@ pub struct FontAtlas {
|
||||
custom_rects: sys::ImVector_ImFontAtlasCustomRect,
|
||||
config_data: sys::ImVector_ImFontConfig,
|
||||
tex_uv_lines: [[f32; 4]; 64],
|
||||
font_builder_io: *const sys::ImFontBuilderIO,
|
||||
font_builder_flags: i32,
|
||||
pack_id_mouse_cursors: i32,
|
||||
pack_id_lines: i32,
|
||||
}
|
||||
@ -302,7 +304,7 @@ pub struct FontConfig {
|
||||
/// Maximum advance_x for glyphs
|
||||
pub glyph_max_advance_x: f32,
|
||||
/// Settings for a custom font rasterizer if used
|
||||
pub rasterizer_flags: u32,
|
||||
pub font_builder_flags: u32,
|
||||
/// Brighten (>1.0) or darken (<1.0) font output
|
||||
pub rasterizer_multiply: f32,
|
||||
/// Explicitly specify the ellipsis character.
|
||||
@ -324,7 +326,7 @@ impl Default for FontConfig {
|
||||
glyph_ranges: FontGlyphRanges::default(),
|
||||
glyph_min_advance_x: 0.0,
|
||||
glyph_max_advance_x: f32::MAX,
|
||||
rasterizer_flags: 0,
|
||||
font_builder_flags: 0,
|
||||
rasterizer_multiply: 1.0,
|
||||
ellipsis_char: None,
|
||||
name: None,
|
||||
@ -343,7 +345,7 @@ impl FontConfig {
|
||||
raw.GlyphRanges = unsafe { self.glyph_ranges.to_ptr(atlas) };
|
||||
raw.GlyphMinAdvanceX = self.glyph_min_advance_x;
|
||||
raw.GlyphMaxAdvanceX = self.glyph_max_advance_x;
|
||||
raw.RasterizerFlags = self.rasterizer_flags;
|
||||
raw.FontBuilderFlags = self.font_builder_flags;
|
||||
raw.RasterizerMultiply = self.rasterizer_multiply;
|
||||
raw.EllipsisChar = self.ellipsis_char.map(|x| x as u16).unwrap_or(0xffff);
|
||||
if let Some(name) = self.name.as_ref() {
|
||||
@ -396,8 +398,8 @@ fn test_font_config_default() {
|
||||
sys_font_config.GlyphMaxAdvanceX
|
||||
);
|
||||
assert_eq!(
|
||||
font_config.rasterizer_flags,
|
||||
sys_font_config.RasterizerFlags
|
||||
font_config.font_builder_flags,
|
||||
sys_font_config.FontBuilderFlags
|
||||
);
|
||||
assert_eq!(
|
||||
font_config.rasterizer_multiply,
|
||||
|
||||
@ -99,7 +99,7 @@ pub fn dear_imgui_version() -> &'static str {
|
||||
#[test]
|
||||
fn test_version() {
|
||||
// TODO: what's the point of this test?
|
||||
assert_eq!(dear_imgui_version(), "1.80");
|
||||
assert_eq!(dear_imgui_version(), "1.81");
|
||||
}
|
||||
|
||||
impl Context {
|
||||
|
||||
@ -9,14 +9,14 @@ use crate::sys;
|
||||
pub struct DrawData {
|
||||
/// Only valid after render() is called and before the next new frame() is called.
|
||||
valid: bool,
|
||||
// Array of DrawList.
|
||||
cmd_lists: *mut *mut DrawList,
|
||||
/// Number of DrawList to render.
|
||||
cmd_lists_count: i32,
|
||||
/// For convenience, sum of all draw list index buffer sizes.
|
||||
pub total_idx_count: i32,
|
||||
/// For convenience, sum of all draw list vertex buffer sizes.
|
||||
pub total_vtx_count: i32,
|
||||
// Array of DrawList.
|
||||
cmd_lists: *mut *mut DrawList,
|
||||
/// Upper-left position of the viewport to render.
|
||||
///
|
||||
/// (= upper-left corner of the orthogonal projection matrix to use)
|
||||
|
||||
@ -4,20 +4,12 @@ use crate::string::ImStr;
|
||||
use crate::sys;
|
||||
use crate::Ui;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
enum Size {
|
||||
Vec(sys::ImVec2),
|
||||
Items {
|
||||
items_count: i32,
|
||||
height_in_items: i32,
|
||||
},
|
||||
}
|
||||
/// Builder for a list box widget
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[must_use]
|
||||
pub struct ListBox<'a> {
|
||||
label: &'a ImStr,
|
||||
size: Size,
|
||||
size: sys::ImVec2,
|
||||
}
|
||||
|
||||
impl<'a> ListBox<'a> {
|
||||
@ -25,21 +17,9 @@ impl<'a> ListBox<'a> {
|
||||
pub const fn new(label: &'a ImStr) -> ListBox<'a> {
|
||||
ListBox {
|
||||
label,
|
||||
size: Size::Vec(sys::ImVec2::zero()),
|
||||
size: sys::ImVec2::zero(),
|
||||
}
|
||||
}
|
||||
/// Sets the list box size based on the number of items that you want to make visible
|
||||
/// Size default to hold ~7.25 items.
|
||||
/// We add +25% worth of item height to allow the user to see at a glance if there are more items up/down, without looking at the scrollbar.
|
||||
/// We don't add this extra bit if items_count <= height_in_items. It is slightly dodgy, because it means a dynamic list of items will make the widget resize occasionally when it crosses that size.
|
||||
#[inline]
|
||||
pub const fn calculate_size(mut self, items_count: i32, height_in_items: i32) -> Self {
|
||||
self.size = Size::Items {
|
||||
items_count,
|
||||
height_in_items,
|
||||
};
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the list box size based on the given width and height
|
||||
/// If width or height are 0 or smaller, a default value is calculated
|
||||
@ -49,7 +29,7 @@ impl<'a> ListBox<'a> {
|
||||
/// Default: [0.0, 0.0], in which case the combobox calculates a sensible width and height
|
||||
#[inline]
|
||||
pub const fn size(mut self, size: [f32; 2]) -> Self {
|
||||
self.size = Size::Vec(sys::ImVec2::new(size[0], size[1]));
|
||||
self.size = sys::ImVec2::new(size[0], size[1]);
|
||||
self
|
||||
}
|
||||
/// Creates a list box and starts appending to it.
|
||||
@ -60,15 +40,7 @@ impl<'a> ListBox<'a> {
|
||||
/// Returns `None` if the list box is not open and no content should be rendered.
|
||||
#[must_use]
|
||||
pub fn begin<'ui>(self, ui: &Ui<'ui>) -> Option<ListBoxToken<'ui>> {
|
||||
let should_render = unsafe {
|
||||
match self.size {
|
||||
Size::Vec(size) => sys::igListBoxHeaderVec2(self.label.as_ptr(), size),
|
||||
Size::Items {
|
||||
items_count,
|
||||
height_in_items,
|
||||
} => sys::igListBoxHeaderInt(self.label.as_ptr(), items_count, height_in_items),
|
||||
}
|
||||
};
|
||||
let should_render = unsafe { sys::igBeginListBox(self.label.as_ptr(), self.size) };
|
||||
if should_render {
|
||||
Some(ListBoxToken::new(ui))
|
||||
} else {
|
||||
@ -91,7 +63,7 @@ create_token!(
|
||||
pub struct ListBoxToken<'ui>;
|
||||
|
||||
/// Ends a list box
|
||||
drop { sys::igListBoxFooter() }
|
||||
drop { sys::igEndListBox() }
|
||||
);
|
||||
|
||||
/// # Convenience functions
|
||||
|
||||
@ -29,11 +29,11 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
/// Sets the horizontal scrolling position
|
||||
pub fn set_scroll_x(&self, scroll_x: f32) {
|
||||
unsafe { sys::igSetScrollX(scroll_x) };
|
||||
unsafe { sys::igSetScrollXFloat(scroll_x) };
|
||||
}
|
||||
/// Sets the vertical scroll position
|
||||
pub fn set_scroll_y(&self, scroll_y: f32) {
|
||||
unsafe { sys::igSetScrollY(scroll_y) };
|
||||
unsafe { sys::igSetScrollYFloat(scroll_y) };
|
||||
}
|
||||
/// Adjusts the horizontal scroll position to make the current cursor position visible
|
||||
pub fn set_scroll_here_x(&self) {
|
||||
@ -65,7 +65,7 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
/// Adjusts the horizontal scroll position to make the given position visible
|
||||
pub fn set_scroll_from_pos_x(&self, local_x: f32) {
|
||||
unsafe { sys::igSetScrollFromPosX(local_x, 0.5) };
|
||||
unsafe { sys::igSetScrollFromPosXFloat(local_x, 0.5) };
|
||||
}
|
||||
/// Adjusts the horizontal scroll position to make the given position visible.
|
||||
///
|
||||
@ -75,11 +75,11 @@ impl<'ui> Ui<'ui> {
|
||||
/// - `0.5`: center
|
||||
/// - `1.0`: right
|
||||
pub fn set_scroll_from_pos_x_with_ratio(&self, local_x: f32, center_x_ratio: f32) {
|
||||
unsafe { sys::igSetScrollFromPosX(local_x, center_x_ratio) };
|
||||
unsafe { sys::igSetScrollFromPosXFloat(local_x, center_x_ratio) };
|
||||
}
|
||||
/// Adjusts the vertical scroll position to make the given position visible
|
||||
pub fn set_scroll_from_pos_y(&self, local_y: f32) {
|
||||
unsafe { sys::igSetScrollFromPosY(local_y, 0.5) };
|
||||
unsafe { sys::igSetScrollFromPosYFloat(local_y, 0.5) };
|
||||
}
|
||||
/// Adjusts the vertical scroll position to make the given position visible.
|
||||
///
|
||||
@ -89,6 +89,6 @@ impl<'ui> Ui<'ui> {
|
||||
/// - `0.5`: center
|
||||
/// - `1.0`: bottom
|
||||
pub fn set_scroll_from_pos_y_with_ratio(&self, local_y: f32, center_y_ratio: f32) {
|
||||
unsafe { sys::igSetScrollFromPosY(local_y, center_y_ratio) };
|
||||
unsafe { sys::igSetScrollFromPosYFloat(local_y, center_y_ratio) };
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user