Skip to content

Commit

Permalink
Merge pull request #576 from Sharktheone/window/icon
Browse files Browse the repository at this point in the history
Window/icon
  • Loading branch information
Sharktheone authored Aug 29, 2024
2 parents 96d5424 + 2f46ca2 commit c4bf40e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions crates/gosub_styling/src/shorthands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ pub enum Multiplier {

impl Multiplier {
fn get_names(self, completed: Vec<&str>, multi: usize) -> Option<Vec<&str>> {
println!("get names: {completed:?}, {multi}");

match self {
Multiplier::NextProp => Some(vec![completed.get(multi)?]),

Expand Down Expand Up @@ -386,17 +384,11 @@ impl FixList {

match props.properties.entry(name.clone()) {
Entry::Occupied(mut entry) => {
println!("Entry occupied");
let prop = entry.get_mut();

dbg!(&prop);

prop.declared.push(decl);
dbg!(&prop);
}
Entry::Vacant(entry) => {
println!("Entry vacant");

let mut prop = CssProperty::new(name);

prop.declared.push(decl);
Expand Down
1 change: 1 addition & 0 deletions crates/gosub_useragent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ slotmap = "1.0.7"
log = "0.4.22"
anyhow = "1.0.82"
url = "2.5.2"
image = "0.25.2"
33 changes: 32 additions & 1 deletion crates/gosub_useragent/src/window.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use anyhow::anyhow;
use image::imageops::FilterType;
use image::GenericImageView;
use log::warn;
use std::cell::LazyCell;
use std::ops::Deref;
use std::sync::mpsc::Sender;
use std::sync::Arc;
use url::Url;
use winit::dpi::LogicalSize;
use winit::event_loop::ActiveEventLoop;
use winit::window::{Window as WinitWindow, WindowId};
use winit::window::{Icon, Window as WinitWindow, WindowId};

use gosub_render_backend::geo::SizeU32;
use gosub_render_backend::layout::{LayoutTree, Layouter};
Expand All @@ -21,6 +25,30 @@ pub enum WindowState<'a, B: RenderBackend> {
Suspended,
}

thread_local! {
static ICON: LazyCell<Icon> = LazyCell::new(|| {
let bytes = include_bytes!("../../../resources/gosub-logo.png");

let Ok(img) = image::load_from_memory(bytes) else {
return Icon::from_rgba(vec![], 0, 0).unwrap();
};


println!("size: {:?}", img.dimensions());
let height = img.height() / (img.width() / 256);

let rgba = img.resize_exact(256, height, FilterType::Nearest).to_rgba8();

println!("size: {:?}", rgba.dimensions());


Icon::from_rgba(rgba.to_vec(), rgba.width(), rgba.height()).unwrap_or(
Icon::from_rgba(vec![], 0, 0).unwrap()
)

});
}

pub struct Window<'a, D: SceneDrawer<B, L, LT>, B: RenderBackend, L: Layouter, LT: LayoutTree<L>> {
pub(crate) state: WindowState<'a, B>,
pub(crate) window: Arc<WinitWindow>,
Expand Down Expand Up @@ -110,8 +138,11 @@ impl<'a, D: SceneDrawer<B, L, LT>, B: RenderBackend, L: Layouter, LT: LayoutTree
fn create_window(event_loop: &ActiveEventLoop) -> Result<Arc<WinitWindow>> {
let attributes = WinitWindow::default_attributes()
.with_title("Gosub Browser")
.with_window_icon(Some(ICON.with(|icon| icon.deref().clone())))
.with_inner_size(LogicalSize::new(1920, 1080));

println!("icon: {:?}", attributes.window_icon.is_some());

event_loop
.create_window(attributes)
.map_err(|e| anyhow!(e.to_string()))
Expand Down
Binary file added resources/gosub-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c4bf40e

Please sign in to comment.