Skip to content

Custom

An area that App::paint draws directly with a cpui_render::Frame. Use it when an area needs the full drawing API or has a lot of content. tag is passed back when painting to tell the areas apart.

ui.custom

Basic

// `App::paint` gets the tag back and draws into the area.
ui.custom(CUSTOM_TAG, 400, 24, CustomOptions::new());

Animated: a waveform

// `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;
}

Drawn again only when the data changes

// 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;
}