Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 192 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ notify = "8.0.0"
taffy = { version = "0.7.7", features = ["serde"]}
slotmap = "1.0.7"
color = "0.3.1"
cosmic-text = "0.13.0"
45 changes: 45 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ impl<'window> ApplicationHandler<CustomEvent> for App<'window> {

gui.compute_layout(size.width, size.height);
gpu.update_instance_buffer(gui.into_instances());

// Collect and render text instances
let text_items = gui.collect_text_instances();
println!("GuiUpdate: collected {} text items", text_items.len());
let mut all_text_instances = Vec::new();

for (text, x, y, font_size, color, max_width) in text_items {
let text_instances = gpu.render_text(&text, x, y, font_size, color, Some(max_width));
all_text_instances.extend(text_instances);
}

println!("GuiUpdate: updating GPU with {} text instances", all_text_instances.len());
gpu.update_text_instances(&all_text_instances);
Copy link

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic to collect and update text instances is duplicated across GuiUpdate, Resized, and ScaleFactorChanged handlers. Consider extracting this into a helper method to reduce code duplication.

Suggested change
let text_items = gui.collect_text_instances();
println!("GuiUpdate: collected {} text items", text_items.len());
let mut all_text_instances = Vec::new();
for (text, x, y, font_size, color, max_width) in text_items {
let text_instances = gpu.render_text(&text, x, y, font_size, color, Some(max_width));
all_text_instances.extend(text_instances);
}
println!("GuiUpdate: updating GPU with {} text instances", all_text_instances.len());
gpu.update_text_instances(&all_text_instances);
self.collect_and_render_text_instances(window, gpu, &mut gui);

Copilot uses AI. Check for mistakes.


window.request_redraw();
}
Expand All @@ -78,11 +91,43 @@ impl<'window> ApplicationHandler<CustomEvent> for App<'window> {
if let Ok(mut gui) = self.gui.lock() {
gui.compute_layout(size.width, size.height);
gpu.update_instance_buffer(gui.into_instances());

// Collect and render text instances
let text_items = gui.collect_text_instances();
println!("Resized: collected {} text items", text_items.len());
let mut all_text_instances = Vec::new();

for (text, x, y, font_size, color, max_width) in text_items {
let text_instances = gpu.render_text(&text, x, y, font_size, color, Some(max_width));
all_text_instances.extend(text_instances);
}

println!("Resized: updating GPU with {} text instances", all_text_instances.len());
gpu.update_text_instances(&all_text_instances);

gpu.set_size(size.width, size.height);
}
}
}
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
if let Some(gpu) = self.gpu.as_mut() {
println!("Scale factor changed to: {}", scale_factor);
gpu.update_scale_factor(scale_factor);

// Re-render text with new scale factor
if let Ok(gui) = self.gui.lock() {
let text_items = gui.collect_text_instances();
let mut all_text_instances = Vec::new();

for (text, x, y, font_size, color, max_width) in text_items {
let text_instances = gpu.render_text(&text, x, y, font_size, color, Some(max_width));
all_text_instances.extend(text_instances);
}

gpu.update_text_instances(&all_text_instances);
}
}
}
WindowEvent::RedrawRequested => {
if let Some(gpu) = self.gpu.as_mut() {
gpu.draw();
Expand Down
Loading