From 64a74bb2770a5dbd18cc1a18d39de1f043c75b2a Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 10 Oct 2016 14:10:46 +0300 Subject: [PATCH] fix theme; fix slider style --- examples/example1/src/example1.d | 4 ++-- src/dlangui/widgets/controls.d | 25 ++++++++++++++++++++++--- src/dlangui/widgets/styles.d | 4 ++-- views/res/slider_background.9.png | Bin 0 -> 245 bytes views/res/theme_default.xml | 4 ++++ views/standard_resources.list | 1 + 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 views/res/slider_background.9.png diff --git a/examples/example1/src/example1.d b/examples/example1/src/example1.d index 42dd6944..22ed6a74 100644 --- a/examples/example1/src/example1.d +++ b/examples/example1/src/example1.d @@ -452,10 +452,10 @@ extern (C) int UIAppMain(string[] args) { HorizontalLayout line2 = new HorizontalLayout(); controls.addChild(line2); - GroupBox gb5 = new GroupBox("scrollbar", "horizontal ScrollBar"d, Orientation.Horizontal); + GroupBox gb5 = new GroupBox("scrollbar", "horizontal ScrollBar"d); gb5.addChild(new ScrollBar("sb1", Orientation.Horizontal).layoutWidth(FILL_PARENT)); line2.addChild(gb5); - GroupBox gb6 = new GroupBox("scrollbar", "horizontal SliderWidget"d, Orientation.Horizontal); + GroupBox gb6 = new GroupBox("scrollbar", "horizontal SliderWidget"d); gb6.addChild(new SliderWidget("sb2", Orientation.Horizontal).layoutWidth(FILL_PARENT)); line2.addChild(gb6); diff --git a/src/dlangui/widgets/controls.d b/src/dlangui/widgets/controls.d index 09e22275..bdd13d0a 100644 --- a/src/dlangui/widgets/controls.d +++ b/src/dlangui/widgets/controls.d @@ -1319,8 +1319,9 @@ class SliderWidget : AbstractSlider, OnClickHandler { /// create with ID parameter this(string ID, Orientation orient = Orientation.Horizontal) { super(ID); - styleId = STYLE_SCROLLBAR; + styleId = STYLE_SLIDER; _orientation = orient; + _pageSize = 1; _pageUp = new PageScrollButton("PAGE_UP"); _pageDown = new PageScrollButton("PAGE_DOWN"); _indicator = new SliderButton(style.customDrawableId(_orientation == Orientation.Vertical ? ATTR_SCROLLBAR_INDICATOR_VERTICAL : ATTR_SCROLLBAR_INDICATOR_HORIZONTAL)); @@ -1498,11 +1499,29 @@ class SliderWidget : AbstractSlider, OnClickHandler { override void onDraw(DrawBuf buf) { if (visibility != Visibility.Visible && !buf.isClippedOut(_pos)) return; - super.onDraw(buf); Rect rc = _pos; applyMargins(rc); - applyPadding(rc); auto saver = ClipRectSaver(buf, rc, alpha); + DrawableRef bg = backgroundDrawable; + if (!bg.isNull) { + Rect r = rc; + if (_orientation == Orientation.Vertical) { + int dw = bg.width; + r.left += (rc.width - dw)/2; + r.right = left + dw; + } else { + int dw = bg.height; + r.top += (rc.height - dw)/2; + r.bottom = top + dw; + } + bg.drawTo(buf, r, state); + } + applyPadding(rc); + if (state & State.Focused) { + rc.expand(FOCUS_RECT_PADDING, FOCUS_RECT_PADDING); + drawFocusRect(buf, rc); + } + _needDraw = false; _pageUp.onDraw(buf); _pageDown.onDraw(buf); _indicator.onDraw(buf); diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index 53b3012e..c9639617 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -71,14 +71,14 @@ immutable string STYLE_HSPACER = "HSPACER"; immutable string STYLE_VSPACER = "VSPACER"; /// standard style id for ScrollBar immutable string STYLE_SCROLLBAR = "SCROLLBAR"; +/// standard style id for SliderWidget +immutable string STYLE_SLIDER = "SLIDER"; /// standard style id for ScrollBar button immutable string STYLE_SCROLLBAR_BUTTON = "SCROLLBAR_BUTTON"; /// standard style id for ScrollBar button immutable string STYLE_SCROLLBAR_BUTTON_TRANSPARENT = "SCROLLBAR_BUTTON_TRANSPARENT"; /// standard style id for ScrollBar page control immutable string STYLE_PAGE_SCROLL = "PAGE_SCROLL"; -/// standard style id for Slider -immutable string STYLE_SLIDER = "SLIDER"; /// standard style id for TabWidget immutable string STYLE_TAB_WIDGET = "TAB_WIDGET"; /// standard style id for Tab with Up alignment diff --git a/views/res/slider_background.9.png b/views/res/slider_background.9.png new file mode 100644 index 0000000000000000000000000000000000000000..3e4cdfba3d2606f4a7c3256ca92baea3c955c6f5 GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsi;J66dPV+~#Xuq1%#er@=ltB<)VvZPmw~~#C^fMp zHASI3vm`^o-P1Q9MK6^dC?4tQ;uxZFe(NMht^*1@Eb5Prf9m|BAHMgOef7$a4U3$t zCpafeSM`1{x9WTY!;&dl(laDC>MotK^1|JdmdrM6456{hSokdzUHx3vIVCg!0JMEiF#rGn literal 0 HcmV?d00001 diff --git a/views/res/theme_default.xml b/views/res/theme_default.xml index 2a4f496a..b6ddc260 100644 --- a/views/res/theme_default.xml +++ b/views/res/theme_default.xml @@ -148,6 +148,10 @@ backgroundColor="#dce2e8" align="Center" /> +