Group not where I expected

Community based support for the Digium Phone Application Programming Interface (API).

Moderators: jwitt, sruffell, malcolmd, Moderator

Group not where I expected

Postby mollett » Tue Mar 04, 2014 4:45 pm

I'm working on an app that has a simple title at 0,0, and then a Group set at 0,Text.LINE_HEIGHT. That group subsequently has a Text item at coordinates 0,0. I expect that Text item's coordinates to be relative to the Group's position, which on the screen would be 0,Text.LINE_HEIGHT. However, when testing, I keep finding the Text item to be at 0,0 on the screen. Here's some sample code:

Code: Select all
var app = require('app');
app.init();
var screen = require('screen');

window.clear();

print("window w, h = " + window.w + ", " + window.h + "\n");

var alertGroup = new Group(0, Text.LINE_HEIGHT,
            window.w, window.h - Text.LINE_HEIGHT);

var alertText = new Text(0, 0, window.w, Text.LINE_HEIGHT);
alertText.align(Widget.TOP | Widget.LEFT | Widget.WRAP);
alertGroup.add(alertText);

window.onkeycancel = digium.background;

window.add(screen.setTitleText({ 'title' : 'Tiny Title' }));   

window.setSoftkeysByList([
    {
   'label'     : '',
   'handler' : ''
    },
    {
   'label'     : '',
   'handler' : ''
    },
    {
   'label'     : '',
   'handler' : ''
    },
    {
   'label'     : 'Close',
   'handler' : digium.background,
   'icon'    : app.images.softKeys.cancel
    }
]);
   
window.add(alertGroup);

alertText.label = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.";
alertText.fitLabel();


What I end up getting is what is showing in the attached screen shot. I know I'm missing something simple, but I sure can't see it...
Attachments
screen_shot.png
screen_shot.png (1.74 KiB) Viewed 5853 times
mollett
Newsterisk
 
Posts: 25
Joined: Mon Apr 01, 2013 12:03 pm

Re: Group not where I expected

Postby mollett » Wed Mar 05, 2014 4:11 pm

I have enhanced my little app (see attached) to give me a little more feedback. I have added a softkey which will dump to the debug log the coordinates of both the Group widget (g) and the Text widget (t). Additionally, I have added a softkey called Group and another called Text. Of these two softkeys, the one with the little wedge is the active one, and using the arrow keys will cause that item to move on the screen in increments of 10.

What I have found is that when the Text item is moved, only the coordinates of the Text item change. However, when the Group item is moved, the coordinates of both the Group and the Text item change by the exact same amount.

Based on this, I have to conclude that subelements of a Group are always relative to the screen with regards to positioning, and not to the Group coordinates. That seems odd to me, but if that's how it is, then that's how it is. Can someone of authority tell me if this conclusion is accurate and expected?

Vic
Attachments
tiny.zip
A Tiny App for Digium Phones
(1.99 KiB) Downloaded 450 times
mollett
Newsterisk
 
Posts: 25
Joined: Mon Apr 01, 2013 12:03 pm

Re: Group not where I expected

Postby sruffell » Wed Mar 05, 2014 6:11 pm

Hi Vic,

You are correct. The widgets position is always expressed relative to the window and not necessarily to it's immediate parent.

I'll see about updating the documentation to make this clear.
sruffell
Oldsterisk
 
Posts: 200
Joined: Fri Jan 07, 2011 2:02 pm

Re: Group not where I expected

Postby mollett » Wed Mar 05, 2014 6:19 pm

Shaun,
Thanks for the confirmation. I did get to thinking and realized that if I build and fill my group at 0,0 and then move it to where I want it, everything will be at the correct position. That may be the technique I use to help me build things relative to their container and not to the screen, and still get stuff where I want it.

Vic
mollett
Newsterisk
 
Posts: 25
Joined: Mon Apr 01, 2013 12:03 pm


Return to Digium Phone API

Who is online

Users browsing this forum: No registered users and 1 guest