Set LineEdit measured size to "aaaaa" size and EditBox to "aaaaa/naaaaa".

This commit is contained in:
and3md 2017-06-25 13:56:37 +02:00
parent 110fc9122e
commit 6980a9b2e3
1 changed files with 30 additions and 4 deletions

View File

@ -1900,6 +1900,10 @@ class EditLine : EditWidgetBase {
protected int[] _measuredTextWidths; protected int[] _measuredTextWidths;
protected Point _measuredTextSize; protected Point _measuredTextSize;
protected Point _measuredTextToSetWidgetSize;
protected dstring _textToSetWidgetSize = "aaaaa"d;
protected int[] _measuredTextToSetWidgetSizeWidths;
protected dchar _passwordChar = 0; protected dchar _passwordChar = 0;
/// password character - 0 for normal editor, some character, e.g. '*' to hide text by replacing all characters with this char /// password character - 0 for normal editor, some character, e.g. '*' to hide text by replacing all characters with this char
@property dchar passwordChar() { return _passwordChar; } @property dchar passwordChar() { return _passwordChar; }
@ -1972,17 +1976,27 @@ class EditLine : EditWidgetBase {
//Point sz = font.textSize(text); //Point sz = font.textSize(text);
_measuredText = applyPasswordChar(text); _measuredText = applyPasswordChar(text);
_measuredTextWidths.length = _measuredText.length; _measuredTextWidths.length = _measuredText.length;
int charsMeasured = font.measureText(_measuredText, _measuredTextWidths, int.max, tabSize); int charsMeasured = font.measureText(_measuredText, _measuredTextWidths, MAX_WIDTH_UNSPECIFIED, tabSize);
_measuredTextSize.x = charsMeasured > 0 ? _measuredTextWidths[charsMeasured - 1]: 0; _measuredTextSize.x = charsMeasured > 0 ? _measuredTextWidths[charsMeasured - 1]: 0;
_measuredTextSize.y = font.height; _measuredTextSize.y = font.height;
return _measuredTextSize; return _measuredTextSize;
} }
protected Point measureTextToSetWidgetSize() {
FontRef font = font();
_measuredTextToSetWidgetSizeWidths.length = _textToSetWidgetSize.length;
int charsMeasured = font.measureText(_textToSetWidgetSize, _measuredTextToSetWidgetSizeWidths, MAX_WIDTH_UNSPECIFIED, tabSize);
_measuredTextToSetWidgetSize.x = charsMeasured > 0 ? _measuredTextToSetWidgetSizeWidths[charsMeasured - 1]: 0;
_measuredTextToSetWidgetSize.y = font.height;
return _measuredTextToSetWidgetSize;
}
/// measure /// measure
override void measure(int parentWidth, int parentHeight) { override void measure(int parentWidth, int parentHeight) {
updateFontProps(); updateFontProps();
measureVisibleText(); measureVisibleText();
measuredContent(parentWidth, parentHeight, _measuredTextSize.x + _leftPaneWidth, _measuredTextSize.y); measureTextToSetWidgetSize();
measuredContent(parentWidth, parentHeight, _measuredTextToSetWidgetSize.x + _leftPaneWidth, _measuredTextToSetWidgetSize.y);
} }
override bool handleAction(const Action a) { override bool handleAction(const Action a) {
@ -2129,6 +2143,10 @@ class EditBox : EditWidgetBase {
protected CustomCharProps[][] _visibleLinesHighlights; protected CustomCharProps[][] _visibleLinesHighlights;
protected CustomCharProps[][] _visibleLinesHighlightsBuf; protected CustomCharProps[][] _visibleLinesHighlightsBuf;
protected Point _measuredTextToSetWidgetSize;
protected dstring _textToSetWidgetSize = "aaaaa/naaaaa"d;
protected int[] _measuredTextToSetWidgetSizeWidths;
override protected int lineCount() { override protected int lineCount() {
return _content.length; return _content.length;
} }
@ -2641,6 +2659,16 @@ class EditBox : EditWidgetBase {
return textSz; return textSz;
} }
// override to set minimum scrollwidget size - default 100x100
override protected Point minimumVisibleContentSize() {
FontRef font = font();
_measuredTextToSetWidgetSizeWidths.length = _textToSetWidgetSize.length;
int charsMeasured = font.measureText(_textToSetWidgetSize, _measuredTextToSetWidgetSizeWidths, MAX_WIDTH_UNSPECIFIED, tabSize);
_measuredTextToSetWidgetSize.x = charsMeasured > 0 ? _measuredTextToSetWidgetSizeWidths[charsMeasured - 1]: 0;
_measuredTextToSetWidgetSize.y = font.height;
return _measuredTextToSetWidgetSize;
}
/// measure /// measure
override void measure(int parentWidth, int parentHeight) { override void measure(int parentWidth, int parentHeight) {
if (visibility == Visibility.Gone) { if (visibility == Visibility.Gone) {
@ -2657,8 +2685,6 @@ class EditBox : EditWidgetBase {
} }
super.measure(parentWidth, parentHeight); super.measure(parentWidth, parentHeight);
// do we need to add vsbwidth, hsbheight ???
//measuredContent(parentWidth, parentHeight, textSz.x + vsbwidth, textSz.y + hsbheight);
} }