use zng_layout::unit::{DipPoint, DipSideOffsets, DipSize, Factor, Frequency, PxPoint};
use zng_txt::Txt;
use zng_var::WeakEq;
use zng_view_api::{
AxisId, DragDropId, Ime,
api_extension::{ApiExtensionId, ApiExtensionPayload},
audio::{AudioDecoded, AudioMetadata},
config::{AnimationsConfig, ColorsConfig, FontAntiAliasing, KeyRepeatConfig, LocaleConfig, MultiClickConfig, TouchConfig},
drag_drop::{DragDropData, DragDropEffect},
image::{ImageDecoded, ImageMetadata},
keyboard::{Key, KeyCode, KeyLocation, KeyState},
mouse::{ButtonState, MouseButton, MouseScrollDelta},
touch::{TouchPhase, TouchUpdate},
window::{EventCause, FrameId, FrameWaitId, HeadlessOpenData, MonitorInfo, WindowStateAll},
};
use crate::{
event::{event, event_args},
view_process::{AudioOutputId, ViewImageHandle, WeakViewAudioHandle, WeakViewAudioOutput},
window::{MonitorId, WindowId},
};
use super::{WeakViewHeadless, WeakViewImageHandle, WeakViewWindow, WindowOpenData, raw_device_events::InputDeviceId};
event_args! {
pub struct RawKeyInputArgs {
pub window_id: WindowId,
pub device_id: InputDeviceId,
pub key_code: KeyCode,
pub key_location: KeyLocation,
pub state: KeyState,
pub key: Key,
pub key_modified: Key,
pub text: Txt,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawImeArgs {
pub window_id: WindowId,
pub ime: Ime,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawWindowFocusArgs {
pub prev_focus: Option<WindowId>,
pub new_focus: Option<WindowId>,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawFrameRenderedArgs {
pub window_id: WindowId,
pub frame_id: FrameId,
pub frame_image: Option<WeakEq<(ViewImageHandle, ImageDecoded)>>,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawWindowOpenArgs {
pub window_id: WindowId,
pub window: WeakViewWindow,
pub data: WindowOpenData,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawHeadlessOpenArgs {
pub window_id: WindowId,
pub surface: WeakViewHeadless,
pub data: HeadlessOpenData,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawWindowOrHeadlessOpenErrorArgs {
pub window_id: WindowId,
pub error: Txt,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawWindowCloseRequestedArgs {
pub window_id: WindowId,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawWindowCloseArgs {
pub window_id: WindowId,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawDragHoveredArgs {
pub window_id: WindowId,
pub data: Vec<DragDropData>,
pub allowed: DragDropEffect,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawDragMovedArgs {
pub window_id: WindowId,
pub coalesced_pos: Vec<DipPoint>,
pub position: DipPoint,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawDragDroppedArgs {
pub window_id: WindowId,
pub data: Vec<DragDropData>,
pub allowed: DragDropEffect,
pub drop_id: DragDropId,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawDragCancelledArgs {
pub window_id: WindowId,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawAppDragEndedArgs {
pub window_id: WindowId,
pub id: DragDropId,
pub applied: DragDropEffect,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawMouseMovedArgs {
pub window_id: WindowId,
pub device_id: InputDeviceId,
pub coalesced_pos: Vec<DipPoint>,
pub position: DipPoint,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawMouseArgs {
pub window_id: WindowId,
pub device_id: InputDeviceId,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawMouseWheelArgs {
pub window_id: WindowId,
pub device_id: InputDeviceId,
pub delta: MouseScrollDelta,
pub phase: TouchPhase,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawMouseInputArgs {
pub window_id: WindowId,
pub device_id: InputDeviceId,
pub state: ButtonState,
pub button: MouseButton,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawTouchpadPressureArgs {
pub window_id: WindowId,
pub device_id: InputDeviceId,
pub pressure: Factor,
pub stage: i64,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawAxisMotionArgs {
pub window_id: WindowId,
pub device_id: InputDeviceId,
pub axis: AxisId,
pub value: f64,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawTouchArgs {
pub window_id: WindowId,
pub device_id: InputDeviceId,
pub touches: Vec<TouchUpdate>,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawScaleFactorChangedArgs {
pub monitor_id: MonitorId,
pub windows: Vec<WindowId>,
pub scale_factor: Factor,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawMonitorsChangedArgs {
pub available_monitors: Vec<(MonitorId, MonitorInfo)>,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawImageMetadataDecodedArgs {
pub handle: WeakViewImageHandle,
pub meta: ImageMetadata,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawImageDecodedArgs {
pub handle: WeakViewImageHandle,
pub image: WeakEq<ImageDecoded>,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawImageDecodeErrorArgs {
pub handle: WeakViewImageHandle,
pub error: Txt,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawAudioMetadataDecodedArgs {
pub handle: WeakViewAudioHandle,
pub meta: AudioMetadata,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawAudioDecodedArgs {
pub handle: WeakViewAudioHandle,
pub audio: WeakEq<AudioDecoded>,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawAudioDecodeErrorArgs {
pub handle: WeakViewAudioHandle,
pub error: Txt,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawAudioOutputOpenArgs {
pub output_id: AudioOutputId,
pub output: WeakViewAudioOutput,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawAudioOutputOpenErrorArgs {
pub output_id: AudioOutputId,
pub error: Txt,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawFontChangedArgs {
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawFontAaChangedArgs {
pub aa: FontAntiAliasing,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawMultiClickConfigChangedArgs {
pub config: MultiClickConfig,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawAnimationsConfigChangedArgs {
pub config: AnimationsConfig,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawKeyRepeatConfigChangedArgs {
pub config: KeyRepeatConfig,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawTouchConfigChangedArgs {
pub config: TouchConfig,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawLocaleChangedArgs {
pub config: LocaleConfig,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawColorsConfigChangedArgs {
pub config: ColorsConfig,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct RawExtensionEventArgs {
pub extension_id: ApiExtensionId,
pub payload: ApiExtensionPayload,
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
pub struct LowMemoryArgs {
..
fn is_in_target(&self, id: WidgetId) -> bool {
true
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct RawWindowChangedArgs {
pub window_id: WindowId,
pub state: Option<WindowStateAll>,
pub position: Option<(PxPoint, DipPoint)>,
pub monitor: Option<MonitorId>,
pub size: Option<DipSize>,
pub safe_padding: Option<DipSideOffsets>,
pub cause: EventCause,
pub frame_wait_id: Option<FrameWaitId>,
pub scale_factor: Option<Factor>,
pub refresh_rate: Option<Frequency>,
#[doc = r" Instant the event happened."]
pub timestamp: crate::DInstant,
#[doc = r" Propagation handle associated with this event instance."]
#[doc = r""]
#[doc = r" Cloned arguments share the same handle, some arguments may also share the handle"]
#[doc = r" of another event if they share the same cause."]
pub propagation: crate::event::EventPropagationHandle,
}
impl RawWindowChangedArgs {
#[doc = r" New args from values that convert [into](Into) the argument types."]
#[allow(clippy::too_many_arguments)]
pub fn new(
timestamp: impl Into<crate::DInstant>,
propagation: crate::event::EventPropagationHandle,
window_id: impl Into<WindowId>,
state: impl Into<Option<WindowStateAll>>,
position: impl Into<Option<(PxPoint, DipPoint)>>,
monitor: impl Into<Option<MonitorId>>,
size: impl Into<Option<DipSize>>,
safe_padding: impl Into<Option<DipSideOffsets>>,
cause: impl Into<EventCause>,
frame_wait_id: impl Into<Option<FrameWaitId>>,
) -> Self {
RawWindowChangedArgs {
timestamp: timestamp.into(),
window_id: window_id.into(),
state: state.into(),
position: position.into(),
monitor: monitor.into(),
size: size.into(),
safe_padding: safe_padding.into(),
scale_factor: None,
refresh_rate: None,
cause: cause.into(),
frame_wait_id: frame_wait_id.into(),
propagation,
}
}
#[doc = r" Arguments for event that happened now (`INSTANT.now`)."]
#[allow(clippy::too_many_arguments)]
pub fn now(
window_id: impl Into<WindowId>,
state: impl Into<Option<WindowStateAll>>,
position: impl Into<Option<(PxPoint, DipPoint)>>,
monitor: impl Into<Option<MonitorId>>,
size: impl Into<Option<DipSize>>,
safe_padding: impl Into<Option<DipSideOffsets>>,
cause: impl Into<EventCause>,
frame_wait_id: impl Into<Option<FrameWaitId>>,
) -> Self {
Self::new(
crate::INSTANT.now(),
crate::event::EventPropagationHandle::new(),
window_id,
state,
position,
monitor,
size,
safe_padding,
cause,
frame_wait_id,
)
}
}
impl crate::event::AnyEventArgs for RawWindowChangedArgs {
fn timestamp(&self) -> crate::DInstant {
self.timestamp
}
#[doc = r" Broadcast to all widgets."]
fn is_in_target(&self, id: crate::widget::WidgetId) -> bool {
let _ = id;
true
}
fn propagation(&self) -> &crate::event::EventPropagationHandle {
&self.propagation
}
fn clone_boxed(&self) -> std::boxed::Box<dyn crate::event::AnyEventArgs> {
Box::new(self.clone())
}
}
impl crate::event::EventArgs for RawWindowChangedArgs {}
event! {
pub static RAW_KEY_INPUT_EVENT: RawKeyInputArgs;
pub static RAW_IME_EVENT: RawImeArgs;
pub static RAW_WINDOW_FOCUS_EVENT: RawWindowFocusArgs;
pub static RAW_WINDOW_CHANGED_EVENT: RawWindowChangedArgs;
pub static RAW_FRAME_RENDERED_EVENT: RawFrameRenderedArgs;
pub static RAW_WINDOW_OPEN_EVENT: RawWindowOpenArgs;
pub static RAW_HEADLESS_OPEN_EVENT: RawHeadlessOpenArgs;
pub static RAW_WINDOW_OR_HEADLESS_OPEN_ERROR_EVENT: RawWindowOrHeadlessOpenErrorArgs;
pub static RAW_WINDOW_CLOSE_REQUESTED_EVENT: RawWindowCloseRequestedArgs;
pub static RAW_WINDOW_CLOSE_EVENT: RawWindowCloseArgs;
pub static RAW_DRAG_HOVERED_EVENT: RawDragHoveredArgs;
pub static RAW_DRAG_MOVED_EVENT: RawDragMovedArgs;
pub static RAW_DRAG_DROPPED_EVENT: RawDragDroppedArgs;
pub static RAW_DRAG_CANCELLED_EVENT: RawDragCancelledArgs;
pub static RAW_APP_DRAG_ENDED_EVENT: RawAppDragEndedArgs;
pub static RAW_MOUSE_MOVED_EVENT: RawMouseMovedArgs;
pub static RAW_MOUSE_ENTERED_EVENT: RawMouseArgs;
pub static RAW_MOUSE_LEFT_EVENT: RawMouseArgs;
pub static RAW_MOUSE_WHEEL_EVENT: RawMouseWheelArgs;
pub static RAW_MOUSE_INPUT_EVENT: RawMouseInputArgs;
pub static RAW_TOUCHPAD_PRESSURE_EVENT: RawTouchpadPressureArgs;
pub static RAW_AXIS_MOTION_EVENT: RawAxisMotionArgs;
pub static RAW_TOUCH_EVENT: RawTouchArgs;
#[deprecated = "use RAW_MONITORS_CHANGED_EVENT"]
pub static RAW_SCALE_FACTOR_CHANGED_EVENT: RawScaleFactorChangedArgs;
pub static RAW_MONITORS_CHANGED_EVENT: RawMonitorsChangedArgs;
pub static RAW_COLORS_CONFIG_CHANGED_EVENT: RawColorsConfigChangedArgs;
pub static RAW_FONT_AA_CHANGED_EVENT: RawFontAaChangedArgs;
pub static RAW_FONT_CHANGED_EVENT: RawFontChangedArgs;
pub static RAW_MULTI_CLICK_CONFIG_CHANGED_EVENT: RawMultiClickConfigChangedArgs;
pub static RAW_ANIMATIONS_CONFIG_CHANGED_EVENT: RawAnimationsConfigChangedArgs;
pub static RAW_KEY_REPEAT_CONFIG_CHANGED_EVENT: RawKeyRepeatConfigChangedArgs;
pub static RAW_TOUCH_CONFIG_CHANGED_EVENT: RawTouchConfigChangedArgs;
pub static RAW_LOCALE_CONFIG_CHANGED_EVENT: RawLocaleChangedArgs;
pub static RAW_IMAGE_METADATA_DECODED_EVENT: RawImageMetadataDecodedArgs;
pub static RAW_IMAGE_DECODED_EVENT: RawImageDecodedArgs;
pub static RAW_IMAGE_DECODE_ERROR_EVENT: RawImageDecodeErrorArgs;
pub static RAW_AUDIO_METADATA_DECODED_EVENT: RawAudioMetadataDecodedArgs;
pub static RAW_AUDIO_DECODED_EVENT: RawAudioDecodedArgs;
pub static RAW_AUDIO_DECODE_ERROR_EVENT: RawAudioDecodeErrorArgs;
pub static RAW_AUDIO_OUTPUT_OPEN_EVENT: RawAudioOutputOpenArgs;
pub static RAW_AUDIO_OUTPUT_OPEN_ERROR_EVENT: RawAudioOutputOpenErrorArgs;
pub static LOW_MEMORY_EVENT: LowMemoryArgs;
pub static RAW_EXTENSION_EVENT: RawExtensionEventArgs;
}