Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8978] Ti API: View.size, View.rect should report values in defaultunit, not system unit

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-06-18T10:28:26.000+0000
Affected Version/sRelease 2.0.1
Fix Version/sRelease 2.1.0, Sprint 2012-12 Core
ComponentsTiAPI
Labelscore, parity, qe-port
ReporterArthur Evans
AssigneeNeeraj Gupta
Created2012-05-03T15:16:37.000+0000
Updated2012-08-09T15:13:18.000+0000

Description

Currently, it appears that Ti.View.size and Ti.View.rect are reported in system default units, regardless of the setting of ti.ui.defaultunit. On Android, this means that these values are reported in pixels, even if you're specifying your entire UI in DIPs. (On iOS, they're reported in DIPs, which is usually what you want anyway; and in mobile web, px and DIP are the same thing.) Is there any reason that we couldn't report these values in defaultunit so that users can do simple math with them without having to convert them back into the unit of their choice?

Comments

  1. Stephen Tramer 2012-06-07

    Testing

    ---- Testing will need to be run on both iOS and Android, ideally with displays which have different densities (in order to ensure that the non-DIP values are treated correctly). Create a new project, with the following app.js:
       var win = Ti.UI.createWindow();
       
       function onLayout(e) {
       	var view = e.source;
       	var rectObj = {
       		width:view.rect.width,
       		height:view.rect.height
       	};
       	var sizeObj = {
       		x:view.size.x,
       		y:view.size.y,
       		width:view.size.width,
       		height:view.size.height
       	};
       	console.log("rect ",view.tag," in default: (",view.rect.x,",",view.rect.y,",",view.rect.width,",",view.rect.height,")");
       	console.log("size ",view.tag," in default: (",view.size.x,",",view.size.y,",",view.size.width,",",view.size.height,")");
       }
       
       var view = Ti.UI.createView({
       	width:"100px",
       	height:"100px",
       	top:"10px",
       	tag:1
       });
       win.add(view);
       view.addEventListener('postlayout', onLayout);
       
       var view2 = Ti.UI.createView({
       	width:"1in",
       	height:"1in",
       	bottom:"10px",
       	tag:2
       });
       win.add(view2);
       view2.addEventListener('postlayout', onLayout);
       
       var view3 = Ti.UI.createView({
       	width:50,
       	height:50,
       	left:10,
       	tag:3
       });
       win.add(view3);
       view3.addEventListener('postlayout', onLayout);
       
       win.open();
       
    Replace the ti.ui.defaultunit property in tiapp.xml with the following values: * unset (not present) ** *iOS*: The units are displayed in DIP ** *Android*: The units are displayed in px * px * in Values should be displayed for the appropriate unit type on various devices. Feel free to contact me for further information, but the most important thing to remember is that 1 dip = 2px on iOS, and 1 in = 160 dip. *NOTE:* Android has a bug where non-px values are always reported as rounded to the nearest integer. This needs to be fixed so that rect sizes can be reported accurately for in/cm/mm.
  2. Olga Romero 2012-08-09

    Verified fix with: Titanium Studio, build: 2.1.1.201207271312 Titanium SDK: 2.1.1.v20120727140110

JSON Source