1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
//! This module contains all window related functionality.

mod builder;

use super::prelude::*;
use super::event::Event;



pub use builder::WindowBuilder;



pub type StandardWindowEvent = Event<'static, WindowHandle>;

/// A handle that exposes all windowing functionality.
#[derive(Clone, Copy)]
pub struct WindowHandle {
	pub(in super) inner: WindowImpl
}

#[derive(Default)]
pub(in crate) struct WindowEvents {
	pub on_close: StandardWindowEvent,
	pub on_destroy: StandardWindowEvent,
	pub on_resize: Event<'static, WindowResizeEventArgs>
}

pub struct WindowResizeEventArgs {
	handle: WindowHandle,
	new_size: Dims2D
}

pub trait OwnedWindow {
	fn window_handle( &self ) -> WindowHandle;
}



impl WindowHandle {
	impl_prop!{ pub content_dimensions: ContentDimensions }
	impl_prop!{ pub opacity: Opacity }
	impl_prop!{ pub position: Position }
	impl_prop!{ pub title: Title }
	impl_prop!{ pub window_dimensions: WindowDimensions }

	/// Destroys the window.
	pub fn close( self ) {
		self.hide();
		// The window will be dropped because ownership of `self` is taken.
	}

	/// Make the window invisible to the user.
	pub fn hide( &self ) {
		self.inner.hide()
	}

	pub(in super) fn new( inner: WindowImpl ) -> Self {
		Self {
			inner
		}
	}

	/// Make the window visible to the user.
	pub fn show( &self ) {
		self.inner.show()
	}
}



prop! { /// Gets or sets the width and height of the content of the window.
	ContentDimensions<Dims2D>( this: WindowHandle ) {
		get => this.inner.get_content_dimensions().into(),
		set(val) => this.inner.set_content_dimensions( val.into() )
	}
}

prop! { /// Gets or sets the opacity of the window.
        /// An opacity of 255 means the window is invisible.
        /// An opacity of 0 means the window is completely visible.
        /// Anything in between makes the window transparent.
        /// 
        /// This feature only works on Windows.
	Opacity<u8>( this: WindowHandle ) {
		get => this.inner.get_opacity(),
		set(val) => this.inner.set_opacity( val )
	}
}

prop! { /// Gets or sets the current position of the window.
	Position<Pos2D>( this: WindowHandle ) {
		get => this.inner.get_position(),
		set(val) => this.inner.set_position( val )
	}
}

prop!{ /// Gets or sets the title of the window.
	pub Title<String, &str>( this: WindowHandle ) {
		get => this.inner.get_title(),
		set(val) => this.inner.set_title( val ).into()
	}
}

prop! { /// Gets or sets the current window size including its border and titlebar.
	WindowDimensions<Dims2D>( this: WindowHandle ) {
		get => this.inner.get_window_dimensions().into(),
		set(val) => this.inner.set_window_dimensions( val.into() )
	}
}