xtk / X

The X Toolkit
http://www.goXTK.com
Other
795 stars 266 forks source link

Wrong caption location when inside absolute container. #116

Closed medihack closed 11 years ago

medihack commented 11 years ago

The location of the caption is wrong if the viewer (that in the end contains the canvas) is placed into an absolute positioned container.

Example:

<!DOCTYPE html>
<html>
<head>
<title>XTK TEST WITHOUT COMPILATION</title>

<style type="text/css">
    html, body {
        margin: 0;
        padding: 0;
        height: 100%;
    }

    #container {
        position: absolute;
        top: 100px;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: #000;
    }

    #viewer {
        width: 100%;
        height: 100%;
    }
</style>

<script type="text/javascript" src="../X/lib/google-closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="../X/xtk-deps.js"></script>

<script type="text/javascript">
  // include all used X-classes here
  // this is only required when using the xtk-deps.js file
  goog.require('X.renderer3D');
  goog.require('X.cube');

  var run = function() {

    var r = new X.renderer3D();
    r.container = 'viewer';
    r.init();

    var sphere = new X.sphere();
    sphere.caption = "Sphere";

        r.add(sphere);

    r.render();
  };
</script>

<body onload="run()">
    <div id="container">
        <div id="viewer"></div>
    </div>
</body>

The caption is placed 100 pixels too high.

medihack commented 11 years ago

It seems that fetching the offset of the parent element by using goog.style.getClientPosition(this._container) instead of directly using this._container.offsetTop resp. this._container.offsetLeft solves this issue (in the showCaption_ function).