Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protextinator"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
description = "Text management, made simple"
keywords = ["text", "rendering", "gui", "graphics", "image"]
Expand Down
14 changes: 7 additions & 7 deletions src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Rect {
/// assert_eq!(rect.height(), 50.0);
/// ```
#[inline(always)]
pub fn new(min: Point, max: Point) -> Self {
pub const fn new(min: Point, max: Point) -> Self {
Self { min, max }
}

Expand All @@ -47,7 +47,7 @@ impl Rect {
/// assert_eq!(rect.height(), 50.0);
/// ```
#[inline(always)]
pub fn height(&self) -> f32 {
pub const fn height(&self) -> f32 {
self.max.y - self.min.y
}

Expand All @@ -61,7 +61,7 @@ impl Rect {
/// assert_eq!(rect.width(), 100.0);
/// ```
#[inline(always)]
pub fn width(&self) -> f32 {
pub const fn width(&self) -> f32 {
self.max.x - self.min.x
}

Expand All @@ -75,7 +75,7 @@ impl Rect {
/// assert_eq!(rect.size(), (100.0, 50.0));
/// ```
#[inline(always)]
pub fn size(&self) -> (f32, f32) {
pub const fn size(&self) -> (f32, f32) {
(self.width(), self.height())
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ impl Point {
/// assert_eq!(point.x, 10.0);
/// assert_eq!(point.y, 20.0);
/// ```
pub fn new(x: f32, y: f32) -> Self {
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}

Expand All @@ -141,7 +141,7 @@ impl Point {
/// assert_eq!(point.to_tuple(), (10.0, 20.0));
/// ```
#[inline(always)]
pub fn to_tuple(self) -> (f32, f32) {
pub const fn to_tuple(self) -> (f32, f32) {
(self.x, self.y)
}

Expand All @@ -164,7 +164,7 @@ impl Point {
/// assert!(!p1.approx_eq(&p2, 0.0001));
/// ```
#[inline(always)]
pub fn approx_eq(&self, other: &Self, epsilon: f32) -> bool {
pub const fn approx_eq(&self, other: &Self, epsilon: f32) -> bool {
(self.x - other.x).abs() <= epsilon && (self.y - other.y).abs() <= epsilon
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Selection {
/// assert!(selection.is_empty());
/// ```
#[inline(always)]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.origin_character_byte_cursor.is_none()
|| self.ends_before_character_byte_cursor.is_none()
}
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<T> TextState<T> {
/// # let state = TextState::new_with_text("", &mut font_system, ());
/// let width = state.caret_width();
/// ```
pub fn caret_width(&self) -> f32 {
pub const fn caret_width(&self) -> f32 {
self.caret_width
}

Expand Down Expand Up @@ -454,7 +454,7 @@ impl<T> TextState<T> {
/// let inner_size = state.inner_size();
/// println!("Text content size: {}x{}", inner_size.x, inner_size.y);
/// ```
pub fn inner_size(&self) -> Size {
pub const fn inner_size(&self) -> Size {
self.inner_dimensions
}

Expand Down
46 changes: 23 additions & 23 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl FontSize {
/// let font_size = FontSize::new(16.0);
/// assert_eq!(font_size.value(), 16.0);
/// ```
pub fn new(size: f32) -> Self {
pub const fn new(size: f32) -> Self {
Self(size)
}

Expand All @@ -102,7 +102,7 @@ impl FontSize {
/// let font_size = FontSize::new(14.0);
/// assert_eq!(font_size.value(), 14.0);
/// ```
pub fn value(&self) -> f32 {
pub const fn value(&self) -> f32 {
self.0
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ impl FontColor {
///
/// let color = FontColor::new(Color::rgb(255, 0, 0));
/// ```
pub fn new(color: Color) -> Self {
pub const fn new(color: Color) -> Self {
Self(color)
}

Expand All @@ -199,7 +199,7 @@ impl FontColor {
/// let green = FontColor::rgb(0, 255, 0);
/// let blue = FontColor::rgb(0, 0, 255);
/// ```
pub fn rgb(r: u8, g: u8, b: u8) -> Self {
pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
Self(Color::rgb(r, g, b))
}

Expand All @@ -218,7 +218,7 @@ impl FontColor {
/// let semi_transparent_red = FontColor::rgba(255, 0, 0, 128);
/// let opaque_blue = FontColor::rgba(0, 0, 255, 255);
/// ```
pub fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
Self(Color::rgba(r, g, b, a))
}
}
Expand Down Expand Up @@ -295,7 +295,7 @@ impl FontFamily {
///
/// let sans_serif = FontFamily::sans_serif();
/// ```
pub fn sans_serif() -> Self {
pub const fn sans_serif() -> Self {
Self::SansSerif
}

Expand All @@ -307,7 +307,7 @@ impl FontFamily {
///
/// let serif = FontFamily::serif();
/// ```
pub fn serif() -> Self {
pub const fn serif() -> Self {
Self::Serif
}

Expand All @@ -319,7 +319,7 @@ impl FontFamily {
///
/// let monospace = FontFamily::monospace();
/// ```
pub fn monospace() -> Self {
pub const fn monospace() -> Self {
Self::Monospace
}

Expand Down Expand Up @@ -384,7 +384,7 @@ pub enum HorizontalTextAlignment {
}

impl HorizontalTextAlignment {
pub fn is_centered(&self) -> bool {
pub const fn is_centered(&self) -> bool {
matches!(self, HorizontalTextAlignment::Center)
}
}
Expand Down Expand Up @@ -476,10 +476,10 @@ impl TextStyle {
///
/// let style = TextStyle::new(14.0, Color::rgb(0, 0, 0));
/// ```
pub fn new(font_size: f32, font_color: Color) -> Self {
pub const fn new(font_size: f32, font_color: Color) -> Self {
Self {
font_size: font_size.into(),
line_height: LineHeight::default(),
font_size: FontSize(font_size),
line_height: LineHeight::DEFAULT,
font_color: FontColor(font_color),
horizontal_alignment: HorizontalTextAlignment::Start,
vertical_alignment: VerticalTextAlignment::Start,
Expand All @@ -499,8 +499,8 @@ impl TextStyle {
///
/// let style = TextStyle::default().with_font_size(18.0);
/// ```
pub fn with_font_size(mut self, font_size: f32) -> Self {
self.font_size = font_size.into();
pub const fn with_font_size(mut self, font_size: f32) -> Self {
self.font_size = FontSize(font_size);
self
}

Expand All @@ -515,8 +515,8 @@ impl TextStyle {
///
/// let style = TextStyle::default().with_line_height(1.2);
/// ```
pub fn with_line_height(mut self, line_height: f32) -> Self {
self.line_height = line_height.into();
pub const fn with_line_height(mut self, line_height: f32) -> Self {
self.line_height = LineHeight(line_height);
self
}

Expand All @@ -531,8 +531,8 @@ impl TextStyle {
///
/// let style = TextStyle::default().with_font_color(FontColor::rgb(255, 0, 0));
/// ```
pub fn with_font_color(mut self, font_color: impl Into<FontColor>) -> Self {
self.font_color = font_color.into();
pub const fn with_font_color(mut self, font_color: FontColor) -> Self {
self.font_color = font_color;
self
}

Expand All @@ -547,7 +547,7 @@ impl TextStyle {
///
/// let style = TextStyle::default().with_horizontal_alignment(HorizontalTextAlignment::Center);
/// ```
pub fn with_horizontal_alignment(mut self, alignment: HorizontalTextAlignment) -> Self {
pub const fn with_horizontal_alignment(mut self, alignment: HorizontalTextAlignment) -> Self {
self.horizontal_alignment = alignment;
self
}
Expand All @@ -563,7 +563,7 @@ impl TextStyle {
///
/// let style = TextStyle::default().with_vertical_alignment(VerticalTextAlignment::Center);
/// ```
pub fn with_vertical_alignment(mut self, alignment: VerticalTextAlignment) -> Self {
pub const fn with_vertical_alignment(mut self, alignment: VerticalTextAlignment) -> Self {
self.vertical_alignment = alignment;
self
}
Expand All @@ -583,7 +583,7 @@ impl TextStyle {
/// VerticalTextAlignment::Center
/// );
/// ```
pub fn with_alignment(
pub const fn with_alignment(
mut self,
horizontal: HorizontalTextAlignment,
vertical: VerticalTextAlignment,
Expand All @@ -604,7 +604,7 @@ impl TextStyle {
///
/// let style = TextStyle::default().with_wrap(TextWrap::Wrap);
/// ```
pub fn with_wrap(mut self, wrap: TextWrap) -> Self {
pub const fn with_wrap(mut self, wrap: TextWrap) -> Self {
self.wrap = Some(wrap);
self
}
Expand All @@ -622,7 +622,7 @@ impl TextStyle {
/// assert_eq!(style.line_height_pt(), 24.0); // 16.0 * 1.5
/// ```
#[inline(always)]
pub fn line_height_pt(&self) -> f32 {
pub const fn line_height_pt(&self) -> f32 {
self.line_height.0 * self.font_size.0
}
}
Loading