Change the way how some widgets are measured, minimumVisibleContentSize() for widgets which content can be bigger than widget size.

This commit is contained in:
and3md 2017-06-25 13:53:23 +02:00
parent cca2b28ce9
commit 110fc9122e
4 changed files with 50 additions and 1 deletions

View File

@ -1533,6 +1533,29 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
sz.y += _rowHeights[i];
return sz;
}
/// calculate minimum size of widget
override Point minimumVisibleContentSize() {
Point sz;
if (_cols == 0 || _rows == 0) {
sz.x = 100;
sz.y = 100;
return sz;
}
// width:
if (_cols < 2)
sz.x = _colWidths[0];
else
sz.x = _colWidths[0] + _colWidths[1];
// height
if (_rows < 2)
sz.y = _rowHeights[0];
else
sz.y = _rowHeights[0] + _rowHeights[1];
return sz;
}
override protected void drawClient(DrawBuf buf) {
if (!_cols || !_rows)

View File

@ -942,6 +942,11 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
if (_adapter)
_adapter.onThemeChanged();
}
/// sets minimum size for the list, override to change
Point minimumVisibleContentSize() {
return Point(100, 100);
}
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
override void measure(int parentWidth, int parentHeight) {
@ -953,6 +958,15 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
_itemSizes.length = itemCount;
Rect m = margins;
Rect p = padding;
// set widget area to small when first measure
if (parentWidth == SIZE_UNSPECIFIED && parentHeight == SIZE_UNSPECIFIED)
{
Point sz = minimumVisibleContentSize;
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
return;
}
// calc size constraints for children
int pwidth = parentWidth;
int pheight = parentHeight;
@ -1041,6 +1055,7 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
}
}
measuredContent(parentWidth, parentHeight, sz.x + _sbsz.x, sz.y + _sbsz.y);
if (_scrollbar.visibility == oldScrollbarVisibility) {
_needLayout = oldNeedLayout;
_scrollbar.cancelLayout();

View File

@ -273,6 +273,11 @@ class ScrollWidgetBase : WidgetGroup, OnScrollHandler {
return sz;
}
// override to set minimum scrollwidget size - default 100x100
Point minimumVisibleContentSize() {
return Point(100,100);
}
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
override void measure(int parentWidth, int parentHeight) {
if (visibility == Visibility.Gone) {
@ -280,6 +285,7 @@ class ScrollWidgetBase : WidgetGroup, OnScrollHandler {
}
Rect m = margins;
Rect p = padding;
// calc size constraints for children
int pwidth = parentWidth;
int pheight = parentHeight;
@ -293,13 +299,14 @@ class ScrollWidgetBase : WidgetGroup, OnScrollHandler {
if (_vscrollbar && _vscrollbarMode == ScrollBarMode.Visible) {
_vscrollbar.measure(pwidth, pheight);
}
Point sz = fullContentSize();
Point sz = minimumVisibleContentSize();
if (_hscrollbar && _hscrollbarMode == ScrollBarMode.Visible) {
sz.y += _hscrollbar.measuredHeight;
}
if (_vscrollbar && _vscrollbarMode == ScrollBarMode.Visible) {
sz.x += _vscrollbar.measuredWidth;
}
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
}

View File

@ -813,6 +813,10 @@ class TreeWidgetBase : ScrollWidget, OnTreeContentChangeListener, OnTreeStateCh
super.layout(rc);
}
override Point minimumVisibleContentSize() {
return Point(200,200);
}
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
override void measure(int parentWidth, int parentHeight) {
if (visibility == Visibility.Gone) {