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

fix: Support alpha channel in AnimColor #771

Merged
merged 8 commits into from
Jul 9, 2024

Conversation

marc2332
Copy link
Owner

@marc2332 marc2332 commented Jul 8, 2024

Closes #770
Depends on #768

@marc2332 marc2332 added the enhancement 🔥 New feature or request label Jul 8, 2024
@marc2332 marc2332 changed the title fix: Rethink rendering of elements fix: Support alpha channel in AnimColor Jul 8, 2024
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 73.64%. Comparing base (5b0981e) to head (86c0ed0).

Files Patch % Lines
crates/hooks/src/use_animation.rs 92.85% 1 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##           fix/element-rendering-rethink     #771   +/-   ##
==============================================================
  Coverage                          73.63%   73.64%           
==============================================================
  Files                                200      200           
  Lines                              20487    20498   +11     
==============================================================
+ Hits                               15086    15096   +10     
- Misses                              5401     5402    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@marc2332 marc2332 marked this pull request as ready for review July 8, 2024 17:02
@Aiving
Copy link
Contributor

Aiving commented Jul 9, 2024

Despite the support of the alpha channel in as_string, it still does not animate, since the is_finished and advance functions do not use or change the alpha channel

fn is_finished(&self, index: i32, direction: AnimDirection) -> bool {
match direction {
AnimDirection::Forward => {
index > self.time.as_millis() as i32
&& self.value.r() >= self.destination.r()
&& self.value.g() >= self.destination.g()
&& self.value.b() >= self.destination.b()
}
AnimDirection::Reverse => {
index > self.time.as_millis() as i32
&& self.value.r() <= self.origin.r()
&& self.value.g() <= self.origin.g()
&& self.value.b() <= self.origin.b()
}
}
}
fn advance(&mut self, index: i32, direction: AnimDirection) {
if !self.is_finished(index, direction) {
let (origin, destination) = match direction {
AnimDirection::Forward => (self.origin, self.destination),
AnimDirection::Reverse => (self.destination, self.origin),
};
let r = apply_value(
origin.r() as f32,
destination.r() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
let g = apply_value(
origin.g() as f32,
destination.g() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
let b = apply_value(
origin.b() as f32,
destination.b() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
self.value = Color::from_rgb(r as u8, g as u8, b as u8);
}
}
}

@marc2332
Copy link
Owner Author

marc2332 commented Jul 9, 2024

Despite the support of the alpha channel in as_string, it still does not animate, since the is_finished and advance functions do not use or change the alpha channel

fn is_finished(&self, index: i32, direction: AnimDirection) -> bool {
match direction {
AnimDirection::Forward => {
index > self.time.as_millis() as i32
&& self.value.r() >= self.destination.r()
&& self.value.g() >= self.destination.g()
&& self.value.b() >= self.destination.b()
}
AnimDirection::Reverse => {
index > self.time.as_millis() as i32
&& self.value.r() <= self.origin.r()
&& self.value.g() <= self.origin.g()
&& self.value.b() <= self.origin.b()
}
}
}
fn advance(&mut self, index: i32, direction: AnimDirection) {
if !self.is_finished(index, direction) {
let (origin, destination) = match direction {
AnimDirection::Forward => (self.origin, self.destination),
AnimDirection::Reverse => (self.destination, self.origin),
};
let r = apply_value(
origin.r() as f32,
destination.r() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
let g = apply_value(
origin.g() as f32,
destination.g() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
let b = apply_value(
origin.b() as f32,
destination.b() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
self.value = Color::from_rgb(r as u8, g as u8, b as u8);
}
}
}

oh man, let me fix that

@marc2332
Copy link
Owner Author

marc2332 commented Jul 9, 2024

Despite the support of the alpha channel in as_string, it still does not animate, since the is_finished and advance functions do not use or change the alpha channel

fn is_finished(&self, index: i32, direction: AnimDirection) -> bool {
match direction {
AnimDirection::Forward => {
index > self.time.as_millis() as i32
&& self.value.r() >= self.destination.r()
&& self.value.g() >= self.destination.g()
&& self.value.b() >= self.destination.b()
}
AnimDirection::Reverse => {
index > self.time.as_millis() as i32
&& self.value.r() <= self.origin.r()
&& self.value.g() <= self.origin.g()
&& self.value.b() <= self.origin.b()
}
}
}
fn advance(&mut self, index: i32, direction: AnimDirection) {
if !self.is_finished(index, direction) {
let (origin, destination) = match direction {
AnimDirection::Forward => (self.origin, self.destination),
AnimDirection::Reverse => (self.destination, self.origin),
};
let r = apply_value(
origin.r() as f32,
destination.r() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
let g = apply_value(
origin.g() as f32,
destination.g() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
let b = apply_value(
origin.b() as f32,
destination.b() as f32,
index.min(self.time.as_millis() as i32),
self.time,
self.ease,
self.function,
);
self.value = Color::from_rgb(r as u8, g as u8, b as u8);
}
}
}

Fixed, I think

Base automatically changed from fix/element-rendering-rethink to main July 9, 2024 19:57
@marc2332 marc2332 merged commit fd39a0b into main Jul 9, 2024
3 of 4 checks passed
@marc2332 marc2332 deleted the feat/support-alpha-channel-in-color-animations branch July 9, 2024 20:00
This was referenced Jul 9, 2024
@github-actions github-actions bot mentioned this pull request Aug 3, 2024
@github-actions github-actions bot mentioned this pull request Aug 10, 2024
This was referenced Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🔥 New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enhancement: Support alpha channel in AnimColor
2 participants