Skip to content

Typed Rust Builders

If you prefer Rust methods and IDE autocomplete over utility class strings, every Tailwind CSS v4 utility and variant is also available as a typed method on IssStyle.

  • use iss::typed::*; imports IssStyle, style(), palette, IssColor, IssLength, TwExt, layout helpers, and tw!.
  • use iss::short::*; re-exports everything in iss::typed::* plus s() (shorthand for IssStyle::new()) and hex(0xRRGGBB).
use iced::widget::container;
use iss::{tw, TwExt};
let card = container(body).tw(tw!(
"w-full p-5 bg-zinc-900 border border-zinc-800 rounded-2xl shadow-lg dark:bg-zinc-950 hover:border-violet-500"
));
use iced::widget::text;
use iss::short::*;
let pill = text("Active").tw(
s().px(2.5)
.py(1)
.text_xs()
.font_semibold()
.text_color(hex(0xF5D0FE))
.bg(hex(0x7C3AED).alpha(0.24))
.rounded_full(),
);

Spacing and sizing methods follow Tailwind’s 1 unit = 4px scale via TwUnit, accepting integers and decimals (.p(4) = 16px, .py(1.5) = 6px). Append _px for exact pixels (.p_px(14), .w_px(280)).

State Builders, .mix(), and Mixing with tw!()

Section titled “State Builders, .mix(), and Mixing with tw!()”

Chain state closures (.hover(...), .focus(...), .active(...), .disabled(...), .dark(...)), compose styles with .mix(...), and freely mix typed builders with tw!() strings:

use iced::widget::{button, text};
use iss::typed::*;
let base = tw!("px-4 py-2 rounded-lg border border-zinc-700 cursor-pointer");
let interactive = IssStyle::new()
.bg(palette::VIOLET_600)
.hover(|s| s.bg(palette::VIOLET_500))
.focus(|s| s.border_color(palette::VIOLET_300))
.active(|s| s.bg(palette::VIOLET_700))
.dark(|s| s.border_color(palette::ZINC_600));
let save_btn = button(text("Save").tw(tw!("text-sm font-semibold text-white")))
.on_press(Message::Save)
.tw(base.mix(interactive));