Skip to main content

ListItem

Struct ListItem 

Source
pub struct ListItem<'a> { /* private fields */ }
Expand description

Individual item in a Material Design list.

List items can contain primary text, secondary text, overline text, leading and trailing icons, and custom actions.

§Example

let item = ListItem::new("Primary Text")
    .secondary_text("Secondary supporting text")
    .leading_icon("person")
    .trailing_icon("more_vert")
    .on_click(|| println!("Item clicked"));

Implementations§

Source§

impl<'a> ListItem<'a>

Source

pub fn new(primary_text: impl Into<String>) -> Self

Create a new list item with primary text.

§Arguments
  • primary_text - The main text to display
§Example
let item = ListItem::new("My List Item");
Source

pub fn secondary_text(self, text: impl Into<String>) -> Self

Set the secondary text for the item.

Secondary text is displayed below the primary text.

§Arguments
  • text - The secondary text to display
§Example
let item = ListItem::new("Item")
    .secondary_text("This is some secondary text");
Source

pub fn overline(self, text: impl Into<String>) -> Self

Set the overline text for the item.

Overline text is displayed above the primary text.

§Arguments
  • text - The overline text to display
§Example
let item = ListItem::new("Item")
    .overline("Important")
    .secondary_text("This is some secondary text");
Source

pub fn leading_icon(self, icon: impl Into<String>) -> Self

Set a leading icon for the item.

A leading icon is displayed at the start of the item, before the text.

§Arguments
  • icon - The name of the icon to display
§Example
let item = ListItem::new("Item")
    .leading_icon("check");
Source

pub fn trailing_icon(self, icon: impl Into<String>) -> Self

Set a trailing icon for the item.

A trailing icon is displayed at the end of the item, after the text.

§Arguments
  • icon - The name of the icon to display
§Example
let item = ListItem::new("Item")
    .trailing_icon("more_vert");
Source

pub fn trailing_text(self, text: impl Into<String>) -> Self

Set trailing text for the item.

Trailing text is displayed at the end of the item, after the icons.

§Arguments
  • text - The trailing text to display
§Example
let item = ListItem::new("Item")
    .trailing_text("99+");
Source

pub fn enabled(self, enabled: bool) -> Self

Enable or disable the item.

Disabled items are not interactive and are typically displayed with reduced opacity.

§Arguments
  • enabled - Whether the item should be enabled
§Example
let item = ListItem::new("Item")
    .enabled(false); // This item is disabled
Source

pub fn selected(self, selected: bool) -> Self

Set the selected state of the item.

Selected items are highlighted with a different background color and may use different text/icon colors.

§Arguments
  • selected - Whether the item should appear selected
§Example
let item = ListItem::new("Item")
    .selected(true); // This item appears selected
Source

pub fn dense(self, dense: bool) -> Self

Set whether this list tile is part of a vertically dense list.

Dense list tiles default to a smaller height.

§Arguments
  • dense - Whether to use dense layout
§Example
let item = ListItem::new("Item")
    .dense(true); // Compact layout
Source

pub fn is_three_line(self, is_three_line: bool) -> Self

Set whether this list tile is intended to display three lines of text.

§Arguments
  • is_three_line - Whether to use three-line layout
§Example
let item = ListItem::new("Item")
    .is_three_line(true);
Source

pub fn visual_density(self, density: VisualDensity) -> Self

Set the visual density for compact/comfortable/spacious layouts.

§Arguments
  • density - The visual density to apply
§Example
let item = ListItem::new("Item")
    .visual_density(VisualDensity::COMPACT);
Source

pub fn style(self, style: ListTileStyle) -> Self

Set the title style (List or Drawer).

§Arguments
  • style - The list tile style
§Example
let item = ListItem::new("Item")
    .style(ListTileStyle::Drawer);
Source

pub fn title_alignment(self, alignment: ListTileTitleAlignment) -> Self

Set how leading and trailing widgets are vertically aligned.

§Arguments
  • alignment - The title alignment mode
§Example
let item = ListItem::new("Item")
    .title_alignment(ListTileTitleAlignment::Center);
Source

pub fn horizontal_title_gap(self, gap: f32) -> Self

Set the horizontal gap between titles and leading/trailing widgets.

§Arguments
  • gap - The gap in pixels
§Example
let item = ListItem::new("Item")
    .horizontal_title_gap(20.0);
Source

pub fn min_vertical_padding(self, padding: f32) -> Self

Set the minimum padding on top and bottom of title/subtitle.

§Arguments
  • padding - The minimum vertical padding in pixels
§Example
let item = ListItem::new("Item")
    .min_vertical_padding(8.0);
Source

pub fn min_leading_width(self, width: f32) -> Self

Set the minimum width allocated for the leading widget.

§Arguments
  • width - The minimum leading width in pixels
§Example
let item = ListItem::new("Item")
    .min_leading_width(48.0);
Source

pub fn min_tile_height(self, height: f32) -> Self

Set the minimum height allocated for the list tile.

§Arguments
  • height - The minimum tile height in pixels
§Example
let item = ListItem::new("Item")
    .min_tile_height(64.0);
Source

pub fn tile_color(self, color: Color32) -> Self

Set the background color when not selected.

§Arguments
  • color - The tile background color
§Example
let item = ListItem::new("Item")
    .tile_color(Color32::from_rgb(240, 240, 240));
Source

pub fn selected_tile_color(self, color: Color32) -> Self

Set the background color when selected.

§Arguments
  • color - The selected tile background color
§Example
let item = ListItem::new("Item")
    .selected_tile_color(Color32::from_rgb(200, 230, 255));
Source

pub fn selected_color(self, color: Color32) -> Self

Set the color for icons and text when selected.

§Arguments
  • color - The selected content color
§Example
let item = ListItem::new("Item")
    .selected_color(Color32::from_rgb(0, 100, 200));
Source

pub fn icon_color(self, color: Color32) -> Self

Set the default color for leading and trailing icons.

§Arguments
  • color - The icon color
§Example
let item = ListItem::new("Item")
    .icon_color(Color32::from_rgb(100, 100, 100));
Source

pub fn text_color(self, color: Color32) -> Self

Set the text color for title, subtitle, leading, and trailing.

§Arguments
  • color - The text color
§Example
let item = ListItem::new("Item")
    .text_color(Color32::from_rgb(0, 0, 0));
Source

pub fn on_click<F>(self, f: F) -> Self
where F: Fn() + 'a,

Set a click action for the item.

§Arguments
  • f - A function to call when the item is clicked
§Example
let item = ListItem::new("Item")
    .on_click(|| {
        println!("Item was clicked!");
    });

Auto Trait Implementations§

§

impl<'a> Freeze for ListItem<'a>

§

impl<'a> !RefUnwindSafe for ListItem<'a>

§

impl<'a> !Send for ListItem<'a>

§

impl<'a> !Sync for ListItem<'a>

§

impl<'a> Unpin for ListItem<'a>

§

impl<'a> UnsafeUnpin for ListItem<'a>

§

impl<'a> !UnwindSafe for ListItem<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more