diff --git a/source/fluid/slider.d b/source/fluid/slider.d index 9ac9c14..282d8d6 100644 --- a/source/fluid/slider.d +++ b/source/fluid/slider.d @@ -10,6 +10,7 @@ import fluid.backend; import fluid.structs; import fluid.io.hover; +import fluid.io.canvas; @safe: @@ -93,6 +94,7 @@ abstract class AbstractSlider : InputNode!Node { enum railWidth = 4; enum minStepDistance = 10; + CanvasIO canvasIO; HoverIO hoverIO; public { @@ -137,6 +139,7 @@ abstract class AbstractSlider : InputNode!Node { override void resizeImpl(Vector2 space) { + use(canvasIO); use(hoverIO); resizeChild(handle, space); @@ -157,7 +160,7 @@ abstract class AbstractSlider : InputNode!Node { _isPressed = checkIsPressed(); // Draw the rail - style.drawBackground(io, rail); + style.drawBackground(io, canvasIO, rail); const availableWidth = rail.width - handle.size.x; const handleOffset = availableWidth * index / (length - 1f); @@ -180,7 +183,7 @@ abstract class AbstractSlider : InputNode!Node { const start = Vector2(firstStepX + visualStepDistance * step, end(rail).y); const end = Vector2(start.x, end(outer).y); - style.drawLine(io, start, end); + style.drawLine(io, canvasIO, start, end); } @@ -296,6 +299,8 @@ class SliderRangeImpl(T) : SliderRange!(ElementType!T) { /// Defines the handle of a slider. class SliderHandle : Node { + CanvasIO canvasIO; + public { Vector2 size = Vector2(16, 20); @@ -310,13 +315,14 @@ class SliderHandle : Node { override void resizeImpl(Vector2 space) { + use(canvasIO); minSize = size; } override void drawImpl(Rectangle outer, Rectangle inner) { - style.drawBackground(io, outer); + style.drawBackground(io, canvasIO, outer); } diff --git a/tests/nodes/slider.d b/tests/nodes/slider.d index 59c4467..f78a989 100644 --- a/tests/nodes/slider.d +++ b/tests/nodes/slider.d @@ -6,6 +6,44 @@ import fluid; @safe: +@("Slider draws a rail and a handle") +unittest { + + auto input = slider!int( + .layout!"fill", + iota(1, 4) + ); + auto root = sizeLock!testSpace( + .sizeLimit(500, 200), + nullTheme.derive( + rule!AbstractSlider( + Rule.backgroundColor = color("#000"), + Rule.lineColor = color("#f00"), + ), + rule!SliderHandle( + Rule.backgroundColor = color("#0f0"), + ), + ), + input, + ); + + root.drawAndAssert( + + // Rail + input.drawsRectangle(0, 8, 500, 4).ofColor("#000"), + + // Marks + input.drawsLine().from( 8, 12).to( 8, 20).ofWidth(1).ofColor("#f00"), + input.drawsLine().from(250, 12).to(250, 20).ofWidth(1).ofColor("#f00"), + input.drawsLine().from(492, 12).to(492, 20).ofWidth(1).ofColor("#f00"), + + // Handle + input.handle.drawsRectangle(0, 0, 16, 20).ofColor("#0f0"), + + ); + +} + @("Slider can be changed with mouse movements") unittest {