1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//! Utility functions for matrix_gui framework.
//!
//! This module provides common utility functions used throughout the framework
//! for creating and manipulating graphical elements.
//!
//! # Functions
//!
//! - [`make_rounded_rect`]: Creates a rounded rectangle with equal corner radii
//! - [`make_text`]: Creates a text element with specified styling
//! - [`text_align_translate`]: Aligns and positions text within a rectangle
//! - [`select`]: Selects one of two values based on a condition
//!
//! # Example
//!
//! ```ignore
//! use matrix_gui::prelude::*;
//! use embedded_graphics::primitives::Rectangle;
//!
//! // Create a rounded rectangle
//! let rect = Rectangle::new(Point::new(10, 10), Size::new(100, 50));
//! let rounded = matrix_utils::make_rounded_rect(&rect, 5);
//!
//! // Create and align text
//! let mut text = matrix_utils::make_text("Hello", font, Rgb565::WHITE);
//! matrix_utils::text_align_translate(&mut text, &rect, HorizontalAlign::Center);
//! ```
use crateHorizontalAlign;
use crate;
use *;
use RoundedRectangle;
use Baseline;
use ;
/// Creates a rounded rectangle with equal corner radii.
///
/// This is a convenience function for creating rounded rectangles where all
/// corners have the same radius.
///
/// # Arguments
///
/// * `area` - The rectangle defining the bounds of the rounded rectangle.
/// * `corner_radius` - The radius for all corners.
///
/// # Returns
///
/// A `RoundedRectangle` with equal corner radii.
///
/// # Example
///
/// ```rust
/// use matrix_gui::prelude::*;
/// use embedded_graphics::primitives::Rectangle;
///
/// let rect = Rectangle::new(Point::new(10, 10), Size::new(100, 50));
/// let rounded = matrix_utils::make_rounded_rect(&rect, 5);
/// ```
pub const
/// Creates a text element with specified styling.
///
/// This is a convenience function for creating text elements with a given
/// label, font, and color. The text is positioned at the origin (0, 0)
/// with top baseline alignment.
///
/// # Type Parameters
///
/// * `'a` - The lifetime of the label string.
/// * `COL` - The pixel color type implementing [`PixelColor`].
///
/// # Arguments
///
/// * `label` - The text string to display.
/// * `font` - The font to use for rendering.
/// * `text_color` - The color of the text.
///
/// # Returns
///
/// A `Text` element with the specified styling.
///
/// # Example
///
/// ```ignore
/// use matrix_gui::prelude::*;
///
/// let text = matrix_utils::make_text("Hello", my_font, Rgb565::WHITE);
/// ```
pub const
/// Aligns and positions text within a rectangle.
///
/// This function calculates the appropriate offset to center the text within
/// the rectangle based on the specified horizontal alignment. The text is
/// positioned at the top-left corner of the rectangle plus the calculated offset.
///
/// # Type Parameters
///
/// * `COL` - The pixel color type implementing [`PixelColor`].
///
/// # Arguments
///
/// * `text` - Mutable reference to the text element to align.
/// * `rect` - The rectangle to align the text within.
/// * `align` - The horizontal alignment strategy.
///
/// # Example
///
/// ```ignore
/// use matrix_gui::prelude::*;
///
/// let mut text = matrix_utils::make_text("Hello", font, Rgb565::WHITE);
/// let rect = Rectangle::new(Point::new(10, 10), Size::new(100, 50));
/// matrix_utils::text_align_translate(&mut text, &rect, HorizontalAlign::Center);
/// ```
/// Selects one of two values based on a condition.
///
/// This is a convenience function for conditional value selection, similar to
/// the ternary operator in other languages.
///
/// # Type Parameters
///
/// * `T` - The type of values to select from.
///
/// # Arguments
///
/// * `condition` - If `true`, returns `true_val`; otherwise returns `false_val`.
/// * `true_val` - The value to return if condition is `true`.
/// * `false_val` - The value to return if condition is `false`.
///
/// # Returns
///
/// `true_val` if `condition` is `true`, otherwise `false_val`.
///
/// # Example
///
/// ```rust
/// use matrix_gui::prelude::*;
///
/// let value = matrix_utils::select(true, 10, 20); // Returns 10
/// let value2 = matrix_utils::select(false, 10, 20); // Returns 20
/// ```