Coder Social home page Coder Social logo

Comments (2)

rozek avatar rozek commented on August 19, 2024

I got it, I got it!

By looking into the source code (we all love open source, don't we?) I realized, that my Image's container still had the size 0x0 (because the image had not been loaded before). Therefore, I just added a "toPreferredSize" after the image had been loaded...et voilà, "repaint" worked!

Thanks for...your patience!

Kind regards,

Andreas Rozek

from zebkit.

barmalei avatar barmalei commented on August 19, 2024

The problem browsers load images asynchronously. What can cause the size of the image is 0. There are few ways to avoid the issue:

  • Images can be preloaded before you start building UI:
   var staticImage1 = null, staticImage2, ...;
   zebra.ready(function(path, result, image) {         
           staticImage1 = zebra.ui.loadImage("myimage1.jpg");
           staticImage2 = zebra.ui.loadImage("myimage2.jpg");
          ...
       },

       // the code will be called only after images loading in method above
       // is completed 
       function() {
           // build zebra UI
           // here it is guaranteed staticImage1 and staticImage2 are completely loaded
           new zebra.ui.zCanvas().root.properties({
               layout : new zebra.layout.FlowLayout(),
               kids   : [ new zebra.ui.ImagePan(staticImage1) ]
           }); 
           ...
       }
   );
  • You can use "zebra.ui.ImagePan". Pass path to image to the component. In this case the component itself will track the image loading to trigger invalidating and repainting:
     //  image panel will care about repainting and validation 
     var myImg = new zebra.ui.ImagePan("myimage.jpg");
     ...
  • You can track image loading to initiates an appropriate component repainting in proper time:
    var pan = new zebra.ui.ImagePan();
    ...
    var img = zebra.ui.loadImage("myimage1", function(path, result, img) {
         // image is loaded
         pan.vrp(); // invalidate and repaint component    
    }); 

   // here image still can have zero size since the image loading
   // is not completed 
   pan.setImage(img);
   ...

from zebkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.