feat(input): Ctrl restricts keyboard zoom to x, Alt to y
This commit is contained in:
1 parent
0ee6e10c81
commit
26a7c82a80
2 files changed
+41
-10
No files matched your search
+20
-10
@@ -323,17 +323,27 @@ void Controller::on_key(const KeyEvent& e) {
|
||||
if (zooms) {
|
||||
const f64 notches = e.key == kKeyZoomIn ? kKeyZoomNotches : -kKeyZoomNotches;
|
||||
const f64 factor = zoom_factor(notches);
|
||||
for (u32 i = 0; i < plot_->x_axis_count(); ++i) {
|
||||
const Axis& a = plot_->x_axis(i);
|
||||
const f64 lo = to_space(a.range.min, a.log);
|
||||
const f64 hi = to_space(a.range.max, a.log);
|
||||
zoom_x_axis(i, from_space(0.5 * (lo + hi), a.log), factor);
|
||||
// Ctrl restricts the zoom to x, Alt to y; bare +/- zooms both. (Shift cannot be
|
||||
// used: '+' is shift+'=' on common layouts, so key_from() folds them together and
|
||||
// a bare zoom-in already arrives with Mod::Shift set.) Ctrl+Alt zooms neither,
|
||||
// which is harmless and needs no special case.
|
||||
const bool only_x = has_mod(e.mods, Mod::Ctrl);
|
||||
const bool only_y = has_mod(e.mods, Mod::Alt);
|
||||
if (!only_y) {
|
||||
for (u32 i = 0; i < plot_->x_axis_count(); ++i) {
|
||||
const Axis& a = plot_->x_axis(i);
|
||||
const f64 lo = to_space(a.range.min, a.log);
|
||||
const f64 hi = to_space(a.range.max, a.log);
|
||||
zoom_x_axis(i, from_space(0.5 * (lo + hi), a.log), factor);
|
||||
}
|
||||
}
|
||||
for (u32 i = 0; i < plot_->y_axis_count(); ++i) {
|
||||
const Axis& a = plot_->y_axis(i);
|
||||
const f64 lo = to_space(a.range.min, a.log);
|
||||
const f64 hi = to_space(a.range.max, a.log);
|
||||
zoom_y_axis(i, from_space(0.5 * (lo + hi), a.log), factor);
|
||||
if (!only_x) {
|
||||
for (u32 i = 0; i < plot_->y_axis_count(); ++i) {
|
||||
const Axis& a = plot_->y_axis(i);
|
||||
const f64 lo = to_space(a.range.min, a.log);
|
||||
const f64 hi = to_space(a.range.max, a.log);
|
||||
zoom_y_axis(i, from_space(0.5 * (lo + hi), a.log), factor);
|
||||
}
|
||||
}
|
||||
} else if (fits) {
|
||||
plot_->auto_fit_x();
|
||||
|
||||
Reference in new issue
Block a user