Skip to content

Commit

Permalink
Merge branch 'main' into grzi-gltf
Browse files Browse the repository at this point in the history
  • Loading branch information
suspistew authored Feb 28, 2021
2 parents a576311 + 1396e6e commit c3b0bba
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 49 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ exclude = [
"amethyst_test",
"examples/Cargo.toml",
"examples/_unused_assets",
"examples/examples.sh",
"examples/README.md",
"examples/LICENSE_ASSETS.md",
"examples/LICENSE_AUDIO.txt",
Expand Down
17 changes: 15 additions & 2 deletions amethyst_ui/src/label.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::marker::PhantomData;

use amethyst_assets::{register_asset_type, Asset, AssetProcessorSystem, Handle};
use amethyst_core::ecs::*;
use amethyst_core::{
ecs::*,
transform::{Parent, Transform},
};

use crate::{
define_widget, Anchor, FontAsset, LineMode, Selectable, Stretch, UiText, UiTransform, WidgetId,
Expand Down Expand Up @@ -196,7 +199,7 @@ impl<'a, G: PartialEq + Send + Sync + 'static, I: WidgetId> UiLabelBuilder<G, I>

/// Build this with the `UiLabelBuilderResources`.
pub fn build_from_world_and_resources(
self,
mut self,
world: &mut World,
resources: &mut Resources,
) -> (I, UiLabel) {
Expand Down Expand Up @@ -246,6 +249,16 @@ impl<'a, G: PartialEq + Send + Sync + 'static, I: WidgetId> UiLabelBuilder<G, I>
text_entry.add_component(Selectable::<G>::new(order));
}

if let Some(parent) = self.parent.take() {
text_entry.add_component(Parent(parent));
}

// FIXME : The current parent update system in amethyst_core is updating based on the Transform component...
// That's actually a 'bad' linkage. Later to legion port, we'll replace the system by legion_transform which is better,
// the following 4 lines won't be usefull anymore.
text_entry.add_component(Transform::default());


(id, widget)
}
}
1 change: 1 addition & 0 deletions amethyst_window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ log = "0.4"
serde = { version = "1", features = ["derive"] }
thread_profiler = { version = "0.3", optional = true }
winit = { version = "0.24", git = "https://github.com/rust-windowing/winit", rev = "38fccebe1fbc4226c75d6180e5317bd93c024951", features = ["serde"] }
image = "0.23.13"

[dev-dependencies]
amethyst = { path = "../", version = "0.15.3", features = ["renderer"] }
Expand Down
64 changes: 44 additions & 20 deletions amethyst_window/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::path::PathBuf;

use serde::{Deserialize, Serialize};
use winit::{
dpi::Size,
window::{Fullscreen, Icon, WindowAttributes, WindowBuilder},
};
use winit::{dpi::Size, window::{Fullscreen, Icon, WindowAttributes, WindowBuilder}};
#[cfg(target_os = "windows")]
use {
log::error,
winit::platform::windows::{IconExtWindows, WindowBuilderExtWindows},
};

use image::{self, DynamicImage};

use crate::monitor::{MonitorIdent, MonitorsAccess};

/// Configuration for a window display.
Expand Down Expand Up @@ -153,27 +151,53 @@ impl DisplayConfig {
{
builder = builder.with_drag_and_drop(false);
}

builder.window = attrs;
builder = builder.with_window_icon(self.loaded_icon);

#[cfg(target_os = "windows")]
if let Some(icon) = self.icon {
let icon = match Icon::from_path(&icon, None) {
Ok(x) => Some(x),
Err(e) => {
error!(
"Failed to load window icon from `{}`: {}",
icon.display(),
e
);

None
if self.loaded_icon.is_some() {
builder = builder.with_window_icon(self.loaded_icon);
}else{
let mut use_fallback = true;
let mut img = DynamicImage::new_rgb8(1, 1);
match self.icon {
Some(icon_path) => {
let image = image::open(icon_path);
if image.is_ok() {
img = image.unwrap();
use_fallback = false;
}
}
None => {}
}

if use_fallback {
let fallback_icon = include_bytes!("fallback.png");
let icon_img = image::load_from_memory_with_format(fallback_icon, image::ImageFormat::Png);
if icon_img.is_ok() {
img = icon_img.unwrap();
}
}


let (icon_rgba, icon_width, icon_height) = {
use image::{GenericImageView, Pixel};
let (width, height) = img.dimensions();
let mut rgba = Vec::with_capacity((width * height) as usize * 4);
for (_, _, pixel) in img.pixels() {
rgba.extend_from_slice(&pixel.to_rgba().channels());
}
(rgba, width, height)
};
match Icon::from_rgba(icon_rgba, icon_width, icon_height) {
Ok(res) => {
builder = builder.with_window_icon(Option::from( res ));
}

Err(_e) => {}
};

builder = builder.with_window_icon(icon);
}


builder
}
}
Binary file added amethyst_window/src/fallback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 0 additions & 26 deletions examples/examples.sh

This file was deleted.

0 comments on commit c3b0bba

Please sign in to comment.