On Fri, 29 Mar 2019 17:11:25 GMT, number wrote:
I'm trying to get a horizontal scale with
Overriding the keypresses works:
import std.stdio;
import gtk.Main;
import gtk.MainWindow;
import gtk.Scale;
import gdk.Event;
import gdk.Keysyms;
import gtk.Widget;
import gtk.Range;
void main(string[] args)
{
Main.init(args);
MainWindow window = new MainWindow("title");
window.setSizeRequest(400, 200);
// ✓ origin left
// ✓ left/right cursor keys
// ✓ up/down cursor keys
Scale scale = new MyScale();
window.add(scale);
window.showAll();
Main.run();
}
class MyScale : Scale
{
this()
{
super(GtkOrientation.HORIZONTAL, 0, 100, 10);
addOnKeyPress(&onKeyPress);
}
bool onKeyPress(Event e, Widget w)
{
bool result = false;
Range r = cast(Range) w;
if (r)
{
switch (e.key.keyval)
{
default:
break;
case GdkKeysyms.GDK_Up:
r.setValue(r.getValue + r.getAdjustment.getStepIncrement);
result = true;
break;
case GdkKeysyms.GDK_Down:
r.setValue(r.getValue - r.getAdjustment.getStepIncrement);
result = true;
break;
case GdkKeysyms.GDK_Page_Up:
r.setValue(r.getValue + r.getAdjustment.getPageIncrement);
result = true;
break;
case GdkKeysyms.GDK_Page_Down:
r.setValue(r.getValue - r.getAdjustment.getPageIncrement);
result = true;
break;
}
}
return result;
}
}