issue 63-Text Height and Width incorrectly calculated
MODIFY
builder/src/main/java/builder/models/TextBoxModel.java
builder/src/main/java/builder/models/TextBoxModel.java
@@ -27,6 +27,7 @@ package builder.models;
import java.awt.Color;
import java.awt.Dimension;
+import java.awt.Font;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -35,6 +36,7 @@ import javax.swing.JTextField;
import builder.common.ColorFactory;
import builder.common.EnumFactory;
import builder.common.FontFactory;
+import builder.common.FontItem;
import builder.events.MsgBoard;
import builder.events.MsgEvent;
import builder.prefs.GeneralEditor;
@@ -276,10 +278,33 @@ public class TextBoxModel extends WidgetModel {
* Calc sizes.
*/
private void calcSizes() {
- Dimension nChSz = ff.measureChar(getFontDisplayName());
- int nCols = (getWidth() - 33) / nChSz.width;
- // rows must be greater than actual or the scroll bar will be disabled
- int nRows = ((getHeight() - 18) / nChSz.height) + 1;
+ int nCols;
+ int nRows;
+ String name = getFontDisplayName();
+ FontItem item = ff.getFontItem(name);
+ if (!item.getDisplayName().equals(name)) {
+ data[PROP_FONT][PROP_VAL_VALUE] = item.getDisplayName();
+ data[PROP_FONT_ENUM][PROP_VAL_VALUE] = item.getFontId();
+ }
+ Font font = ff.getFont(item.getDisplayName());
+ // calculate the real sizes of our display font
+ String strText = "AaBbCcDd%$";
+ // now figure out the rect size needed on the target platform
+ // that we show to our user and also push out during code generation.
+ if (getFontDisplayName().startsWith("BuiltIn")) {
+ Dimension nChSz = ff.measureAdafruitText(strText,getFontDisplayName());
+ nCols = (getWidth() - 33) / (nChSz.width / 10);
+ nRows = ((getHeight() - 10) / nChSz.height) + 1;
+ System.out.println("getWidth(): " + getWidth() + " nChSz.width: " + nChSz.width);
+ System.out.println("getHeight(): " + getHeight() + " nChSz.height: " + nChSz.height);
+ } else {
+ // if font is not one of the built-in fonts than actual size is correct even though font is scaled.
+ Dimension d = ff.measureText(strText, font);
+ nCols = (getWidth() - 33) / (d.width / 10);
+ nRows = (getHeight() / d.height) + 10;
+ System.out.println("getWidth(): " + getWidth() + " d.width: " + d.width);
+ System.out.println("getHeight(): " + getHeight() + " d.height: " + d.height);
+ }
data[PROP_ROWS][PROP_VAL_VALUE]= Integer.valueOf(nRows);
data[PROP_COLS][PROP_VAL_VALUE]=Integer.valueOf(nCols);
}

MODIFY
builder/src/main/java/builder/models/TextModel.java
builder/src/main/java/builder/models/TextModel.java
@@ -518,12 +518,12 @@ public class TextModel extends WidgetModel {
// that we show to our user and also push out during code generation.
if (getFontDisplayName().startsWith("BuiltIn")) {
Dimension nChSz = ff.measureAdafruitText(getText(),getFontDisplayName());
- if (nChSz.width > getWidth()) setWidth(nChSz.width);
- if (nChSz.height > getHeight()) setHeight(nChSz.height);
+ if (nChSz.width > getTargetWidth()) setWidth(nChSz.width);
+ if (nChSz.height > getTargetHeight()) setHeight(nChSz.height);
} else {
// if font is not one of the built-in fonts than actual size is correct even though font is scaled.
- if (d.width > getWidth()) setWidth(d.width);
- if (d.height > getHeight()) setHeight(d.height);
+ if (d.width > getTargetWidth()) setWidth(d.width);
+ if (d.height > getTargetHeight()) setHeight(d.height);
}
if (fireUpdates) {
fireTableCellUpdated(PROP_WIDTH, COLUMN_VALUE);

MODIFY
builder/src/main/java/resources/templates/arduino.t
builder/src/main/java/resources/templates/arduino.t
@@ -217,7 +217,7 @@ bool CbSlidePos(void* pvGui,void* pvElemRef,int16_t nPos)
// Create textbox
pElemRef = gslc_ElemXTextboxCreate(&m_gui,$<WIDGET_ENUM>,$<PAGE_ENUM>,&m_sTextbox$<ID>,
- (gslc_tsRect){$<X>+2,$<Y>+4,$<WIDTH>-23,$<HEIGHT>-8},$<FONT_ID>,(char*)&m_acTextboxBuf$<ID>,$<ROWS>,$<COLS>);
+ (gslc_tsRect){$<X>+2,$<Y>+4,$<WIDTH>-23,$<HEIGHT>-5},$<FONT_ID>,(char*)&m_acTextboxBuf$<ID>,$<ROWS>,$<COLS>);
gslc_ElemXTextboxWrapSet(&m_gui,pElemRef,$<CHECKED>);
gslc_ElemSetCol(&m_gui,pElemRef,$<FRAME_COLOR>,$<FILL_COLOR>,$<GLOW_COLOR>);

MODIFY
builder/src/main/java/resources/templates/arduino_min.t
builder/src/main/java/resources/templates/arduino_min.t
@@ -226,7 +226,7 @@ bool CbSlidePos(void* pvGui,void* pvElemRef,int16_t nPos)
// Create textbox $<WIDGET_ENUM>
// - NOTE: XTextbox does not have a FLASH-based version yet (ElemXTextboxCreate_P)
pElemRef = gslc_ElemXTextboxCreate(&m_gui,$<WIDGET_ENUM>,$<PAGE_ENUM>,&m_sTextbox$<ID>,
- (gslc_tsRect){$<X>+2,$<Y>+4,$<WIDTH>-23,$<HEIGHT>-8},$<FONT_ID>,(char*)&m_acTextboxBuf$<ID>,$<ROWS>,$<COLS>);
+ (gslc_tsRect){$<X>+2,$<Y>+4,$<WIDTH>-23,$<HEIGHT>-5},$<FONT_ID>,(char*)&m_acTextboxBuf$<ID>,$<ROWS>,$<COLS>);
gslc_ElemXTextboxWrapSet(&m_gui,pElemRef,$<CHECKED>);
gslc_ElemSetCol(&m_gui,pElemRef,$<FRAME_COLOR>,$<FILL_COLOR>,$<FILL_COLOR>);

MODIFY
builder/src/main/java/resources/templates/linux.t
builder/src/main/java/resources/templates/linux.t
@@ -225,7 +225,7 @@ bool CbSlidePos(void* pvGui,void* pvElemRef,int16_t nPos)
// Create textbox
pElemRef = gslc_ElemXTextboxCreate(&m_gui,$<WIDGET_ENUM>,$<PAGE_ENUM>,&m_sTextbox$<ID>,
- (gslc_tsRect){$<X>+2,$<Y>+4,$<WIDTH>-23,$<HEIGHT>-8},$<FONT_ID>,(char*)&m_acTextboxBuf$<ID>,$<ROWS>,$<COLS>);
+ (gslc_tsRect){$<X>+2,$<Y>+4,$<WIDTH>-23,$<HEIGHT>-5},$<FONT_ID>,(char*)&m_acTextboxBuf$<ID>,$<ROWS>,$<COLS>);
gslc_ElemXTextboxWrapSet(&m_gui,pElemRef,$<CHECKED>);
gslc_ElemSetCol(&m_gui,pElemRef,$<FRAME_COLOR>,$<FILL_COLOR>,$<GLOW_COLOR>);

issue 63-Text Height and Width incorrectly calculated