Search in sources :

Example 6 with Rectangle

use of org.rstudio.core.client.Rectangle in project rstudio by rstudio.

the class DomUtilsStandardImpl method getCursorBounds.

public Rectangle getCursorBounds(Document doc) {
    Selection sel = Selection.get(NativeWindow.get(doc));
    Range selRng = sel.getRangeAt(0);
    if (selRng == null)
        return null;
    sel.removeAllRanges();
    SpanElement span = doc.createSpanElement();
    Range rng = selRng.cloneRange();
    rng.collapse(true);
    rng.insertNode(span);
    int x = span.getAbsoluteLeft();
    int y = span.getAbsoluteTop();
    int w = 0;
    int h = span.getOffsetHeight();
    Rectangle result = new Rectangle(x, y, w, h);
    ElementEx parent = (ElementEx) span.getParentElement();
    parent.removeChild(span);
    parent.normalize();
    sel.setRange(selRng);
    return result;
}
Also used : SpanElement(com.google.gwt.dom.client.SpanElement) ElementEx(org.rstudio.core.client.dom.ElementEx) Rectangle(org.rstudio.core.client.Rectangle)

Example 7 with Rectangle

use of org.rstudio.core.client.Rectangle in project rstudio by rstudio.

the class MiniPopupPanel method positionNearRange.

public void positionNearRange(DocDisplay display, Range range) {
    Rectangle bounds = display.getRangeBounds(range);
    Point center = bounds.center();
    int pageX = center.getX() - (getOffsetWidth() / 2);
    // prefer displaying popup below associated text, but place above text
    // if it won't fit below
    int pageY = bounds.getBottom() + 10;
    if (pageY + getOffsetHeight() > display.getBounds().getBottom()) {
        pageY = bounds.getTop() - 10 - getOffsetHeight();
    }
    // avoid leaking off left side of page
    pageX = Math.max(20, pageX);
    pageY = Math.max(20, pageY);
    setPopupPosition(pageX, pageY);
}
Also used : Rectangle(org.rstudio.core.client.Rectangle) Point(org.rstudio.core.client.Point) Point(org.rstudio.core.client.Point)

Example 8 with Rectangle

use of org.rstudio.core.client.Rectangle in project rstudio by rstudio.

the class CompletionList method getSelectionRect.

/**
    * Gets the rectangle of the selected row in absolute (document-relative)
    * coordinates, or null if nothing is selected.
    */
public Rectangle getSelectionRect() {
    int index = getSelectedIndex();
    if (index < 0)
        return null;
    com.google.gwt.dom.client.Element el = DomUtils.getTableCell(grid_.getElement(), index, 0);
    return new Rectangle(el.getAbsoluteLeft(), el.getAbsoluteTop(), el.getOffsetWidth(), el.getOffsetHeight());
}
Also used : Rectangle(org.rstudio.core.client.Rectangle) com.google.gwt.event.dom.client(com.google.gwt.event.dom.client) Point(org.rstudio.core.client.Point)

Example 9 with Rectangle

use of org.rstudio.core.client.Rectangle in project rstudio by rstudio.

the class PlotsPanePreviewer method getPreviewClientRect.

public Rectangle getPreviewClientRect() {
    WindowEx win = imageFrame_.getElement().<IFrameElementEx>cast().getContentWindow();
    Document doc = win.getDocument();
    NodeList<Element> images = doc.getElementsByTagName("img");
    if (images.getLength() > 0) {
        ElementEx img = images.getItem(0).cast();
        return new Rectangle(img.getClientLeft(), img.getClientTop(), img.getClientWidth(), img.getClientHeight());
    } else {
        return new Rectangle(0, 0, 0, 0);
    }
}
Also used : IFrameElementEx(org.rstudio.core.client.dom.IFrameElementEx) ElementEx(org.rstudio.core.client.dom.ElementEx) Element(com.google.gwt.dom.client.Element) Rectangle(org.rstudio.core.client.Rectangle) WindowEx(org.rstudio.core.client.dom.WindowEx) Document(com.google.gwt.dom.client.Document)

Example 10 with Rectangle

use of org.rstudio.core.client.Rectangle in project rstudio by rstudio.

the class AceEditor method getPositionBounds.

@Override
public Rectangle getPositionBounds(Position position) {
    Renderer renderer = widget_.getEditor().getRenderer();
    ScreenCoordinates start = renderer.textToScreenCoordinates(position.getRow(), position.getColumn());
    return new Rectangle(start.getPageX(), start.getPageY(), (int) Math.round(renderer.getCharacterWidth()), (int) (renderer.getLineHeight() * 0.8));
}
Also used : Rectangle(org.rstudio.core.client.Rectangle) ScreenCoordinates(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Renderer.ScreenCoordinates)

Aggregations

Rectangle (org.rstudio.core.client.Rectangle)13 ElementEx (org.rstudio.core.client.dom.ElementEx)3 ScreenCoordinates (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Renderer.ScreenCoordinates)3 PositionCallback (com.google.gwt.user.client.ui.PopupPanel.PositionCallback)2 Point (org.rstudio.core.client.Point)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Document (com.google.gwt.dom.client.Document)1 Element (com.google.gwt.dom.client.Element)1 SpanElement (com.google.gwt.dom.client.SpanElement)1 com.google.gwt.event.dom.client (com.google.gwt.event.dom.client)1 Command (com.google.gwt.user.client.Command)1 IFrameElementEx (org.rstudio.core.client.dom.IFrameElementEx)1 WindowEx (org.rstudio.core.client.dom.WindowEx)1 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)1 InputEditorPosition (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition)1 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)1 SourcePosition (org.rstudio.studio.client.workbench.views.source.model.SourcePosition)1