Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a basic example + Image renderer #24

Closed
wants to merge 36 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
image clip
Kharif committed Jan 30, 2025

Verified

This commit was signed with the committer’s verified signature. The key has expired.
charlyx Charles-Henri GUERIN
commit 1c63df2f446140d3232f53be1baab55e3891d571
31 changes: 20 additions & 11 deletions examples/image_example/src/app.rs
Original file line number Diff line number Diff line change
@@ -88,11 +88,6 @@ impl RenderImage {
self
}

pub fn overflow_hidden(&mut self) -> &mut Self {
self.clip_overflow = true;
self
}

pub fn overflow_visible(&mut self) -> &mut Self {
self.clip_overflow = false;
self
@@ -416,6 +411,7 @@ impl ImageRenderer {
let stored_image = &self.stored_images[image.index.index];

let mut skip = false;

if image.clip_overflow {
let window_width = self.window_size.width as f32;
let window_height = self.window_size.height as f32;
@@ -441,6 +437,9 @@ impl ImageRenderer {
scissor_height,
);
}
} else {
// Reset scissor to the entire window when overflow is visible
render_pass.set_scissor_rect(0, 0, self.window_size.width, self.window_size.height);
}

if skip {
@@ -825,31 +824,41 @@ impl ApplicationHandler for App {
image_renderer.begin_frame();
image_renderer
.image(context.images[0])
.fit(Fit::Contain)
.v_align(AxisAlign::Start)
.frame([300.0, 300.0])
.offset([0.0, 0.0]);
image_renderer
.image(context.images[0])
.fit(Fit::Contain)
.v_align(AxisAlign::Start)
.v_align(AxisAlign::Center)
.frame([300.0, 300.0])
.offset([0.0, 320.0]);
.offset([320.0, 0.0]);
image_renderer
.image(context.images[0])
.v_align(AxisAlign::End)
.fit(Fit::Contain)
.frame([300.0, 300.0])
.offset([640.0, 320.0]);
.offset([640.0, 0.0]);
image_renderer
.image(context.images[0])
.frame([300.0, 300.0])
.offset([0.0, 640.0]);
.offset([0.0, 320.0]);
image_renderer
.image(context.images[0])
.fit(Fit::Cover)
.h_align(AxisAlign::Center)
.v_align(AxisAlign::Center)
.h_align(AxisAlign::End)
.v_align(AxisAlign::End)
.frame([300.0, 300.0])
.offset([320.0, 320.0]);
image_renderer
.image(context.images[0])
.fit(Fit::Cover)
.h_align(AxisAlign::Start)
.v_align(AxisAlign::Start)
.overflow_visible()
.frame([300.0, 300.0])
.offset([640.0, 320.0]);
image_renderer.render(&mut encoder, &view);
}