()
| 940 | } |
| 941 | |
| 942 | void initAutoResize() { |
| 943 | if (autoSizeMode) { |
| 944 | Style s = getUnselectedStyle(); |
| 945 | int p = s.getHorizontalPadding(); |
| 946 | int w = getWidth(); |
| 947 | if (w > p + 10) { |
| 948 | if (originalFont == null) { |
| 949 | originalFont = s.getFont(); |
| 950 | } else { |
| 951 | if (w == widthAtLastCheck) { |
| 952 | return; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | Font currentFont = getUnselectedStyle().getFont(); |
| 957 | float fontSize = currentFont.getPixelSize(); |
| 958 | if (fontSize < 1) { |
| 959 | Log.p("Autosize disabled probably because component wasn't using native fonts for UIID: " + getUIID()); |
| 960 | autoSizeMode = false; |
| 961 | return; |
| 962 | } |
| 963 | widthAtLastCheck = w; |
| 964 | autoSizeMode = false; |
| 965 | int currentWidth = calcPreferredSize().getWidth(); |
| 966 | int maxSizePixel = Display.getInstance().convertToPixels(maxAutoSize); |
| 967 | while (currentWidth < w) { |
| 968 | fontSize++; |
| 969 | if (fontSize >= maxSizePixel) { |
| 970 | fontSize = maxSizePixel; |
| 971 | currentFont = currentFont.derive(maxSizePixel, currentFont.getStyle()); |
| 972 | getAllStyles().setFont(currentFont); |
| 973 | currentWidth = calcPreferredSize().getWidth(); |
| 974 | break; |
| 975 | } |
| 976 | currentFont = currentFont.derive(fontSize, currentFont.getStyle()); |
| 977 | getAllStyles().setFont(currentFont); |
| 978 | currentWidth = calcPreferredSize().getWidth(); |
| 979 | } |
| 980 | int minSizePixel = Display.getInstance().convertToPixels(minAutoSize); |
| 981 | while (currentWidth > w) { |
| 982 | fontSize--; |
| 983 | if (fontSize <= minSizePixel) { |
| 984 | currentFont = currentFont.derive(minSizePixel, currentFont.getStyle()); |
| 985 | getAllStyles().setFont(currentFont); |
| 986 | break; |
| 987 | } |
| 988 | currentFont = currentFont.derive(fontSize, currentFont.getStyle()); |
| 989 | getAllStyles().setFont(currentFont); |
| 990 | currentWidth = calcPreferredSize().getWidth(); |
| 991 | } |
| 992 | autoSizeMode = true; |
| 993 | } |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | /// {@inheritDoc} |
| 998 | @Override |
no test coverage detected