/* 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 rand::{rngs::OsRng, Rng};
use std::sync::{Arc, Mutex as SyncMutex, OnceLock, Weak};
use crate::{
gfx::{
GfxDrawCall, GfxDrawInstruction, GfxDrawMesh, GfxTextureId, ManagedTexturePtr, Rectangle,
RenderApi,
},
mesh::{Color, MeshBuilder, MeshInfo, COLOR_BLUE, COLOR_RED, COLOR_WHITE},
prop::{
PropertyAtomicGuard, PropertyBool, PropertyColor, PropertyFloat32, PropertyPtr,
PropertyRect, PropertyStr, PropertyUint32, Role,
},
scene::{Pimpl, SceneNodePtr, SceneNodeWeak},
text::{self, GlyphPositionIter, TextShaper, TextShaperPtr},
text2,
util::unixtime,
ExecutorPtr,
};
use super::{DrawUpdate, OnModify, UIObject};
macro_rules! d { ($($arg:tt)*) => { debug!(target: "ui::text", $($arg)*); } }
macro_rules! t { ($($arg:tt)*) => { trace!(target: "ui::text", $($arg)*); } }
pub type TextPtr = Arc;
#[derive(Clone)]
struct TextRenderInfo {
mesh: MeshInfo,
texture: ManagedTexturePtr,
}
pub struct Text {
node: SceneNodeWeak,
render_api: RenderApi,
text_shaper: TextShaperPtr,
tasks: OnceLock>>,
dc_key: u64,
rect: PropertyRect,
z_index: PropertyUint32,
priority: PropertyUint32,
text: PropertyStr,
font_size: PropertyFloat32,
text_color: PropertyColor,
baseline: PropertyFloat32,
debug: PropertyBool,
window_scale: PropertyFloat32,
parent_rect: SyncMutex