Commit 108f4eb6 authored by Gordon Lu's avatar Gordon Lu Committed by Susan Rati Lane

Fixed FontSize bugs of CheckBox and Switch

parent 79c49d35
......@@ -7,6 +7,7 @@
package com.google.appinventor.client.editor.simple.components;
import com.google.appinventor.client.editor.simple.SimpleEditor;
import com.google.appinventor.client.editor.youngandroid.YaFormEditor;
import com.google.appinventor.client.editor.simple.components.utils.SVGPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
......@@ -141,6 +142,20 @@ public final class MockCheckBox extends MockToggleBase<HorizontalPanel> {
paintCheckBox(checked);
}
@Override
protected void setFontSizeProperty(String text) {
MockForm form = ((YaFormEditor) editor).getForm();
if (Float.parseFloat(text) == FONT_DEFAULT_SIZE
&& form != null
&& form.getPropertyValue("BigDefaultText").equals("True")) {
MockComponentsUtil.setWidgetFontSize(toggleWidget.getWidget(1), "24");
} else {
MockComponentsUtil.setWidgetFontSize(toggleWidget.getWidget(1), text);
}
updatePreferredSize();
}
@Override
public void onPropertyChange(String propertyName, String newValue) {
super.onPropertyChange(propertyName, newValue);
......
......@@ -6,6 +6,7 @@
package com.google.appinventor.client.editor.simple.components;
import com.google.appinventor.client.editor.simple.SimpleEditor;
import com.google.appinventor.client.editor.youngandroid.YaFormEditor;
import com.google.appinventor.client.editor.simple.components.utils.SVGPanel;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
......@@ -157,7 +158,15 @@ public final class MockSwitch extends MockToggleBase<HorizontalPanel> {
@Override
protected void setFontSizeProperty(String text) {
MockComponentsUtil.setWidgetFontSize(toggleWidget.getWidget(0), text);
MockForm form = ((YaFormEditor) editor).getForm();
if (Float.parseFloat(text) == FONT_DEFAULT_SIZE
&& form != null
&& form.getPropertyValue("BigDefaultText").equals("True")) {
MockComponentsUtil.setWidgetFontSize(toggleWidget.getWidget(0), "24");
} else {
MockComponentsUtil.setWidgetFontSize(toggleWidget.getWidget(0), text);
}
updatePreferredSize();
}
......
......@@ -30,6 +30,18 @@ abstract class MockToggleBase<T extends Widget> extends MockWrapper implements F
super(editor, type, icon);
}
@Override
protected void onAttach() {
super.onAttach();
((YaFormEditor) editor).getForm().addFormChangeListener(this);
}
@Override
protected void onDetach() {
super.onDetach();
((YaFormEditor) editor).getForm().removeFormChangeListener(this);
}
protected final Widget createClonedWidget() {
// We override updatePreferredSize directly, so this shouldn't be called.
throw new UnsupportedOperationException();
......@@ -46,6 +58,12 @@ abstract class MockToggleBase<T extends Widget> extends MockWrapper implements F
int hint = super.getHeightHint();
if (hint == MockVisibleComponent.LENGTH_PREFERRED) {
float height = Float.parseFloat(getPropertyValue(MockVisibleComponent.PROPERTY_NAME_FONTSIZE));
MockForm form = ((YaFormEditor) editor).getForm();
if (height == FONT_DEFAULT_SIZE
&& form != null
&& form.getPropertyValue("BigDefaultText").equals("True")) {
return 24;
}
return Math.round(height);
} else {
return hint;
......@@ -169,6 +187,7 @@ abstract class MockToggleBase<T extends Widget> extends MockWrapper implements F
public void onComponentPropertyChanged(MockComponent component, String propertyName, String propertyValue) {
if (component.getType().equals(MockForm.TYPE) && propertyName.equals("BigDefaultText")) {
setFontSizeProperty(getPropertyValue(PROPERTY_NAME_FONTSIZE));
updatePreferredSize();
refreshForm();
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment