1 module soundtab.ui.slidercontroller; 2 3 import dlangui.widgets.widget; 4 import dlangui.widgets.layouts; 5 import dlangui.widgets.controls; 6 import dlangui.widgets.scrollbar; 7 import dlangui.widgets.groupbox; 8 import dlangui.core.signals; 9 import std.conv : to; 10 11 import soundtab.audio.instruments; 12 13 interface SliderControllerHandler { 14 void onController(SliderController source, int value); 15 } 16 17 //version = SLIDER_CONTROLLER_GROUPBOX; 18 version = SLIDER_CONTROLLER_VERTICAL_LAYOUT; 19 version (SLIDER_CONTROLLER_GROUPBOX) { 20 alias SliderControllerBase = GroupBox; 21 } else { 22 alias SliderControllerBase = VerticalLayout; 23 } 24 25 class SliderController : SliderControllerBase { 26 Signal!SliderControllerHandler onChange; 27 private SliderWidget _slider; 28 private ControllerId _controllerId; 29 version(SLIDER_CONTROLLER_VERTICAL_LAYOUT) { 30 TextWidget _label; 31 } 32 33 @property ControllerId controllerId() { return _controllerId; } 34 35 this(ControllerId ID, dstring label, int minValue, int maxValue, int value) { 36 version(SLIDER_CONTROLLER_VERTICAL_LAYOUT) { 37 super(to!string(ID)); 38 _label = new TextWidget(null, label); 39 addChild(_label); 40 margins = Rect(5, 0, 5, 0).pointsToPixels; 41 padding = Rect(5, 0, 5, 0).pointsToPixels; 42 } else { 43 super(to!string(ID), label); 44 } 45 minWidth = 100.pointsToPixels; 46 _controllerId = ID; 47 _slider = new SliderWidget(null, Orientation.Horizontal); 48 _slider.setRange(minValue, maxValue); 49 _slider.position = value; 50 _slider.scrollEvent = &onScrollEvent; 51 addChild(_slider); 52 } 53 54 @property int value() { return _slider.position; } 55 @property SliderController value(int newValue) { _slider.position = newValue; return this; } 56 57 protected bool onScrollEvent(AbstractSlider source, ScrollEvent event) { 58 if (onChange.assigned) 59 onChange(this, event.position); 60 return true; 61 } 62 }