-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for images * Elide explicit lifetime in draw_img + code formatting * Change draw_img of VgerRenderer to accept the img by ref * Apply improvements suggested by clippy * Code formatting
- Loading branch information
1 parent
2ef077e
commit 8d8e7a3
Showing
13 changed files
with
407 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,31 @@ | ||
> [!WARNING] | ||
> **Work in progress, which is subject to frequent change.** | ||
If you plan to add changes, please make sure you reach out in our discord first. | ||
|
||
The end-goal is to support reactive animations, similar to Swift UI(including spring animations). | ||
The API we are currently aiming for looks something like this: | ||
```rust | ||
let (is_hovered, set_is_hovered) = create_signal(false); | ||
let (scroll_offset_pct, set_scroll_offset_pct) = create_signal(0.); | ||
|
||
scroll({ | ||
button() | ||
.style(|s| { | ||
s.width(move || {50.0}) | ||
}) | ||
.animation(|s| { | ||
s.width(300) | ||
// we get animation on scroll "for free", since everything is integrated with the reactive system | ||
.opacity(move || scroll_offset_pct) | ||
.scale(move || is_hovered.get() {1.2} else {1.0} ) | ||
.easing_fn(EasingFn::Cubic) | ||
.ease_in_out() | ||
.duration(Duration::from_secs(1)) | ||
}) | ||
}.on_scroll(move |scroll| { | ||
let offset_pct = ......snip........ | ||
set_scroll_offset_pct.update(|value| *value = offset_pct); | ||
true | ||
}) | ||
) | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,37 @@ | ||
use floem::{ | ||
unit::UnitExt, | ||
view::View, | ||
views::{img, scroll, Decorators}, | ||
}; | ||
|
||
use crate::form::{form, form_item}; | ||
|
||
pub fn img_view() -> impl View { | ||
let ferris = include_bytes!("./../assets/ferris.png"); | ||
let sunflower = include_bytes!("./../assets/sunflower.jpg"); | ||
|
||
scroll(form({ | ||
( | ||
form_item("PNG:".to_string(), 120.0, move || { | ||
img(move || ferris.to_vec()) | ||
}), | ||
form_item("PNG(resized):".to_string(), 120.0, move || { | ||
img(move || ferris.to_vec()).style(|s| s.width(230.px()).height(153.px())) | ||
}), | ||
form_item("JPG:".to_string(), 120.0, move || { | ||
img(move || sunflower.to_vec()) | ||
}), | ||
form_item("JPG(resized):".to_string(), 120.0, move || { | ||
img(move || sunflower.to_vec()).style(|s| s.width(320.px()).height(490.px())) | ||
}), | ||
//TODO: support percentages for width/height | ||
// img(move || ferris.to_vec()).style(|s| s.width(90.pct()).height(90.pct())) | ||
// | ||
//TODO: object fit and object position | ||
// img(move || ferris.to_vec()) | ||
// .object_fit(ObjectFit::Contain).object_position(VertPosition::Top, HorizPosition::Left)) | ||
// | ||
) | ||
})) | ||
.style(|s| s.flex_col().min_width(1000.px())) | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.