iced_utils

Crates.ioiced_utils
lib.rsiced_utils
version0.1.0
created_at2025-10-14 01:26:33.522306+00
updated_at2025-10-14 01:26:33.522306+00
descriptionA collection of useful functions and macros for Iced
homepage
repositoryhttps://github.com/minty-sh/iced_utils
max_upload_size
id1881433
size23,506
minty (minty-sh)

documentation

README

iced_utils

iced_utils is a collection of:

  • utility wrappers
  • helper functions
  • macros designed to make common tasks and patterns simpler when building apps using iced.

This crate provides convenient abstractions over Iced's core functionalities, making development faster and more ergonomic.

Table of Contents

Features

Font builder

A builder for creating iced::Font instances with a fluent API. This simplifies the process of defining custom fonts by allowing you to chain method calls for family, weight, stretch, and style.

Use Case: Easily define a specific font for a text element without verbose iced::Font struct initialization.

Example:

use iced_utils::widget::font::FontBuilder;
use iced::font::{Family, Weight, Style};

let custom_font = FontBuilder::new()
    .family(Family::Name("Open Sans"))
    .weight(Weight::Bold)
    .style(Style::Italic)
    .build();

// Use custom_font in your Iced application
// text("Hello, Iced!").font(custom_font);

Font Styling Constants

The iced_utils::widget::font::style module provides convenient constants for common font styles and text colors.

Use Cases:

  • Quickly apply bold or italic styles to text.
  • Set common text colors (white, green, red) without re-defining iced::Color or iced::widget::text::Style.

Examples:

use iced_utils::widget::font::style;
use iced::widget::text;
use iced::Theme;

// Apply bold font
// text("Bold Text").font(style::BOLD);

// Apply italic font
// text("Italic Text").font(style::ITALIC);

// Apply white text color
let white_text_style = style::WHITE_TEXT(&Theme::Light);
// text("White Text").style(white_text_style);

// Apply green text color
let green_text_style = style::GREEN_TEXT(&Theme::Light);
// text("Green Text").style(green_text_style);

Simplified Input Field Handling

The input! macro simplifies handling message variants in your update function, especially for input-related messages.

It allows for:

  • unconditional assignment;
  • conditional assignment;
  • conditional assignment with an error handler.

Use Case: Simplify the match statement in your update function when processing messages that update specific fields (such as user input in text fields) in your application's state, often with validation logic.

Example

#[derive(Default)]
struct MyApp {
    value: String,
    full_name: String,
    age_val: i32,
    error_message: Option<String>,
}

#[derive(Debug, Clone)]
enum Message {
    SetValue(String),
    SetName(String),
    SetAge(i32),
}

impl MyApp {
    // in your update function...
    fn update(&mut self, message: Message) {
        match message {
            // performs no validation, just assigns self.value to v
            input!(Message::SetValue(v) => v, value),
            // only if the condition is met, assigns the value to full_name
            input!(Message::SetName(name) => name, full_name, if !name.is_empty()),
            // runs Self::handle_invalid_age if the condition isn't met
            input!(Message::SetAge(age) => age, age_val, if age > 0, else Self::handle_invalid_age),
            _ => {} // Handle other messages
        }
    }
}

License

This project is licensed under the MIT License.

Commit count: 0

cargo fmt