Skip to content

Commit

Permalink
Migrate to a data file for licensing reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Jan 17, 2025
1 parent ca485a6 commit 0b251ad
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/copyright.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Check all the standard Rust source files
# Exclude the Emoji picker example because it also has some MIT licensed content
output=$(rg "^// Copyright (19|20)[\d]{2} (.+ and )?the Xilem Authors( and .+)?$\n^// SPDX-License-Identifier: Apache-2\.0$\n\n" --files-without-match --multiline -g "*.rs" -g "!xilem/examples/emoji_picker/emoji_data.rs" .)
output=$(rg "^// Copyright (19|20)[\d]{2} (.+ and )?the Xilem Authors( and .+)?$\n^// SPDX-License-Identifier: Apache-2\.0$\n\n" --files-without-match --multiline -g "*.rs" .)

if [ -n "$output" ]; then
echo -e "The following files lack the correct copyright header:\n"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ 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).
- The data file (`emoji.csv`) in `xilem/resources/data/emoji_names/` is licensed solely as documented in that folder (and is not licensed under the Apache License, Version 2.0).

## Contribution

Expand Down
8 changes: 6 additions & 2 deletions xilem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ license.workspace = true
repository.workspace = true
homepage.workspace = true
rust-version.workspace = true
exclude = ["/resources/fonts/roboto_flex/", "/resources/data/http_cats_status/"]
exclude = [
"/resources/fonts/roboto_flex/",
"/resources/data/http_cats_status/",
"/resources/data/emoji_names/",
]

[package.metadata.docs.rs]
all-features = true
Expand Down Expand Up @@ -83,7 +87,7 @@ name = "emoji_picker"

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

Expand Down
1 change: 1 addition & 0 deletions xilem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ 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).
* The data file (`emoji.csv`) in `resources/data/emoji_names/` 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.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
// Copyright 2024 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// SPDX-License-Identifier: Apache 2.0

//! A simple emoji picker.
//! It is expected that the Emoji in this example may not render.
//! This is because Vello does not support any kinds of bitmap fonts.
//!
//! Note that the MIT license is needed because of the emoji data.
//! Everything except for the [`EMOJI`] constant is Apache 2.0 licensed.
#![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")]

mod emoji_data;

use emoji_data::EMOJI;
use winit::error::EventLoopError;
use xilem::{
core::map_state,
Expand Down Expand Up @@ -40,12 +32,12 @@ fn app_logic(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> {
paginate(
data.start_index,
(data.size * data.size) as usize,
EMOJI.len(),
data.emoji.len(),
),
|state: &mut EmojiPagination| &mut state.start_index,
),
data.last_selected
.map(|idx| label(format!("Selected: {}", EMOJI[idx].display)).text_size(40.)),
.map(|idx| label(format!("Selected: {}", data.emoji[idx].display)).text_size(40.)),
))
.direction(Axis::Vertical)
}
Expand All @@ -60,7 +52,7 @@ fn picker(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> {
let row_idx = data.start_index + y * data.size as usize;
for x in 0..data.size as usize {
let idx = row_idx + x;
let emoji = EMOJI.get(idx);
let emoji = data.emoji.get(idx);
// TODO: Use OneOf2
let view: Box<AnyWidgetView<EmojiPagination>> = match emoji {
Some(emoji) => {
Expand Down Expand Up @@ -123,29 +115,54 @@ struct EmojiPagination {
size: u32,
last_selected: Option<usize>,
start_index: usize,
emoji: Vec<EmojiInfo>,
}

fn run(event_loop: EventLoopBuilder) -> Result<(), EventLoopError> {
let emoji = EmojiInfo::parse_file();
let data = EmojiPagination {
size: 4,
last_selected: None,
start_index: 0,
emoji,
};

let app = Xilem::new(data, app_logic);
app.run_windowed(event_loop, "First Example".into())
}

// Helpers for the emoji_data module. That is a separate file for licensing reasons.
struct EmojiInfo {
name: &'static str,
display: &'static str,
}

const fn e(display: &'static str, name: &'static str) -> EmojiInfo {
EmojiInfo { name, display }
impl EmojiInfo {
/// Parse the supported emoji's information.
fn parse_file() -> Vec<Self> {
let mut lines = EMOJI_NAMES_CSV.lines();
let first_line = lines.next();
assert_eq!(
first_line,
Some("display,name"),
"Probably wrong CSV-like file"
);
lines.flat_map(Self::parse_single).collect()
}

fn parse_single(line: &'static str) -> Option<Self> {
let (display, name) = line.split_once(',')?;
Some(Self { display, name })
}
}

/// A subset of emoji data from <https://github.com/iamcal/emoji-data>, used under the MIT license.
/// Full details can be found in `xilem/resources/data/emoji_names/README.md` from
/// the workspace root.
const EMOJI_NAMES_CSV: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/resources/data/emoji_names/emoji.csv",
));

// Boilerplate code: Identical across all applications which support Android

#[expect(clippy::allow_attributes, reason = "No way to specify the condition")]
Expand Down
129 changes: 0 additions & 129 deletions xilem/examples/emoji_picker/emoji_data.rs

This file was deleted.

21 changes: 21 additions & 0 deletions xilem/resources/data/emoji_names/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 Cal Henderson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions xilem/resources/data/emoji_names/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Emoji names

The data in emoji.csv was adapted as a subset of <https://github.com/iamcal/emoji-data>.
These were extracted from <https://github.com/iamcal/emoji-data/blob/master/emoji_pretty.json> on 2024-09-03,
specifically as at commit [`a8174c74675355c8c6a9564516b2e961fe7257ef`](https://github.com/iamcal/emoji-data/blob/a8174c74675355c8c6a9564516b2e961fe7257ef/emoji_pretty.json).
Full license text can be found above in the source file.

## License

These are licensed solely under the MIT license, as found in [LICENSE](./LICENSE).
Loading

0 comments on commit 0b251ad

Please sign in to comment.