Search in sources :

Example 1 with Span

use of com.codename1.ui.TextSelection.Span in project CodenameOne by codenameone.

the class SpanLabelTests2980 method runTest.

@Override
public boolean runTest() throws Exception {
    if (layout == null) {
        Layout[] layouts = new Layout[] { new FlowLayout(), BoxLayout.x(), BoxLayout.y() };
        for (Layout l : layouts) {
            layout = l;
            runTest();
        }
        return true;
    }
    System.out.println("Laying out SpanLabel with layout " + layout);
    Label label = new Label("Tap the following");
    Container cnt = new Container(layout) {

        @Override
        protected Dimension calcPreferredSize() {
            return new Dimension(label.getPreferredW(), CN.convertToPixels(1000));
        }

        @Override
        public int getWidth() {
            return label.getPreferredW();
        }

        @Override
        public int getHeight() {
            return CN.convertToPixels(1000);
        }
    };
    cnt.setScrollableX(false);
    cnt.setScrollableY(false);
    cnt.setWidth(label.getPreferredW());
    cnt.setHeight(CN.convertToPixels(1000));
    SpanLabel sl = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos.");
    sl.setName("TheSpanLabel");
    cnt.add(sl);
    cnt.add(new Button("Click Me"));
    cnt.setShouldCalcPreferredSize(true);
    cnt.layoutContainer();
    assertTrue(sl.getHeight() > label.getPreferredH() * 2, "Span Label height is too low for layout " + layout + ": was " + sl.getHeight() + " but should be at least " + (label.getPreferredH() * 2));
    SpanButton sb = new SpanButton("Tap the following button to open the gallery. You should be able to select multiple images and videos.");
    sb.setName("TheSpanButton");
    cnt.removeAll();
    cnt.add(sb);
    cnt.add(new Button("Click Me"));
    cnt.setShouldCalcPreferredSize(true);
    cnt.layoutContainer();
    assertTrue(sb.getHeight() > label.getPreferredH() * 2, "Span button height is too low for layout " + layout + ": was " + sb.getHeight() + " but should be at least " + (label.getPreferredH() * 2));
    testBorderLayout();
    return true;
}
Also used : FlowLayout(com.codename1.ui.layouts.FlowLayout) Layout(com.codename1.ui.layouts.Layout) BoxLayout(com.codename1.ui.layouts.BoxLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) SpanButton(com.codename1.components.SpanButton) SpanLabel(com.codename1.components.SpanLabel) SpanButton(com.codename1.components.SpanButton) Dimension(com.codename1.ui.geom.Dimension) SpanLabel(com.codename1.components.SpanLabel)

Example 2 with Span

use of com.codename1.ui.TextSelection.Span in project CodenameOne by codenameone.

the class SpanLabelTests2980 method testBorderLayout.

private void testBorderLayout() {
    System.out.println("Testing SpanLabel preferred size in BorderLayout.  https://github.com/codenameone/CodenameOne/issues/3000");
    // Button showPopUp = new Button("Show PopUp in Border Layout");
    Form f = new Form(BoxLayout.y());
    f.setName("testBorderLayout");
    // f.add(showPopUp);
    SpanLabel messageSpanLabel = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos. Tap the following button to open the gallery. You should be able to select multiple images and videos.");
    // showPopUp.addActionListener((e) -> {
    Runnable showPopup = () -> {
        messageSpanLabel.setName("messageSpanLabel");
        Container centerContainerOuter = new Container(new BorderLayout(CENTER_BEHAVIOR_CENTER));
        centerContainerOuter.add(CENTER, messageSpanLabel);
        Container layeredPane = getCurrentForm().getLayeredPane();
        layeredPane.setLayout(new LayeredLayout());
        layeredPane.add(centerContainerOuter);
        layeredPane.setVisible(true);
        getCurrentForm().revalidate();
    };
    // showPopUp.setName("showBorderLayout");
    f.show();
    waitForFormName("testBorderLayout");
    // clickButtonByName("showBorderLayout");
    showPopup.run();
    // give time for click to take effect
    waitFor(500);
    // (SpanLabel)findByName("messageSpanLabel");
    SpanLabel spanLabel = messageSpanLabel;
    Label l = new Label("Tap the following");
    assertTrue(spanLabel.getHeight() > l.getPreferredH() * 2, "Span Label height is too small.  Should be at least a few lines.");
    System.out.println("Finished SpanLabel BorderLayout test");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) CN.getCurrentForm(com.codename1.ui.CN.getCurrentForm) SpanLabel(com.codename1.components.SpanLabel) SpanLabel(com.codename1.components.SpanLabel) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 3 with Span

use of com.codename1.ui.TextSelection.Span in project CodenameOne by codenameone.

the class DefaultLookAndFeel method append.

private void append(TextSelection sel, Component l, Span span, String text, Font f, int posOffset, int x, int y, int h) {
    int len = text.length();
    int xPos = 0;
    int curPos = 1;
    // int ty = l.getAbsoluteY() - sel.getSelectionRoot().getAbsoluteY() - l.getY();
    while (curPos <= len) {
        int newXpos = f.stringWidth(text.substring(0, curPos));
        Char next = sel.newChar(posOffset + curPos - 1, x + xPos, y, newXpos - xPos, h);
        span.add(next);
        xPos = newXpos;
        curPos++;
    }
}
Also used : Char(com.codename1.ui.TextSelection.Char)

Example 4 with Span

use of com.codename1.ui.TextSelection.Span in project CodenameOne by codenameone.

the class DefaultLookAndFeel method calculateTextFieldSpan.

public Spans calculateTextFieldSpan(TextSelection sel, TextArea ta) {
    // setFG(g, ta);
    Span out = sel.newSpan(ta);
    // display ******** if it is a password field
    String displayText = getTextFieldString(ta);
    Style style = ta.getStyle();
    int x = 0;
    // ta.getCursorX();
    int cursorCharPosition = ta.hasFocus() ? ta.getCursorPosition() : 0;
    Font f = style.getFont();
    int cursorX = 0;
    int xPos = 0;
    int align = reverseAlignForBidi(ta);
    int displayX = 0;
    String inputMode = ta.getInputMode();
    int inputModeWidth = f.stringWidth(inputMode);
    // QWERTY devices don't quite have an input mode hide it also when we have a VK
    if (!Display.getInstance().platformUsesInputMode() || ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) {
        inputMode = "";
        inputModeWidth = 0;
    }
    if (ta.isSingleLineTextArea()) {
        // there is currently no support for CENTER aligned text fields
        if (align == Component.LEFT) {
            if (cursorCharPosition > 0) {
                cursorCharPosition = Math.min(displayText.length(), cursorCharPosition);
                xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
                cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos;
                // no point in showing the input mode when there is only one input mode...
                if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length == 1) {
                    inputModeWidth = 0;
                }
                if (ta.isEnableInputScroll()) {
                    if (ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL())) {
                        if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2) {
                            x = ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2 - xPos - 1;
                        }
                    }
                }
            }
            displayX = ta.getX() + x + style.getPaddingLeft(ta.isRTL());
        } else {
            x = 0;
            cursorX = getTextFieldCursorX(ta);
            int baseX = ta.getX() + style.getPaddingLeftNoRTL() + inputModeWidth;
            int endX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL();
            if (cursorX < baseX) {
                x = baseX - cursorX;
            } else {
                if (cursorX > endX) {
                    x = endX - cursorX;
                }
            }
            displayX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL() - f.stringWidth(displayText) + x;
        }
        // int cx = g.getClipX();
        // int cy = g.getClipY();
        // int cw = g.getClipWidth();
        // int ch = g.getClipHeight();
        // int clipx = ta.getX() + style.getPaddingLeft(ta.isRTL());
        // int clipw = ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - style.getPaddingRight(ta.isRTL());
        // g.pushClip();
        // g.clipRect(clipx, cy, clipw, ch);
        // int xOffset = 0;
        // int len = displayText.length();
        // int charH = f.getHeight();
        int h = getSelectionHeight(f);
        switch(ta.getVerticalAlignment()) {
            case Component.BOTTOM:
                // g.drawString(displayText, displayX, ta.getY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight(), style.getTextDecoration());
                append(sel, ta, out, displayText, f, 0, displayX, ta.getY() + ta.getHeight() - style.getPaddingBottom() - h, h);
                // c = sel.newChar(i, charX, ta.getY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight(), charW , charH);
                break;
            case Component.CENTER:
                // g.drawString(displayText, displayX, ta.getY() + ta.getHeight() / 2  - f.getHeight() / 2, style.getTextDecoration());
                // c = sel.newChar(i, charX, ta.getY() + ta.getHeight() / 2  - f.getHeight() / 2, charW, charH);
                append(sel, ta, out, displayText, f, 0, displayX, ta.getY() + ta.getHeight() / 2 - h / 2, h);
                break;
            default:
                // g.drawString(displayText, displayX, ta.getY() + style.getPaddingTop(), style.getTextDecoration());
                // c = sel.newChar(i, charX, ta.getY() + style.getPaddingTop(), charW, charH);
                append(sel, ta, out, displayText, f, 0, displayX, ta.getY() + style.getPaddingTop(), h);
                break;
        }
        // g.setClip(cx, cy, cw, ch);
        // g.popClip();
        out = out.translate(ta.getAbsoluteX() - sel.getSelectionRoot().getAbsoluteX() - ta.getX(), ta.getAbsoluteY() - sel.getSelectionRoot().getAbsoluteY() - ta.getY());
        Spans spansOut = sel.newSpans();
        spansOut.add(out);
        return spansOut;
    } else {
        // drawTextArea(g, ta);
        return calculateTextAreaSpan(sel, ta);
    }
}
Also used : Span(com.codename1.ui.TextSelection.Span) Font(com.codename1.ui.Font) Spans(com.codename1.ui.TextSelection.Spans)

Example 5 with Span

use of com.codename1.ui.TextSelection.Span in project CodenameOne by codenameone.

the class SwipableContainerTest2766 method start.

public void start() {
    // TEST: SWIPEABLE CONTAINER ALSO SWIPES UNDERLYING CONTAINER AS WELL
    Form hi = new Form("Welcome", new BorderLayout());
    Container list = new Container(BoxLayout.y());
    for (int i = 0; i < 20; i++) {
        SwipeableContainer swip = new SwipeableContainer(null, new Label("SWIPE"), new Label("ListElement " + i + " + a lot of fill text to make the element span over several lines so the dragging of the underlying Swipeable is normally noticeable"));
        list.add(swip);
    }
    list.setScrollableY(true);
    Container cont = hi.getContentPane();
    cont.add(BorderLayout.CENTER, list);
    SwipeableContainer swip = new SwipeableContainer(null, new SpanLabel("SOUTHSWIPE"), new SpanLabel("SOUTH CONTAINER"));
    cont.add(BorderLayout.SOUTH, swip);
    hi.show();
}
Also used : Container(com.codename1.ui.Container) SwipeableContainer(com.codename1.ui.SwipeableContainer) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) SpanLabel(com.codename1.components.SpanLabel) Label(com.codename1.ui.Label) SwipeableContainer(com.codename1.ui.SwipeableContainer) SpanLabel(com.codename1.components.SpanLabel)

Aggregations

Font (com.codename1.ui.Font)5 SpanLabel (com.codename1.components.SpanLabel)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 Form (com.codename1.ui.Form)3 Span (com.codename1.ui.TextSelection.Span)3 SpanButton (com.codename1.components.SpanButton)2 Button (com.codename1.ui.Button)2 Container (com.codename1.ui.Container)2 Char (com.codename1.ui.TextSelection.Char)2 Spans (com.codename1.ui.TextSelection.Spans)2 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)2 BrowserComponent (com.codename1.ui.BrowserComponent)1 CN.getCurrentForm (com.codename1.ui.CN.getCurrentForm)1 FontImage (com.codename1.ui.FontImage)1 Image (com.codename1.ui.Image)1 Label (com.codename1.ui.Label)1 SwipeableContainer (com.codename1.ui.SwipeableContainer)1 TextField (com.codename1.ui.TextField)1 Dimension (com.codename1.ui.geom.Dimension)1 BoxLayout (com.codename1.ui.layouts.BoxLayout)1