use crate::{
BasicFrontResource, BasicFrontResourceConfig, BorderKind, DisplayInfo, PositionSizeConfig,
RustConstructorResource,
};
use egui::TextureHandle;
use std::{
any::Any,
fmt::{Debug, Formatter},
};
#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
pub struct CustomRectConfig {
pub position_size_config: Option<PositionSizeConfig>,
pub clip_rect: Option<Option<PositionSizeConfig>>,
pub hidden: Option<bool>,
pub ignore_render_layer: Option<bool>,
pub rounding: Option<f32>,
pub color: Option<[u8; 3]>,
pub alpha: Option<u8>,
pub overlay_color: Option<[u8; 3]>,
pub overlay_alpha: Option<Option<u8>>,
pub border_width: Option<f32>,
pub border_color: Option<[u8; 3]>,
pub border_alpha: Option<u8>,
pub overlay_border_color: Option<[u8; 3]>,
pub overlay_border_alpha: Option<Option<u8>>,
pub border_kind: Option<BorderKind>,
pub tags: Option<Vec<[String; 2]>>,
}
impl CustomRectConfig {
pub fn from_custom_rect(custom_rect: &CustomRect) -> Self {
Self {
position_size_config: Some(
custom_rect.basic_front_resource_config.position_size_config,
),
clip_rect: Some(custom_rect.basic_front_resource_config.clip_rect),
hidden: Some(custom_rect.display_info.hidden),
ignore_render_layer: Some(custom_rect.display_info.ignore_render_layer),
rounding: Some(custom_rect.rounding),
color: Some(custom_rect.color),
alpha: Some(custom_rect.alpha),
overlay_color: Some(custom_rect.overlay_color),
overlay_alpha: Some(custom_rect.overlay_alpha),
border_width: Some(custom_rect.border_width),
border_color: Some(custom_rect.border_color),
border_alpha: Some(custom_rect.border_alpha),
overlay_border_color: Some(custom_rect.overlay_border_color),
overlay_border_alpha: Some(custom_rect.overlay_border_alpha),
border_kind: Some(custom_rect.border_kind),
tags: Some(custom_rect.tags.clone()),
}
}
#[inline]
pub fn position_size_config(
mut self,
position_size_config: Option<PositionSizeConfig>,
) -> Self {
self.position_size_config = position_size_config;
self
}
#[inline]
pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
self.clip_rect = clip_rect;
self
}
#[inline]
pub fn hidden(mut self, hidden: Option<bool>) -> Self {
self.hidden = hidden;
self
}
#[inline]
pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
self.ignore_render_layer = ignore_render_layer;
self
}
#[inline]
pub fn rounding(mut self, rounding: Option<f32>) -> Self {
self.rounding = rounding;
self
}
#[inline]
pub fn color(mut self, color: Option<[u8; 3]>) -> Self {
self.color = color;
self
}
#[inline]
pub fn alpha(mut self, alpha: Option<u8>) -> Self {
self.alpha = alpha;
self
}
#[inline]
pub fn overlay_color(mut self, overlay_color: Option<[u8; 3]>) -> Self {
self.overlay_color = overlay_color;
self
}
#[inline]
pub fn overlay_alpha(mut self, overlay_alpha: Option<Option<u8>>) -> Self {
self.overlay_alpha = overlay_alpha;
self
}
#[inline]
pub fn border_width(mut self, border_width: Option<f32>) -> Self {
self.border_width = border_width;
self
}
#[inline]
pub fn border_color(mut self, border_color: Option<[u8; 3]>) -> Self {
self.border_color = border_color;
self
}
#[inline]
pub fn border_alpha(mut self, border_alpha: Option<u8>) -> Self {
self.border_alpha = border_alpha;
self
}
#[inline]
pub fn overlay_border_color(mut self, overlay_border_color: Option<[u8; 3]>) -> Self {
self.overlay_border_color = overlay_border_color;
self
}
#[inline]
pub fn overlay_border_alpha(mut self, overlay_border_alpha: Option<Option<u8>>) -> Self {
self.overlay_border_alpha = overlay_border_alpha;
self
}
#[inline]
pub fn border_kind(mut self, border_kind: Option<BorderKind>) -> Self {
self.border_kind = border_kind;
self
}
#[inline]
pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
self.tags = tags;
self
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct CustomRect {
pub basic_front_resource_config: BasicFrontResourceConfig,
pub position: [f32; 2],
pub size: [f32; 2],
pub display_info: DisplayInfo,
pub rounding: f32,
pub color: [u8; 3],
pub alpha: u8,
pub overlay_color: [u8; 3],
pub overlay_alpha: Option<u8>,
pub border_width: f32,
pub border_color: [u8; 3],
pub border_alpha: u8,
pub overlay_border_color: [u8; 3],
pub overlay_border_alpha: Option<u8>,
pub border_kind: BorderKind,
pub tags: Vec<[String; 2]>,
}
impl RustConstructorResource for CustomRect {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
Some(self.display_info)
}
fn modify_display_info(&mut self, display_info: DisplayInfo) {
self.display_info = display_info;
}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl BasicFrontResource for CustomRect {
fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
self.basic_front_resource_config.clone()
}
fn display_position_size_config(&self) -> PositionSizeConfig {
self.basic_front_resource_config.position_size_config
}
fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
self.basic_front_resource_config.clip_rect
}
fn display_position(&self) -> [f32; 2] {
self.position
}
fn display_size(&self) -> [f32; 2] {
self.size
}
fn modify_basic_front_resource_config(
&mut self,
basic_front_resource_config: BasicFrontResourceConfig,
) {
self.basic_front_resource_config = basic_front_resource_config;
}
fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
self.basic_front_resource_config.position_size_config = position_size_config;
}
fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
self.basic_front_resource_config.clip_rect = clip_rect;
}
}
impl Default for CustomRect {
fn default() -> Self {
Self {
basic_front_resource_config: BasicFrontResourceConfig::default(),
position: [0_f32, 0_f32],
size: [0_f32, 0_f32],
display_info: DisplayInfo::default(),
rounding: 2_f32,
color: [255, 255, 255],
alpha: 255,
overlay_border_color: [255, 255, 255],
overlay_alpha: None,
border_width: 2_f32,
border_color: [0, 0, 0],
border_alpha: 255,
overlay_color: [255, 255, 255],
overlay_border_alpha: None,
border_kind: BorderKind::default(),
tags: Vec::new(),
}
}
}
impl CustomRect {
pub fn from_config(mut self, config: &CustomRectConfig) -> Self {
if let Some(position_size_config) = config.position_size_config {
self.basic_front_resource_config.position_size_config = position_size_config;
};
if let Some(clip_rect) = config.clip_rect {
self.basic_front_resource_config.clip_rect = clip_rect;
};
if let Some(hidden) = config.hidden {
self.display_info.hidden = hidden;
};
if let Some(ignore_render_layer) = config.ignore_render_layer {
self.display_info.ignore_render_layer = ignore_render_layer;
};
if let Some(rounding) = config.rounding {
self.rounding = rounding;
};
if let Some(color) = config.color {
self.color = color;
};
if let Some(alpha) = config.alpha {
self.alpha = alpha;
};
if let Some(overlay_color) = config.overlay_color {
self.overlay_color = overlay_color;
};
if let Some(overlay_alpha) = config.overlay_alpha {
self.overlay_alpha = overlay_alpha;
};
if let Some(border_width) = config.border_width {
self.border_width = border_width;
};
if let Some(border_color) = config.border_color {
self.border_color = border_color;
};
if let Some(border_alpha) = config.border_alpha {
self.border_alpha = border_alpha;
};
if let Some(overlay_border_color) = config.overlay_border_color {
self.overlay_border_color = overlay_border_color;
};
if let Some(overlay_border_alpha) = config.overlay_border_alpha {
self.overlay_border_alpha = overlay_border_alpha;
};
if let Some(border_kind) = config.border_kind {
self.border_kind = border_kind;
};
if let Some(tags) = config.tags.clone() {
self.tags = tags;
};
self
}
#[inline]
pub fn basic_front_resource_config(
mut self,
basic_front_resource_config: &BasicFrontResourceConfig,
) -> Self {
self.basic_front_resource_config = basic_front_resource_config.clone();
self
}
#[inline]
pub fn hidden(mut self, hidden: bool) -> Self {
self.display_info.hidden = hidden;
self
}
#[inline]
pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
self.display_info.ignore_render_layer = ignore_render_layer;
self
}
#[inline]
pub fn rounding(mut self, rounding: f32) -> Self {
self.rounding = rounding;
self
}
#[inline]
pub fn color(mut self, r: u8, g: u8, b: u8) -> Self {
self.color = [r, g, b];
self
}
#[inline]
pub fn alpha(mut self, alpha: u8) -> Self {
self.alpha = alpha;
self
}
#[inline]
pub fn overlay_color(mut self, r: u8, g: u8, b: u8) -> Self {
self.overlay_color = [r, g, b];
self
}
#[inline]
pub fn overlay_alpha(mut self, overlay_alpha: Option<u8>) -> Self {
self.overlay_alpha = overlay_alpha;
self
}
#[inline]
pub fn border_width(mut self, border_width: f32) -> Self {
self.border_width = border_width;
self
}
#[inline]
pub fn border_color(mut self, r: u8, g: u8, b: u8) -> Self {
self.border_color = [r, g, b];
self
}
#[inline]
pub fn border_alpha(mut self, border_alpha: u8) -> Self {
self.border_alpha = border_alpha;
self
}
#[inline]
pub fn overlay_border_color(mut self, r: u8, g: u8, b: u8) -> Self {
self.overlay_border_color = [r, g, b];
self
}
#[inline]
pub fn overlay_border_alpha(mut self, overlay_border_alpha: Option<u8>) -> Self {
self.overlay_border_alpha = overlay_border_alpha;
self
}
#[inline]
pub fn border_kind(mut self, border_kind: BorderKind) -> Self {
self.border_kind = border_kind;
self
}
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct DebugTextureHandle(pub TextureHandle);
impl Debug for DebugTextureHandle {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
f.debug_struct("DebugTextureHandle").finish()
}
}
impl DebugTextureHandle {
pub fn new(texture_handle: &TextureHandle) -> Self {
Self(texture_handle.clone())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ImageLoadMethod {
ByPath((String, [bool; 2])),
ByTexture(DebugTextureHandle),
}
#[derive(Debug, Default, Clone, PartialEq)]
pub struct ImageConfig {
pub position_size_config: Option<PositionSizeConfig>,
pub clip_rect: Option<Option<PositionSizeConfig>>,
pub hidden: Option<bool>,
pub ignore_render_layer: Option<bool>,
pub alpha: Option<u8>,
pub overlay_color: Option<[u8; 3]>,
pub overlay_alpha: Option<u8>,
pub background_color: Option<[u8; 3]>,
pub background_alpha: Option<u8>,
pub rotate_angle: Option<f32>,
pub rotate_center: Option<[f32; 2]>,
pub image_load_method: Option<ImageLoadMethod>,
pub tags: Option<Vec<[String; 2]>>,
}
impl ImageConfig {
pub fn from_image(image: &Image) -> Self {
Self {
position_size_config: Some(image.basic_front_resource_config.position_size_config),
clip_rect: Some(image.basic_front_resource_config.clip_rect),
hidden: Some(image.display_info.hidden),
ignore_render_layer: Some(image.display_info.ignore_render_layer),
alpha: Some(image.alpha),
overlay_color: Some(image.overlay_color),
overlay_alpha: Some(image.overlay_alpha),
background_color: Some(image.background_color),
background_alpha: Some(image.background_alpha),
rotate_angle: Some(image.rotate_angle),
rotate_center: Some(image.rotate_center),
image_load_method: Some(image.image_load_method.clone()),
tags: Some(image.tags.clone()),
}
}
#[inline]
pub fn position_size_config(
mut self,
position_size_config: Option<PositionSizeConfig>,
) -> Self {
self.position_size_config = position_size_config;
self
}
#[inline]
pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
self.clip_rect = clip_rect;
self
}
#[inline]
pub fn hidden(mut self, hidden: Option<bool>) -> Self {
self.hidden = hidden;
self
}
#[inline]
pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
self.ignore_render_layer = ignore_render_layer;
self
}
#[inline]
pub fn alpha(mut self, alpha: Option<u8>) -> Self {
self.alpha = alpha;
self
}
#[inline]
pub fn overlay_color(mut self, overlay_color: Option<[u8; 3]>) -> Self {
self.overlay_color = overlay_color;
self
}
#[inline]
pub fn overlay_alpha(mut self, overlay_alpha: Option<u8>) -> Self {
self.overlay_alpha = overlay_alpha;
self
}
#[inline]
pub fn background_color(mut self, background_color: Option<[u8; 3]>) -> Self {
self.background_color = background_color;
self
}
#[inline]
pub fn background_alpha(mut self, background_alpha: Option<u8>) -> Self {
self.background_alpha = background_alpha;
self
}
#[inline]
pub fn rotate_angle(mut self, rotate_angle: Option<f32>) -> Self {
self.rotate_angle = rotate_angle;
self
}
#[inline]
pub fn rotate_center(mut self, rotate_center: Option<[f32; 2]>) -> Self {
self.rotate_center = rotate_center;
self
}
#[inline]
pub fn image_load_method(mut self, image_load_method: Option<ImageLoadMethod>) -> Self {
self.image_load_method = image_load_method;
self
}
#[inline]
pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
self.tags = tags;
self
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Image {
pub basic_front_resource_config: BasicFrontResourceConfig,
pub position: [f32; 2],
pub size: [f32; 2],
pub display_info: DisplayInfo,
pub texture: Option<DebugTextureHandle>,
pub alpha: u8,
pub overlay_color: [u8; 3],
pub overlay_alpha: u8,
pub background_color: [u8; 3],
pub background_alpha: u8,
pub rotate_angle: f32,
pub rotate_center: [f32; 2],
pub image_load_method: ImageLoadMethod,
pub last_frame_path: String,
pub tags: Vec<[String; 2]>,
}
impl RustConstructorResource for Image {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
Some(self.display_info)
}
fn modify_display_info(&mut self, display_info: DisplayInfo) {
self.display_info = display_info;
}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl BasicFrontResource for Image {
fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
self.basic_front_resource_config.clone()
}
fn display_position_size_config(&self) -> PositionSizeConfig {
self.basic_front_resource_config.position_size_config
}
fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
self.basic_front_resource_config.clip_rect
}
fn display_position(&self) -> [f32; 2] {
self.position
}
fn display_size(&self) -> [f32; 2] {
self.size
}
fn modify_basic_front_resource_config(
&mut self,
basic_front_resource_config: BasicFrontResourceConfig,
) {
self.basic_front_resource_config = basic_front_resource_config;
}
fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
self.basic_front_resource_config.position_size_config = position_size_config;
}
fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
self.basic_front_resource_config.clip_rect = clip_rect;
}
}
impl Default for Image {
fn default() -> Self {
Self {
basic_front_resource_config: BasicFrontResourceConfig::default(),
position: [0_f32, 0_f32],
size: [0_f32, 0_f32],
display_info: DisplayInfo::default(),
texture: None,
alpha: 255,
overlay_color: [255, 255, 255],
overlay_alpha: 255,
background_color: [0, 0, 0],
background_alpha: 0,
rotate_angle: 0_f32,
rotate_center: [0_f32, 0_f32],
image_load_method: ImageLoadMethod::ByPath((String::new(), [false, false])),
last_frame_path: String::new(),
tags: Vec::new(),
}
}
}
impl Image {
pub fn from_config(mut self, config: &ImageConfig) -> Self {
if let Some(position_size_config) = config.position_size_config {
self.basic_front_resource_config.position_size_config = position_size_config;
};
if let Some(clip_rect) = config.clip_rect {
self.basic_front_resource_config.clip_rect = clip_rect;
};
if let Some(hidden) = config.hidden {
self.display_info.hidden = hidden;
};
if let Some(ignore_render_layer) = config.ignore_render_layer {
self.display_info.ignore_render_layer = ignore_render_layer;
};
if let Some(alpha) = config.alpha {
self.alpha = alpha;
};
if let Some(overlay_color) = config.overlay_color {
self.overlay_color = overlay_color;
};
if let Some(overlay_alpha) = config.overlay_alpha {
self.overlay_alpha = overlay_alpha;
};
if let Some(background_color) = config.background_color {
self.background_color = background_color;
};
if let Some(background_alpha) = config.background_alpha {
self.background_alpha = background_alpha;
};
if let Some(rotate_angle) = config.rotate_angle {
self.rotate_angle = rotate_angle;
};
if let Some(rotate_center) = config.rotate_center {
self.rotate_center = rotate_center;
};
if let Some(image_load_method) = config.image_load_method.clone() {
self.image_load_method = image_load_method;
};
if let Some(tags) = config.tags.clone() {
self.tags = tags;
};
self
}
#[inline]
pub fn basic_front_resource_config(
mut self,
basic_front_resource_config: &BasicFrontResourceConfig,
) -> Self {
self.basic_front_resource_config = basic_front_resource_config.clone();
self
}
#[inline]
pub fn hidden(mut self, hidden: bool) -> Self {
self.display_info.hidden = hidden;
self
}
#[inline]
pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
self.display_info.ignore_render_layer = ignore_render_layer;
self
}
#[inline]
pub fn alpha(mut self, alpha: u8) -> Self {
self.alpha = alpha;
self
}
#[inline]
pub fn overlay_color(mut self, r: u8, g: u8, b: u8) -> Self {
self.overlay_color = [r, g, b];
self
}
#[inline]
pub fn overlay_alpha(mut self, overlay_alpha: u8) -> Self {
self.overlay_alpha = overlay_alpha;
self
}
#[inline]
pub fn background_color(mut self, r: u8, g: u8, b: u8) -> Self {
self.background_color = [r, g, b];
self
}
#[inline]
pub fn background_alpha(mut self, background_alpha: u8) -> Self {
self.background_alpha = background_alpha;
self
}
#[inline]
pub fn rotate_angle(mut self, rotate_angle: f32) -> Self {
self.rotate_angle = rotate_angle;
self
}
#[inline]
pub fn rotate_center(mut self, x: f32, y: f32) -> Self {
self.rotate_center = [x, y];
self
}
#[inline]
pub fn image_load_method(mut self, image_load_method: &ImageLoadMethod) -> Self {
self.image_load_method = image_load_method.clone();
self
}
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum HyperlinkSelectMethod {
All(String),
Segment(Vec<(usize, String)>),
}
#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
pub struct TextConfig {
pub position_size_config: Option<PositionSizeConfig>,
pub clip_rect: Option<Option<PositionSizeConfig>>,
pub hidden: Option<bool>,
pub ignore_render_layer: Option<bool>,
pub content: Option<String>,
pub font_size: Option<f32>,
pub color: Option<[u8; 3]>,
pub alpha: Option<u8>,
pub background_color: Option<[u8; 3]>,
pub background_alpha: Option<u8>,
pub background_rounding: Option<f32>,
pub font: Option<String>,
pub selectable: Option<bool>,
pub hyperlink_text: Option<Vec<(String, HyperlinkSelectMethod)>>,
pub auto_fit: Option<[bool; 2]>,
pub tags: Option<Vec<[String; 2]>>,
}
impl TextConfig {
pub fn from_text(text: &Text) -> Self {
Self {
position_size_config: Some(text.basic_front_resource_config.position_size_config),
clip_rect: Some(text.basic_front_resource_config.clip_rect),
hidden: Some(text.display_info.hidden),
ignore_render_layer: Some(text.display_info.ignore_render_layer),
content: Some(text.content.clone()),
font_size: Some(text.font_size),
color: Some(text.color),
alpha: Some(text.alpha),
background_color: Some(text.background_color),
background_alpha: Some(text.background_alpha),
background_rounding: Some(text.background_rounding),
font: Some(text.font.clone()),
selectable: Some(text.selectable),
hyperlink_text: Some(text.hyperlink_text.clone()),
auto_fit: Some(text.auto_fit),
tags: Some(text.tags.clone()),
}
}
#[inline]
pub fn position_size_config(
mut self,
position_size_config: Option<PositionSizeConfig>,
) -> Self {
self.position_size_config = position_size_config;
self
}
#[inline]
pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
self.clip_rect = clip_rect;
self
}
#[inline]
pub fn hidden(mut self, hidden: Option<bool>) -> Self {
self.hidden = hidden;
self
}
#[inline]
pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
self.ignore_render_layer = ignore_render_layer;
self
}
#[inline]
pub fn content(mut self, content: Option<String>) -> Self {
self.content = content;
self
}
#[inline]
pub fn font_size(mut self, font_size: Option<f32>) -> Self {
self.font_size = font_size;
self
}
#[inline]
pub fn color(mut self, color: Option<[u8; 3]>) -> Self {
self.color = color;
self
}
#[inline]
pub fn alpha(mut self, alpha: Option<u8>) -> Self {
self.alpha = alpha;
self
}
#[inline]
pub fn background_color(mut self, background_color: Option<[u8; 3]>) -> Self {
self.background_color = background_color;
self
}
#[inline]
pub fn background_alpha(mut self, background_alpha: Option<u8>) -> Self {
self.background_alpha = background_alpha;
self
}
#[inline]
pub fn background_rounding(mut self, background_rounding: Option<f32>) -> Self {
self.background_rounding = background_rounding;
self
}
#[inline]
pub fn font(mut self, font: Option<String>) -> Self {
self.font = font;
self
}
#[inline]
pub fn selectable(mut self, selectable: Option<bool>) -> Self {
self.selectable = selectable;
self
}
#[inline]
pub fn hyperlink_text(
mut self,
hyperlink_text: Option<Vec<(String, HyperlinkSelectMethod)>>,
) -> Self {
self.hyperlink_text = hyperlink_text;
self
}
#[inline]
pub fn auto_fit(mut self, auto_fit: Option<[bool; 2]>) -> Self {
self.auto_fit = auto_fit;
self
}
#[inline]
pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
self.tags = tags;
self
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct Text {
pub basic_front_resource_config: BasicFrontResourceConfig,
pub position: [f32; 2],
pub size: [f32; 2],
pub display_info: DisplayInfo,
pub content: String,
pub font_size: f32,
pub color: [u8; 3],
pub alpha: u8,
pub background_color: [u8; 3],
pub background_alpha: u8,
pub background_rounding: f32,
pub font: String,
pub selectable: bool,
pub hyperlink_text: Vec<(String, HyperlinkSelectMethod)>,
pub hyperlink_index: Vec<(usize, usize, String)>,
pub auto_fit: [bool; 2],
pub last_frame_content: String,
pub selection: Option<(usize, usize)>,
pub truncate_size: [f32; 2],
pub actual_size: [f32; 2],
pub tags: Vec<[String; 2]>,
}
impl RustConstructorResource for Text {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
Some(self.display_info)
}
fn modify_display_info(&mut self, display_info: DisplayInfo) {
self.display_info = display_info;
}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl BasicFrontResource for Text {
fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
self.basic_front_resource_config.clone()
}
fn display_position_size_config(&self) -> PositionSizeConfig {
self.basic_front_resource_config.position_size_config
}
fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
self.basic_front_resource_config.clip_rect
}
fn display_position(&self) -> [f32; 2] {
self.position
}
fn display_size(&self) -> [f32; 2] {
self.size
}
fn modify_basic_front_resource_config(
&mut self,
basic_front_resource_config: BasicFrontResourceConfig,
) {
self.basic_front_resource_config = basic_front_resource_config;
}
fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
self.basic_front_resource_config.position_size_config = position_size_config;
}
fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
self.basic_front_resource_config.clip_rect = clip_rect;
}
}
impl Default for Text {
fn default() -> Self {
Self {
basic_front_resource_config: BasicFrontResourceConfig::default(),
position: [0_f32, 0_f32],
size: [0_f32, 0_f32],
display_info: DisplayInfo::default(),
content: String::from("Hello world"),
font_size: 16_f32,
color: [255, 255, 255],
alpha: 255,
background_color: [0, 0, 0],
background_alpha: 0,
background_rounding: 2_f32,
font: String::new(),
selectable: true,
auto_fit: [true, true],
hyperlink_text: Vec::new(),
hyperlink_index: Vec::new(),
last_frame_content: String::from(""),
selection: None,
truncate_size: [0_f32, 0_f32],
actual_size: [0_f32, 0_f32],
tags: Vec::new(),
}
}
}
impl Text {
pub fn from_config(mut self, config: &TextConfig) -> Self {
if let Some(position_size_config) = config.position_size_config {
self.basic_front_resource_config.position_size_config = position_size_config;
};
if let Some(clip_rect) = config.clip_rect {
self.basic_front_resource_config.clip_rect = clip_rect;
};
if let Some(hidden) = config.hidden {
self.display_info.hidden = hidden;
};
if let Some(ignore_render_layer) = config.ignore_render_layer {
self.display_info.ignore_render_layer = ignore_render_layer;
};
if let Some(content) = config.content.clone() {
self.content = content;
};
if let Some(font_size) = config.font_size {
self.font_size = font_size;
};
if let Some(color) = config.color {
self.color = color;
};
if let Some(alpha) = config.alpha {
self.alpha = alpha;
};
if let Some(background_color) = config.background_color {
self.background_color = background_color;
};
if let Some(background_alpha) = config.background_alpha {
self.background_alpha = background_alpha;
};
if let Some(background_rounding) = config.background_rounding {
self.background_rounding = background_rounding;
};
if let Some(font) = config.font.clone() {
self.font = font;
};
if let Some(selectable) = config.selectable {
self.selectable = selectable;
};
if let Some(hyperlink_text) = config.hyperlink_text.clone() {
self.hyperlink_text = hyperlink_text;
};
if let Some(auto_fit) = config.auto_fit {
self.auto_fit = auto_fit;
};
if let Some(tags) = config.tags.clone() {
self.tags = tags;
};
self
}
#[inline]
pub fn basic_front_resource_config(
mut self,
basic_front_resource_config: &BasicFrontResourceConfig,
) -> Self {
self.basic_front_resource_config = basic_front_resource_config.clone();
self
}
#[inline]
pub fn hidden(mut self, hidden: bool) -> Self {
self.display_info.hidden = hidden;
self
}
#[inline]
pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
self.display_info.ignore_render_layer = ignore_render_layer;
self
}
#[inline]
pub fn content(mut self, content: &str) -> Self {
self.content = content.to_string();
self
}
#[inline]
pub fn font_size(mut self, font_size: f32) -> Self {
self.font_size = font_size;
self
}
#[inline]
pub fn color(mut self, r: u8, g: u8, b: u8) -> Self {
self.color = [r, g, b];
self
}
#[inline]
pub fn alpha(mut self, alpha: u8) -> Self {
self.alpha = alpha;
self
}
#[inline]
pub fn background_color(mut self, r: u8, g: u8, b: u8) -> Self {
self.background_color = [r, g, b];
self
}
#[inline]
pub fn background_alpha(mut self, alpha: u8) -> Self {
self.background_alpha = alpha;
self
}
#[inline]
pub fn background_rounding(mut self, background_rounding: f32) -> Self {
self.background_rounding = background_rounding;
self
}
#[inline]
pub fn font(mut self, font: &str) -> Self {
self.font = font.to_string();
self
}
#[inline]
pub fn selectable(mut self, selectable: bool) -> Self {
self.selectable = selectable;
self
}
#[inline]
pub fn push_hyperlink_text(
mut self,
target_text: &str,
select_method: HyperlinkSelectMethod,
) -> Self {
self.hyperlink_text
.push((target_text.to_string(), select_method));
self
}
#[inline]
pub fn hyperlink_text(mut self, hyperlink_text: Vec<(String, HyperlinkSelectMethod)>) -> Self {
self.hyperlink_text = hyperlink_text;
self
}
#[inline]
pub fn auto_fit(mut self, x: bool, y: bool) -> Self {
self.auto_fit = [x, y];
self
}
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}