pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vmuu...@fastmail.com
Subject UI zooming and buttons detection in Apache Pivot at program start
Date Tue, 03 Mar 2015 08:53:21 GMT
Hi there,

I have been testing Apache Pivot one week now and I'am very impressed of
this library! It is easy, simple and good looking UI library without any
new tool.

Currently I'am trying to use UI scaling (zooming) feature which work
nicely with Ctrl Shift +/- keys (and mouse too), but I cannot make it
work right at program start so that buttons could be detected from
correct location. So, I like to run an application and set some
predefined scale so that a user need not to adjust it at all. This is
beacuse I know the target device screen resolution where the application
will be run.

I have tried two different apporaches here:


1) Using ApplicationContext.scaleUp():

    ApplicationContext.DisplayHost displayHost = new
    ApplicationContext.DisplayHost();
    Graphics2D graphics = (Graphics2D) displayHost.getGraphics();
    displayHost.setScale( scale );

So this is not working - the code is located at startup method before or
after "window.open(display);" call.


2) Using ScaleDecorator.setScale will scale the UI correctly...:

    final ScaleDecorator sd = new ScaleDecorator();
    window.getDecorators().add( sd );
    sd.setHorizontalAlignment( HorizontalAlignment.LEFT );
    sd.setVerticalAlignment( VerticalAlignment.TOP );
    sd.setScale( scale );
    sd.update();

... but all buttons will be detected as if the UI is using scale factor
1.0. So all buttons are detected (with mouse) from wrong screen
locations (x/y -coordinates).


This effect can be easily tested with ApachePivot
org.apache.pivot.demos.text.TextPaneDemo by adding the code above just
before window.open(display) call like this:

    ....
        final ScaleDecorator sd = new ScaleDecorator();
        window.getDecorators().add( sd );
        sd.setHorizontalAlignment( HorizontalAlignment.LEFT );
        sd.setVerticalAlignment( VerticalAlignment.TOP );
        sd.setScale( 2.0f );
        sd.update();

        window.open(display);
        textPane.requestFocus();
    }

The program UI will scale correctly the but buttons will react from
wrong locations.


I have searched through all tutorials, demos, faq, mailing lists, Google
and Stack Overflow but have not found an example or right way to do
this. I guess I have missed something? Any tips will be appreciated.
Thank you.

Mime
View raw message