Skip to main content

rust_constructor/
basic_front.rs

1//! This file contains basic front resources. Basic front resources can be used independently or to create advanced front-end resources.
2//!
3//! 此文件包含基本前端资源。基本前端资源可以单独使用,也可被用于创建高级前端资源。
4use crate::{
5    BasicFrontResource, BasicFrontResourceConfig, BorderKind, DisplayInfo, PositionSizeConfig,
6    RustConstructorResource,
7};
8#[cfg(feature = "bevy")]
9use egui_bevy::TextureHandle;
10#[cfg(feature = "standard")]
11use egui_standard::TextureHandle;
12use std::{
13    any::Any,
14    fmt::{Debug, Formatter},
15};
16
17/// Config options for custom rectangles.
18///
19/// 矩形的可配置选项。
20///
21/// This struct contains all configurable properties for creating and modifying
22/// rectangular UI elements with various visual properties.
23///
24/// 该结构体包含用于创建和修改具有各种视觉属性的矩形UI元素的所有可配置属性。
25#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
26pub struct CustomRectConfig {
27    /// Config for position, size, and layout of the rectangle.
28    ///
29    /// 矩形的位置、尺寸和布局配置。
30    pub position_size_config: Option<PositionSizeConfig>,
31
32    /// Optional clipping rectangle that defines the visible area.
33    ///
34    /// 定义可见区域的可选裁剪矩形。
35    pub clip_rect: Option<Option<PositionSizeConfig>>,
36
37    /// Controls whether the rectangle is visible or hidden.
38    ///
39    /// 控制矩形是否可见或隐藏。
40    pub hidden: Option<bool>,
41
42    /// If true, the rectangle ignores render layer.
43    ///
44    /// 如果为true,矩形忽略渲染层。
45    pub ignore_render_layer: Option<bool>,
46
47    /// Radius for rounded corners. Zero for sharp corners.
48    ///
49    /// 圆角半径。零表示直角。
50    pub rounding: Option<f32>,
51
52    /// Fill color of the rectangle as [R, G, B].
53    ///
54    /// 矩形的填充颜色,格式为[R, G, B]。
55    pub color: Option<[u8; 3]>,
56
57    /// Opacity of the rectangle (0-255).
58    ///
59    /// 矩形的不透明度(0-255)。
60    pub alpha: Option<u8>,
61
62    /// Fill color overlay of the rectangle as [R, G, B].
63    ///
64    /// 矩形的填充颜色覆盖层,格式为[R, G, B]。
65    pub overlay_color: Option<[u8; 3]>,
66
67    /// Opacity of the fill color overlay (0-255).
68    ///
69    /// 矩形的填充颜色覆盖层不透明度(0-255)。
70    pub overlay_alpha: Option<Option<u8>>,
71
72    /// Width of the border.
73    ///
74    /// 边框宽度。
75    pub border_width: Option<f32>,
76
77    /// Color of the border as [R, G, B].
78    ///
79    /// 边框颜色,格式为[R, G, B]。
80    pub border_color: Option<[u8; 3]>,
81
82    /// Opacity of the border (0-255).
83    ///
84    /// 边框的不透明度(0-255)。
85    pub border_alpha: Option<u8>,
86
87    /// Color overlay of the border as [R, G, B].
88    ///
89    /// 边框的颜色覆盖层,格式为[R, G, B]。
90    pub overlay_border_color: Option<[u8; 3]>,
91
92    /// Opacity of the border color overlay (0-255).
93    ///
94    /// 边框的颜色覆盖层不透明度(0-255)。
95    pub overlay_border_alpha: Option<Option<u8>>,
96
97    /// Placement of the border relative to the rectangle's bounds.
98    ///
99    /// 边框相对于矩形边界的放置方式。
100    pub border_kind: Option<BorderKind>,
101
102    /// Key-value pairs for categorization and metadata.
103    ///
104    /// 用于分类和元数据的键值对标签。
105    pub tags: Option<Vec<[String; 2]>>,
106}
107
108impl CustomRectConfig {
109    pub fn from_custom_rect(custom_rect: &CustomRect) -> Self {
110        Self {
111            position_size_config: Some(
112                custom_rect.basic_front_resource_config.position_size_config,
113            ),
114            clip_rect: Some(custom_rect.basic_front_resource_config.clip_rect),
115            hidden: Some(custom_rect.display_info.hidden),
116            ignore_render_layer: Some(custom_rect.display_info.ignore_render_layer),
117            rounding: Some(custom_rect.rounding),
118            color: Some(custom_rect.color),
119            alpha: Some(custom_rect.alpha),
120            overlay_color: Some(custom_rect.overlay_color),
121            overlay_alpha: Some(custom_rect.overlay_alpha),
122            border_width: Some(custom_rect.border_width),
123            border_color: Some(custom_rect.border_color),
124            border_alpha: Some(custom_rect.border_alpha),
125            overlay_border_color: Some(custom_rect.overlay_border_color),
126            overlay_border_alpha: Some(custom_rect.overlay_border_alpha),
127            border_kind: Some(custom_rect.border_kind),
128            tags: Some(custom_rect.tags.clone()),
129        }
130    }
131
132    #[inline]
133    pub fn position_size_config(
134        mut self,
135        position_size_config: Option<PositionSizeConfig>,
136    ) -> Self {
137        self.position_size_config = position_size_config;
138        self
139    }
140
141    #[inline]
142    pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
143        self.clip_rect = clip_rect;
144        self
145    }
146
147    #[inline]
148    pub fn hidden(mut self, hidden: Option<bool>) -> Self {
149        self.hidden = hidden;
150        self
151    }
152
153    #[inline]
154    pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
155        self.ignore_render_layer = ignore_render_layer;
156        self
157    }
158
159    #[inline]
160    pub fn rounding(mut self, rounding: Option<f32>) -> Self {
161        self.rounding = rounding;
162        self
163    }
164
165    #[inline]
166    pub fn color(mut self, color: Option<[u8; 3]>) -> Self {
167        self.color = color;
168        self
169    }
170
171    #[inline]
172    pub fn alpha(mut self, alpha: Option<u8>) -> Self {
173        self.alpha = alpha;
174        self
175    }
176
177    #[inline]
178    pub fn overlay_color(mut self, overlay_color: Option<[u8; 3]>) -> Self {
179        self.overlay_color = overlay_color;
180        self
181    }
182
183    #[inline]
184    pub fn overlay_alpha(mut self, overlay_alpha: Option<Option<u8>>) -> Self {
185        self.overlay_alpha = overlay_alpha;
186        self
187    }
188
189    #[inline]
190    pub fn border_width(mut self, border_width: Option<f32>) -> Self {
191        self.border_width = border_width;
192        self
193    }
194
195    #[inline]
196    pub fn border_color(mut self, border_color: Option<[u8; 3]>) -> Self {
197        self.border_color = border_color;
198        self
199    }
200
201    #[inline]
202    pub fn border_alpha(mut self, border_alpha: Option<u8>) -> Self {
203        self.border_alpha = border_alpha;
204        self
205    }
206
207    #[inline]
208    pub fn overlay_border_color(mut self, overlay_border_color: Option<[u8; 3]>) -> Self {
209        self.overlay_border_color = overlay_border_color;
210        self
211    }
212
213    #[inline]
214    pub fn overlay_border_alpha(mut self, overlay_border_alpha: Option<Option<u8>>) -> Self {
215        self.overlay_border_alpha = overlay_border_alpha;
216        self
217    }
218
219    #[inline]
220    pub fn border_kind(mut self, border_kind: Option<BorderKind>) -> Self {
221        self.border_kind = border_kind;
222        self
223    }
224
225    #[inline]
226    pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
227        self.tags = tags;
228        self
229    }
230}
231
232/// Custom rectangle resource for drawing rectangles with various visual properties.
233///
234/// 自定义矩形资源,用于绘制具有各种视觉属性的矩形。
235#[derive(Debug, Clone, PartialEq, PartialOrd)]
236pub struct CustomRect {
237    /// Config for basic front resource properties.
238    ///
239    /// 基本前端资源属性配置。
240    pub basic_front_resource_config: BasicFrontResourceConfig,
241
242    /// Current display position of the rectangle as [x, y].
243    ///
244    /// 矩形的当前显示位置,为[x, y]。
245    pub position: [f32; 2],
246
247    /// Current display size of the rectangle as [width, height].
248    ///
249    /// 矩形的当前显示尺寸,为[width, height]。
250    pub size: [f32; 2],
251
252    /// Display info controlling visibility and rendering.
253    ///
254    /// 显示信息,控制可见性和渲染。
255    pub display_info: DisplayInfo,
256
257    /// Radius for rounded corners.
258    ///
259    /// 圆角。
260    pub rounding: f32,
261
262    /// Fill color of the rectangle as [R, G, B].
263    ///
264    /// 填充矩形颜色,为[R, G, B]。
265    pub color: [u8; 3],
266
267    /// Opacity of the rectangle (0-255).
268    ///
269    /// 矩形的不透明度(0-255)。
270    pub alpha: u8,
271
272    /// Fill color overlay of the rectangle as [R, G, B].
273    ///
274    /// 矩形的填充颜色覆盖层,格式为[R, G, B]。
275    pub overlay_color: [u8; 3],
276
277    /// Opacity of the fill color overlay (0-255).
278    ///
279    /// 矩形的填充颜色覆盖层不透明度(0-255)。
280    pub overlay_alpha: Option<u8>,
281
282    /// Width of the border.
283    ///
284    /// 边框宽度。
285    pub border_width: f32,
286
287    /// Color of the border as [R, G, B].
288    ///
289    /// 边框颜色,为[R, G, B]。
290    pub border_color: [u8; 3],
291
292    /// Opacity of the border (0-255).
293    ///
294    /// 边框的不透明度(0-255)。
295    pub border_alpha: u8,
296
297    /// Color overlay of the border as [R, G, B].
298    ///
299    /// 边框的颜色覆盖层,格式为[R, G, B]。
300    pub overlay_border_color: [u8; 3],
301
302    /// Opacity of the border color overlay (0-255).
303    ///
304    /// 边框的颜色覆盖层不透明度(0-255)。
305    pub overlay_border_alpha: Option<u8>,
306
307    /// Placement of the border relative to the rectangle's bounds.
308    ///
309    /// 边框相对于矩形边界的位置。
310    pub border_kind: BorderKind,
311
312    /// Key-value pairs for categorization and metadata.
313    ///
314    /// 用于分类和元数据的键值对标签。
315    pub tags: Vec<[String; 2]>,
316}
317
318impl RustConstructorResource for CustomRect {
319    fn as_any(&self) -> &dyn Any {
320        self
321    }
322
323    fn as_any_mut(&mut self) -> &mut dyn Any {
324        self
325    }
326
327    fn display_display_info(&self) -> Option<DisplayInfo> {
328        Some(self.display_info)
329    }
330
331    fn modify_display_info(&mut self, display_info: DisplayInfo) {
332        self.display_info = display_info;
333    }
334
335    fn display_tags(&self) -> Vec<[String; 2]> {
336        self.tags.clone()
337    }
338
339    fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
340        if replace {
341            self.tags = tags.to_owned();
342        } else {
343            for tag in tags {
344                if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
345                    self.tags.remove(index);
346                };
347            }
348            self.tags.extend(tags.iter().cloned());
349        };
350    }
351}
352
353impl BasicFrontResource for CustomRect {
354    fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
355        self.basic_front_resource_config.clone()
356    }
357
358    fn display_position_size_config(&self) -> PositionSizeConfig {
359        self.basic_front_resource_config.position_size_config
360    }
361
362    fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
363        self.basic_front_resource_config.clip_rect
364    }
365
366    fn display_position(&self) -> [f32; 2] {
367        self.position
368    }
369
370    fn display_size(&self) -> [f32; 2] {
371        self.size
372    }
373
374    fn modify_basic_front_resource_config(
375        &mut self,
376        basic_front_resource_config: BasicFrontResourceConfig,
377    ) {
378        self.basic_front_resource_config = basic_front_resource_config;
379    }
380
381    fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
382        self.basic_front_resource_config.position_size_config = position_size_config;
383    }
384
385    fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
386        self.basic_front_resource_config.clip_rect = clip_rect;
387    }
388}
389
390impl Default for CustomRect {
391    fn default() -> Self {
392        Self {
393            basic_front_resource_config: BasicFrontResourceConfig::default(),
394            position: [0_f32, 0_f32],
395            size: [0_f32, 0_f32],
396            display_info: DisplayInfo::default(),
397            rounding: 2_f32,
398            color: [255, 255, 255],
399            alpha: 255,
400            overlay_border_color: [255, 255, 255],
401            overlay_alpha: None,
402            border_width: 2_f32,
403            border_color: [0, 0, 0],
404            border_alpha: 255,
405            overlay_color: [255, 255, 255],
406            overlay_border_alpha: None,
407            border_kind: BorderKind::default(),
408            tags: Vec::new(),
409        }
410    }
411}
412
413impl CustomRect {
414    pub fn from_config(mut self, config: &CustomRectConfig) -> Self {
415        if let Some(position_size_config) = config.position_size_config {
416            self.basic_front_resource_config.position_size_config = position_size_config;
417        };
418        if let Some(clip_rect) = config.clip_rect {
419            self.basic_front_resource_config.clip_rect = clip_rect;
420        };
421        if let Some(hidden) = config.hidden {
422            self.display_info.hidden = hidden;
423        };
424        if let Some(ignore_render_layer) = config.ignore_render_layer {
425            self.display_info.ignore_render_layer = ignore_render_layer;
426        };
427        if let Some(rounding) = config.rounding {
428            self.rounding = rounding;
429        };
430        if let Some(color) = config.color {
431            self.color = color;
432        };
433        if let Some(alpha) = config.alpha {
434            self.alpha = alpha;
435        };
436        if let Some(overlay_color) = config.overlay_color {
437            self.overlay_color = overlay_color;
438        };
439        if let Some(overlay_alpha) = config.overlay_alpha {
440            self.overlay_alpha = overlay_alpha;
441        };
442        if let Some(border_width) = config.border_width {
443            self.border_width = border_width;
444        };
445        if let Some(border_color) = config.border_color {
446            self.border_color = border_color;
447        };
448        if let Some(border_alpha) = config.border_alpha {
449            self.border_alpha = border_alpha;
450        };
451        if let Some(overlay_border_color) = config.overlay_border_color {
452            self.overlay_border_color = overlay_border_color;
453        };
454        if let Some(overlay_border_alpha) = config.overlay_border_alpha {
455            self.overlay_border_alpha = overlay_border_alpha;
456        };
457        if let Some(border_kind) = config.border_kind {
458            self.border_kind = border_kind;
459        };
460        if let Some(tags) = config.tags.clone() {
461            self.tags = tags;
462        };
463        self
464    }
465
466    #[inline]
467    pub fn basic_front_resource_config(
468        mut self,
469        basic_front_resource_config: &BasicFrontResourceConfig,
470    ) -> Self {
471        self.basic_front_resource_config = basic_front_resource_config.clone();
472        self
473    }
474
475    #[inline]
476    pub fn hidden(mut self, hidden: bool) -> Self {
477        self.display_info.hidden = hidden;
478        self
479    }
480
481    #[inline]
482    pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
483        self.display_info.ignore_render_layer = ignore_render_layer;
484        self
485    }
486
487    #[inline]
488    pub fn rounding(mut self, rounding: f32) -> Self {
489        self.rounding = rounding;
490        self
491    }
492
493    #[inline]
494    pub fn color(mut self, r: u8, g: u8, b: u8) -> Self {
495        self.color = [r, g, b];
496        self
497    }
498
499    #[inline]
500    pub fn alpha(mut self, alpha: u8) -> Self {
501        self.alpha = alpha;
502        self
503    }
504
505    #[inline]
506    pub fn overlay_color(mut self, r: u8, g: u8, b: u8) -> Self {
507        self.overlay_color = [r, g, b];
508        self
509    }
510
511    #[inline]
512    pub fn overlay_alpha(mut self, overlay_alpha: Option<u8>) -> Self {
513        self.overlay_alpha = overlay_alpha;
514        self
515    }
516
517    #[inline]
518    pub fn border_width(mut self, border_width: f32) -> Self {
519        self.border_width = border_width;
520        self
521    }
522
523    #[inline]
524    pub fn border_color(mut self, r: u8, g: u8, b: u8) -> Self {
525        self.border_color = [r, g, b];
526        self
527    }
528
529    #[inline]
530    pub fn border_alpha(mut self, border_alpha: u8) -> Self {
531        self.border_alpha = border_alpha;
532        self
533    }
534
535    #[inline]
536    pub fn overlay_border_color(mut self, r: u8, g: u8, b: u8) -> Self {
537        self.overlay_border_color = [r, g, b];
538        self
539    }
540
541    #[inline]
542    pub fn overlay_border_alpha(mut self, overlay_border_alpha: Option<u8>) -> Self {
543        self.overlay_border_alpha = overlay_border_alpha;
544        self
545    }
546
547    #[inline]
548    pub fn border_kind(mut self, border_kind: BorderKind) -> Self {
549        self.border_kind = border_kind;
550        self
551    }
552
553    #[inline]
554    pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
555        if replace {
556            self.tags = tags.to_owned();
557        } else {
558            for tag in tags {
559                if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
560                    self.tags.remove(index);
561                };
562            }
563            self.tags.extend(tags.iter().cloned());
564        };
565        self
566    }
567}
568
569/// Wrapper for TextureHandle that supports Debug trait derivation.
570///
571/// 支持Debug特征派生的TextureHandle包装器。
572#[derive(Clone, PartialEq, Eq, Hash)]
573pub struct DebugTextureHandle(pub TextureHandle);
574
575impl Debug for DebugTextureHandle {
576    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
577        // 只输出类型信息,不输出具体纹理数据
578        f.debug_struct("DebugTextureHandle").finish()
579    }
580}
581
582impl DebugTextureHandle {
583    pub fn new(texture_handle: &TextureHandle) -> Self {
584        Self(texture_handle.clone())
585    }
586}
587
588/// Methods for loading images into the resource.
589///
590/// 将图像加载到资源中的方法。
591#[derive(Debug, Clone, PartialEq, Eq, Hash)]
592pub enum ImageLoadMethod {
593    /// Load image from a file path.
594    ///
595    /// 从文件路径加载图像。
596    ByPath((String, [bool; 2])),
597
598    /// Use an existing TextureHandle for the image.
599    ///
600    /// 使用现有的TextureHandle作为图像。
601    ByTexture(DebugTextureHandle),
602}
603
604/// Config options for image resources.
605///
606/// 图像资源的配置选项。
607#[derive(Debug, Default, Clone, PartialEq)]
608pub struct ImageConfig {
609    /// Config for position, size, and layout.
610    ///
611    /// 位置、尺寸和布局配置。
612    pub position_size_config: Option<PositionSizeConfig>,
613
614    /// Optional clipping rectangle that defines the visible area.
615    ///
616    /// 定义可见区域的可选裁剪矩形。
617    pub clip_rect: Option<Option<PositionSizeConfig>>,
618
619    /// Controls whether the image is visible or hidden.
620    ///
621    /// 控制图像是否可见或隐藏。
622    pub hidden: Option<bool>,
623
624    /// If true, the image ignores render layer.
625    ///
626    /// 如果为true,图像忽略渲染层。
627    pub ignore_render_layer: Option<bool>,
628
629    /// Opacity of the image (0-255).
630    ///
631    /// 图像的不透明度(0-255)。
632    pub alpha: Option<u8>,
633
634    /// Color overlay applied to the image as [R, G, B].
635    ///
636    /// 应用于图像的色彩覆盖,格式为[R, G, B]。
637    pub overlay_color: Option<[u8; 3]>,
638
639    /// Opacity of the overlay (0-255).
640    ///
641    /// 覆盖层的不透明度(0-255)。
642    pub overlay_alpha: Option<u8>,
643
644    /// Background color behind the image as [R, G, B].
645    ///
646    /// 图像背后的背景颜色,格式为[R, G, B]。
647    pub background_color: Option<[u8; 3]>,
648
649    /// Opacity of the background (0-255).
650    ///
651    /// 背景的不透明度(0-255)。
652    pub background_alpha: Option<u8>,
653
654    /// Rotation angle of the image in degrees.
655    ///
656    /// 图像的旋转角度(度)。
657    pub rotate_angle: Option<f32>,
658
659    /// Center point for rotation, compare it with the actual size to obtain as [width, height].
660    ///
661    /// 旋转中心点,通过与实际大小的比得出,为[width, height]。
662    pub rotate_center: Option<[f32; 2]>,
663
664    /// Method used to load the image.
665    ///
666    /// 用于加载图像的方法。
667    pub image_load_method: Option<ImageLoadMethod>,
668
669    /// Key-value pairs for categorization and metadata.
670    ///
671    /// 用于分类和元数据的键值对标签。
672    pub tags: Option<Vec<[String; 2]>>,
673}
674
675impl ImageConfig {
676    pub fn from_image(image: &Image) -> Self {
677        Self {
678            position_size_config: Some(image.basic_front_resource_config.position_size_config),
679            clip_rect: Some(image.basic_front_resource_config.clip_rect),
680            hidden: Some(image.display_info.hidden),
681            ignore_render_layer: Some(image.display_info.ignore_render_layer),
682            alpha: Some(image.alpha),
683            overlay_color: Some(image.overlay_color),
684            overlay_alpha: Some(image.overlay_alpha),
685            background_color: Some(image.background_color),
686            background_alpha: Some(image.background_alpha),
687            rotate_angle: Some(image.rotate_angle),
688            rotate_center: Some(image.rotate_center),
689            image_load_method: Some(image.image_load_method.clone()),
690            tags: Some(image.tags.clone()),
691        }
692    }
693
694    #[inline]
695    pub fn position_size_config(
696        mut self,
697        position_size_config: Option<PositionSizeConfig>,
698    ) -> Self {
699        self.position_size_config = position_size_config;
700        self
701    }
702
703    #[inline]
704    pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
705        self.clip_rect = clip_rect;
706        self
707    }
708
709    #[inline]
710    pub fn hidden(mut self, hidden: Option<bool>) -> Self {
711        self.hidden = hidden;
712        self
713    }
714
715    #[inline]
716    pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
717        self.ignore_render_layer = ignore_render_layer;
718        self
719    }
720
721    #[inline]
722    pub fn alpha(mut self, alpha: Option<u8>) -> Self {
723        self.alpha = alpha;
724        self
725    }
726
727    #[inline]
728    pub fn overlay_color(mut self, overlay_color: Option<[u8; 3]>) -> Self {
729        self.overlay_color = overlay_color;
730        self
731    }
732
733    #[inline]
734    pub fn overlay_alpha(mut self, overlay_alpha: Option<u8>) -> Self {
735        self.overlay_alpha = overlay_alpha;
736        self
737    }
738
739    #[inline]
740    pub fn background_color(mut self, background_color: Option<[u8; 3]>) -> Self {
741        self.background_color = background_color;
742        self
743    }
744
745    #[inline]
746    pub fn background_alpha(mut self, background_alpha: Option<u8>) -> Self {
747        self.background_alpha = background_alpha;
748        self
749    }
750
751    #[inline]
752    pub fn rotate_angle(mut self, rotate_angle: Option<f32>) -> Self {
753        self.rotate_angle = rotate_angle;
754        self
755    }
756
757    #[inline]
758    pub fn rotate_center(mut self, rotate_center: Option<[f32; 2]>) -> Self {
759        self.rotate_center = rotate_center;
760        self
761    }
762
763    #[inline]
764    pub fn image_load_method(mut self, image_load_method: Option<ImageLoadMethod>) -> Self {
765        self.image_load_method = image_load_method;
766        self
767    }
768
769    #[inline]
770    pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
771        self.tags = tags;
772        self
773    }
774}
775
776/// Image resource for displaying graphical content in the GUI.
777///
778/// 用于在GUI中显示图形内容的图像资源。
779#[derive(Debug, Clone, PartialEq)]
780pub struct Image {
781    /// Config for basic front resource properties.
782    ///
783    /// 基本前端资源属性配置。
784    pub basic_front_resource_config: BasicFrontResourceConfig,
785
786    /// Current display position of the image as [x, y].
787    ///
788    /// 图像的当前显示位置,坐标为[x, y]。
789    pub position: [f32; 2],
790
791    /// Current display size of the image as [width, height].
792    ///
793    /// 图像的当前显示尺寸,为[width, height]。
794    pub size: [f32; 2],
795
796    /// Display info controlling visibility and rendering.
797    ///
798    /// 显示信息,控制可见性和渲染。
799    pub display_info: DisplayInfo,
800
801    /// Handle to the loaded texture, if available.
802    ///
803    /// 已加载纹理的句柄(如果可用)。
804    pub texture: Option<DebugTextureHandle>,
805
806    /// Opacity of the image (0-255).
807    ///
808    /// 图像的不透明度(0-255)。
809    pub alpha: u8,
810
811    /// Color overlay applied to the image as [R, G, B].
812    ///
813    /// 应用于图像的色彩覆盖,格式为[R, G, B]。
814    pub overlay_color: [u8; 3],
815
816    /// Opacity of the overlay (0-255).
817    ///
818    /// 覆盖层的不透明度(0-255)。
819    pub overlay_alpha: u8,
820
821    /// Background color behind the image as [R, G, B].
822    ///
823    /// 图像背后的背景颜色,格式为[R, G, B]。
824    pub background_color: [u8; 3],
825
826    /// Opacity of the background (0-255).
827    ///
828    /// 背景的不透明度(0-255)。
829    pub background_alpha: u8,
830
831    /// Rotation angle of the image in degrees.
832    ///
833    /// 图像的旋转角度(度)。
834    pub rotate_angle: f32,
835
836    /// Center point for rotation, compare it with the actual size to obtain as [width, height].
837    ///
838    /// 旋转中心点,通过与实际大小的比得出,为[width, height]。
839    pub rotate_center: [f32; 2],
840
841    /// Method used to load the image.
842    ///
843    /// 用于加载图像的方法。
844    pub image_load_method: ImageLoadMethod,
845
846    /// The path for loading the image in the previous frame.
847    ///
848    /// 上一帧加载图片的路径。
849    pub last_frame_path: String,
850
851    /// Key-value pairs for categorization and metadata.
852    ///
853    /// 用于分类和元数据的键值对标签。
854    pub tags: Vec<[String; 2]>,
855}
856
857impl RustConstructorResource for Image {
858    fn as_any(&self) -> &dyn Any {
859        self
860    }
861
862    fn as_any_mut(&mut self) -> &mut dyn Any {
863        self
864    }
865
866    fn display_display_info(&self) -> Option<DisplayInfo> {
867        Some(self.display_info)
868    }
869
870    fn modify_display_info(&mut self, display_info: DisplayInfo) {
871        self.display_info = display_info;
872    }
873
874    fn display_tags(&self) -> Vec<[String; 2]> {
875        self.tags.clone()
876    }
877
878    fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
879        if replace {
880            self.tags = tags.to_owned();
881        } else {
882            for tag in tags {
883                if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
884                    self.tags.remove(index);
885                };
886            }
887            self.tags.extend(tags.iter().cloned());
888        };
889    }
890}
891
892impl BasicFrontResource for Image {
893    fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
894        self.basic_front_resource_config.clone()
895    }
896
897    fn display_position_size_config(&self) -> PositionSizeConfig {
898        self.basic_front_resource_config.position_size_config
899    }
900
901    fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
902        self.basic_front_resource_config.clip_rect
903    }
904
905    fn display_position(&self) -> [f32; 2] {
906        self.position
907    }
908
909    fn display_size(&self) -> [f32; 2] {
910        self.size
911    }
912
913    fn modify_basic_front_resource_config(
914        &mut self,
915        basic_front_resource_config: BasicFrontResourceConfig,
916    ) {
917        self.basic_front_resource_config = basic_front_resource_config;
918    }
919
920    fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
921        self.basic_front_resource_config.position_size_config = position_size_config;
922    }
923
924    fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
925        self.basic_front_resource_config.clip_rect = clip_rect;
926    }
927}
928
929impl Default for Image {
930    fn default() -> Self {
931        Self {
932            basic_front_resource_config: BasicFrontResourceConfig::default(),
933            position: [0_f32, 0_f32],
934            size: [0_f32, 0_f32],
935            display_info: DisplayInfo::default(),
936            texture: None,
937            alpha: 255,
938            overlay_color: [255, 255, 255],
939            overlay_alpha: 255,
940            background_color: [0, 0, 0],
941            background_alpha: 0,
942            rotate_angle: 0_f32,
943            rotate_center: [0_f32, 0_f32],
944            image_load_method: ImageLoadMethod::ByPath((String::new(), [false, false])),
945            last_frame_path: String::new(),
946            tags: Vec::new(),
947        }
948    }
949}
950
951impl Image {
952    pub fn from_config(mut self, config: &ImageConfig) -> Self {
953        if let Some(position_size_config) = config.position_size_config {
954            self.basic_front_resource_config.position_size_config = position_size_config;
955        };
956        if let Some(clip_rect) = config.clip_rect {
957            self.basic_front_resource_config.clip_rect = clip_rect;
958        };
959        if let Some(hidden) = config.hidden {
960            self.display_info.hidden = hidden;
961        };
962        if let Some(ignore_render_layer) = config.ignore_render_layer {
963            self.display_info.ignore_render_layer = ignore_render_layer;
964        };
965        if let Some(alpha) = config.alpha {
966            self.alpha = alpha;
967        };
968        if let Some(overlay_color) = config.overlay_color {
969            self.overlay_color = overlay_color;
970        };
971        if let Some(overlay_alpha) = config.overlay_alpha {
972            self.overlay_alpha = overlay_alpha;
973        };
974        if let Some(background_color) = config.background_color {
975            self.background_color = background_color;
976        };
977        if let Some(background_alpha) = config.background_alpha {
978            self.background_alpha = background_alpha;
979        };
980        if let Some(rotate_angle) = config.rotate_angle {
981            self.rotate_angle = rotate_angle;
982        };
983        if let Some(rotate_center) = config.rotate_center {
984            self.rotate_center = rotate_center;
985        };
986        if let Some(image_load_method) = config.image_load_method.clone() {
987            self.image_load_method = image_load_method;
988        };
989        if let Some(tags) = config.tags.clone() {
990            self.tags = tags;
991        };
992        self
993    }
994
995    #[inline]
996    pub fn basic_front_resource_config(
997        mut self,
998        basic_front_resource_config: &BasicFrontResourceConfig,
999    ) -> Self {
1000        self.basic_front_resource_config = basic_front_resource_config.clone();
1001        self
1002    }
1003
1004    #[inline]
1005    pub fn hidden(mut self, hidden: bool) -> Self {
1006        self.display_info.hidden = hidden;
1007        self
1008    }
1009
1010    #[inline]
1011    pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
1012        self.display_info.ignore_render_layer = ignore_render_layer;
1013        self
1014    }
1015
1016    #[inline]
1017    pub fn alpha(mut self, alpha: u8) -> Self {
1018        self.alpha = alpha;
1019        self
1020    }
1021
1022    #[inline]
1023    pub fn overlay_color(mut self, r: u8, g: u8, b: u8) -> Self {
1024        self.overlay_color = [r, g, b];
1025        self
1026    }
1027
1028    #[inline]
1029    pub fn overlay_alpha(mut self, overlay_alpha: u8) -> Self {
1030        self.overlay_alpha = overlay_alpha;
1031        self
1032    }
1033
1034    #[inline]
1035    pub fn background_color(mut self, r: u8, g: u8, b: u8) -> Self {
1036        self.background_color = [r, g, b];
1037        self
1038    }
1039
1040    #[inline]
1041    pub fn background_alpha(mut self, background_alpha: u8) -> Self {
1042        self.background_alpha = background_alpha;
1043        self
1044    }
1045
1046    #[inline]
1047    pub fn rotate_angle(mut self, rotate_angle: f32) -> Self {
1048        self.rotate_angle = rotate_angle;
1049        self
1050    }
1051
1052    #[inline]
1053    pub fn rotate_center(mut self, x: f32, y: f32) -> Self {
1054        self.rotate_center = [x, y];
1055        self
1056    }
1057
1058    #[inline]
1059    pub fn image_load_method(mut self, image_load_method: &ImageLoadMethod) -> Self {
1060        self.image_load_method = image_load_method.clone();
1061        self
1062    }
1063
1064    #[inline]
1065    pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
1066        if replace {
1067            self.tags = tags.to_owned();
1068        } else {
1069            for tag in tags {
1070                if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
1071                    self.tags.remove(index);
1072                };
1073            }
1074            self.tags.extend(tags.iter().cloned());
1075        };
1076        self
1077    }
1078}
1079
1080/// Control the selection method of hyperlinks.
1081///
1082/// 控制超链接的选取方法。
1083#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
1084pub enum HyperlinkSelectMethod {
1085    /// Selects all occurrences of the hyperlink text.
1086    ///
1087    /// 选取所有匹配的超链接文本。
1088    All(String),
1089    /// Selects specific segments of the hyperlink text with indices.
1090    ///
1091    /// 选取指定的超链接文本段。
1092    Segment(Vec<(usize, String)>),
1093}
1094
1095/// Config options for text resources.
1096///
1097/// 文本资源的配置选项。
1098#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
1099pub struct TextConfig {
1100    /// Config for position, size, and layout.
1101    ///
1102    /// 位置、尺寸和布局配置。
1103    pub position_size_config: Option<PositionSizeConfig>,
1104
1105    /// Optional clipping rectangle that defines the visible area.
1106    ///
1107    /// 定义可见区域的可选裁剪矩形。
1108    pub clip_rect: Option<Option<PositionSizeConfig>>,
1109
1110    /// Controls whether the text is visible or hidden.
1111    ///
1112    /// 控制文本是否可见或隐藏。
1113    pub hidden: Option<bool>,
1114
1115    /// If true, the text ignores render layer.
1116    ///
1117    /// 如果为true,文本忽略渲染层。
1118    pub ignore_render_layer: Option<bool>,
1119
1120    /// Text content to be displayed.
1121    ///
1122    /// 要显示的文本内容。
1123    pub content: Option<String>,
1124
1125    /// Font size in points.
1126    ///
1127    /// 字体大小(点)。
1128    pub font_size: Option<f32>,
1129
1130    /// Text color as [R, G, B].
1131    ///
1132    /// 文本颜色,格式为[R, G, B]。
1133    pub color: Option<[u8; 3]>,
1134
1135    /// Opacity of the text (0-255).
1136    ///
1137    /// 文本的不透明度(0-255)。
1138    pub alpha: Option<u8>,
1139
1140    /// Background color behind the text as [R, G, B].
1141    ///
1142    /// 文本背后的背景颜色,格式为[R, G, B]。
1143    pub background_color: Option<[u8; 3]>,
1144
1145    /// Opacity of the background (0-255).
1146    ///
1147    /// 背景的不透明度(0-255)。
1148    pub background_alpha: Option<u8>,
1149
1150    /// Radius for rounded corners of the background.
1151    ///
1152    /// 背景圆角半径。
1153    pub background_rounding: Option<f32>,
1154
1155    /// The font used for the specified text.
1156    ///
1157    /// 指定文本使用的字体。
1158    pub font: Option<String>,
1159
1160    /// Whether the text can be selected by the user.
1161    ///
1162    /// 文本是否可以被用户选择。
1163    pub selectable: Option<bool>,
1164
1165    /// Hyperlink texts for clickable regions.
1166    ///
1167    /// 可点击区域的超链接文本。
1168    pub hyperlink_text: Option<Vec<(String, HyperlinkSelectMethod)>>,
1169
1170    /// Automatically adjust size to fit content.
1171    ///
1172    /// 自动调整尺寸以适应内容。
1173    pub auto_fit: Option<[bool; 2]>,
1174
1175    /// Key-value pairs for categorization and metadata.
1176    ///
1177    /// 用于分类和元数据的键值对标签。
1178    pub tags: Option<Vec<[String; 2]>>,
1179}
1180
1181impl TextConfig {
1182    pub fn from_text(text: &Text) -> Self {
1183        Self {
1184            position_size_config: Some(text.basic_front_resource_config.position_size_config),
1185            clip_rect: Some(text.basic_front_resource_config.clip_rect),
1186            hidden: Some(text.display_info.hidden),
1187            ignore_render_layer: Some(text.display_info.ignore_render_layer),
1188            content: Some(text.content.clone()),
1189            font_size: Some(text.font_size),
1190            color: Some(text.color),
1191            alpha: Some(text.alpha),
1192            background_color: Some(text.background_color),
1193            background_alpha: Some(text.background_alpha),
1194            background_rounding: Some(text.background_rounding),
1195            font: Some(text.font.clone()),
1196            selectable: Some(text.selectable),
1197            hyperlink_text: Some(text.hyperlink_text.clone()),
1198            auto_fit: Some(text.auto_fit),
1199            tags: Some(text.tags.clone()),
1200        }
1201    }
1202
1203    #[inline]
1204    pub fn position_size_config(
1205        mut self,
1206        position_size_config: Option<PositionSizeConfig>,
1207    ) -> Self {
1208        self.position_size_config = position_size_config;
1209        self
1210    }
1211
1212    #[inline]
1213    pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
1214        self.clip_rect = clip_rect;
1215        self
1216    }
1217
1218    #[inline]
1219    pub fn hidden(mut self, hidden: Option<bool>) -> Self {
1220        self.hidden = hidden;
1221        self
1222    }
1223
1224    #[inline]
1225    pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
1226        self.ignore_render_layer = ignore_render_layer;
1227        self
1228    }
1229
1230    #[inline]
1231    pub fn content(mut self, content: Option<String>) -> Self {
1232        self.content = content;
1233        self
1234    }
1235
1236    #[inline]
1237    pub fn font_size(mut self, font_size: Option<f32>) -> Self {
1238        self.font_size = font_size;
1239        self
1240    }
1241
1242    #[inline]
1243    pub fn color(mut self, color: Option<[u8; 3]>) -> Self {
1244        self.color = color;
1245        self
1246    }
1247
1248    #[inline]
1249    pub fn alpha(mut self, alpha: Option<u8>) -> Self {
1250        self.alpha = alpha;
1251        self
1252    }
1253
1254    #[inline]
1255    pub fn background_color(mut self, background_color: Option<[u8; 3]>) -> Self {
1256        self.background_color = background_color;
1257        self
1258    }
1259
1260    #[inline]
1261    pub fn background_alpha(mut self, background_alpha: Option<u8>) -> Self {
1262        self.background_alpha = background_alpha;
1263        self
1264    }
1265
1266    #[inline]
1267    pub fn background_rounding(mut self, background_rounding: Option<f32>) -> Self {
1268        self.background_rounding = background_rounding;
1269        self
1270    }
1271
1272    #[inline]
1273    pub fn font(mut self, font: Option<String>) -> Self {
1274        self.font = font;
1275        self
1276    }
1277
1278    #[inline]
1279    pub fn selectable(mut self, selectable: Option<bool>) -> Self {
1280        self.selectable = selectable;
1281        self
1282    }
1283
1284    #[inline]
1285    pub fn hyperlink_text(
1286        mut self,
1287        hyperlink_text: Option<Vec<(String, HyperlinkSelectMethod)>>,
1288    ) -> Self {
1289        self.hyperlink_text = hyperlink_text;
1290        self
1291    }
1292
1293    #[inline]
1294    pub fn auto_fit(mut self, auto_fit: Option<[bool; 2]>) -> Self {
1295        self.auto_fit = auto_fit;
1296        self
1297    }
1298
1299    #[inline]
1300    pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
1301        self.tags = tags;
1302        self
1303    }
1304}
1305
1306/// Text resource for displaying and interacting with textual content.
1307///
1308/// 用于显示和交互文本内容的文本资源。
1309#[derive(Debug, Clone, PartialEq, PartialOrd)]
1310pub struct Text {
1311    /// Config for basic front resource properties.
1312    ///
1313    /// 基本前端资源属性配置。
1314    pub basic_front_resource_config: BasicFrontResourceConfig,
1315
1316    /// Current display position of the text as [x, y].
1317    ///
1318    /// 文本的当前显示位置,坐标为[x, y]。
1319    pub position: [f32; 2],
1320
1321    /// Current display size of the text as [width, height].
1322    ///
1323    /// 文本的当前显示尺寸,为[width, height]。
1324    pub size: [f32; 2],
1325
1326    /// Display info controlling visibility and rendering.
1327    ///
1328    /// 显示信息,控制可见性和渲染。
1329    pub display_info: DisplayInfo,
1330
1331    /// Text content to be displayed.
1332    ///
1333    /// 要显示的文本内容。
1334    pub content: String,
1335
1336    /// Font size in points.
1337    ///
1338    /// 字体大小(点)。
1339    pub font_size: f32,
1340
1341    /// Text color as [R, G, B].
1342    ///
1343    /// 文本颜色,格式为[R, G, B]。
1344    pub color: [u8; 3],
1345
1346    /// Opacity of the text (0-255).
1347    ///
1348    /// 文本的不透明度(0-255)。
1349    pub alpha: u8,
1350
1351    /// Background color behind the text as [R, G, B].
1352    ///
1353    /// 文本背后的背景颜色,格式为[R, G, B]。
1354    pub background_color: [u8; 3],
1355
1356    /// Opacity of the background (0-255).
1357    ///
1358    /// 背景的不透明度(0-255)。
1359    pub background_alpha: u8,
1360
1361    /// Radius for rounded corners of the background.
1362    ///
1363    /// 背景圆角半径。
1364    pub background_rounding: f32,
1365
1366    /// The font used for the specified text.
1367    ///
1368    /// 指定文本使用的字体。
1369    pub font: String,
1370
1371    /// Whether the text can be selected by the user.
1372    ///
1373    /// 文本是否可以被用户选择。
1374    pub selectable: bool,
1375
1376    /// Hyperlink texts with their selection methods for clickable regions.
1377    ///
1378    /// 可点击区域的超链接文本及其选择方法。
1379    pub hyperlink_text: Vec<(String, HyperlinkSelectMethod)>,
1380
1381    /// Hyperlink indices and URLs: (start_index, end_index, url).
1382    ///
1383    /// 超链接索引值和链接:(起始索引, 结束索引, 链接)。
1384    pub hyperlink_index: Vec<(usize, usize, String)>,
1385
1386    /// Auto-fit behavior: [horizontal_fit, vertical_fit].
1387    ///
1388    /// 是否让渲染层大小自动匹配实际大小:[水平适应, 垂直适应]。
1389    pub auto_fit: [bool; 2],
1390
1391    /// Text content from the previous frame for change detection.
1392    ///
1393    /// 上一帧的文本内容,用于变化检测。
1394    pub last_frame_content: String,
1395
1396    /// Currently selected text range (start_index, end_index).
1397    ///
1398    /// 框选选中的文本范围(起始索引, 结束索引)。
1399    pub selection: Option<(usize, usize)>,
1400
1401    /// Size at which text is truncated for display.
1402    ///
1403    /// 文本被截断以供显示的尺寸。
1404    pub truncate_size: [f32; 2],
1405
1406    /// Actual size of the text content.
1407    ///
1408    /// 文本内容的实际尺寸。
1409    pub actual_size: [f32; 2],
1410
1411    /// Key-value pairs for categorization and metadata.
1412    ///
1413    /// 用于分类和元数据的键值对标签。
1414    pub tags: Vec<[String; 2]>,
1415}
1416
1417impl RustConstructorResource for Text {
1418    fn as_any(&self) -> &dyn Any {
1419        self
1420    }
1421
1422    fn as_any_mut(&mut self) -> &mut dyn Any {
1423        self
1424    }
1425
1426    fn display_display_info(&self) -> Option<DisplayInfo> {
1427        Some(self.display_info)
1428    }
1429
1430    fn modify_display_info(&mut self, display_info: DisplayInfo) {
1431        self.display_info = display_info;
1432    }
1433
1434    fn display_tags(&self) -> Vec<[String; 2]> {
1435        self.tags.clone()
1436    }
1437
1438    fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
1439        if replace {
1440            self.tags = tags.to_owned();
1441        } else {
1442            for tag in tags {
1443                if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
1444                    self.tags.remove(index);
1445                };
1446            }
1447            self.tags.extend(tags.iter().cloned());
1448        };
1449    }
1450}
1451
1452impl BasicFrontResource for Text {
1453    fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
1454        self.basic_front_resource_config.clone()
1455    }
1456
1457    fn display_position_size_config(&self) -> PositionSizeConfig {
1458        self.basic_front_resource_config.position_size_config
1459    }
1460
1461    fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
1462        self.basic_front_resource_config.clip_rect
1463    }
1464
1465    fn display_position(&self) -> [f32; 2] {
1466        self.position
1467    }
1468
1469    fn display_size(&self) -> [f32; 2] {
1470        self.size
1471    }
1472
1473    fn modify_basic_front_resource_config(
1474        &mut self,
1475        basic_front_resource_config: BasicFrontResourceConfig,
1476    ) {
1477        self.basic_front_resource_config = basic_front_resource_config;
1478    }
1479
1480    fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
1481        self.basic_front_resource_config.position_size_config = position_size_config;
1482    }
1483
1484    fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
1485        self.basic_front_resource_config.clip_rect = clip_rect;
1486    }
1487}
1488
1489impl Default for Text {
1490    fn default() -> Self {
1491        Self {
1492            basic_front_resource_config: BasicFrontResourceConfig::default(),
1493            position: [0_f32, 0_f32],
1494            size: [0_f32, 0_f32],
1495            display_info: DisplayInfo::default(),
1496            content: String::from("Hello world"),
1497            font_size: 16_f32,
1498            color: [255, 255, 255],
1499            alpha: 255,
1500            background_color: [0, 0, 0],
1501            background_alpha: 0,
1502            background_rounding: 2_f32,
1503            font: String::new(),
1504            selectable: true,
1505            auto_fit: [true, true],
1506            hyperlink_text: Vec::new(),
1507            hyperlink_index: Vec::new(),
1508            last_frame_content: String::from(""),
1509            selection: None,
1510            truncate_size: [0_f32, 0_f32],
1511            actual_size: [0_f32, 0_f32],
1512            tags: Vec::new(),
1513        }
1514    }
1515}
1516
1517impl Text {
1518    pub fn from_config(mut self, config: &TextConfig) -> Self {
1519        if let Some(position_size_config) = config.position_size_config {
1520            self.basic_front_resource_config.position_size_config = position_size_config;
1521        };
1522        if let Some(clip_rect) = config.clip_rect {
1523            self.basic_front_resource_config.clip_rect = clip_rect;
1524        };
1525        if let Some(hidden) = config.hidden {
1526            self.display_info.hidden = hidden;
1527        };
1528        if let Some(ignore_render_layer) = config.ignore_render_layer {
1529            self.display_info.ignore_render_layer = ignore_render_layer;
1530        };
1531        if let Some(content) = config.content.clone() {
1532            self.content = content;
1533        };
1534        if let Some(font_size) = config.font_size {
1535            self.font_size = font_size;
1536        };
1537        if let Some(color) = config.color {
1538            self.color = color;
1539        };
1540        if let Some(alpha) = config.alpha {
1541            self.alpha = alpha;
1542        };
1543        if let Some(background_color) = config.background_color {
1544            self.background_color = background_color;
1545        };
1546        if let Some(background_alpha) = config.background_alpha {
1547            self.background_alpha = background_alpha;
1548        };
1549        if let Some(background_rounding) = config.background_rounding {
1550            self.background_rounding = background_rounding;
1551        };
1552        if let Some(font) = config.font.clone() {
1553            self.font = font;
1554        };
1555        if let Some(selectable) = config.selectable {
1556            self.selectable = selectable;
1557        };
1558        if let Some(hyperlink_text) = config.hyperlink_text.clone() {
1559            self.hyperlink_text = hyperlink_text;
1560        };
1561        if let Some(auto_fit) = config.auto_fit {
1562            self.auto_fit = auto_fit;
1563        };
1564        if let Some(tags) = config.tags.clone() {
1565            self.tags = tags;
1566        };
1567        self
1568    }
1569
1570    #[inline]
1571    pub fn basic_front_resource_config(
1572        mut self,
1573        basic_front_resource_config: &BasicFrontResourceConfig,
1574    ) -> Self {
1575        self.basic_front_resource_config = basic_front_resource_config.clone();
1576        self
1577    }
1578
1579    #[inline]
1580    pub fn hidden(mut self, hidden: bool) -> Self {
1581        self.display_info.hidden = hidden;
1582        self
1583    }
1584
1585    #[inline]
1586    pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
1587        self.display_info.ignore_render_layer = ignore_render_layer;
1588        self
1589    }
1590
1591    #[inline]
1592    pub fn content(mut self, content: &str) -> Self {
1593        self.content = content.to_string();
1594        self
1595    }
1596
1597    #[inline]
1598    pub fn font_size(mut self, font_size: f32) -> Self {
1599        self.font_size = font_size;
1600        self
1601    }
1602
1603    #[inline]
1604    pub fn color(mut self, r: u8, g: u8, b: u8) -> Self {
1605        self.color = [r, g, b];
1606        self
1607    }
1608
1609    #[inline]
1610    pub fn alpha(mut self, alpha: u8) -> Self {
1611        self.alpha = alpha;
1612        self
1613    }
1614
1615    #[inline]
1616    pub fn background_color(mut self, r: u8, g: u8, b: u8) -> Self {
1617        self.background_color = [r, g, b];
1618        self
1619    }
1620
1621    #[inline]
1622    pub fn background_alpha(mut self, alpha: u8) -> Self {
1623        self.background_alpha = alpha;
1624        self
1625    }
1626
1627    #[inline]
1628    pub fn background_rounding(mut self, background_rounding: f32) -> Self {
1629        self.background_rounding = background_rounding;
1630        self
1631    }
1632
1633    #[inline]
1634    pub fn font(mut self, font: &str) -> Self {
1635        self.font = font.to_string();
1636        self
1637    }
1638
1639    #[inline]
1640    pub fn selectable(mut self, selectable: bool) -> Self {
1641        self.selectable = selectable;
1642        self
1643    }
1644
1645    #[inline]
1646    pub fn push_hyperlink_text(
1647        mut self,
1648        target_text: &str,
1649        select_method: HyperlinkSelectMethod,
1650    ) -> Self {
1651        self.hyperlink_text
1652            .push((target_text.to_string(), select_method));
1653        self
1654    }
1655
1656    #[inline]
1657    pub fn hyperlink_text(mut self, hyperlink_text: Vec<(String, HyperlinkSelectMethod)>) -> Self {
1658        self.hyperlink_text = hyperlink_text;
1659        self
1660    }
1661
1662    #[inline]
1663    pub fn auto_fit(mut self, x: bool, y: bool) -> Self {
1664        self.auto_fit = [x, y];
1665        self
1666    }
1667
1668    #[inline]
1669    pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
1670        if replace {
1671            self.tags = tags.to_owned();
1672        } else {
1673            for tag in tags {
1674                if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
1675                    self.tags.remove(index);
1676                };
1677            }
1678            self.tags.extend(tags.iter().cloned());
1679        };
1680        self
1681    }
1682}