implement #441 - menu separators

This commit is contained in:
Vadim Lopatin 2017-09-15 16:18:48 +03:00
parent 46a8f1029a
commit 80c0da2768
7 changed files with 75 additions and 40 deletions

View File

@ -2806,7 +2806,9 @@ class EditBox : EditWidgetBase {
/// calculate full content size in pixels
override Point fullContentSize() {
Point textSz = measureVisibleText();
Point textSz;
textSz.y = _lineHeight * _content.length;
textSz.x = _maxLineWidth;
//int maxy = _lineHeight * 5; // limit measured height
//if (textSz.y > maxy)
// textSz.y = maxy;

View File

@ -307,6 +307,8 @@ class MenuItemWidget : WidgetGroupDefaultDrawing {
_accelWidth = maxAccelWidth;
}
void measureSubitems(ref int maxLabelWidth, ref int maxHeight, ref int maxIconWidth, ref int maxAccelWidth) {
if (_item.type == MenuItemType.Separator)
return;
_label.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
if (maxLabelWidth < _label.measuredWidth)
maxLabelWidth = _label.measuredWidth;
@ -332,6 +334,10 @@ class MenuItemWidget : WidgetGroupDefaultDrawing {
updateState();
Rect m = margins;
Rect p = padding;
if (_item.type == MenuItemType.Separator) {
measuredContent(parentWidth, parentHeight, 1, 1); // for vertical (popup menu)
return;
}
// calc size constraints for children
int pwidth = parentWidth;
int pheight = parentHeight;
@ -354,6 +360,9 @@ class MenuItemWidget : WidgetGroupDefaultDrawing {
return;
}
_pos = rc;
if (_item.type == MenuItemType.Separator)
return;
applyMargins(rc);
applyPadding(rc);
Rect labelRc = rc;
@ -395,8 +404,13 @@ class MenuItemWidget : WidgetGroupDefaultDrawing {
id="menuitem";
_mainMenu = mainMenu;
_item = item;
styleId = STYLE_MENU_ITEM;
updateState();
if (_item.type == MenuItemType.Separator) {
styleId = "MENU_SEPARATOR";
trackHover = false;
clickable = false;
} else {
styleId = STYLE_MENU_ITEM;
string iconId = _item.action !is null ? _item.action.iconId : "";
if (_item.type == MenuItemType.Check)
iconId = "btn_check";
@ -438,6 +452,14 @@ class MenuItemWidget : WidgetGroupDefaultDrawing {
clickable = true;
}
}
}
class SeparatorMenuItemWidget : MenuItemWidget {
this(MenuItem item, bool mainMenu) {
super(item, mainMenu);
id="menuseparator";
}
}
/// base class for menus
class MenuWidgetBase : ListWidget {

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

View File

@ -174,6 +174,10 @@
backgroundImageId="menu_item_background_dark"
>
</style>
<style id="MENU_SEPARATOR"
backgroundImageId="menu_separator_dark"
>
</style>
<style id="MENU_ICON"
>
<state state_enabled="false" alpha="160"/>

View File

@ -238,7 +238,12 @@
/>
<style id="MENU_ITEM"
backgroundImageId="menu_item_background"
padding="4,2,4,2"
padding="4pt,2pt,4pt,2pt"
>
</style>
<style id="MENU_SEPARATOR"
backgroundImageId="menu_separator"
padding="4pt,2pt,4pt,2pt"
>
</style>
<style id="MENU_ICON"

View File

@ -208,6 +208,8 @@ res/mdpi/list_item_hovered_dark.9.png
res/mdpi/list_item_selected.9.png
res/mdpi/list_item_selected_dark.9.png
res/mdpi/media-flash-sd-mmc.png
res/mdpi/menu_separator.9.png
res/mdpi/menu_separator_dark.9.png
res/mdpi/popup_window_background.9.png
res/mdpi/popup_window_background_dark.9.png
res/mdpi/switch_off.png