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

Xilem example for http cats API, requiring workers and image component #571

Merged
merged 13 commits into from
Sep 3, 2024
516 changes: 511 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ cargo update -p package_name --precise 0.1.1
Licensed under the Apache License, Version 2.0
([LICENSE](LICENSE) or <http://www.apache.org/licenses/LICENSE-2.0>)

The font file (`RobotoFlex-Subset.ttf`) in `xilem/resources/fonts/roboto_flex/` is licensed solely as documented in that folder,
(and is not licensed under the Apache License, Version 2.0).
Some files used for examples are under different licenses:

- The font file (`RobotoFlex-Subset.ttf`) in `xilem/resources/fonts/roboto_flex/` is licensed solely as documented in that folder (and is not licensed under the Apache License, Version 2.0).
- The data file (`status.csv`) in `xilem/resources/data/http_cats_status/` is licensed solely as documented in that folder (and is not licensed under the Apache License, Version 2.0).

## Contribution

Expand Down
20 changes: 9 additions & 11 deletions masonry/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ impl Image {
/// Create an image drawing widget from an image buffer.
///
/// By default, the Image will scale to fit its box constraints ([`FillStrat::Fill`]).

#[inline]
pub fn new(image_data: ImageBuf) -> Self {
Image {
Expand Down Expand Up @@ -82,17 +81,16 @@ impl Widget for Image {
// If either the width or height is constrained calculate a value so that the image fits
// in the size exactly. If it is unconstrained by both width and height take the size of
// the image.
let max = bc.max();
let image_size = Size::new(self.image_data.width as f64, self.image_data.height as f64);
let size = if bc.is_width_bounded() && !bc.is_height_bounded() {
let ratio = max.width / image_size.width;
Size::new(max.width, ratio * image_size.height)
} else if bc.is_height_bounded() && !bc.is_width_bounded() {
let ratio = max.height / image_size.height;
Size::new(ratio * image_size.width, max.height)
} else {
bc.constrain(image_size)
};
if image_size.is_empty() {
let size = bc.min();
trace!("Computed size: {}", size);
return size;
}
// This size logic has NOT been carefully considered
// TODO: Carefully consider it
let size =
bc.constrain_aspect_ratio(image_size.height / image_size.width, image_size.width);
trace!("Computed size: {}", size);
size
}
Expand Down
32 changes: 30 additions & 2 deletions xilem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license.workspace = true
repository.workspace = true
homepage.workspace = true
rust-version.workspace = true
exclude = ["/resources/fonts/roboto_flex/"]
exclude = ["/resources/fonts/roboto_flex/", "/resources/data/http_cats_status/"]

[package.metadata.docs.rs]
all-features = true
Expand All @@ -36,6 +36,16 @@ path = "examples/calc.rs"
# cdylib is required for cargo-apk
crate-type = ["cdylib"]

[[example]]
name = "http_cats"

[[example]]
name = "http_cats_android"
path = "examples/http_cats.rs"
# cdylib is required for cargo-apk
crate-type = ["cdylib"]


[[example]]
name = "stopwatch"

Expand Down Expand Up @@ -65,14 +75,28 @@ tracing.workspace = true
vello.workspace = true
smallvec.workspace = true
accesskit.workspace = true
tokio = { version = "1.39.1", features = ["rt", "rt-multi-thread", "time"] }
tokio = { version = "1.39.1", features = [
"rt",
"rt-multi-thread",
"time",
"sync",
] }

[dev-dependencies]
# Used for `variable_clock`
time = { workspace = true, features = ["local-offset"] }

# Used for http_cats
reqwest = { version = "0.12.7", default-features = false, features = [
# We use rustls as Android doesn't ship with openssl
# and this is likely to be easiest to get working.
"rustls-tls",
] }
image = { workspace = true, features = ["jpeg"] }

# Make wgpu use tracing for its spans.
profiling = { version = "1.0.15", features = ["profile-with-tracing"] }
anyhow = "1.0.86"

[target.'cfg(target_os = "android")'.dev-dependencies]
winit = { features = ["android-native-activity"], workspace = true }
Expand All @@ -81,3 +105,7 @@ winit = { features = ["android-native-activity"], workspace = true }
# Do not use when releasing a production app.
[package.metadata.android.application]
debuggable = true

[[package.metadata.android.uses_permission]]
# Needed for http_cats
name = "android.permission.INTERNET"
9 changes: 6 additions & 3 deletions xilem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ Unless you explicitly state otherwise, any contribution intentionally submitted

Licensed under the Apache License, Version 2.0 ([LICENSE](LICENSE) or <http://www.apache.org/licenses/LICENSE-2.0>)

The font file (`RobotoFlex-Subset.ttf`) in `resources/fonts/roboto_flex/` is licensed solely as documented in that folder,
(and is not licensed under the Apache License, Version 2.0).
Note that this file is *not* distributed with the.
Some files used for examples are under different licenses:

* The font file (`RobotoFlex-Subset.ttf`) in `resources/fonts/roboto_flex/` is licensed solely as documented in that folder (and is not licensed under the Apache License, Version 2.0).
* The data file (`status.csv`) in `resources/data/http_cats_status/` is licensed solely as documented in that folder (and is not licensed under the Apache License, Version 2.0).

Note that these files are *not* distributed with the released crate.

[Masonry]: https://crates.io/crates/masonry
[Druid]: https://crates.io/crates/druid
Expand Down
Loading