From 80c0da276820a28bbd316de8ba90d818df32be3c Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 15 Sep 2017 16:18:48 +0300 Subject: [PATCH] implement #441 - menu separators --- src/dlangui/widgets/editors.d | 4 +- src/dlangui/widgets/menu.d | 98 ++++++++++++++--------- views/res/mdpi/menu_separator.9.png | Bin 0 -> 237 bytes views/res/mdpi/menu_separator_dark.9.png | Bin 0 -> 250 bytes views/res/theme_dark.xml | 4 + views/res/theme_default.xml | 7 +- views/standard_resources.list | 2 + 7 files changed, 75 insertions(+), 40 deletions(-) create mode 100644 views/res/mdpi/menu_separator.9.png create mode 100644 views/res/mdpi/menu_separator_dark.9.png diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 152d449c..49a3a287 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -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; diff --git a/src/dlangui/widgets/menu.d b/src/dlangui/widgets/menu.d index 0c10a961..bdd1b45d 100644 --- a/src/dlangui/widgets/menu.d +++ b/src/dlangui/widgets/menu.d @@ -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,47 +404,60 @@ class MenuItemWidget : WidgetGroupDefaultDrawing { id="menuitem"; _mainMenu = mainMenu; _item = item; - styleId = STYLE_MENU_ITEM; updateState(); - string iconId = _item.action !is null ? _item.action.iconId : ""; - if (_item.type == MenuItemType.Check) - iconId = "btn_check"; - else if (_item.type == MenuItemType.Radio) - iconId = "btn_radio"; - // icon - if (_item.action && iconId.length) { - _icon = new ImageWidget("MENU_ICON", iconId); - _icon.styleId = STYLE_MENU_ICON; - _icon.state = State.Parent; - addChild(_icon); - } - // label - _label = new TextWidget("MENU_LABEL"); - _label.text = _item.label; - _label.styleId = _mainMenu ? "MAIN_MENU_LABEL" : "MENU_LABEL"; - _label.state = State.Parent; - addChild(_label); - // accelerator - dstring acc = _item.acceleratorText; - if (_item.isSubmenu && !mainMenu) { - version (Windows) { - acc = ">"d; - //acc = "►"d; - } else { - acc = "‣"d; + 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"; + else if (_item.type == MenuItemType.Radio) + iconId = "btn_radio"; + // icon + if (_item.action && iconId.length) { + _icon = new ImageWidget("MENU_ICON", iconId); + _icon.styleId = STYLE_MENU_ICON; + _icon.state = State.Parent; + addChild(_icon); } + // label + _label = new TextWidget("MENU_LABEL"); + _label.text = _item.label; + _label.styleId = _mainMenu ? "MAIN_MENU_LABEL" : "MENU_LABEL"; + _label.state = State.Parent; + addChild(_label); + // accelerator + dstring acc = _item.acceleratorText; + if (_item.isSubmenu && !mainMenu) { + version (Windows) { + acc = ">"d; + //acc = "►"d; + } else { + acc = "‣"d; + } + } + if (acc !is null) { + _accel = new TextWidget("MENU_ACCEL"); + _accel.styleId = STYLE_MENU_ACCEL; + _accel.text = acc; + _accel.state = State.Parent; + if (_item.isSubmenu && !mainMenu) + _accel.alignment = Align.Right | Align.VCenter; + addChild(_accel); + } + trackHover = true; + clickable = true; } - if (acc !is null) { - _accel = new TextWidget("MENU_ACCEL"); - _accel.styleId = STYLE_MENU_ACCEL; - _accel.text = acc; - _accel.state = State.Parent; - if (_item.isSubmenu && !mainMenu) - _accel.alignment = Align.Right | Align.VCenter; - addChild(_accel); - } - trackHover = true; - clickable = true; + } +} + +class SeparatorMenuItemWidget : MenuItemWidget { + this(MenuItem item, bool mainMenu) { + super(item, mainMenu); + id="menuseparator"; } } diff --git a/views/res/mdpi/menu_separator.9.png b/views/res/mdpi/menu_separator.9.png new file mode 100644 index 0000000000000000000000000000000000000000..99618aa5ed57819c9568efbefd33562550cda86c GIT binary patch literal 237 zcmeAS@N?(olHy`uVBq!ia0vp^vOvti!3HE*JHDs`DYhhUcNd2LAh=-f^2tCE&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=kdvR6Rqe6tCvTvTY-UJAiF1B#Zfaf$kjuc}T$Gwv zlA5AWo>`Ki;O^-gkfN8$4ipdcba4#PIKOwYA=d!|9_CV2{tN%(U&?EEbE~%K<<>5q z?tEg=sx3*@zdBYW?cF%}-`R`0Tjmye&tg-bFdh=kdvR6jYH(w8h4`Ki;O^-gkfN8$4it~`ba4#PIKOxDL0$$$4i@%g#*&1j@UV>Pk^{Bp`VH&e zCCsZ)<6bjE(t6daKP@v)+D)EpGHa4d``s?p?E6=Ue>SmWOkee6dd7~QS1W#8#mvv4FO#nZGP@@0< literal 0 HcmV?d00001 diff --git a/views/res/theme_dark.xml b/views/res/theme_dark.xml index 847e3870..d24a570c 100644 --- a/views/res/theme_dark.xml +++ b/views/res/theme_dark.xml @@ -174,6 +174,10 @@ backgroundImageId="menu_item_background_dark" > + +