On 29-03-2019 18:11, number wrote:

I'm trying to get a horizontal scale with

  • origin on the left
  • cursor keys left/right = decrease/increase
  • cursor keys up/down = increase/decrease (and the same for pageup/pagedown/end/home)

setInverted(true) doesn't help much because then I get the origin to the right. Would I have to intercept/override some key events to do this?

You can use the OnKeyPress event to change the way the buttons are handled.

import std.algorithm : max, min;

import gdk.Keysyms;
import gtk.Adjustment;
import gtk.Box;
import gtk.Main;
import gtk.MainWindow;
import gtk.Scale;

void main(string[] args)
{
	Main.init(args);

	MainWindow window = new MainWindow("title");
	window.setSizeRequest(400, 200);
	Box box = new Box(Orientation.VERTICAL, 5);
	{
		// ✓ origin left
		// ✓ left/right cursor keys
		// ✕ up/down cursor keys
		Scale scale1 = new Scale(GtkOrientation.HORIZONTAL, 0, 100, 10);
		scale1.addOnKeyPress((GdkEventKey* event, _){
			Adjustment a = scale1.getAdjustment();

			if (event.keyval == Keysyms.GDK_Up)
			{
				a.setValue(min(a.getUpper(), a.getValue() + a.getStepIncrement()));
				return true;
			}
			else if (event.keyval == Keysyms.GDK_Down)
			{
				a.setValue(max(a.getLower(), a.getValue() - a.getStepIncrement()));
				return true;
			}
			return false;
		});
		box.add(scale1);
	}
	window.add(box);

	window.showAll();
	Main.run();
}