mirror of https://github.com/buggins/dlangui.git
update styles for buttons, checkboxes, radiobuttons
This commit is contained in:
parent
37d5f1efcd
commit
50d82fd414
|
@ -441,11 +441,15 @@ extern (C) int UIAppMain(string[] args) {
|
|||
layout3.addChild(buttons1);
|
||||
|
||||
WidgetGroup buttons11 = new HorizontalLayout();
|
||||
buttons11.addChild(new TextWidget(null, "Construct buttons by action: "d));
|
||||
buttons11.addChild(new TextWidget(null, "Construct buttons by action (Button, ImageButton, ImageTextButton): "d));
|
||||
Action FILE_OPEN_ACTION = new Action(ACTION_FILE_OPEN, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag.Control);
|
||||
buttons11.addChild(new Button(FILE_OPEN_ACTION));
|
||||
buttons11.addChild(new ImageButton(FILE_OPEN_ACTION));
|
||||
buttons11.addChild(new ImageTextButton(FILE_OPEN_ACTION));
|
||||
buttons11.addChild(new TextWidget(null, "The same in disabled state: "d));
|
||||
buttons11.addChild((new Button(FILE_OPEN_ACTION)).enabled(false));
|
||||
buttons11.addChild((new ImageButton(FILE_OPEN_ACTION)).enabled(false));
|
||||
buttons11.addChild((new ImageTextButton(FILE_OPEN_ACTION)).enabled(false));
|
||||
layout3.addChild(buttons11);
|
||||
|
||||
layout3.addChild(new VSpacer());
|
||||
|
@ -478,7 +482,7 @@ extern (C) int UIAppMain(string[] args) {
|
|||
layout3.addChild(new VSpacer());
|
||||
layout3.addChild(new TextWidget(null, "In vertical layouts:"d));
|
||||
HorizontalLayout hlayout2 = new HorizontalLayout();
|
||||
hlayout2.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
hlayout2.layoutHeight(FILL_PARENT); //layoutWidth(FILL_PARENT).
|
||||
|
||||
buttons1 = new VerticalLayout();
|
||||
buttons1.addChild(new TextWidget(null, "Buttons"d));
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
margins="5,5,5,5"
|
||||
focusRectColors="#000"
|
||||
textFlags="UnderlineHotKeys"
|
||||
/>
|
||||
>
|
||||
<state state_enabled="true" state_hovered="true" textColor="#006080"/>
|
||||
<state state_enabled="false" textColor="#80000000"/>
|
||||
</style>
|
||||
<style id="BUTTON_TRANSPARENT"
|
||||
backgroundImageId="btn_background_transparent"
|
||||
align="Center"
|
||||
|
@ -16,10 +19,43 @@
|
|||
margins="2,2,2,2"
|
||||
align="Left|VCenter"
|
||||
textFlags="UnderlineHotKeys"
|
||||
/>
|
||||
<style id="BUTTON_ICON"
|
||||
>
|
||||
<state state_enabled="false" textColor="#80000000"/>
|
||||
<state state_enabled="true" state_hovered="true" textColor="#006080"/>
|
||||
</style>
|
||||
<style id="BUTTON_IMAGE"
|
||||
margins="2,2,2,2"
|
||||
align="Center"
|
||||
/>
|
||||
<style id="CHECKBOX"
|
||||
backgroundImageId="@null"
|
||||
margins="2,2,2,2"
|
||||
padding="2,2,2,2"
|
||||
focusRectColors="@null"
|
||||
/>
|
||||
<style id="CHECKBOX_IMAGE" parent="BUTTON_IMAGE"
|
||||
align="Center"
|
||||
margins="2,2,2,2"
|
||||
/>
|
||||
<style id="CHECKBOX_LABEL" parent="BUTTON_LABEL"
|
||||
align="Left|VCenter"
|
||||
focusRectColors="#000"
|
||||
>
|
||||
<state state_enabled="true" state_hovered="true" textColor="#006080"/>
|
||||
</style>
|
||||
<style id="RADIOBUTTON" parent="CHECKBOX"
|
||||
margins="2,2,2,2"
|
||||
padding="2,2,2,2"
|
||||
/>
|
||||
<style id="RADIOBUTTON_IMAGE" parent="CHECKBOX_IMAGE"
|
||||
align="Center"
|
||||
margins="2,2,2,2"
|
||||
/>
|
||||
<style id="RADIOBUTTON_LABEL" parent="CHECKBOX_LABEL"
|
||||
align="Left|VCenter"
|
||||
>
|
||||
<state state_enabled="true" state_hovered="true" textColor="#006080"/>
|
||||
</style>
|
||||
<style id="TEXT"
|
||||
margins="2,2,2,2"
|
||||
padding="1,1,1,1"
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
// Written in the D programming language.
|
||||
|
||||
/**
|
||||
This module contains declaration of useful color related operations.
|
||||
|
||||
In dlangui, colors are represented as 32 bit uint AARRGGBB values.
|
||||
|
||||
Synopsis:
|
||||
|
||||
----
|
||||
import dlangui.graphics.colors;
|
||||
|
||||
----
|
||||
|
||||
Copyright: Vadim Lopatin, 2015
|
||||
License: Boost License 1.0
|
||||
Authors: Vadim Lopatin, coolreader.org@gmail.com
|
||||
*/
|
||||
module dlangui.graphics.colors;
|
||||
|
||||
private import std.string : strip;
|
||||
|
|
|
@ -57,12 +57,12 @@ class HSpacer : Widget {
|
|||
class TextWidget : Widget {
|
||||
this(string ID = null, string textResourceId = null) {
|
||||
super(ID);
|
||||
styleId = "TEXT";
|
||||
styleId = STYLE_TEXT;
|
||||
_text = textResourceId;
|
||||
}
|
||||
this(string ID, dstring rawText) {
|
||||
super(ID);
|
||||
styleId = "TEXT";
|
||||
styleId = STYLE_TEXT;
|
||||
_text = rawText;
|
||||
}
|
||||
protected UIString _text;
|
||||
|
@ -249,6 +249,7 @@ class ImageTextButton : HorizontalLayout {
|
|||
protected void init(string drawableId, UIString caption) {
|
||||
styleId = "BUTTON";
|
||||
_icon = new ImageWidget("icon", drawableId);
|
||||
_icon.styleId = "BUTTON_IMAGE";
|
||||
_label = new TextWidget("label", caption);
|
||||
_label.styleId = "BUTTON_LABEL";
|
||||
_icon.state = State.Parent;
|
||||
|
@ -285,12 +286,17 @@ class ImageTextButton : HorizontalLayout {
|
|||
class CheckBox : ImageTextButton {
|
||||
this(string ID = null, string textResourceId = null) {
|
||||
super(ID, "btn_check", textResourceId);
|
||||
styleId = "TRANSPARENT_BUTTON_BACKGROUND";
|
||||
checkable = true;
|
||||
}
|
||||
this(string ID, dstring labelText) {
|
||||
super(ID, "btn_check", labelText);
|
||||
styleId = "TRANSPARENT_BUTTON_BACKGROUND";
|
||||
}
|
||||
override protected void init(string drawableId, UIString caption) {
|
||||
super.init(drawableId, caption);
|
||||
styleId = "CHECKBOX";
|
||||
if (_icon)
|
||||
_icon.styleId = "CHECKBOX_IMAGE";
|
||||
if (_label)
|
||||
_label.styleId = "CHECKBOX_LABEL";
|
||||
checkable = true;
|
||||
}
|
||||
// called to process click and notify listeners
|
||||
|
@ -304,12 +310,17 @@ class CheckBox : ImageTextButton {
|
|||
class RadioButton : ImageTextButton {
|
||||
this(string ID = null, string textResourceId = null) {
|
||||
super(ID, "btn_radio", textResourceId);
|
||||
styleId = "TRANSPARENT_BUTTON_BACKGROUND";
|
||||
checkable = true;
|
||||
}
|
||||
this(string ID, dstring labelText) {
|
||||
super(ID, "btn_radio", labelText);
|
||||
styleId = "TRANSPARENT_BUTTON_BACKGROUND";
|
||||
}
|
||||
override protected void init(string drawableId, UIString caption) {
|
||||
super.init(drawableId, caption);
|
||||
styleId = STYLE_RADIOBUTTON;
|
||||
if (_icon)
|
||||
_icon.styleId = STYLE_RADIOBUTTON_IMAGE;
|
||||
if (_label)
|
||||
_label.styleId = STYLE_RADIOBUTTON_LABEL;
|
||||
checkable = true;
|
||||
}
|
||||
|
||||
|
@ -351,7 +362,7 @@ class Button : Widget {
|
|||
}
|
||||
|
||||
private void init(UIString label) {
|
||||
styleId = "BUTTON";
|
||||
styleId = STYLE_BUTTON;
|
||||
_text = label;
|
||||
clickable = true;
|
||||
focusable = true;
|
||||
|
|
|
@ -30,6 +30,35 @@ import dlangui.graphics.fonts;
|
|||
import dlangui.graphics.drawbuf;
|
||||
import dlangui.graphics.resources;
|
||||
|
||||
// Standard style constants
|
||||
/// standard style id for TextWidget
|
||||
immutable string STYLE_TEXT = "TEXT";
|
||||
/// standard style id for Button
|
||||
immutable string STYLE_BUTTON = "BUTTON";
|
||||
/// standard style id for CheckBox
|
||||
immutable string STYLE_CHECKBOX = "CHECKBOX";
|
||||
/// standard style id for CheckBox image
|
||||
immutable string STYLE_CHECKBOX_IMAGE = "CHECKBOX_IMAGE";
|
||||
/// standard style id for CheckBox label
|
||||
immutable string STYLE_CHECKBOX_LABEL = "CHECKBOX_LABEL";
|
||||
/// standard style id for RadioButton
|
||||
immutable string STYLE_RADIOBUTTON = "RADIOBUTTON";
|
||||
/// standard style id for RadioButton image
|
||||
immutable string STYLE_RADIOBUTTON_IMAGE = "RADIOBUTTON_IMAGE";
|
||||
/// standard style id for RadioButton label
|
||||
immutable string STYLE_RADIOBUTTON_LABEL = "RADIOBUTTON_LABEL";
|
||||
|
||||
// Layout size constants
|
||||
/// layout option, to occupy all available place
|
||||
immutable int FILL_PARENT = int.max - 1;
|
||||
/// layout option, for size based on content
|
||||
immutable int WRAP_CONTENT = int.max - 2;
|
||||
/// use as widget.layout() param to avoid applying of parent size
|
||||
immutable int SIZE_UNSPECIFIED = int.max;
|
||||
|
||||
// Other style constants
|
||||
|
||||
/// unspecified align - to take parent's value instead
|
||||
immutable ubyte ALIGN_UNSPECIFIED = 0;
|
||||
/// unspecified font size constant - to take parent style property value
|
||||
immutable ushort FONT_SIZE_UNSPECIFIED = 0xFFFF;
|
||||
|
@ -41,21 +70,16 @@ immutable ubyte FONT_STYLE_UNSPECIFIED = 0xFF;
|
|||
immutable ubyte FONT_STYLE_NORMAL = 0x00;
|
||||
/// italic font style constant
|
||||
immutable ubyte FONT_STYLE_ITALIC = 0x01;
|
||||
/// use as widget.layout() param to avoid applying of parent size
|
||||
immutable int SIZE_UNSPECIFIED = int.max;
|
||||
/// use text flags from parent style
|
||||
immutable uint TEXT_FLAGS_UNSPECIFIED = uint.max;
|
||||
/// use text flags from parent widget
|
||||
immutable uint TEXT_FLAGS_USE_PARENT = uint.max - 1;
|
||||
/// layout option, to occupy all available place
|
||||
immutable int FILL_PARENT = int.max - 1;
|
||||
/// layout option, for size based on content
|
||||
immutable int WRAP_CONTENT = int.max - 2;
|
||||
/// to take layout weight from parent
|
||||
immutable int WEIGHT_UNSPECIFIED = -1;
|
||||
|
||||
/// returns true for WRAP_CONTENT, WRAP_CONTENT, SIZE_UNSPECIFIED
|
||||
bool isSpecialSize(int sz) {
|
||||
// don't forget to update if more special constants added
|
||||
return sz >= WRAP_CONTENT;
|
||||
}
|
||||
|
||||
|
@ -526,8 +550,11 @@ class Style {
|
|||
|
||||
/// returns colors to draw focus rectangle (one for solid, two for vertical gradient) or null if no focus rect should be drawn for style
|
||||
@property const(uint[]) focusRectColors() const {
|
||||
if (_focusRectColors)
|
||||
if (_focusRectColors) {
|
||||
if (_focusRectColors.length == 1 && _focusRectColors[0] == COLOR_UNSPECIFIED)
|
||||
return null;
|
||||
return cast(const)_focusRectColors;
|
||||
}
|
||||
return parentStyle.focusRectColors;
|
||||
}
|
||||
|
||||
|
@ -881,6 +908,8 @@ private import std.array : split;
|
|||
|
||||
/// Decode color list attribute, e.g.: "#84A, #99FFFF" -> [0x8844aa, 0x99ffff]
|
||||
uint[] decodeFocusRectColors(string s) {
|
||||
if (s.equal("@null"))
|
||||
return [COLOR_UNSPECIFIED];
|
||||
string[] colors = split(s, ",");
|
||||
if (colors.length < 1)
|
||||
return null;
|
||||
|
|
|
@ -850,9 +850,9 @@ class Widget {
|
|||
return parent.visible;
|
||||
}
|
||||
|
||||
/// returns true if widget is focusable and visible
|
||||
/// returns true if widget is focusable and visible and enabled
|
||||
@property bool canFocus() {
|
||||
return focusable && visible;
|
||||
return focusable && visible && enabled;
|
||||
}
|
||||
|
||||
/// sets focus to this widget or suitable focusable child, returns previously focused widget
|
||||
|
@ -1138,7 +1138,7 @@ class Widget {
|
|||
bg.drawTo(buf, rc, state);
|
||||
}
|
||||
applyPadding(rc);
|
||||
if ((state & State.Focused) && focusable) {
|
||||
if (state & State.Focused) {
|
||||
rc.expand(FOCUS_RECT_PADDING, FOCUS_RECT_PADDING);
|
||||
drawFocusRect(buf, rc);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue