iced icon indicating copy to clipboard operation
iced copied to clipboard

Introduce `text` macro

Open derezzedex opened this issue 11 months ago • 3 comments

This PR introduces a text macro in the widget::helpers module analogous to the std::format macro.

Implementation

This is a simple macro similar to the row and column helper macros, it uses format internally. The macro_rules definition:

#[macro_export]
macro_rules! text {
    ($($arg:tt)*) => {
        $crate::Text::new(format!($($arg)*))
    };
}

Usage

Since it uses the std::format macro internally, it's usage is analogous and should be familiar to most users, but some examples are documented in the macro definition:

use iced::Element;
use iced::widget::text;

fn view(&self) -> Element<Message> {
    let simple = text!("Hello, world!");

    let keyword = text!("Hello, {}", "world!");

    let planet = "Earth";
    let local_variable = text!("Hello, {planet}!");
    // ...
}

As a result, the text(format!( pattern has been replaced with the new text macro throughout the examples.

derezzedex avatar Mar 18 '24 23:03 derezzedex

It would be nice to be able to receive as a second parameter (optional) a custom style.

romancitodev avatar Mar 20 '24 00:03 romancitodev

It would be nice to be able to receive as a second parameter (optional) a custom style.

I don't think this would help much, have you seen #2312?

I would say that .style() or .color() express the styling intent much better than a second parameter on this macro.

derezzedex avatar Mar 25 '24 20:03 derezzedex

I would say that .style() or .color() express the styling intent much better than a second parameter on this macro.

Well, that's make more sense!

romancitodev avatar Mar 26 '24 02:03 romancitodev