Skip to main content

Module binding

Module binding 

Source
Expand description

Three ways to bind a widget’s value (ADR 0009): plain &mut T as in egui, bound to a value store (writes with an origin, a drag is one gesture, listeners told), or watch-only.

use std::sync::{Arc, Mutex};
use egui_pop_core::binding::{self, Binding};
use egui_pop_model::ids::OwnerId;
use egui_pop_model::values::{Descriptor, Store};

let store = Arc::new(Mutex::new(Store::new()));
store.lock().unwrap()
    .declare(&OwnerId::FRAMEWORK, "settings/volume", Descriptor::float("Volume", 0.0, 1.0, 0.5))
    .unwrap();

fn draw(ui: &mut egui::Ui, store: &binding::SharedStore, local: &mut f64) {
    // As in egui:
    binding::edit(ui, Binding::plain(local), |ui, v| ui.add(egui::Slider::new(v, 0.0..=1.0)));
    // Bound to the store:
    binding::edit(ui, Binding::bound(store, "settings/volume"), |ui, v: &mut f64| {
        ui.add(egui::Slider::new(v, 0.0..=1.0))
    });
    // Shown, never written:
    binding::edit(ui, Binding::watch(store, "settings/volume"), |ui, v: &mut f64| {
        ui.add(egui::Slider::new(v, 0.0..=1.0))
    });
}

Structs§

Choice
One of a descriptor’s choices, as a widget edits it (a String would be written as free text).

Enums§

Binding
How a widget’s value is held.

Traits§

Bindable
A type a widget edits that the store can hold.

Functions§

cancel_gesture
Tells the binding around a widget that its gesture is given up (the widget has put its value back): bound to a store, the gesture’s writes are undone and leave no undo step.
edit
Draws a widget over a binding. widget edits a local copy; what changed goes back as the binding says.
read
Reads a path as a type.

Type Aliases§

SharedStore
A store shared between the application, its widgets and its commands.