Skip to Content
组件ScrollView

ScrollView

ScrollView 是“给单个 child 提供 viewport”的 widget。

ScrollView
ScrollView 终端效果图
ScrollView 的终端效果图

最小示例

let transcript = ScrollView::new() .offset(self.offset) .on_scroll(Message::ScrollTo) .layout(Layout { width: Length::Fill, height: Length::Fixed(4) }) .child(Paragraph::new(self.log.clone()).build()) .build();

什么时候用

  • 一个 child 可能比 viewport 更高
  • 滚动 offset 需要进 state 或 continuity contract
  • 你想和 Scrollbar 配合

常见组合

最常见的组合就是:

  • ScrollView 负责内容 viewport
  • Scrollbar 负责可视位置反馈
  • 二者共享同一个 offset 状态

去哪里看真实用法

Last updated on