Expand description
A curve editor: control points the user adds, moves and deletes,
through a spline the application supplies (Spline), over an
optional histogram, with the targeted adjustment of photo editors (a
value picked under the pointer in the image selects or adds the
point to drag).
Points are [x, y] in 0..1, sorted by x, at least two. The editor
owns no curve maths: Spline::eval draws the curve through them
(MonotoneCubic by default, Linear for straight segments).
Gestures:
- On a point: a press selects it, a drag moves it between its
neighbours (Ctrl finer, Shift coarser; Escape puts it back), a
double click or a right click deletes it (two points stay). The
editor claims the secondary click on its rect
(
egui_pop_core::pointer::claim): a context menu around it does not open there. - On the curve: a press adds a point there, and a drag moves it at once.
- Elsewhere: a double click puts the curve back to its default
(
CurveEditor::default_points, the identity unless given). - Keys when focused (
CurveKeys): Page Down and Page Up select the next and the previous point, the arrows move the selected one (Ctrl finer, Shift coarser), Insert adds a point halfway to the next one, Delete or Backspace deletes it, R resets the curve. - Pick (
CurveEditor::pick): the application passes the value under the pointer in the image; the editor marks it and highlights the nearest point; pressing selects that point, or adds one on the curve there, and the application’s vertical drag moves it.
Every change goes through the on_change
hook (Change of the whole list of points): a drag’s frames with
done: false, its end once more from the points before it with
done: true (a veto puts them back), and each key, addition,
deletion and reset. egui-pop-imaging runs the finished ones as the
curve.change step of an application.
Accessibility. The editor is an AccessKit slider named by its label, whose value says which point is selected and where; increment and decrement move that point’s output by a step, set-value sets it.
use egui_pop_viewport::curve::{CurveEditor, Pick, PickAction};
fn tone(ui: &mut egui::Ui, points: &mut Vec<[f32; 2]>, luma_bins: &[f32], under: Option<f32>) {
CurveEditor::new(points, "Tone curve")
.histogram(luma_bins)
.pick(under.map(|x| Pick { x, action: PickAction::Hover }))
.show(ui);
}Structs§
- Curve
Editor - The curve editor.
- Curve
Keys - The editor’s keys, as data so a profile can remap them
(
set_keys). - Curve
Output - What the editor did in a frame.
- Curve
Tokens - The curve editor’s colours, from the theme (
curve.*). - Linear
- Straight segments between the points, flat past the ends.
- Monotone
Cubic - A monotone cubic (Fritsch and Carlson): smooth, through every point, and never overshooting between two of them, so a rising set of points gives a rising curve. Flat past the ends.
- Pick
- A value picked under the pointer in the image (its input on the curve, 0..1) and what the pointer does.
Enums§
- Pick
Action - What the application does with the value picked in the image.
Constants§
- MIN_GAP
- The smallest distance kept between two points’ inputs.
- PICK_
TOLERANCE - How close a picked value must be to a point’s input to take it.
Traits§
- Spline
- The curve’s maths, supplied by the application.
Functions§
- identity
- The identity: output equals input.
- insert
- Inserts a point in order; its index, or
Nonewhen it is too close to another point’s input. - keys
- The curve editors’ keys in a context (the defaults until set).
- moved
- Point
imoved toto, kept inside 0..1 and between its neighbours’ inputs. - nearest
- The index of the point whose input is nearest
x, withintolerance. - set_
keys - Remaps the curve editors’ keys in a context (an input profile).