Opened 15 years ago

Closed 15 years ago

Last modified 14 years ago

#2955 closed task (fixed)

layout(), resize(), onResized() refactor

Reported by: bill Owned by: bill
Priority: high Milestone: 0.9beta
Component: Dijit Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

Concerning sizing:

There are two categories of widgets: children, and top level. Child widgets (ex: a split container inside a tabcontainer) get their size set by the parent widget. Top level widgets need to monitor when their size changes because (for example) the window has changed size.

The onResized() call from 0.4 is inefficient because it tells each widget "your size changed" without telling it what the new size is; widgets should be changed to implement and call resize({w: 500, h: 500}) which sets the margin box of the widget. There should be no onResized() method. Maybe we can also get rid of all the calls to getContentBox(), since the margin box size is passed to resize().

This brings up the problem with layout() and resize(). After all widgets are created, layout() is called on each widget, to let it "hook up" to other widgets such as it's parent/children/widgets it references. The problem is that, given a parent and child widget, parent.layout() wants to size itself and then call child.resize(), but that's not really valid until after child.layout() is called. Have to rethink the lifecycle.

  1. Change dijit.base.Layout.layoutChildren() to take coordinates (l,t,w,h) about box into which to place children.
  1. Modify all widgets to have resize() method rather than onResized() method
  1. Rename Widget.layout() to startup(), to match method name in dijit.Sizable
  1. In the past we've seen that setMarginBox() followed by getContentBox() can fail (return NaN or 0), due to race conditions or if some things are hidden. Maybe we can work around it w/code like:
	setMarginGetContent: function(node, mb){
		dojo.marginBox(node, mb);
		var cs = dojo.getComputedStyle(node);
		var me=dojo._getMarginExtents(node, cs);
		var pb=dojo._getPadBounds(node, cs);
		return { l: pb.l, t: pb.t, w: mb.w - me.w - pb.w, h: mb.h - me.h - pb.h };

Change History (10)

comment:1 Changed 15 years ago by bill

Description: modified (diff)

comment:2 Changed 15 years ago by bill

Owner: changed from koranteng to bill
Status: newassigned

comment:3 Changed 15 years ago by bill

(In [8641]) Start refactor of startup()/layout()/onResized()/resize() functions. Widgets should now implement these two functions:

startup(): This should do any initialization that can't be done until all the other widgets have been created, and then should call Layout.startup(). It shouldn't do anything relating to sizing.

layout(): This is called after startup(), and also when the widget's size has been changed. It should layout the contents of the widget and call resize(size) on each child widget, if appropriate. Reference this._contentBox to get the size of the widget content area.

Refs #2955

comment:4 Changed 15 years ago by bill

(In [8642]) Pass in size to layoutChildren(). Cleanup calculation of size of content box. Refs #2955

comment:5 Changed 15 years ago by bill

(In [8653]) Cleanup TabContainer? some. Refs #2955.

comment:6 Changed 15 years ago by bill

Component: WidgetsDijit

OK, I'm gonna close this bug; the refactor is finished. If there are some other issues can file new bugs (or just fix the issues, referencing this bug).

comment:7 Changed 15 years ago by bill

Resolution: fixed
Status: assignedclosed

comment:8 Changed 15 years ago by bill

(In [8742]) Since PageController?.startup() may be called before or after PageContainer?.startup(), do a more deterministic mechanism for initializing the PageController?. Fixes the problem w/no tab being initially selected. Refs #2955.

comment:9 Changed 15 years ago by bill

(In [9186]) Remove sizing code in postCreate(). It's handled in layout(). Refs #2955.

comment:10 Changed 14 years ago by bill

(In [13603]) This file is out of date and information is better covered in drupal, so removing it. Refs #2955 etc.

Note: See TracTickets for help on using tickets.