⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layout.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 5 页
字号:
    if (this.vertical == null) {        this.vertical = (this.orientation == Layout.VERTICAL);    } else {        this.orientation = (this.vertical ? Layout.VERTICAL : Layout.HORIZONTAL);    }    // for horizontal layouts in RTL, set (or flip) the reverseOrder flag    if (this.isRTL() && !this.vertical) this.reverseOrder = !this.reverseOrder;    if (this.members == null) this.members = [];    else if (!isc.isA.Array(this.members)) this.members = [this.members];        if (this.members === this._prototype.members) {        //this.logWarn("Detected members array as instance property")        this.members = this.members.duplicate();    }    // NOTE: trickiness with timing of creating members/children/peers:    // Once we add the "members" as children or peers, Canvas code will auto-create any members    // specified as instantiation blocks rather than live widgets.  Therefore, we make sure all    // members have been instantiated here, because if we allow Canvas code to do the    // instantiation, our "members" array will contain pointers to instantiation blocks instead    // of the live Canvii.    if (this.membersAreChildren) {        if (this.members.length == 0 && this.children != null &&             !this._allGeneratedChildren())         {            // since no members were specified, but children were specified, and this is a            // Layout, assume all children are members.  NOTE: don't be fooled by having a            // children Array that contains only generated components, which doesn't indicate            // old-style usage, rather it indicates a Layout subclass that creates            // non-member children.            // NOTE: ensure this.members contains live Canvii            this.members = this.children = this.createMemberCanvii(this.children);        } else {            // explicit list of members: create them and add them to the children array            // NOTE: ensure this.members contains live Canvii            this.members = this.createMemberCanvii(this.members);            if (this.children == null) this.children = [];             this.children.addList(this.members);        }    } else {        this.logInfo("members are peers", "layout");        // we override drawPeers() to do our special drawing.  The Layout itself *will not draw*        // since there's no need.          // override draw() to avoid actually drawing this Canvas.                  this.addMethods({draw:this._drawOverride});        // explicit list of members: create them and add them to the peers array        // NOTE: ensure this.members contains live Canvii        this.members = this.createMemberCanvii(this.members);        if (this.peers == null) this.peers = [];        this.peers.addList(this.members);    }        // set up per-side margin properties based on settings    this.setLayoutMargin();},// createMemberCanvii - resolves specified members / children to actual canvas instances, and// unlike createCanvii, clears out anything that didn't resolve to a Canvas with a warningcreateMemberCanvii : function (members) {    members = this.createCanvii(members);    for (var i = members.length-1; i >= 0; i--) {        // Skip null entries - we handle these separately        if (members[i] == null) continue;        if (!isc.isA.Canvas(members[i])) {            this.logWarn("Layout unable to resolve member:" + this.echo(members[i]) +                          " to a Canvas - ignoring this member");            members.removeAt(i);        }    }    return members;},_allGeneratedChildren : function () {    for (var i = 0; i < this.children.length; i++) {        var child = this.children[i];        if (child != null && !child._generated) return false;    }    return true;},// Margins handling// ---------------------------------------------------------------------------------------//> @method layout.setLayoutMargin()// Method to force a reflow of the layout after directly assigning a value to any of the// layout*Margin properties. Takes no arguments.//// @group layoutMargin// @visibility external//<setLayoutMargin : function () {    var lhm = this.layoutHMargin,        lvm = this.layoutVMargin,        lm = this.layoutMargin,        // if we are reversed and eg horizontal, the start margin should be on the right, etc        sm = this.reverseOrder ? this.layoutEndMargin : this.layoutStartMargin,        em = this.reverseOrder ? this.layoutStartMargin : this.layoutEndMargin;            var lpm, rpm, tpm, bpm;    if (this.paddingAsLayoutMargin) {        var padding = this._calculatePadding();        lpm = padding.left; rpm = padding.right;        tpm = padding.top; bpm = padding.bottom;    }        this._leftMargin = this._firstNonNull(this.layoutLeftMargin,                                           (!this.vertical ? sm : null),                                           lhm, lm, lpm, 0);    this._rightMargin = this._firstNonNull(this.layoutRightMargin,                                            (!this.vertical ? em : null),                                           lhm, lm, rpm, 0);    this._topMargin = this._firstNonNull(this.layoutTopMargin,                                           (this.vertical ? sm : null),                                          lvm, lm, tpm, 0);    this._bottomMargin = this._firstNonNull(this.layoutBottomMargin,                                            (this.vertical ? em : null),                                           lvm, lm, bpm, 0);    this._breadthChanged = true;    this.reflow();},_getSideMargin : function (vertical) {    if (this._leftMargin == null) this.setLayoutMargin();        if (vertical) return this._leftMargin + this._rightMargin;    else return this._topMargin + this._bottomMargin;},_getBreadthMargin : function () { return this._getSideMargin(this.vertical); },_getLengthMargin : function () { return this._getSideMargin(!this.vertical); },// ---------------------------------------------------------------------------------------// draw() override for members-aren't-children mode._drawOverride : function () {    //!DONTCOMBINE    if (isc._traceMarkers) arguments.__this = this;    if (!this.membersAreChildren) {        // we draw the members now, and never draw the Layout as such                this._setupMembers();        // draw all the other members.    	this.layoutChildren(this._$initial_draw);        this.drawPeers();        this._drawn = true;        return;    }     //StackDepth do a manual Super to avoid stack depth (and its faster)    isc.Canvas._instancePrototype.draw.apply(this, arguments);    //this.Super("draw", arguments);},// if our members are peers, suppress the normal behavior of resizing peers with the parent resizePeersBy : function (a,b,c) {    if (!this.membersAreChildren) return;        isc.Canvas._instancePrototype.resizePeersBy.call(this, a,b,c);        //this.Super("resizePeersBy", arguments);},markForRedraw : function () {    if (this.membersAreChildren) return this.Super("markForRedraw", arguments);    // if members aren't children, we don't draw, so ignore the redraw and just treat it as    // dirtying the layout    this.reflow("markedForRedraw");},// NOTE: we need to override drawChildren because if we don't, we will have to run the layout// policy after the children have already been drawn, hence resizing them all and causing them// to redraw.drawChildren : function () {    if (this.membersAreChildren) {        // members are all children: handle drawing them specially        this._setupMembers();        // draw all the members.        // NOTE: odd behavior of Layouts: because layoutChildren() skips hidden members, members        // which are initially hidden DO NOT DRAW.  This is unlike any other Canvas        // parent-child relationship, where it is guaranteed that all children have been drawn        // if the parent has been drawn.  The primary reason not to draw hidden members is        // performance.    	this.layoutChildren(this._$initial_draw);        // if there are any children who are not members, call draw on them.  NOTE: a typical        // case is the *peers of our members*.  This also implies that we must draw members        // before non-member children, since peers must draw after their masters.        this._drawNonMemberChildren();    }    // if members aren't children, we don't draw ourselves, so we can't draw children     return;},// We manage our members' tab index._memberCanFocus : function (member) {    return true;},//>	@method	layout._setupMembers()// Do one time setup of members.// Sets initial breadth for all members.// Returns the set of members that should be predrawn.//<	_setupMembers : function () {	for (var i = 0; i < this.members.length; i++) {        var member = this.members[i];        if (member == null) {            this.logWarn("members array: " + this.members + " includes null entry at position "                          + i + ". Removing");            this.members.removeAt(i);            i-=1;            continue;        }                // If the member can be focused upon, and doesn't have a user-defined tab-index, make sure        // it appears at the end of the current set of members in the tab order.        if (this._memberCanFocus(member) &&             (member._autoTabIndex || member.tabIndex == null))         {            this.updateMemberTabIndex(member);        }        // set each member's breadth        this.autoSetBreadth(member);	}},// when one of our members 'canFocus' property changes, update it's tab index to put it in// the right place in the tab order.childCanFocusChanged : function (member) {    if (!this.members.contains(member)) return;    this.updateMemberTabIndex(member);},    // _drawNonMemberChildren// Iterate through the children array, and for any children that are not members, draw them without// managing their layout// (Duplicates some code to achieve this from Canvas.drawChildren())_drawNonMemberChildren : function () {    // bail for the case where members are not children for now    if (!this.membersAreChildren || !this.children) return;        for (var i = 0; i < this.children.length; i++) {        var child = this.children[i];        if (this.members.contains(child)) continue;        if (!isc.isA.Canvas(child)) {            child.autoDraw = false;            child = isc.Canvas.create(child);        }                  if (!child.isDrawn()) child.draw();    }},// Setting member sizes// --------------------------------------------------------------------------------------------//> @attr layout.managePercentBreadth (boolean : true : IR)// If set, a Layout with breadthPolicy:"fill" will specially interpret a percentage breadth on// a member as a percentage of available space excluding the +link{layoutMargin}.  If false,// percentages work exactly as for a non-member, with layoutMargins, if any, ignored.// @visibility external//<managePercentBreadth:true,//> @method layout.getMemberDefaultBreadth() [A]// Return the breadth for a member of this layout which either didn't specify a breadth or// specified a percent breadth with +link{managePercentBreadth}:true.// <P>// Called only for Layouts which have a +link{type:LayoutPolicy,layout policy} for the breadth// axis of "fill", since Layouts with a breadth policy of "none" leave all member breadths alone.//// @param member (Canvas) Component to be sized// @param defaultBreadth (Number) Value of the currently calculated member breadth. This//      may be returned verbatim or manipulated in this method.// @group layoutMember// @visibility external//<_getMemberDefaultBreadth : function (member) {    var explicitBreadth = this._explicitBreadth(member),        percentBreadth = isc.isA.String(explicitBreadth) && isc.endsWith(explicitBreadth,this._$percent)                     ? explicitBreadth : null,        availableBreadth = Math.max(this.getBreadth() - this._getBreadthMargin(), 1);        if (this._willScrollLength && !this.leaveScrollbarGap) {        //this.logWarn("resizeMembers using smaller breath for scrolling, overflowersOnly: " +        //             overflowersOnly);        availableBreadth -= this.getScrollbarSize();    }    var breadth = (percentBreadth == null ? availableBreadth :                   Math.floor(availableBreadth * (parseInt(percentBreadth)/100)));    // call user-specified override, if any    if (this.getMemberDefaultBreadth == null) return breadth;    return this.getMemberDefaultBreadth(member, breadth);},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -