This commit is contained in:
LunarAkai 2025-08-03 01:07:52 +02:00
commit bbd2a6089c
10 changed files with 62 additions and 16 deletions

View file

@ -6,4 +6,5 @@ authors.workspace = true
[dependencies]
moonhare_log = { path = "../moonhare_log" }
moonhare_event = { path = "../moonhare_event" }
gtk4 = "*"

View file

@ -1,12 +1,5 @@
//! Provides functionality to create either a vulkan or opengl window
use std::marker;
#[cfg(target_os = "linux")]
use crate::platforms::gtk_window::GTKWindow;
pub mod window_config;
pub mod platforms;
#[derive(Debug, Clone, Copy)]
@ -30,7 +23,8 @@ pub struct Window {
impl Window {
/// creates a gtk4 window
/// creates a gtk4 window while spaning a new thread that the window runs on.
/// here: gtk sends engine events when _things happen_ with the window that other engine parts can interact with
#[cfg(target_os = "linux")]
pub fn create(context: WindowRenderContext) {
match context {
@ -51,7 +45,6 @@ impl Window {
});
},
}
}
#[cfg(not(target_os = "linux"))]

View file

@ -1,4 +1,5 @@
use gtk4::{gio::prelude::ApplicationExt, glib, prelude::{GtkWindowExt, WidgetExt}, Application, ApplicationWindow};
use gtk4::{gio::{prelude::{ActionMapExtManual, ApplicationExt}, ActionEntry}, glib, prelude::{GtkWindowExt, WidgetExt}, Application, ApplicationWindow};
use moonhare_event::{event::Event, events::window_events::window_close_event::WindowCloseEvent};
use crate::{window_config, MoonhareWindow};
@ -21,8 +22,20 @@ impl GTKWindow {
window.set_default_size(window_config.width as i32, window_config.height as i32);
window.set_visible(window_config.visble);
// Add action "close" to `window` taking no parameter
let action_close = ActionEntry::builder("close")
.activate(|window: &ApplicationWindow, _, _| {
GTKWindow::shutdown();
window.close();
})
.build();
window.add_action_entries([action_close]);
window.show();
}
}
impl MoonhareWindow for GTKWindow {
@ -43,6 +56,8 @@ impl MoonhareWindow for GTKWindow {
}
fn shutdown() {
// todo: emit WindowCloseEvent
}
}