From c6f3388e35403246fd5171d89e035e532c826e6c Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 29 Jul 2013 16:03:16 +0800 Subject: [PATCH] add missing scrollbar widget --- frontend/ui/widget/scrollbar.lua | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 frontend/ui/widget/scrollbar.lua diff --git a/frontend/ui/widget/scrollbar.lua b/frontend/ui/widget/scrollbar.lua new file mode 100644 index 000000000..3a3a1a553 --- /dev/null +++ b/frontend/ui/widget/scrollbar.lua @@ -0,0 +1,34 @@ + +VerticalScrollBar = Widget:new{ + enable = true, + low = 0, + high = 1, + + width = 6, + height = 50, + bordersize = 1, + bordercolor = 15, + radius = 0, + rectcolor = 15, +} + +function VerticalScrollBar:getSize() + return Geom:new{ + w = self.width, + h = self.height + } +end + +function VerticalScrollBar:set(low, high) + self.low = low > 0 and low or 0 + self.high = high < 1 and high or 1 +end + +function VerticalScrollBar:paintTo(bb, x, y) + if not self.enable then return end + bb:paintBorder(x, y, self.width, self.height, + self.bordersize, self.bordercolor, self.radius) + bb:paintRect(x + self.bordersize, y + self.bordersize + self.low*self.height, + self.width - 2*self.bordersize, + self.height * (self.high - self.low), self.rectcolor) +end