Skip to content

Commit b600954

Browse files
Update imgui to 0.8 and winit to 0.25 (#73)
* Update imgui to 0.8 and winit to 0.25 This also omits some id (label with `##`) assignments which are unnecessary when the item resides inside a stack with a unique item: https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-can-i-have-multiple-widgets-with-the-same-label These labels should only be used when: - The label changes based on some dynamic variable like a counter while still representing the same object; - Duplicate labels inside the same stack-item. Co-authored-by: Jasper Bekkers <bekkers@gmail.com>
1 parent 4498abf commit b600954

File tree

3 files changed

+56
-97
lines changed

3 files changed

+56
-97
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ ash = { version = "0.33", optional = true }
2525
# Only needed for d3d12.
2626
winapi = { version = "0.3.9", features = ["d3d12", "winerror", "impl-default", "impl-debug"], optional = true }
2727
# Only needed for visualizer.
28-
imgui = { version = "0.7", optional = true }
29-
imgui-winit-support = { version = "0.7", optional = true }
28+
imgui = { version = "0.8", optional = true }
29+
imgui-winit-support = { version = "0.8", optional = true }
3030

3131
[dev-dependencies]
3232
ash-window = "0.7"
3333
hassle-rs = "0.5.2"
3434
raw-window-handle = "0.3"
3535
widestring = "0.4.3"
3636
winapi = { version = "0.3.9", features = ["d3d12", "d3d12sdklayers", "dxgi1_6", "winerror", "impl-default", "impl-debug", "winuser", "windowsx", "libloaderapi"] }
37-
winit = "0.24"
37+
winit = "0.25"
3838

3939
[[example]]
4040
name = "vulkan-buffer"

src/d3d12/visualizer.rs

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ impl AllocatorVisualizer {
7878
}
7979

8080
fn render_main_window(&mut self, ui: &imgui::Ui, alloc: &Allocator) {
81-
imgui::Window::new(imgui::im_str!("Allocator visualization"))
81+
imgui::Window::new("Allocator visualization")
8282
.collapsed(true, Condition::FirstUseEver)
8383
.size([512.0, 512.0], imgui::Condition::FirstUseEver)
8484
.build(ui, || {
8585
use imgui::*;
8686

87-
if CollapsingHeader::new(&im_str!(
87+
if CollapsingHeader::new(format!(
8888
"Memory Types: ({} types)",
8989
alloc.memory_types.len()
9090
))
@@ -93,7 +93,7 @@ impl AllocatorVisualizer {
9393
{
9494
ui.indent();
9595
for (mem_type_i, mem_type) in alloc.memory_types.iter().enumerate() {
96-
if CollapsingHeader::new(&im_str!("Type: {}", mem_type_i)).build(ui) {
96+
if CollapsingHeader::new(format!("Type: {}", mem_type_i)).build(ui) {
9797
let mut total_block_size = 0;
9898
let mut total_allocated = 0;
9999
for block in mem_type.memory_blocks.iter().flatten() {
@@ -127,13 +127,7 @@ impl AllocatorVisualizer {
127127
ui.text(format!("block count: {}", active_block_count));
128128
for (block_i, block) in mem_type.memory_blocks.iter().enumerate() {
129129
if let Some(block) = block {
130-
TreeNode::new(&im_str!(
131-
"Block: {}##memtype({})",
132-
block_i,
133-
mem_type_i
134-
))
135-
.label(&im_str!("Block: {}", block_i))
136-
.build(ui, || {
130+
TreeNode::new(format!("Block: {}", block_i)).build(ui, || {
137131
ui.indent();
138132
ui.text(format!(
139133
"size: {} KiB",
@@ -146,32 +140,21 @@ impl AllocatorVisualizer {
146140
ui.text(format!("D3D12 heap: {:?}", block.heap));
147141
block.sub_allocator.draw_base_info(ui);
148142

149-
if block.sub_allocator.supports_visualization() {
150-
let button_name = format!(
151-
"visualize##memtype({})block({})",
152-
mem_type_i, block_i
153-
);
154-
if ui.small_button(&ImString::new(button_name)) {
155-
match self
156-
.selected_blocks
157-
.iter()
158-
.enumerate()
159-
.find_map(|(i, x)| {
160-
if x.memory_type_index == mem_type_i
161-
&& x.block_index == block_i
162-
{
163-
Some((i, (x)))
164-
} else {
165-
None
166-
}
167-
}) {
168-
Some(x) => self.focus = Some(x.0),
169-
None => self.selected_blocks.push(
170-
AllocatorVisualizerBlockWindow::new(
171-
mem_type_i, block_i,
172-
),
143+
if block.sub_allocator.supports_visualization()
144+
&& ui.small_button("visualize")
145+
{
146+
match self.selected_blocks.iter().enumerate().find(
147+
|(_, x)| {
148+
x.memory_type_index == mem_type_i
149+
&& x.block_index == block_i
150+
},
151+
) {
152+
Some(x) => self.focus = Some(x.0),
153+
None => self.selected_blocks.push(
154+
AllocatorVisualizerBlockWindow::new(
155+
mem_type_i, block_i,
173156
),
174-
}
157+
),
175158
}
176159
}
177160
ui.unindent();
@@ -186,7 +169,6 @@ impl AllocatorVisualizer {
186169
}
187170

188171
fn render_memory_block_windows(&mut self, ui: &imgui::Ui, alloc: &Allocator) {
189-
use imgui::*;
190172
// Copy here to workaround the borrow checker.
191173
let focus_opt = self.focus;
192174
// Keep track of a list of windows that are signaled by imgui to be closed.
@@ -201,10 +183,9 @@ impl AllocatorVisualizer {
201183
false
202184
};
203185
let mut is_open = true;
204-
imgui::Window::new(&imgui::im_str!(
186+
imgui::Window::new(format!(
205187
"Block Visualizer##memtype({})block({})",
206-
window.memory_type_index,
207-
window.block_index
188+
window.memory_type_index, window.block_index
208189
))
209190
.size([1920.0 * 0.5, 1080.0 * 0.5], imgui::Condition::FirstUseEver)
210191
.title_bar(true)
@@ -227,13 +208,13 @@ impl AllocatorVisualizer {
227208
));
228209

229210
if alloc.debug_settings.store_stack_traces {
230-
ui.checkbox(im_str!("Show backtraces"), &mut window.show_backtraces);
211+
ui.checkbox("Show backtraces", &mut window.show_backtraces);
231212
}
232213
// Slider for changing the 'zoom' level of the visualizer.
233214
const BYTES_PER_UNIT_MIN: i32 = 1;
234215
const BYTES_PER_UNIT_MAX: i32 = 1024 * 1024;
235-
Drag::new(im_str!("Bytes per Pixel (zoom)"))
236-
.range(BYTES_PER_UNIT_MIN..=BYTES_PER_UNIT_MAX)
216+
Drag::new("Bytes per Pixel (zoom)")
217+
.range(BYTES_PER_UNIT_MIN, BYTES_PER_UNIT_MAX)
237218
.speed(10.0f32)
238219
.build(ui, &mut window.bytes_per_unit);
239220

@@ -244,10 +225,9 @@ impl AllocatorVisualizer {
244225
.max(BYTES_PER_UNIT_MIN);
245226

246227
// Draw the visualization in a child window.
247-
imgui::ChildWindow::new(&im_str!(
228+
imgui::ChildWindow::new(&format!(
248229
"Visualization Sub-window##memtype({})block({})",
249-
window.memory_type_index,
250-
window.block_index
230+
window.memory_type_index, window.block_index
251231
))
252232
.scrollable(true)
253233
.scroll_bar(true)

src/vulkan/visualizer.rs

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl AllocatorVisualizer {
4444
}
4545

4646
fn render_main_window(&mut self, ui: &imgui::Ui, alloc: &Allocator) {
47-
imgui::Window::new(imgui::im_str!("Allocator visualization"))
47+
imgui::Window::new("Allocator visualization")
4848
.collapsed(true, Condition::FirstUseEver)
4949
.size([512.0, 512.0], imgui::Condition::FirstUseEver)
5050
.build(ui, || {
@@ -56,11 +56,10 @@ impl AllocatorVisualizer {
5656
));
5757

5858
let heap_count = alloc.memory_heaps.len();
59-
if CollapsingHeader::new(&im_str!("Memory Heaps ({} heaps)", heap_count)).build(ui)
60-
{
59+
if CollapsingHeader::new(format!("Memory Heaps ({} heaps)", heap_count)).build(ui) {
6160
for (i, heap) in alloc.memory_heaps.iter().enumerate() {
6261
ui.indent();
63-
if CollapsingHeader::new(&im_str!("Heap: {}", i)).build(ui) {
62+
if CollapsingHeader::new(format!("Heap: {}", i)).build(ui) {
6463
ui.indent();
6564
ui.text(format!("flags: {:?}", heap.flags));
6665
ui.text(format!(
@@ -73,7 +72,7 @@ impl AllocatorVisualizer {
7372
}
7473
}
7574

76-
if CollapsingHeader::new(&im_str!(
75+
if CollapsingHeader::new(format!(
7776
"Memory Types: ({} types)",
7877
alloc.memory_types.len()
7978
))
@@ -82,8 +81,8 @@ impl AllocatorVisualizer {
8281
{
8382
ui.indent();
8483
for (mem_type_i, mem_type) in alloc.memory_types.iter().enumerate() {
85-
if CollapsingHeader::new(&im_str!(
86-
"Type: {} ({} blocks)###Type{}",
84+
if CollapsingHeader::new(format!(
85+
"Type: {} ({} blocks)##Type{}",
8786
mem_type_i,
8887
mem_type.memory_blocks.len(),
8988
mem_type_i,
@@ -109,13 +108,7 @@ impl AllocatorVisualizer {
109108
ui.text(format!("block count: {}", active_block_count));
110109
for (block_i, block) in mem_type.memory_blocks.iter().enumerate() {
111110
if let Some(block) = block {
112-
TreeNode::new(&im_str!(
113-
"Block: {}##memtype({})",
114-
block_i,
115-
mem_type_i
116-
))
117-
.label(&im_str!("Block: {}", block_i))
118-
.build(ui, || {
111+
TreeNode::new(format!("Block: {}", block_i)).build(ui, || {
119112
use ash::vk::Handle;
120113
ui.indent();
121114
ui.text(format!("size: {} KiB", block.size / 1024));
@@ -134,32 +127,21 @@ impl AllocatorVisualizer {
134127

135128
block.sub_allocator.draw_base_info(ui);
136129

137-
if block.sub_allocator.supports_visualization() {
138-
let button_name = format!(
139-
"visualize##memtype({})block({})",
140-
mem_type_i, block_i
141-
);
142-
if ui.small_button(&ImString::new(button_name)) {
143-
match self
144-
.selected_blocks
145-
.iter()
146-
.enumerate()
147-
.find_map(|(i, x)| {
148-
if x.memory_type_index == mem_type_i
149-
&& x.block_index == block_i
150-
{
151-
Some((i, (x)))
152-
} else {
153-
None
154-
}
155-
}) {
156-
Some(x) => self.focus = Some(x.0),
157-
None => self.selected_blocks.push(
158-
AllocatorVisualizerBlockWindow::new(
159-
mem_type_i, block_i,
160-
),
130+
if block.sub_allocator.supports_visualization()
131+
&& ui.small_button("visualize")
132+
{
133+
match self.selected_blocks.iter().enumerate().find(
134+
|(_, x)| {
135+
x.memory_type_index == mem_type_i
136+
&& x.block_index == block_i
137+
},
138+
) {
139+
Some(x) => self.focus = Some(x.0),
140+
None => self.selected_blocks.push(
141+
AllocatorVisualizerBlockWindow::new(
142+
mem_type_i, block_i,
161143
),
162-
}
144+
),
163145
}
164146
}
165147
ui.unindent();
@@ -174,7 +156,6 @@ impl AllocatorVisualizer {
174156
}
175157

176158
fn render_memory_block_windows(&mut self, ui: &imgui::Ui, alloc: &Allocator) {
177-
use imgui::*;
178159
// Copy here to workaround the borrow checker.
179160
let focus_opt = self.focus;
180161
// Keep track of a list of windows that are signaled by imgui to be closed.
@@ -189,10 +170,9 @@ impl AllocatorVisualizer {
189170
false
190171
};
191172
let mut is_open = true;
192-
imgui::Window::new(&imgui::im_str!(
173+
imgui::Window::new(format!(
193174
"Block Visualizer##memtype({})block({})",
194-
window.memory_type_index,
195-
window.block_index
175+
window.memory_type_index, window.block_index
196176
))
197177
.size([1920.0 * 0.5, 1080.0 * 0.5], imgui::Condition::FirstUseEver)
198178
.title_bar(true)
@@ -215,13 +195,13 @@ impl AllocatorVisualizer {
215195
));
216196

217197
if alloc.debug_settings.store_stack_traces {
218-
ui.checkbox(im_str!("Show backtraces"), &mut window.show_backtraces);
198+
ui.checkbox("Show backtraces", &mut window.show_backtraces);
219199
}
220200
// Slider for changing the 'zoom' level of the visualizer.
221201
const BYTES_PER_UNIT_MIN: i32 = 1;
222202
const BYTES_PER_UNIT_MAX: i32 = 1024 * 1024;
223-
Drag::new(im_str!("Bytes per Pixel (zoom)"))
224-
.range(BYTES_PER_UNIT_MIN..=BYTES_PER_UNIT_MAX)
203+
Drag::new("Bytes per Pixel (zoom)")
204+
.range(BYTES_PER_UNIT_MIN, BYTES_PER_UNIT_MAX)
225205
.speed(10.0f32)
226206
.build(ui, &mut window.bytes_per_unit);
227207

@@ -232,10 +212,9 @@ impl AllocatorVisualizer {
232212
.max(BYTES_PER_UNIT_MIN);
233213

234214
// Draw the visualization in a child window.
235-
imgui::ChildWindow::new(&im_str!(
215+
imgui::ChildWindow::new(&format!(
236216
"Visualization Sub-window##memtype({})block({})",
237-
window.memory_type_index,
238-
window.block_index
217+
window.memory_type_index, window.block_index
239218
))
240219
.scrollable(true)
241220
.scroll_bar(true)

0 commit comments

Comments
 (0)