自定义绘制
由 App::paint 用 cpui_render::Frame 直接绘制的区域。区域需要完整的绘制接口,或者内容很多时使用。绘制时会把 tag 传回来,用来区分各个区域。
ui.custom基本用法
// `App::paint` gets the tag back and draws into the area.ui.custom(CUSTOM_TAG, 400, 24, CustomOptions::new());动画:波形
// `App::paint` draws 200 bars straight into the frame; none of them is a widget.self.ink = ui.theme().accent;ui.custom(WAVE_TAG, 400, 56, CustomOptions::new());let now = ui.elapsed().as_secs_f32();if self.wave_playing { // The wave moves with the clock, and asks for the next frame only while playing. self.wave_time += now - self.wave_seen; ui.request_repaint();}self.wave_seen = now;let label = if self.wave_playing { "Pause" } else { "Play" };if ui.button(label).small().clicked() { self.wave_playing = !self.wave_playing;}只在数据变化时重绘
// With a revision, the area is repainted only when the number changes.let options = CustomOptions::new().revision(self.cells_version);ui.custom(CELLS_TAG, 400, 64, options);if ui.button("Shuffle").small().clicked() { self.cells_version += 1;}