FramingConstraints suggestion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

FramingConstraints suggestion

Ian Bartholomew-12
Andy/Blair,

I've included a package below that implements what I think might be a useful
addition to FramingConstraints.  What I wanted was a way of laying out a
series of similar views (typically buttons) that maintain their individual
size and identical relative positions (button-button and button-frame) when
their enclosing frame is resized. Non of the existing "fixed" LayoutManagers
seem to do this and a relative FramingLayout only works for the gaps between
subviews, the frame-button gaps end up being different sizes, and it is
fiddly to get it to do even that .

A picture is worth a thousand words -

before resize (f = frame, s = space, b = button)

fssbbbbssbbbbssbbbbssf

after resize

fssssssbbbbssssssbbbbssssssbbbbssssssf

The package just adds four new geometry methods (centerRelativeParentXXX) to
FramingConstraints but has to alter some existing methods to integrate
itself.

The only caveats are
- It works best if all the subviews are the same size. It does still work if
this isn't true but the gaps between subviews are not then identical,
although the position of the centre of the button still corresponds to the
buttons offset.
- The #offset fields need to be structured in a fixed way. If you have three
buttons then the offsets, left to right, need to be specified as 1/4, 2/4
(or 1/2) and 3/4 (Floats will not work)

I was just going to add it to one of my goodies (and still can) but as it
modifies existing methods and is, I think, quite useful I thought I would
offer it to you first - at a very reasonable price :-)

Ian

| package |

package := Package name: 'Framing'.

package paxVersion: 0;

basicComment: ''.

package basicScriptAt: #postinstall put: 'FramingConstraints initialize'.

package methodNames

add: #FramingConstraints ->
#frameCenterRelativeParentHeight:dominant:parent:view:;

add: #FramingConstraints ->
#frameCenterRelativeParentWidth:dominant:parent:view:;

add: #FramingConstraints ->
#offsetCenterRelativeParentHeight:dominant:parent:view:;

add: #FramingConstraints ->
#offsetCenterRelativeParentWidth:dominant:parent:view:;

add: 'FramingConstraints class' -> #frameCalcs;

add: 'FramingConstraints class' -> #offsetCalcs;

add: 'FramingConstraints class' -> #publishedAspectsOfInstances;

yourself.

package binaryGlobalNames: (Set new

yourself).

package globalAliases: (Set new

yourself).

package allResourceNames: (Set new

yourself).

package setPrerequisites: (IdentitySet new

add: 'Object Arts\Dolphin\IDE\Base\Development System';

add: 'Object Arts\Dolphin\Base\Dolphin';

add: 'Object Arts\Dolphin\MVP\Base\Dolphin MVP Base';

yourself).

package!

"Class Definitions"!



"Global Aliases"!



"Loose Methods"!

!FramingConstraints methodsFor!

frameCenterRelativeParentHeight: b dominant: d parent: p view: v

"Private - Answer the result of performing the #centerRelativeParentBottom
framing calculation against the arguments,

b, v, d, and p, which are respectively the <Rectangle> being calculated, the
<integer> dominent offset,

the <Point> specifying the parent extent, and the <View> whose build
rectangle is being calculated."

| buttonSpace gapSize |

buttonSpace := (d denominator - 1) * v height.

gapSize := (p y - buttonSpace) / d denominator.

^gapSize + ((d numerator - 1) * (v height + gapSize))!

frameCenterRelativeParentWidth: b dominant: d parent: p view: v

"Private - Answer the result of performing the #centerRelativeParentRight
framing calculation against the arguments,

b, v, d, and p, which are respectively the <Rectangle> being calculated, the
<integer> dominent offset,

the <Point> specifying the parent extent, and the <View> whose build
rectangle is being calculated."

| buttonSpace gapSize |

buttonSpace := (d denominator - 1) * v width.

gapSize := (p x - buttonSpace) / d denominator.

^gapSize + ((d numerator - 1) * (v width + gapSize))!

offsetCenterRelativeParentHeight: b dominant: d parent: p view: v

"Private - Answer the result of performing the #relativeParentBottom offset
calculation against the arguments,

b, v, d, and p, which are respectively the <Rectangle> being calculated, the
<integer> dominent offset,

the <Point> specifying the parent extent, and the <View> whose build
rectangle is being calculated."

^d / p y!

offsetCenterRelativeParentWidth: b dominant: d parent: p view: v

"Private - Answer the result of performing the #relativeParentRight offset
calculation against the arguments,

b, v, d, and p, which are respectively the <Rectangle> being calculated, the
<integer> dominent offset,

the <Point> specifying the parent extent, and the <View> whose build
rectangle is being calculated."

^d / p x! !

!FramingConstraints categoriesFor:
#frameCenterRelativeParentHeight:dominant:parent:view:!geometry!private! !

!FramingConstraints categoriesFor:
#frameCenterRelativeParentWidth:dominant:parent:view:!geometry!private! !

!FramingConstraints categoriesFor:
#offsetCenterRelativeParentHeight:dominant:parent:view:!geometry!private! !

!FramingConstraints categoriesFor:
#offsetCenterRelativeParentWidth:dominant:parent:view:!geometry!private! !

!FramingConstraints class methodsFor!

frameCalcs

"Private - Answer a map of symbolic frame calculation names to the selectors
which

can be sent to calculate that frame."

^(IdentityDictionary new: 20)

at: #fixedParentBottom put: #frameFixedParentBottom:dominant:parent:view:;

at: #fixedParentLeft put: #frameFixedParentLeft:dominant:parent:view:;

at: #fixedParentRight put: #frameFixedParentRight:dominant:parent:view:;

at: #fixedParentTop put: #frameFixedParentTop:dominant:parent:view:;

at: #fixedViewBottom put: #frameFixedViewBottom:dominant:parent:view:;

at: #fixedViewLeft put: #frameFixedViewLeft:dominant:parent:view:;

at: #fixedViewRight put: #frameFixedViewRight:dominant:parent:view:;

at: #fixedViewTop put: #frameFixedViewTop:dominant:parent:view:;

at: #fixedPreviousBottom put:
#frameFixedPreviousBottom:dominant:parent:view:;

at: #fixedPreviousLeft put: #frameFixedPreviousLeft:dominant:parent:view:;

at: #fixedPreviousRight put: #frameFixedPreviousRight:dominant:parent:view:;

at: #fixedPreviousTop put: #frameFixedPreviousTop:dominant:parent:view:;

at: #relativeParentHeight put:
#frameRelativeParentHeight:dominant:parent:view:;

at: #relativeParentWidth put:
#frameRelativeParentWidth:dominant:parent:view:;

at: #centerRelativeParentHeight

put: #frameCenterRelativeParentHeight:dominant:parent:view:;

at: #centerRelativeParentWidth put:
#frameCenterRelativeParentWidth:dominant:parent:view:;

yourself!

offsetCalcs

"Private - Answer a map of symbolic offset calculation names to the
selectors which

can be performed to calculate that offset."

^(IdentityDictionary new: 20)

at: #fixedParentBottom put: #offsetFixedParentBottom:dominant:parent:view:;

at: #fixedParentLeft put: #offsetFixedParentLeft:dominant:parent:view:;

at: #fixedParentRight put: #offsetFixedParentRight:dominant:parent:view:;

at: #fixedParentTop put: #offsetFixedParentTop:dominant:parent:view:;

at: #fixedViewBottom put: #offsetFixedViewBottom:dominant:parent:view:;

at: #fixedViewLeft put: #offsetFixedViewLeft:dominant:parent:view:;

at: #fixedViewRight put: #offsetFixedViewRight:dominant:parent:view:;

at: #fixedViewTop put: #offsetFixedViewTop:dominant:parent:view:;

at: #fixedPreviousBottom put:
#offsetFixedPreviousBottom:dominant:parent:view:;

at: #fixedPreviousLeft put: #offsetFixedPreviousLeft:dominant:parent:view:;

at: #fixedPreviousRight put:
#offsetFixedPreviousRight:dominant:parent:view:;

at: #fixedPreviousTop put: #offsetFixedPreviousTop:dominant:parent:view:;

at: #relativeParentHeight put:
#offsetRelativeParentHeight:dominant:parent:view:;

at: #relativeParentWidth put:
#offsetRelativeParentWidth:dominant:parent:view:;

at: #centerRelativeParentHeight

put: #offsetCenterRelativeParentHeight:dominant:parent:view:;

at: #centerRelativeParentWidth put:
#offsetCenterRelativeParentWidth:dominant:parent:view:;

yourself!

publishedAspectsOfInstances

"Answer a <LookupTable> of the <Aspect>s published by instances of the
receiver."

| topBottomFramingChoices leftRightFramingChoices |

topBottomFramingChoices := #(#fixedParentBottom #fixedParentTop
#fixedViewBottom #fixedViewTop #fixedPreviousBottom #fixedPreviousTop
#relativeParentHeight #centerRelativeParentHeight).

leftRightFramingChoices := #(#fixedParentLeft #fixedParentRight
#fixedViewLeft #fixedViewRight #fixedPreviousRight #fixedPreviousLeft
#relativeParentWidth #centerRelativeParentWidth).

^(super publishedAspectsOfInstances)

add: (Aspect integer: #topOffset);

add: (Aspect choice: #topFraming from: topBottomFramingChoices);

add: (Aspect integer: #bottomOffset);

add: (Aspect choice: #bottomFraming from: topBottomFramingChoices);

add: (Aspect integer: #leftOffset);

add: (Aspect choice: #leftFraming from: leftRightFramingChoices);

add: (Aspect integer: #rightOffset);

add: (Aspect choice: #rightFraming from: leftRightFramingChoices);

yourself! !

!FramingConstraints class categoriesFor: #frameCalcs!initializing!private! !

!FramingConstraints class categoriesFor: #offsetCalcs!initializing!private!
!

!FramingConstraints class categoriesFor:
#publishedAspectsOfInstances!constants!development!public! !

"End of package definition"!

"Source Globals"!

"Classes"!

"Binary Globals"!

"Resources"!


Reply | Threaded
Open this post in threaded view
|

Re: FramingConstraints suggestion

Blair McGlashan
"Ian Bartholomew" <[hidden email]> wrote in message
news:WQ6I8.1420$xU5.177560@wards...
> Andy/Blair,
>
> I've included a package below that implements what I think might be a
useful
> addition to FramingConstraints.  What I wanted was a way of laying out a
> series of similar views (typically buttons) that maintain their individual
> size and identical relative positions (button-button and button-frame)
when
> their enclosing frame is resized. Non of the existing "fixed"
LayoutManagers
> seem to do this and a relative FramingLayout only works for the gaps
between
> subviews, the frame-button gaps end up being different sizes, and it is
> fiddly to get it to do even that .
> ....
> I was just going to add it to one of my goodies (and still can) but as it
> modifies existing methods and is, I think, quite useful I thought I would
> offer it to you first - at a very reasonable price :-)
>

Thanks Ian, we can include it in the next patch level if that is acceptable
to you?

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: FramingConstraints suggestion

Ian Bartholomew-13
Blair,

> Thanks Ian, we can include it in the next patch level if that is
acceptable
> to you?

Sure, if you feel it is worthwhile.  I've added it to one of the D5 goodie
packages anyway but it can easily be removed if you do include it in the
image.

Ian