mirror of https://github.com/buggins/dlangui.git
Implement SwitchWidget - close issue #205
This commit is contained in:
parent
b0361baeb8
commit
aca556d794
|
@ -567,6 +567,11 @@ extern (C) int UIAppMain(string[] args) {
|
|||
buttons10.addChild(new TextWidget(null, "ImageTextButton widgets: "d));
|
||||
buttons10.addChild(new ImageTextButton("btn5", "text-plain", "Enabled"d));
|
||||
buttons10.addChild((new ImageTextButton("btn6", "folder", "Disabled"d)).enabled(false));
|
||||
buttons10.addChild(new TextWidget(null, "SwitchWidget widgets: "d));
|
||||
buttons10.addChild((new SwitchWidget("SW1")).checked(true));
|
||||
buttons10.addChild((new SwitchWidget("SW2")).checked(false));
|
||||
buttons10.addChild((new SwitchWidget("SW3")).checked(true).enabled(false));
|
||||
buttons10.addChild((new SwitchWidget("SW4")).checked(false).enabled(false));
|
||||
layout3.addChild(buttons10);
|
||||
|
||||
WidgetGroup buttons11 = new HorizontalLayout();
|
||||
|
|
|
@ -159,6 +159,49 @@ class MultilineTextWidget : TextWidget {
|
|||
}
|
||||
}
|
||||
|
||||
/// Switch (on/off) widget
|
||||
class SwitchWidget : Widget {
|
||||
this(string ID = null) {
|
||||
super(ID);
|
||||
styleId = STYLE_SWITCH;
|
||||
clickable = true;
|
||||
focusable = true;
|
||||
trackHover = true;
|
||||
}
|
||||
// called to process click and notify listeners
|
||||
override protected bool handleClick() {
|
||||
checked = !checked;
|
||||
return super.handleClick();
|
||||
}
|
||||
override void measure(int parentWidth, int parentHeight) {
|
||||
DrawableRef img = backgroundDrawable;
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
if (!img.isNull) {
|
||||
w = img.width;
|
||||
h = img.height;
|
||||
}
|
||||
measuredContent(parentWidth, parentHeight, w, h);
|
||||
}
|
||||
|
||||
override void onDraw(DrawBuf buf) {
|
||||
if (visibility != Visibility.Visible)
|
||||
return;
|
||||
Rect rc = _pos;
|
||||
applyMargins(rc);
|
||||
auto saver = ClipRectSaver(buf, rc, alpha);
|
||||
DrawableRef img = backgroundDrawable;
|
||||
if (!img.isNull) {
|
||||
Point sz;
|
||||
sz.x = img.width;
|
||||
sz.y = img.height;
|
||||
applyAlign(rc, sz);
|
||||
uint st = state;
|
||||
img.drawTo(buf, rc, st);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// static image widget
|
||||
class ImageWidget : Widget {
|
||||
|
||||
|
|
|
@ -49,6 +49,8 @@ immutable string STYLE_BUTTON_IMAGE = "BUTTON_IMAGE";
|
|||
immutable string STYLE_BUTTON_TRANSPARENT = "BUTTON_TRANSPARENT";
|
||||
/// style id for Button w/o margins
|
||||
immutable string STYLE_BUTTON_NOMARGINS = "BUTTON_NOMARGINS";
|
||||
/// standard style id for Switch
|
||||
immutable string STYLE_SWITCH = "SWITCH";
|
||||
/// standard style id for CheckBox
|
||||
immutable string STYLE_CHECKBOX = "CHECKBOX";
|
||||
/// standard style id for CheckBox image
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 946 B |
Binary file not shown.
After Width: | Height: | Size: 869 B |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_checked="false" android:state_enabled="true"
|
||||
android:drawable="@drawable/switch_off" />
|
||||
<item android:state_checked="true" android:state_enabled="true"
|
||||
android:drawable="@drawable/switch_on" />
|
||||
<item android:state_checked="false" android:drawable="@drawable/switch_off_disabled" />
|
||||
<item android:state_checked="true" android:drawable="@drawable/switch_on_disabled" />
|
||||
</selector>
|
||||
|
|
@ -66,6 +66,11 @@
|
|||
margins="2,2,2,2"
|
||||
align="Center"
|
||||
/>
|
||||
<style id="SWITCH"
|
||||
margins="2,2,2,2"
|
||||
align="Center"
|
||||
backgroundImageId="switch"
|
||||
/>
|
||||
<style id="CHECKBOX"
|
||||
backgroundImageId="@null"
|
||||
margins="2,2,2,2"
|
||||
|
|
|
@ -169,6 +169,10 @@ res/mdpi/folder.png
|
|||
res/mdpi/media-flash-sd-mmc.png
|
||||
res/mdpi/popup_window_background.9.png
|
||||
res/mdpi/popup_window_background_dark.9.png
|
||||
res/mdpi/switch_off.png
|
||||
res/mdpi/switch_off_disabled.png
|
||||
res/mdpi/switch_on.png
|
||||
res/mdpi/switch_on_disabled.png
|
||||
res/mdpi/tab_btn_dark_down_focused.9.png
|
||||
res/mdpi/tab_btn_dark_down_focused_dark.9.png
|
||||
res/mdpi/tab_btn_dark_down_focused_selected.9.png
|
||||
|
@ -234,6 +238,7 @@ res/scrollbar_btn_up.png
|
|||
res/scrollbar_btn_up_dark.png
|
||||
res/scrollbar_indicator_horizontal.png
|
||||
res/scrollbar_indicator_vertical.png
|
||||
res/switch.xml
|
||||
res/tab_btn_dark_down.xml
|
||||
res/tab_btn_dark_down_dark.xml
|
||||
res/tab_btn_dark_up.xml
|
||||
|
|
Loading…
Reference in New Issue