settings dialog layout fixes; tree widget scrollbars fixes; fix #435, buggins/dlangide#285

This commit is contained in:
Vadim Lopatin 2017-09-13 13:12:21 +03:00
parent f0ab7f1b45
commit ab061120fb
4 changed files with 74 additions and 29 deletions

View File

@ -52,6 +52,8 @@ class CheckboxItem : SettingsItem {
/// create setting widget /// create setting widget
override Widget[] createWidgets(Setting settings) { override Widget[] createWidgets(Setting settings) {
CheckBox res = new CheckBox(_id, _label); CheckBox res = new CheckBox(_id, _label);
res.minWidth = 60.pointsToPixels;
res.layoutWidth = FILL_PARENT;
Setting setting = settings.settingByPath(_id, SettingType.FALSE); Setting setting = settings.settingByPath(_id, SettingType.FALSE);
res.checked = setting.boolean ^ _inverse; res.checked = setting.boolean ^ _inverse;
res.checkChange = delegate(Widget source, bool checked) { res.checkChange = delegate(Widget source, bool checked) {
@ -73,7 +75,8 @@ class StringComboBoxItem : SettingsItem {
override Widget[] createWidgets(Setting settings) { override Widget[] createWidgets(Setting settings) {
TextWidget lbl = new TextWidget(_id ~ "-label", _label); TextWidget lbl = new TextWidget(_id ~ "-label", _label);
ComboBox cb = new ComboBox(_id, _items); ComboBox cb = new ComboBox(_id, _items);
cb.minWidth = 200; cb.minWidth = 60.pointsToPixels;
cb.layoutWidth = FILL_PARENT;
Setting setting = settings.settingByPath(_id, SettingType.STRING); Setting setting = settings.settingByPath(_id, SettingType.STRING);
string itemId = setting.str; string itemId = setting.str;
int index = -1; int index = -1;
@ -105,7 +108,8 @@ class IntComboBoxItem : SettingsItem {
override Widget[] createWidgets(Setting settings) { override Widget[] createWidgets(Setting settings) {
TextWidget lbl = new TextWidget(_id ~ "-label", _label); TextWidget lbl = new TextWidget(_id ~ "-label", _label);
ComboBox cb = new ComboBox(_id, _items); ComboBox cb = new ComboBox(_id, _items);
cb.minWidth = 100; cb.minWidth = 60.pointsToPixels;
cb.layoutWidth = FILL_PARENT;
Setting setting = settings.settingByPath(_id, SettingType.INTEGER); Setting setting = settings.settingByPath(_id, SettingType.INTEGER);
long itemId = setting.integer; long itemId = setting.integer;
int index = -1; int index = -1;
@ -139,7 +143,8 @@ class FloatComboBoxItem : SettingsItem {
override Widget[] createWidgets(Setting settings) { override Widget[] createWidgets(Setting settings) {
TextWidget lbl = new TextWidget(_id ~ "-label", _label); TextWidget lbl = new TextWidget(_id ~ "-label", _label);
ComboBox cb = new ComboBox(_id, _items); ComboBox cb = new ComboBox(_id, _items);
cb.minWidth = 100; cb.minWidth = 60.pointsToPixels;
cb.layoutWidth = FILL_PARENT;
Setting setting = settings.settingByPath(_id, SettingType.FLOAT); Setting setting = settings.settingByPath(_id, SettingType.FLOAT);
long itemId = cast(long)(setting.floating * _divider + 0.5f); long itemId = cast(long)(setting.floating * _divider + 0.5f);
int index = -1; int index = -1;
@ -177,7 +182,8 @@ class NumberEditItem : SettingsItem {
override Widget[] createWidgets(Setting settings) { override Widget[] createWidgets(Setting settings) {
TextWidget lbl = new TextWidget(_id ~ "-label", _label); TextWidget lbl = new TextWidget(_id ~ "-label", _label);
EditLine ed = new EditLine(_id ~ "-edit", _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); Setting setting = settings.settingByPath(_id, SettingType.INTEGER);
int n = cast(int)setting.integerDef(_defaultValue); int n = cast(int)setting.integerDef(_defaultValue);
if (_minValue != int.max && n < _minValue) if (_minValue != int.max && n < _minValue)
@ -211,7 +217,8 @@ class StringEditItem : SettingsItem {
override Widget[] createWidgets(Setting settings) { override Widget[] createWidgets(Setting settings) {
TextWidget lbl = new TextWidget(_id ~ "-label", _label); TextWidget lbl = new TextWidget(_id ~ "-label", _label);
EditLine ed = new EditLine(_id ~ "-edit"); EditLine ed = new EditLine(_id ~ "-edit");
ed.minWidth = 200; ed.minWidth = 60.pointsToPixels;
ed.layoutWidth = FILL_PARENT;
Setting setting = settings.settingByPath(_id, SettingType.STRING); Setting setting = settings.settingByPath(_id, SettingType.STRING);
string value = setting.strDef(_defaultValue); string value = setting.strDef(_defaultValue);
setting.str = value; setting.str = value;
@ -235,7 +242,7 @@ class FileNameEditItem : SettingsItem {
import dlangui.dialogs.filedlg; import dlangui.dialogs.filedlg;
TextWidget lbl = new TextWidget(_id ~ "-label", _label); TextWidget lbl = new TextWidget(_id ~ "-label", _label);
FileNameEditLine ed = new FileNameEditLine(_id ~ "-filename-edit"); FileNameEditLine ed = new FileNameEditLine(_id ~ "-filename-edit");
ed.minWidth = 200; ed.minWidth = 60.pointsToPixels;
Setting setting = settings.settingByPath(_id, SettingType.STRING); Setting setting = settings.settingByPath(_id, SettingType.STRING);
string value = setting.strDef(_defaultValue); string value = setting.strDef(_defaultValue);
setting.str = value; setting.str = value;
@ -260,7 +267,8 @@ class ExecutableFileNameEditItem : SettingsItem {
TextWidget lbl = new TextWidget(_id ~ "-label", _label); TextWidget lbl = new TextWidget(_id ~ "-label", _label);
FileNameEditLine ed = new FileNameEditLine(_id ~ "-filename-edit"); FileNameEditLine ed = new FileNameEditLine(_id ~ "-filename-edit");
ed.addFilter(FileFilterEntry(UIString.fromId("MESSAGE_EXECUTABLES"c), "*.exe", true)); 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); Setting setting = settings.settingByPath(_id, SettingType.STRING);
string value = setting.strDef(_defaultValue); string value = setting.strDef(_defaultValue);
setting.str = value; setting.str = value;
@ -285,7 +293,8 @@ class PathNameEditItem : SettingsItem {
TextWidget lbl = new TextWidget(_id ~ "-label", _label); TextWidget lbl = new TextWidget(_id ~ "-label", _label);
DirEditLine ed = new DirEditLine(_id ~ "-path-edit"); DirEditLine ed = new DirEditLine(_id ~ "-path-edit");
ed.addFilter(FileFilterEntry(UIString.fromId("MESSAGE_ALL_FILES"c), "*.*")); 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); Setting setting = settings.settingByPath(_id, SettingType.STRING);
string value = setting.strDef(_defaultValue); string value = setting.strDef(_defaultValue);
setting.str = value; setting.str = value;
@ -411,7 +420,7 @@ class SettingsPage {
/// create page widget (default implementation creates empty page) /// create page widget (default implementation creates empty page)
Widget createWidget(Setting settings) { Widget createWidget(Setting settings) {
VerticalLayout res = new VerticalLayout(_id); 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) { if (itemCount > 0) {
TextWidget caption = new TextWidget("prop-body-caption-" ~ _id, _label); TextWidget caption = new TextWidget("prop-body-caption-" ~ _id, _label);
caption.styleId = STYLE_SETTINGS_PAGE_TITLE; caption.styleId = STYLE_SETTINGS_PAGE_TITLE;
@ -427,6 +436,7 @@ class SettingsPage {
} else if (w.length == 2) { } else if (w.length == 2) {
if (!tbl) { if (!tbl) {
tbl = new TableLayout(); tbl = new TableLayout();
tbl.layoutWidth = FILL_PARENT;
tbl.colCount = 2; tbl.colCount = 2;
res.addChild(tbl); res.addChild(tbl);
} }
@ -485,20 +495,22 @@ class SettingsDialog : Dialog {
/// override to implement creation of dialog controls /// override to implement creation of dialog controls
override void initialize() { override void initialize() {
minWidth(600).minHeight(400); import dlangui.widgets.scroll;
_tree = new TreeWidget("prop_tree"); 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.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.selectionChange = &onTreeItemSelected;
_tree.fontSize = 16; _tree.fontSize = 16;
_frame = new FrameLayout("prop_pages"); _frame = new FrameLayout("prop_pages");
_frame.styleId = STYLE_SETTINGS_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); createControls(_layout, _tree.items);
HorizontalLayout content = new HorizontalLayout("settings_dlg_content"); HorizontalLayout content = new HorizontalLayout("settings_dlg_content");
content.addChild(_tree); content.addChild(_tree);
content.addChild(_frame); content.addChild(_frame);
content.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT); content.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
addChild(content); addChild(content);
addChild(createButtonsPanel([ACTION_APPLY, ACTION_CANCEL], 0, 0)); addChild(createButtonsPanel([ACTION_APPLY, ACTION_CANCEL], 0, 0));
if (_layout.childCount > 0) if (_layout.childCount > 0)

View File

@ -203,7 +203,7 @@ class LayoutItems {
contentSecondarySize = maxItem; contentSecondarySize = maxItem;
else else
contentSecondarySize = rc.height; 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 delta = rc.width - totalSize; // total space to add to fit
else if (totalSize > rc.width) else if (totalSize > rc.width)
delta = rc.width - totalSize; // total space to reduce to fit delta = rc.width - totalSize; // total space to reduce to fit
@ -491,18 +491,18 @@ class ResizerWidget : Widget {
} }
if (event.action == MouseAction.Move && trackHover) { if (event.action == MouseAction.Move && trackHover) {
if (!(state & State.Hovered)) { if (!(state & State.Hovered)) {
Log.d("Hover ", id); //Log.d("Hover ", id);
setState(State.Hovered); setState(State.Hovered);
} }
return true; return true;
} }
if ((event.action == MouseAction.Leave || event.action == MouseAction.Cancel) && trackHover) { if ((event.action == MouseAction.Leave || event.action == MouseAction.Cancel) && trackHover) {
Log.d("Leave ", id); //Log.d("Leave ", id);
resetState(State.Hovered); resetState(State.Hovered);
return true; return true;
} }
if (event.action == MouseAction.Cancel) { if (event.action == MouseAction.Cancel) {
Log.d("SliderButton.onMouseEvent event.action == MouseAction.Cancel"); //Log.d("SliderButton.onMouseEvent event.action == MouseAction.Cancel");
if (_dragging) { if (_dragging) {
resetState(State.Pressed); resetState(State.Pressed);
_dragging = false; _dragging = false;
@ -564,6 +564,7 @@ class LinearLayout : WidgetGroupDefaultDrawing {
_pos = rc; _pos = rc;
applyMargins(rc); applyMargins(rc);
applyPadding(rc); applyPadding(rc);
//debug Log.d("LinearLayout.layout id=", _id, " rc=", rc, " fillHoriz=", layoutWidth == FILL_PARENT);
_layoutItems.layout(rc); _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) { 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); initialize(cc, rc, layoutWidthFill, layoutHeightFill);
for (int y = 0; y < rc; y++) { for (int y = 0; y < rc; y++) {
for (int x = 0; x < cc; x++) { for (int x = 0; x < cc; x++) {
int index = y * cc + x; int index = y * cc + x;
Widget child = index < parent.childCount ? parent.child(index) : null; Widget child = index < parent.childCount ? parent.child(index) : null;
cell(x, y).measure(child, pwidth, pheight); 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 // calc total row size
@ -807,6 +811,7 @@ class TableLayout : WidgetGroupDefaultDrawing {
} }
totalWidth += col(x).measuredSize; totalWidth += col(x).measuredSize;
} }
//Log.d(" ", parent.id, " w=", totalWidth, " h=", totalHeight);
return Point(totalWidth, totalHeight); return Point(totalWidth, totalHeight);
} }
@ -855,6 +860,13 @@ class TableLayout : WidgetGroupDefaultDrawing {
delta0 = 0; 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;
}
}
} }
} }
} }

View File

@ -303,19 +303,24 @@ class ScrollWidgetBase : WidgetGroup, OnScrollHandler {
pwidth -= m.left + m.right + p.left + p.right; pwidth -= m.left + m.right + p.left + p.right;
if (parentHeight != SIZE_UNSPECIFIED) if (parentHeight != SIZE_UNSPECIFIED)
pheight -= m.top + m.bottom + p.top + p.bottom; 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); _hscrollbar.measure(pwidth, pheight);
hsbh = _hscrollbar.measuredHeight;
} }
if (_vscrollbar && _vscrollbarMode == ScrollBarMode.Visible) { if (_vscrollbar && (_vscrollbarMode == ScrollBarMode.Visible || _vscrollbarMode == ScrollBarMode.Auto)) {
_vscrollbar.measure(pwidth, pheight); _vscrollbar.measure(pwidth, pheight);
vsbw = _vscrollbar.measuredWidth;
} }
Point sz = minimumVisibleContentSize(); Point sz = minimumVisibleContentSize();
if (_hscrollbar && _hscrollbarMode == ScrollBarMode.Visible) {
sz.y += _hscrollbar.measuredHeight; //if (_hscrollbar && _hscrollbarMode == ScrollBarMode.Visible) {
} sz.y += hsbh;
if (_vscrollbar && _vscrollbarMode == ScrollBarMode.Visible) { //}
sz.x += _vscrollbar.measuredWidth; //if (_vscrollbar && _vscrollbarMode == ScrollBarMode.Visible) {
} sz.x += vsbw;
//}
measuredContent(parentWidth, parentHeight, sz.x, sz.y); measuredContent(parentWidth, parentHeight, sz.x, sz.y);
} }

View File

@ -847,7 +847,18 @@ class TreeWidgetBase : ScrollWidget, OnTreeContentChangeListener, OnTreeStateCh
} }
override Point minimumVisibleContentSize() { 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). /// 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) { override void onTreeContentChange(TreeItems source) {
_needUpdateWidgets = true; _needUpdateWidgets = true;
requestLayout(); requestLayout();
//updateScrollBars();
} }
override void onTreeStateChange(TreeItems source) { override void onTreeStateChange(TreeItems source) {
_needUpdateWidgetStates = true; _needUpdateWidgetStates = true;
requestLayout(); requestLayout();
//updateScrollBars();
} }
override void onTreeExpandedStateChange(TreeItems source, TreeItem item) { override void onTreeExpandedStateChange(TreeItems source, TreeItem item) {
if (expandedChange.assigned) if (expandedChange.assigned)
expandedChange(source, item); expandedChange(source, item);
layout(pos);
//requestLayout();
//updateScrollBars();
} }
TreeItemWidget findItemWidget(TreeItem item) { TreeItemWidget findItemWidget(TreeItem item) {
@ -979,7 +995,7 @@ class TreeWidget : TreeWidgetBase {
this(null); this(null);
} }
/// create with ID parameter /// create with ID parameter
this(string ID) { this(string ID, ScrollBarMode hscrollbarMode = ScrollBarMode.Visible, ScrollBarMode vscrollbarMode = ScrollBarMode.Visible) {
super(ID); super(ID, hscrollbarMode, vscrollbarMode);
} }
} }