Skip to content
Open
Show file tree
Hide file tree
Changes from all 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"
54 changes: 54 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ impl<'window> ApplicationHandler<CustomEvent> for App<'window> {
if let Ok(mut gui) = self.gui.lock() {
let size = window.inner_size();

// 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);

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

Expand All @@ -76,13 +93,50 @@ impl<'window> ApplicationHandler<CustomEvent> for App<'window> {
WindowEvent::Resized(size) => {
if let Some(gpu) = self.gpu.as_mut() {
if let Ok(mut gui) = self.gui.lock() {
// 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);

gui.compute_layout(size.width, size.height);
gpu.update_instance_buffer(gui.into_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