-
Notifications
You must be signed in to change notification settings - Fork 0
Add CoreAnimation-style border rendering to Layer #31
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
Draft
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/add-border-rendering-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8132179
Initial plan
Copilot 8732ccf
Add border rendering support to Layer with CoreAnimation-style API
Copilot 54b572e
Add tests and documentation for border rendering feature
Copilot e31e3cc
Address code review feedback: clarify shader coordinate space and imp…
Copilot 77dd9df
Improve code clarity: rename padding fields and add comprehensive doc…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| // Copyright (c) 2021 Joone Hur <joone@chromium.org> All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| // This example demonstrates border rendering with CoreAnimation-style API | ||
|
|
||
| use std::sync::Arc; | ||
| use winit::{ | ||
| event::{Event, KeyEvent, WindowEvent}, | ||
| event_loop::{ControlFlow, EventLoop}, | ||
| keyboard::{KeyCode, PhysicalKey}, | ||
| window::WindowBuilder, | ||
| }; | ||
|
|
||
| use rust_animation::layer::LayoutMode; | ||
| use rust_animation::layer::Layer; | ||
| use rust_animation::play::Play; | ||
|
|
||
| fn main() { | ||
| let event_loop = EventLoop::new().unwrap(); | ||
| let window = Arc::new( | ||
| WindowBuilder::new() | ||
| .with_title("Border Rendering Demo") | ||
| .with_inner_size(winit::dpi::LogicalSize::new(1280, 720)) | ||
| .build(&event_loop) | ||
| .unwrap(), | ||
| ); | ||
|
|
||
| // Get the actual window size (may differ from requested due to DPI scaling) | ||
| let window_size = window.inner_size(); | ||
| let (width, height) = (window_size.width, window_size.height); | ||
|
|
||
| let mut play = Play::new( | ||
| "Border Rendering Demo".to_string(), | ||
| width as i32, | ||
| height as i32, | ||
| LayoutMode::UserDefine, | ||
| ); | ||
|
|
||
| // Initialize wgpu context with surface using actual window size | ||
| play.init_wgpu_with_surface(window.clone(), width, height); | ||
|
|
||
| let mut stage = Layer::new("stage".to_string(), width, height, None); | ||
| stage.set_visible(true); | ||
| stage.set_background_color(0.95, 0.95, 0.95); // Light gray background | ||
|
|
||
| // Example 1: Red layer with black border | ||
| let mut layer1 = Layer::new("layer1".to_string(), 150, 150, None); | ||
| layer1.set_position(100, 100); | ||
| layer1.set_background_color(1.0, 0.0, 0.0); // Red | ||
| layer1.set_border(5.0, 0.0, 0.0, 0.0, 1.0); // 5px black border | ||
|
|
||
| // Example 2: Green layer with white border | ||
| let mut layer2 = Layer::new("layer2".to_string(), 150, 150, None); | ||
| layer2.set_position(300, 100); | ||
| layer2.set_background_color(0.0, 1.0, 0.0); // Green | ||
| layer2.set_border(3.0, 1.0, 1.0, 1.0, 1.0); // 3px white border | ||
|
|
||
| // Example 3: Blue layer with yellow border | ||
| let mut layer3 = Layer::new("layer3".to_string(), 150, 150, None); | ||
| layer3.set_position(500, 100); | ||
| layer3.set_background_color(0.0, 0.0, 1.0); // Blue | ||
| layer3.set_border(10.0, 1.0, 1.0, 0.0, 1.0); // 10px yellow border | ||
|
|
||
| // Example 4: White layer with semi-transparent red border | ||
| let mut layer4 = Layer::new("layer4".to_string(), 150, 150, None); | ||
| layer4.set_position(700, 100); | ||
| layer4.set_background_color(1.0, 1.0, 1.0); // White | ||
| layer4.set_border(8.0, 1.0, 0.0, 0.0, 0.5); // 8px semi-transparent red border | ||
|
|
||
| // Example 5: Nested layers with borders | ||
| let mut parent_layer = Layer::new("parent".to_string(), 200, 200, None); | ||
| parent_layer.set_position(100, 300); | ||
| parent_layer.set_background_color(0.8, 0.8, 0.8); // Light gray | ||
| parent_layer.set_border(5.0, 0.2, 0.2, 0.2, 1.0); // 5px dark gray border | ||
|
|
||
| let mut child_layer = Layer::new("child".to_string(), 100, 100, None); | ||
| child_layer.set_position(50, 50); | ||
| child_layer.set_background_color(1.0, 0.5, 0.0); // Orange | ||
| child_layer.set_border(3.0, 0.5, 0.0, 0.5, 1.0); // 3px purple border | ||
|
|
||
| parent_layer.add_sublayer(child_layer); | ||
|
|
||
| // Example 6: Various border widths | ||
| let border_widths = vec![1.0, 2.0, 5.0, 10.0, 15.0]; | ||
| for (i, width) in border_widths.iter().enumerate() { | ||
| let mut layer = Layer::new(format!("border_{}", i), 80, 80, None); | ||
| layer.set_position(350 + (i as i32 * 100), 300); | ||
| layer.set_background_color(0.5, 0.5, 1.0); // Light blue | ||
| layer.set_border(*width, 0.0, 0.0, 0.5, 1.0); // Dark blue border | ||
| stage.add_sublayer(layer); | ||
| } | ||
|
|
||
| // Example 7: Layer with border and optional image | ||
| // If splash.png exists, it will be displayed with a border, otherwise just the border is shown | ||
| let mut image_layer = Layer::new("image_layer".to_string(), 200, 200, None); | ||
| image_layer.set_position(100, 520); | ||
| image_layer.set_background_color(0.9, 0.9, 0.9); // Light gray fallback | ||
| image_layer.set_image("examples/splash.png".to_string()); | ||
| image_layer.set_border(5.0, 1.0, 0.0, 1.0, 1.0); // 5px magenta border | ||
|
|
||
| // Add all layers to stage | ||
| stage.add_sublayer(layer1); | ||
| stage.add_sublayer(layer2); | ||
| stage.add_sublayer(layer3); | ||
| stage.add_sublayer(layer4); | ||
| stage.add_sublayer(parent_layer); | ||
| stage.add_sublayer(image_layer); | ||
|
|
||
| play.add_stage(stage); | ||
|
|
||
| println!("Border Rendering Demo"); | ||
| println!("====================="); | ||
| println!("Demonstrates various border styles:"); | ||
| println!("- Top row: Different colors and widths"); | ||
| println!("- Middle left: Nested layers with borders"); | ||
| println!("- Middle: Progressive border widths (1px to 15px)"); | ||
| println!("- Bottom: Image with border"); | ||
| println!("\nPress ESC to exit"); | ||
|
|
||
| event_loop | ||
| .run(move |event, elwt| { | ||
| elwt.set_control_flow(ControlFlow::Poll); | ||
|
|
||
| match event { | ||
| Event::WindowEvent { event, .. } => match event { | ||
| WindowEvent::CloseRequested => elwt.exit(), | ||
| WindowEvent::KeyboardInput { | ||
| event: | ||
| KeyEvent { | ||
| physical_key: PhysicalKey::Code(KeyCode::Escape), | ||
| .. | ||
| }, | ||
| .. | ||
| } => elwt.exit(), | ||
| WindowEvent::Resized(new_size) => { | ||
| // Update wgpu surface and projection when window is resized | ||
| play.resize(new_size.width, new_size.height); | ||
| } | ||
| WindowEvent::RedrawRequested => { | ||
| play.render(); | ||
| window.request_redraw(); | ||
| } | ||
| _ => {} | ||
| }, | ||
| Event::AboutToWait => { | ||
| window.request_redraw(); | ||
| } | ||
| _ => {} | ||
| } | ||
| }) | ||
| .unwrap(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright (c) 2026 Joone Hur joone@chromium.org All rights reserved