Expand description
An alternative view widget.
The extra requirement for this one is that you can create a Layout that defines the bounds of all widgets that can be rendered.
It works in 4 phases:
use rat_focus::FocusFlag;
use rat_widget::layout::GenericLayout;
///
/// Create the layout. The layout can be stored long-term
/// and needs to be rebuilt only if your widget layout changes.
///
///> __Note__: add() returns a handle for the area. Can be used later
///> to refer to the stored area.
if state.clipper.layout.is_empty() {
let mut cl = GenericLayout::new();
for i in 0..100 {
cl.add(state.check_states[i].focus.clone(),
Rect::new(10, i as u16 *11, 15, 10),
None,
Rect::default()
);
}
}
/// The given area plus the current scroll offset define the
/// view area. With the view area a temporary buffer is created
/// that is big enough to fit all widgets that are at least
/// partially visible.
let clipper = Clipper::new();
let mut clip_buf = clipper
.into_buffer(l2[1], &mut state.clipper);
///
/// The widgets are rendered to that buffer.
///
for i in 0..100 {
// refer by handle
clip_buf.render(
state.check_states[i].focus.clone(),
|| {
Checkbox::new()
.text(format!("{:?}", i))
},
&mut state.check_states[i],
);
}
///
/// The last step clips and copies the buffer to the frame buffer.
///
clip_buf
.into_widget()
.render(l2[1], &mut buf, &mut state.clipper);
StatefulWidget
For this to work with StatefulWidgets they must cooperate by implementing the RelocatableState trait. With this trait the widget can clip/hide all areas that it stores in its state.
See
Structsยง
- Clipper styles.