| Crates.io | iced_utils |
| lib.rs | iced_utils |
| version | 0.1.0 |
| created_at | 2025-10-14 01:26:33.522306+00 |
| updated_at | 2025-10-14 01:26:33.522306+00 |
| description | A collection of useful functions and macros for Iced |
| homepage | |
| repository | https://github.com/minty-sh/iced_utils |
| max_upload_size | |
| id | 1881433 |
| size | 23,506 |
iced_utils is a collection of:
This crate provides convenient abstractions over Iced's core functionalities, making development faster and more ergonomic.
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);
The iced_utils::widget::font::style module provides convenient constants for common font styles and text colors.
Use Cases:
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);
The input! macro simplifies handling message variants in your update function, especially for input-related messages.
It allows for:
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.
#[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
}
}
}
This project is licensed under the MIT License.