tui_widget_list

Trait PreRender

Source
pub trait PreRender: Widget {
    // Required method
    fn pre_render(&mut self, context: &PreRenderContext) -> u16;
}
👎Deprecated since 0.11.0: Use ListView with ListBuilder instead.
Expand description

This trait should be implemented for items that are intended to be used within a List widget.

Required Methods§

Source

fn pre_render(&mut self, context: &PreRenderContext) -> u16

👎Deprecated since 0.11.0: Use ListView with ListBuilder instead.

This method is called before rendering the widget.

§Arguments
  • self: Captured by value, allowing modification within the pre-render hook.
  • context: Rendering context providing additional information like selection status, cross-axis size, scroll direction and the widgets index in the list.
§Returns
  • The (modified) widget.
  • The widget’s main axis size, used for layouting.
§Example
ⓘ
 use ratatui::prelude::*;
 use tui_widget_list::{PreRenderContext, PreRender};

 impl PreRender for MyWidget {
     fn pre_render(self, context: &PreRenderContext) -> (Self, u16) {
         // Modify the widget based on the selection state
         if context.is_selected {
             self.style = self.style.reversed();
         }

         // Example: set main axis size to 1
         let main_axis_size = 1;

         (self, main_axis_size)
     }
 }

Implementors§