From 98f90165ba246c25625a842f3de16f4ee804b36d Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 30 Jan 2015 10:59:07 +0300 Subject: [PATCH] fix issue #42 - editors update after loading of file; fix theme --- src/dlangui/widgets/editors.d | 35 ++++++++++++++++---- src/dlangui/widgets/tabs.d | 9 ++++- views/res/mdpi/toolbar_control_normal.9.png | Bin 247 -> 249 bytes views/res/theme_default.xml | 13 ++++---- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index acff5c6e..5e323fdd 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1149,6 +1149,9 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction protected uint _iconsPaneWidth = 16; protected uint _foldingPaneWidth = 16; protected uint _modificationMarksPaneWidth = 8; + /// when true, call measureVisibileText on next layout + protected bool _contentChanged = true; + /// Modified state change listener Signal!ModifiedStateListener onModifiedStateChangeListener; @@ -1496,23 +1499,27 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction override void onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source) { //Log.d("onContentChange rangeBefore=", rangeBefore, " rangeAfter=", rangeAfter, " text=", operation.content); - updateMaxLineWidth(); - measureVisibleText(); if (source is this) { if (operation.action == EditAction.ReplaceContent) { - // loaded from file + _contentChanged = true; + // fully replaced, e.g., loaded from file or text property is assigned _caretPos = rangeAfter.end; _selectionRange.start = _caretPos; _selectionRange.end = _caretPos; + updateMaxLineWidth(); + measureVisibleText(); ensureCaretVisible(); correctCaretPos(); requestLayout(); } else if (operation.action == EditAction.SaveContent) { // saved } else { - _caretPos = rangeAfter.end; + _contentChanged = true; + _caretPos = rangeAfter.end; _selectionRange.start = _caretPos; _selectionRange.end = _caretPos; + updateMaxLineWidth(); + measureVisibleText(); ensureCaretVisible(); } } else { @@ -2283,6 +2290,10 @@ class EditLine : EditWidgetBase { _clientRect = rc; applyMargins(_clientRect); applyPadding(_clientRect); + if (_contentChanged) { + measureVisibleText(); + _contentChanged = false; + } } @@ -2401,6 +2412,18 @@ class EditBox : EditWidgetBase { return this; } + /// Set widget rectangle to specified value and layout widget contents. (Step 2 of two phase layout). + override void layout(Rect rc) { + if (visibility == Visibility.Gone) { + return; + } + super.layout(rc); + if (_contentChanged) { + measureVisibleText(); + _contentChanged = false; + } + } + override protected Point measureVisibleText() { Point sz; FontRef font = font(); @@ -2442,7 +2465,7 @@ class EditBox : EditWidgetBase { /// update verticat scrollbar widget position override protected void updateVScrollBar() { - int visibleLines = _clientRect.height / _lineHeight; // fully visible lines + int visibleLines = _lineHeight ? _clientRect.height / _lineHeight : 1; // fully visible lines if (visibleLines < 1) visibleLines = 1; _vscrollbar.setRange(0, _content.length - 1); @@ -2494,7 +2517,7 @@ class EditBox : EditWidgetBase { _caretPos.line = _content.length - 1; if (_caretPos.line < 0) _caretPos.line = 0; - int visibleLines = _clientRect.height / _lineHeight; // fully visible lines + int visibleLines = _lineHeight > 0 ? _clientRect.height / _lineHeight : 1; // fully visible lines if (visibleLines < 1) visibleLines = 1; if (_caretPos.line < _firstVisibleLine) { diff --git a/src/dlangui/widgets/tabs.d b/src/dlangui/widgets/tabs.d index 7b3bb9a2..6eda33b5 100644 --- a/src/dlangui/widgets/tabs.d +++ b/src/dlangui/widgets/tabs.d @@ -531,12 +531,16 @@ class TabHost : FrameLayout, TabHandler { return this; } + protected Visibility _hiddenTabsVisibility = Visibility.Invisible; + @property Visibility hiddenTabsVisibility() { return _hiddenTabsVisibility; } + @property void hiddenTabsVisibility(Visibility v) { _hiddenTabsVisibility = v; } + /// signal of tab change (e.g. by clicking on tab header) Signal!TabHandler onTabChangedListener; protected override void onTabChanged(string newActiveTabId, string previousTabId) { if (newActiveTabId !is null) { - showChild(newActiveTabId, Visibility.Invisible, true); + showChild(newActiveTabId, _hiddenTabsVisibility, true); } if (onTabChangedListener.assigned) onTabChangedListener(newActiveTabId, previousTabId); @@ -671,6 +675,9 @@ class TabWidget : VerticalLayout, TabHandler, TabCloseHandler { _tabControl.renameTab(index, name); } + @property Visibility hiddenTabsVisibility() { return _tabHost.hiddenTabsVisibility; } + @property void hiddenTabsVisibility(Visibility v) { _tabHost.hiddenTabsVisibility = v; } + /// select tab void selectTab(string ID, bool updateAccess = true) { _tabHost.selectTab(ID, updateAccess); diff --git a/views/res/mdpi/toolbar_control_normal.9.png b/views/res/mdpi/toolbar_control_normal.9.png index 3e94da9c4082a60b1d962bc228c17235fe9b4070..fbfb7acba51e3f7d41f6e9f2dc0c2fa9dd3bd673 100644 GIT binary patch delta 168 zcmey)_>*yhmT4cuY=%8YSY)jj7#KJUJR*x37`TN&n2}-D90{Nxdx@v7EBk#$Id)^A z1?~L1fkJH)0 z^U9f4TzQa~YM{K8_wVmid*!n+XPDMHN?gmo?HSvg7}^QcwMR$w`tK7p44w~E(;P2U RivsOn@O1TaS?83{1OSSfH`@RJ delta 166 zcmey#_?>ZrmT5nOAcNrEg{7Sg3=EtF9+AZi4BWyX%*Zfnjs#GUy~NYkmHj@WD4!yi z@cHNsK%th2@kVI}fZ&2v;l=;<_5T7`xBJC>`Tu_UUmhPG6DA*#7EQkcXCD8Uzf4cg zwBpKxz~=U;2YarVeF3WIF)23m&6?1a66q!u5vr6Z!K&|l@~fSZJcCtN-lJXrgYtkj OFnGH9xvX - @@ -241,7 +242,7 @@ backgroundColor="#D0D0D0" layoutWidth="FILL_PARENT" layoutHeight="WRAP_CONTENT" - padding="4,4,4,4" + padding="1,1,1,1" layoutWeight="0" />