From ab061120fb7564ef55d92b538ce828b87e70f0b1 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Wed, 13 Sep 2017 13:12:21 +0300 Subject: [PATCH] settings dialog layout fixes; tree widget scrollbars fixes; fix #435, buggins/dlangide#285 --- src/dlangui/dialogs/settingsdialog.d | 40 ++++++++++++++++++---------- src/dlangui/widgets/layouts.d | 20 +++++++++++--- src/dlangui/widgets/scroll.d | 21 +++++++++------ src/dlangui/widgets/tree.d | 22 ++++++++++++--- 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/src/dlangui/dialogs/settingsdialog.d b/src/dlangui/dialogs/settingsdialog.d index 632a187a..358a4929 100644 --- a/src/dlangui/dialogs/settingsdialog.d +++ b/src/dlangui/dialogs/settingsdialog.d @@ -52,6 +52,8 @@ class CheckboxItem : SettingsItem { /// create setting widget override Widget[] createWidgets(Setting settings) { CheckBox res = new CheckBox(_id, _label); + res.minWidth = 60.pointsToPixels; + res.layoutWidth = FILL_PARENT; Setting setting = settings.settingByPath(_id, SettingType.FALSE); res.checked = setting.boolean ^ _inverse; res.checkChange = delegate(Widget source, bool checked) { @@ -73,7 +75,8 @@ class StringComboBoxItem : SettingsItem { override Widget[] createWidgets(Setting settings) { TextWidget lbl = new TextWidget(_id ~ "-label", _label); ComboBox cb = new ComboBox(_id, _items); - cb.minWidth = 200; + cb.minWidth = 60.pointsToPixels; + cb.layoutWidth = FILL_PARENT; Setting setting = settings.settingByPath(_id, SettingType.STRING); string itemId = setting.str; int index = -1; @@ -105,7 +108,8 @@ class IntComboBoxItem : SettingsItem { override Widget[] createWidgets(Setting settings) { TextWidget lbl = new TextWidget(_id ~ "-label", _label); ComboBox cb = new ComboBox(_id, _items); - cb.minWidth = 100; + cb.minWidth = 60.pointsToPixels; + cb.layoutWidth = FILL_PARENT; Setting setting = settings.settingByPath(_id, SettingType.INTEGER); long itemId = setting.integer; int index = -1; @@ -139,7 +143,8 @@ class FloatComboBoxItem : SettingsItem { override Widget[] createWidgets(Setting settings) { TextWidget lbl = new TextWidget(_id ~ "-label", _label); ComboBox cb = new ComboBox(_id, _items); - cb.minWidth = 100; + cb.minWidth = 60.pointsToPixels; + cb.layoutWidth = FILL_PARENT; Setting setting = settings.settingByPath(_id, SettingType.FLOAT); long itemId = cast(long)(setting.floating * _divider + 0.5f); int index = -1; @@ -177,7 +182,8 @@ class NumberEditItem : SettingsItem { override Widget[] createWidgets(Setting settings) { TextWidget lbl = new TextWidget(_id ~ "-label", _label); EditLine ed = new EditLine(_id ~ "-edit", _label); - ed.minWidth = 100; + ed.minWidth = 60.pointsToPixels; + ed.layoutWidth = FILL_PARENT; Setting setting = settings.settingByPath(_id, SettingType.INTEGER); int n = cast(int)setting.integerDef(_defaultValue); if (_minValue != int.max && n < _minValue) @@ -211,7 +217,8 @@ class StringEditItem : SettingsItem { override Widget[] createWidgets(Setting settings) { TextWidget lbl = new TextWidget(_id ~ "-label", _label); EditLine ed = new EditLine(_id ~ "-edit"); - ed.minWidth = 200; + ed.minWidth = 60.pointsToPixels; + ed.layoutWidth = FILL_PARENT; Setting setting = settings.settingByPath(_id, SettingType.STRING); string value = setting.strDef(_defaultValue); setting.str = value; @@ -235,7 +242,7 @@ class FileNameEditItem : SettingsItem { import dlangui.dialogs.filedlg; TextWidget lbl = new TextWidget(_id ~ "-label", _label); FileNameEditLine ed = new FileNameEditLine(_id ~ "-filename-edit"); - ed.minWidth = 200; + ed.minWidth = 60.pointsToPixels; Setting setting = settings.settingByPath(_id, SettingType.STRING); string value = setting.strDef(_defaultValue); setting.str = value; @@ -260,7 +267,8 @@ class ExecutableFileNameEditItem : SettingsItem { TextWidget lbl = new TextWidget(_id ~ "-label", _label); FileNameEditLine ed = new FileNameEditLine(_id ~ "-filename-edit"); ed.addFilter(FileFilterEntry(UIString.fromId("MESSAGE_EXECUTABLES"c), "*.exe", true)); - ed.minWidth = 200; + ed.minWidth = 60.pointsToPixels; + ed.layoutWidth = FILL_PARENT; Setting setting = settings.settingByPath(_id, SettingType.STRING); string value = setting.strDef(_defaultValue); setting.str = value; @@ -285,7 +293,8 @@ class PathNameEditItem : SettingsItem { TextWidget lbl = new TextWidget(_id ~ "-label", _label); DirEditLine ed = new DirEditLine(_id ~ "-path-edit"); ed.addFilter(FileFilterEntry(UIString.fromId("MESSAGE_ALL_FILES"c), "*.*")); - ed.minWidth = 200; + ed.minWidth = 60.pointsToPixels; + ed.layoutWidth = FILL_PARENT; Setting setting = settings.settingByPath(_id, SettingType.STRING); string value = setting.strDef(_defaultValue); setting.str = value; @@ -411,7 +420,7 @@ class SettingsPage { /// create page widget (default implementation creates empty page) Widget createWidget(Setting settings) { VerticalLayout res = new VerticalLayout(_id); - res.minWidth(200).minHeight(200).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); + res.minWidth(80.pointsToPixels).minHeight(200.pointsToPixels).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); if (itemCount > 0) { TextWidget caption = new TextWidget("prop-body-caption-" ~ _id, _label); caption.styleId = STYLE_SETTINGS_PAGE_TITLE; @@ -427,6 +436,7 @@ class SettingsPage { } else if (w.length == 2) { if (!tbl) { tbl = new TableLayout(); + tbl.layoutWidth = FILL_PARENT; tbl.colCount = 2; res.addChild(tbl); } @@ -485,20 +495,22 @@ class SettingsDialog : Dialog { /// override to implement creation of dialog controls override void initialize() { - minWidth(600).minHeight(400); - _tree = new TreeWidget("prop_tree"); + import dlangui.widgets.scroll; + minWidth(150.pointsToPixels).minHeight(150.pointsToPixels); + layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT); + _tree = new TreeWidget("prop_tree", ScrollBarMode.Auto, ScrollBarMode.Auto); _tree.styleId = STYLE_SETTINGS_TREE; - _tree.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT).minHeight(200).minWidth(100); + _tree.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT).minHeight(200.pointsToPixels).minWidth(50.pointsToPixels); _tree.selectionChange = &onTreeItemSelected; _tree.fontSize = 16; _frame = new FrameLayout("prop_pages"); _frame.styleId = STYLE_SETTINGS_PAGES; - _frame.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT).minHeight(200).minWidth(100); + _frame.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT).minHeight(200.pointsToPixels).minWidth(100.pointsToPixels); createControls(_layout, _tree.items); HorizontalLayout content = new HorizontalLayout("settings_dlg_content"); content.addChild(_tree); content.addChild(_frame); - content.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT); + content.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); addChild(content); addChild(createButtonsPanel([ACTION_APPLY, ACTION_CANCEL], 0, 0)); if (_layout.childCount > 0) diff --git a/src/dlangui/widgets/layouts.d b/src/dlangui/widgets/layouts.d index 4b9c90ce..9d5b8f06 100644 --- a/src/dlangui/widgets/layouts.d +++ b/src/dlangui/widgets/layouts.d @@ -203,7 +203,7 @@ class LayoutItems { contentSecondarySize = maxItem; else contentSecondarySize = rc.height; - if ((_layoutWidth == FILL_PARENT || isPercentSize(_layoutHeight)) && totalSize < rc.width && resizableSize > 0) + if ((_layoutWidth == FILL_PARENT || isPercentSize(_layoutWidth)) && totalSize < rc.width && resizableSize > 0) delta = rc.width - totalSize; // total space to add to fit else if (totalSize > rc.width) delta = rc.width - totalSize; // total space to reduce to fit @@ -491,18 +491,18 @@ class ResizerWidget : Widget { } if (event.action == MouseAction.Move && trackHover) { if (!(state & State.Hovered)) { - Log.d("Hover ", id); + //Log.d("Hover ", id); setState(State.Hovered); } return true; } if ((event.action == MouseAction.Leave || event.action == MouseAction.Cancel) && trackHover) { - Log.d("Leave ", id); + //Log.d("Leave ", id); resetState(State.Hovered); return true; } if (event.action == MouseAction.Cancel) { - Log.d("SliderButton.onMouseEvent event.action == MouseAction.Cancel"); + //Log.d("SliderButton.onMouseEvent event.action == MouseAction.Cancel"); if (_dragging) { resetState(State.Pressed); _dragging = false; @@ -564,6 +564,7 @@ class LinearLayout : WidgetGroupDefaultDrawing { _pos = rc; applyMargins(rc); applyPadding(rc); + //debug Log.d("LinearLayout.layout id=", _id, " rc=", rc, " fillHoriz=", layoutWidth == FILL_PARENT); _layoutItems.layout(rc); } @@ -783,12 +784,15 @@ class TableLayout : WidgetGroupDefaultDrawing { } Point measure(Widget parent, int cc, int rc, int pwidth, int pheight, bool layoutWidthFill, bool layoutHeightFill) { + //Log.d("grid measure ", parent.id, " pw=", pwidth, " ph=", pheight); initialize(cc, rc, layoutWidthFill, layoutHeightFill); for (int y = 0; y < rc; y++) { for (int x = 0; x < cc; x++) { int index = y * cc + x; Widget child = index < parent.childCount ? parent.child(index) : null; cell(x, y).measure(child, pwidth, pheight); + //if (child) + // Log.d("cell ", x, ",", y, " child=", child.id, " measuredWidth=", child.measuredWidth, " minWidth=", child.minWidth); } } // calc total row size @@ -807,6 +811,7 @@ class TableLayout : WidgetGroupDefaultDrawing { } totalWidth += col(x).measuredSize; } + //Log.d(" ", parent.id, " w=", totalWidth, " h=", totalHeight); return Point(totalWidth, totalHeight); } @@ -855,6 +860,13 @@ class TableLayout : WidgetGroupDefaultDrawing { delta0 = 0; } } + } else if (extraSize < 0) { + for (int x = 0; x < colCount; x++) { + if (fillCount == 0 || col(x).fill) { + col(x).size += delta + delta0; + delta0 = 0; + } + } } } } diff --git a/src/dlangui/widgets/scroll.d b/src/dlangui/widgets/scroll.d index 82f917a9..82ec632a 100644 --- a/src/dlangui/widgets/scroll.d +++ b/src/dlangui/widgets/scroll.d @@ -303,19 +303,24 @@ class ScrollWidgetBase : WidgetGroup, OnScrollHandler { pwidth -= m.left + m.right + p.left + p.right; if (parentHeight != SIZE_UNSPECIFIED) pheight -= m.top + m.bottom + p.top + p.bottom; - if (_hscrollbar && _hscrollbarMode == ScrollBarMode.Visible) { + int vsbw = 0; + int hsbh = 0; + if (_hscrollbar && (_hscrollbarMode == ScrollBarMode.Visible || _hscrollbarMode == ScrollBarMode.Auto)) { _hscrollbar.measure(pwidth, pheight); + hsbh = _hscrollbar.measuredHeight; } - if (_vscrollbar && _vscrollbarMode == ScrollBarMode.Visible) { + if (_vscrollbar && (_vscrollbarMode == ScrollBarMode.Visible || _vscrollbarMode == ScrollBarMode.Auto)) { _vscrollbar.measure(pwidth, pheight); + vsbw = _vscrollbar.measuredWidth; } Point sz = minimumVisibleContentSize(); - if (_hscrollbar && _hscrollbarMode == ScrollBarMode.Visible) { - sz.y += _hscrollbar.measuredHeight; - } - if (_vscrollbar && _vscrollbarMode == ScrollBarMode.Visible) { - sz.x += _vscrollbar.measuredWidth; - } + + //if (_hscrollbar && _hscrollbarMode == ScrollBarMode.Visible) { + sz.y += hsbh; + //} + //if (_vscrollbar && _vscrollbarMode == ScrollBarMode.Visible) { + sz.x += vsbw; + //} measuredContent(parentWidth, parentHeight, sz.x, sz.y); } diff --git a/src/dlangui/widgets/tree.d b/src/dlangui/widgets/tree.d index 901a0fd0..2af5831f 100644 --- a/src/dlangui/widgets/tree.d +++ b/src/dlangui/widgets/tree.d @@ -847,7 +847,18 @@ class TreeWidgetBase : ScrollWidget, OnTreeContentChangeListener, OnTreeStateCh } override Point minimumVisibleContentSize() { - return Point(200,200); + return Point(100.pointsToPixels, 100.pointsToPixels); + } + + /// calculate full content size in pixels + override Point fullContentSize() { + if (_needUpdateWidgets) + updateWidgets(); + if (_needUpdateWidgetStates) + updateWidgetStates(); + return super.fullContentSize(); + //_contentWidget.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED); + //return Point(_contentWidget.measuredWidth,_contentWidget.measuredHeight); } /// Measure widget according to desired width and height constraints. (Step 1 of two phase layout). @@ -866,16 +877,21 @@ class TreeWidgetBase : ScrollWidget, OnTreeContentChangeListener, OnTreeStateCh override void onTreeContentChange(TreeItems source) { _needUpdateWidgets = true; requestLayout(); + //updateScrollBars(); } override void onTreeStateChange(TreeItems source) { _needUpdateWidgetStates = true; requestLayout(); + //updateScrollBars(); } override void onTreeExpandedStateChange(TreeItems source, TreeItem item) { if (expandedChange.assigned) expandedChange(source, item); + layout(pos); + //requestLayout(); + //updateScrollBars(); } TreeItemWidget findItemWidget(TreeItem item) { @@ -979,7 +995,7 @@ class TreeWidget : TreeWidgetBase { this(null); } /// create with ID parameter - this(string ID) { - super(ID); + this(string ID, ScrollBarMode hscrollbarMode = ScrollBarMode.Visible, ScrollBarMode vscrollbarMode = ScrollBarMode.Visible) { + super(ID, hscrollbarMode, vscrollbarMode); } }