1 module ws.gui.sliderDecorated; 2 3 import 4 std.conv, 5 ws.event, 6 ws.string, 7 ws.gl.draw, 8 ws.gui.base, 9 ws.gui.inputField, 10 ws.gui.text, 11 ws.gui.slider; 12 13 14 class SliderDecorated: Base { 15 16 this(string t, float min = 0, float max = 1, float start = 0.5){ 17 style.bg = [0, 0, 0, 0.5]; 18 title = addNew!Text; 19 title.text = t; 20 title.moveLocal([0,0]); 21 input = addNew!InputField; 22 input.text = tostring(start); 23 input.onEnter ~= (line){ 24 if(!isNumeric(line)) 25 throw new InputException(input, "Not a number!"); 26 float d = to!float(line); 27 if(d < min || d > max) 28 throw new InputException(input, "Too " ~ (d<min ? " small" : " large")); 29 slider.setValue(d); 30 }; 31 slider = addNew!Slider; 32 slider.set(start, min, max); 33 slider.onSlide ~= (v){ 34 input.text = to!string(v); 35 }; 36 onSlide = slider.onSlide; 37 } 38 39 override void resize(int[2] size){ 40 41 //input.setFont("UbuntuMono-R", cast(int)(size.h/1.4)); 42 //title.setFont("UbuntuMono-R", cast(int)(size.h/1.4)); 43 44 int inputSize = size.h*5; 45 int divider = (size.w - inputSize)/2; 46 47 title.resize([divider, size.h]); 48 slider.moveLocal([divider, 0]); 49 slider.resize([divider, size.h]); 50 input.moveLocal([size.w-inputSize, 0]); 51 input.resize([inputSize, size.h]); 52 53 super.resize(size); 54 55 assert(0); 56 } 57 58 override void onDraw(){ 59 draw.setColor(style.bg.normal); 60 draw.rect(pos, size); 61 super.onDraw(); 62 } 63 64 Event!float onSlide; 65 66 protected { 67 Text title; 68 InputField input; 69 Slider slider; 70 } 71 72 } 73