/* This file is part of DarkFi (https://dark.fi)
*
* Copyright (C) 2020-2025 Dyne.org foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
use async_trait::async_trait;
use futures::stream::{FuturesUnordered, StreamExt};
use miniquad::{KeyCode, KeyMods, MouseButton, TouchPhase};
use std::sync::{Arc, Weak};
use crate::{
gfx::{DrawCall, Point, Rectangle},
prop::{BatchGuardPtr, ModifyAction, PropertyAtomicGuard, PropertyPtr, Role},
scene::{Pimpl, SceneNode as SceneNode3, SceneNodePtr, SceneNodeWeak},
util::i18n::I18nBabelFish,
ExecutorPtr,
};
mod button;
pub use button::{Button, ButtonPtr};
pub mod chatview;
pub use chatview::{ChatView, ChatViewPtr};
mod edit;
pub use edit::{BaseEdit, BaseEditPtr, BaseEditType};
pub mod emoji_picker;
pub use emoji_picker::{EmojiPicker, EmojiPickerPtr};
mod gesture;
pub use gesture::GesturePtr;
mod image;
#[allow(unused_imports)]
pub use image::{Image, ImagePtr};
mod video;
pub use video::{Video, VideoPtr};
mod vector_art;
pub use vector_art::{
shape::{ShapeVertex, VectorShape},
VectorArt, VectorArtPtr,
};
mod layer;
pub use layer::{Layer, LayerPtr};
mod shortcut;
pub use shortcut::{Shortcut, ShortcutPtr};
mod text;
pub use text::{Text, TextPtr};
mod win;
pub use win::{Window, WindowPtr};
macro_rules! e { ($($arg:tt)*) => { error!(target: "scene::on_modify", $($arg)*); } }
macro_rules! t { ($($arg:tt)*) => { trace!(target: "scene::on_modify", $($arg)*); } }
type DrawTrace = u32;
#[async_trait]
pub trait UIObject: Sync {
fn priority(&self) -> u32;
fn init(&self) {}
async fn start(self: Arc, _ex: ExecutorPtr) {}
/// Clear all buffers and caches
fn stop(&self) {}
async fn draw(
&self,
_parent_rect: Rectangle,
_trace: DrawTrace,
_atom: &mut PropertyAtomicGuard,
) -> Option {
None
}
async fn handle_char(&self, _key: char, _mods: KeyMods, _repeat: bool) -> bool {
false
}
async fn handle_key_down(&self, _key: KeyCode, _mods: KeyMods, _repeat: bool) -> bool {
false
}
async fn handle_key_up(&self, _key: KeyCode, _mods: KeyMods) -> bool {
false
}
async fn handle_mouse_btn_down(&self, _btn: MouseButton, _mouse_pos: Point) -> bool {
false
}
async fn handle_mouse_btn_up(&self, _btn: MouseButton, _mouse_pos: Point) -> bool {
false
}
async fn handle_mouse_move(&self, _mouse_pos: Point) -> bool {
false
}
async fn handle_mouse_wheel(&self, _wheel_pos: Point) -> bool {
false
}
async fn handle_touch(&self, _phase: TouchPhase, _id: u64, _touch_pos: Point) -> bool {
false
}
fn set_i18n(&self, _i18n_fish: &I18nBabelFish) {}
}
pub struct DrawUpdate {
pub key: u64,
pub draw_calls: Vec<(u64, DrawCall)>,
}
pub struct OnModify {
ex: ExecutorPtr,
#[allow(dead_code)]
node: SceneNodeWeak,
me: Weak,
pub tasks: Vec>,
}
impl OnModify {
pub fn new(ex: ExecutorPtr, node: SceneNodeWeak, me: Weak) -> Self {
Self { ex, node, me, tasks: vec![] }
}
pub fn when_change(
&mut self,
prop: PropertyPtr,
f: impl Fn(Arc, BatchGuardPtr) -> F + Send + 'static,
) where
F: std::future::Future