mirror of https://github.com/buggins/dlangui.git
Merge pull request #383 from and3md/measure_fixes
Measure fixes and improvments
This commit is contained in:
commit
e4b54778d9
|
@ -208,6 +208,8 @@ class Dialog : VerticalLayout {
|
||||||
_popup = _parentWindow.showPopup(_frame);
|
_popup = _parentWindow.showPopup(_frame);
|
||||||
_popup.flags(PopupFlags.Modal);
|
_popup.flags(PopupFlags.Modal);
|
||||||
} else {
|
} else {
|
||||||
|
if (_initialWidth == 0 && _initialHeight == 0)
|
||||||
|
wflags |= WindowFlag.MeasureSize;
|
||||||
_window = Platform.instance.createWindow(_caption, _parentWindow, wflags, _initialWidth, _initialHeight);
|
_window = Platform.instance.createWindow(_caption, _parentWindow, wflags, _initialWidth, _initialHeight);
|
||||||
static if (BACKEND_GUI) {
|
static if (BACKEND_GUI) {
|
||||||
if (_window && _icon)
|
if (_window && _icon)
|
||||||
|
|
|
@ -600,6 +600,8 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
_fileList.multiSelect = _allowMultipleFiles;
|
_fileList.multiSelect = _allowMultipleFiles;
|
||||||
_fileList.cellPopupMenu = &getCellPopupMenu;
|
_fileList.cellPopupMenu = &getCellPopupMenu;
|
||||||
_fileList.menuItemAction = &handleAction;
|
_fileList.menuItemAction = &handleAction;
|
||||||
|
_fileList.minVisibleRows = 10;
|
||||||
|
_fileList.minVisibleCols = 4;
|
||||||
|
|
||||||
_fileList.keyEvent = delegate(Widget source, KeyEvent event) {
|
_fileList.keyEvent = delegate(Widget source, KeyEvent event) {
|
||||||
if (_shortcutHelper.onKeyEvent(event))
|
if (_shortcutHelper.onKeyEvent(event))
|
||||||
|
@ -766,13 +768,15 @@ class FilePathPanelButtons : WidgetGroupDefaultDrawing {
|
||||||
override void measure(int parentWidth, int parentHeight) {
|
override void measure(int parentWidth, int parentHeight) {
|
||||||
Rect m = margins;
|
Rect m = margins;
|
||||||
Rect p = padding;
|
Rect p = padding;
|
||||||
|
|
||||||
// calc size constraints for children
|
// calc size constraints for children
|
||||||
int pwidth = parentWidth;
|
int pwidth = 0;
|
||||||
int pheight = parentHeight;
|
int pheight = 0;
|
||||||
if (parentWidth != SIZE_UNSPECIFIED)
|
if (parentWidth != SIZE_UNSPECIFIED)
|
||||||
pwidth -= m.left + m.right + p.left + p.right;
|
pwidth = parentWidth - (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 = parentHeight - (m.top + m.bottom + p.top + p.bottom);
|
||||||
int reservedForEmptySpace = parentWidth / 20;
|
int reservedForEmptySpace = parentWidth / 20;
|
||||||
if (reservedForEmptySpace > 40.pointsToPixels)
|
if (reservedForEmptySpace > 40.pointsToPixels)
|
||||||
reservedForEmptySpace = 40.pointsToPixels;
|
reservedForEmptySpace = 40.pointsToPixels;
|
||||||
|
@ -785,17 +789,14 @@ class FilePathPanelButtons : WidgetGroupDefaultDrawing {
|
||||||
bool exceeded = false;
|
bool exceeded = false;
|
||||||
for (int i = 0; i < _children.count; i++) {
|
for (int i = 0; i < _children.count; i++) {
|
||||||
Widget item = _children.get(i);
|
Widget item = _children.get(i);
|
||||||
item.visibility = Visibility.Visible;
|
|
||||||
item.measure(pwidth, pheight);
|
item.measure(pwidth, pheight);
|
||||||
if (sz.y < item.measuredHeight)
|
if (sz.y < item.measuredHeight)
|
||||||
sz.y = item.measuredHeight;
|
sz.y = item.measuredHeight;
|
||||||
if (sz.x + item.measuredWidth > pwidth) {
|
if (sz.x + item.measuredWidth > pwidth) {
|
||||||
exceeded = true;
|
exceeded = true;
|
||||||
}
|
}
|
||||||
if (!exceeded || i == 0) // at least one item must be visible
|
if (!exceeded || i == 0) // at least one item must be measured
|
||||||
sz.x += item.measuredWidth;
|
sz.x += item.measuredWidth;
|
||||||
else
|
|
||||||
item.visibility = Visibility.Gone;
|
|
||||||
}
|
}
|
||||||
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
|
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ enum WindowFlag : uint {
|
||||||
Fullscreen = 2,
|
Fullscreen = 2,
|
||||||
/// modal window - grabs input focus
|
/// modal window - grabs input focus
|
||||||
Modal = 4,
|
Modal = 4,
|
||||||
|
/// measure window size on window.show() - helps if you want scrollWindow but on show() you want to set window to mainWidget measured size
|
||||||
|
MeasureSize = 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Window states
|
/// Window states
|
||||||
|
|
|
@ -352,6 +352,9 @@ class SDLWindow : Window {
|
||||||
}
|
}
|
||||||
if (_mainWidget) {
|
if (_mainWidget) {
|
||||||
_mainWidget.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
|
_mainWidget.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
|
||||||
|
if (flags & WindowFlag.MeasureSize) {
|
||||||
|
resizeWindow(Point(_mainWidget.measuredWidth, _mainWidget.measuredHeight));
|
||||||
|
}
|
||||||
adjustWindowOrContentSize(_mainWidget.measuredWidth, _mainWidget.measuredHeight);
|
adjustWindowOrContentSize(_mainWidget.measuredWidth, _mainWidget.measuredHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,8 +402,17 @@ class SDLWindow : Window {
|
||||||
res = true;
|
res = true;
|
||||||
break;
|
break;
|
||||||
case WindowState.normal:
|
case WindowState.normal:
|
||||||
if (_windowState != WindowState.normal)
|
if (_windowState != WindowState.normal) {
|
||||||
SDL_RestoreWindow(_win);
|
SDL_RestoreWindow(_win);
|
||||||
|
version(linux) {
|
||||||
|
// some SDL versions, reset windows size and position to values from create window (SDL 2.0.4) on linux (don't know how it works on macOS)
|
||||||
|
if (newWindowRect.bottom == int.min && newWindowRect.right == int.min)
|
||||||
|
SDL_SetWindowSize(_win, _windowRect.right, _windowRect.bottom);
|
||||||
|
|
||||||
|
if (newWindowRect.top == int.min && newWindowRect.left == int.min)
|
||||||
|
SDL_SetWindowPosition(_win, _windowRect.left, _windowRect.top);
|
||||||
|
}
|
||||||
|
}
|
||||||
res = true;
|
res = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -432,9 +432,10 @@ class Win32Window : Window {
|
||||||
_mainWidget = new Widget();
|
_mainWidget = new Widget();
|
||||||
}
|
}
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
|
|
||||||
if (_mainWidget) {
|
if (_mainWidget) {
|
||||||
_mainWidget.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
|
_mainWidget.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
|
||||||
|
if (flags & WindowFlag.MeasureSize)
|
||||||
|
resizeWindow(Point(_mainWidget.measuredWidth, _mainWidget.measuredHeight));
|
||||||
adjustWindowOrContentSize(_mainWidget.measuredWidth, _mainWidget.measuredHeight);
|
adjustWindowOrContentSize(_mainWidget.measuredWidth, _mainWidget.measuredHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,26 +488,34 @@ class Win32Window : Window {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
res = true;
|
||||||
}
|
}
|
||||||
return true;
|
break;
|
||||||
case WindowState.maximized:
|
case WindowState.maximized:
|
||||||
if (_windowState != WindowState.maximized || activate)
|
if (_windowState != WindowState.maximized || activate) {
|
||||||
ShowWindow(_hwnd, activate ? SW_SHOWMAXIMIZED : SW_MAXIMIZE);
|
ShowWindow(_hwnd, activate ? SW_SHOWMAXIMIZED : SW_MAXIMIZE);
|
||||||
return true;
|
res = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case WindowState.minimized:
|
case WindowState.minimized:
|
||||||
if (_windowState != WindowState.minimized || activate)
|
if (_windowState != WindowState.minimized || activate) {
|
||||||
ShowWindow(_hwnd, activate ? SW_SHOWMINIMIZED : SW_MINIMIZE);
|
ShowWindow(_hwnd, activate ? SW_SHOWMINIMIZED : SW_MINIMIZE);
|
||||||
return true;
|
res = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case WindowState.hidden:
|
case WindowState.hidden:
|
||||||
if (_windowState != WindowState.hidden)
|
if (_windowState != WindowState.hidden) {
|
||||||
ShowWindow(_hwnd, SW_HIDE);
|
ShowWindow(_hwnd, SW_HIDE);
|
||||||
return true;
|
res = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case WindowState.normal:
|
case WindowState.normal:
|
||||||
if (_windowState != WindowState.normal || activate) {
|
if (_windowState != WindowState.normal || activate) {
|
||||||
ShowWindow(_hwnd, activate ? SW_SHOWNORMAL : SW_SHOWNA); // SW_RESTORE
|
ShowWindow(_hwnd, activate ? SW_SHOWNORMAL : SW_SHOWNA); // SW_RESTORE
|
||||||
|
res = true;
|
||||||
}
|
}
|
||||||
res = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -519,13 +528,13 @@ class Win32Window : Window {
|
||||||
// no position specified
|
// no position specified
|
||||||
if (newWindowRect.bottom != int.min && newWindowRect.right != int.min) {
|
if (newWindowRect.bottom != int.min && newWindowRect.right != int.min) {
|
||||||
// change size only
|
// change size only
|
||||||
SetWindowPos(_hwnd, NULL, 0, 0, newWindowRect.right, newWindowRect.bottom, flags | SWP_NOMOVE);
|
SetWindowPos(_hwnd, NULL, 0, 0, newWindowRect.right + 2 * GetSystemMetrics(SM_CXDLGFRAME), newWindowRect.bottom + GetSystemMetrics(SM_CYCAPTION) + 2 * GetSystemMetrics(SM_CYDLGFRAME), flags | SWP_NOMOVE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (newWindowRect.bottom != int.min && newWindowRect.right != int.min) {
|
if (newWindowRect.bottom != int.min && newWindowRect.right != int.min) {
|
||||||
// change size and position
|
// change size and position
|
||||||
SetWindowPos(_hwnd, NULL, newWindowRect.left, newWindowRect.top, newWindowRect.width, newWindowRect.height, flags);
|
SetWindowPos(_hwnd, NULL, newWindowRect.left, newWindowRect.top, newWindowRect.right + 2 * GetSystemMetrics(SM_CXDLGFRAME), newWindowRect.bottom + GetSystemMetrics(SM_CYCAPTION) + 2 * GetSystemMetrics(SM_CYDLGFRAME), flags);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// change position only
|
// change position only
|
||||||
|
|
|
@ -430,6 +430,8 @@ class X11Window : DWindow {
|
||||||
}
|
}
|
||||||
if (_mainWidget) {
|
if (_mainWidget) {
|
||||||
_mainWidget.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
|
_mainWidget.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
|
||||||
|
if (flags & WindowFlag.MeasureSize)
|
||||||
|
resizeWindow(Point(_mainWidget.measuredWidth, _mainWidget.measuredHeight));
|
||||||
_windowRect.right = _dx;// hack to set windowRect, remove when _windowRect will be full supported on X11
|
_windowRect.right = _dx;// hack to set windowRect, remove when _windowRect will be full supported on X11
|
||||||
_windowRect.bottom = _dy;
|
_windowRect.bottom = _dy;
|
||||||
adjustWindowOrContentSize(_mainWidget.measuredWidth, _mainWidget.measuredHeight);
|
adjustWindowOrContentSize(_mainWidget.measuredWidth, _mainWidget.measuredHeight);
|
||||||
|
|
|
@ -59,7 +59,7 @@ import dlangui.widgets.scroll;
|
||||||
import dlangui.widgets.menu;
|
import dlangui.widgets.menu;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
import std.container.rbtree;
|
import std.container.rbtree;
|
||||||
import std.algorithm : equal;
|
import std.algorithm : equal, min;
|
||||||
|
|
||||||
/// cellPopupMenu signal handler interface
|
/// cellPopupMenu signal handler interface
|
||||||
interface CellPopupMenuHandler {
|
interface CellPopupMenuHandler {
|
||||||
|
@ -1534,6 +1534,32 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int _minVisibleCols = 2;
|
||||||
|
protected int _minVisibleRows = 2;
|
||||||
|
|
||||||
|
/// returns number of columns from 0 that are taken to measure minimum visible width
|
||||||
|
@property int minVisibleCols() {
|
||||||
|
return _minVisibleCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// sets number of columns from 0 that are taken to measure minimum visible width
|
||||||
|
@property void minVisibleCols(int newMinVisibleCols) {
|
||||||
|
_minVisibleCols = newMinVisibleCols;
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// returns number of rows from 0 that are taken to measure minimum visible height
|
||||||
|
@property int minVisibleRows() {
|
||||||
|
return _minVisibleRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// sets number of rows from 0 that are taken to measure minimum visible height, if there are too little rows last row height is multiplied
|
||||||
|
@property void minVisibleRows(int newMinVisibleRows) {
|
||||||
|
_minVisibleRows = newMinVisibleRows;
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// calculate minimum size of widget
|
/// calculate minimum size of widget
|
||||||
override Point minimumVisibleContentSize() {
|
override Point minimumVisibleContentSize() {
|
||||||
Point sz;
|
Point sz;
|
||||||
|
@ -1542,17 +1568,17 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
|
||||||
sz.y = 100;
|
sz.y = 100;
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
// width:
|
// width:
|
||||||
if (_cols < 2)
|
for (int i = 0 ; i < min(_cols, _minVisibleCols) ; i++)
|
||||||
sz.x = _colWidths[0];
|
sz.x += _colWidths[i];
|
||||||
else
|
|
||||||
sz.x = _colWidths[0] + _colWidths[1];
|
|
||||||
|
|
||||||
// height
|
// height
|
||||||
if (_rows < 2)
|
for (int i = 0 ; i < min(_rows, _minVisibleRows) ; i++)
|
||||||
sz.y = _rowHeights[0];
|
sz.y += _rowHeights[i];
|
||||||
else
|
|
||||||
sz.y = _rowHeights[0] + _rowHeights[1];
|
if (_rows<_minVisibleRows)
|
||||||
|
sz.y += (_minVisibleRows - _rows) * _rowHeights[_rows-1];
|
||||||
|
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue