Separator.st
author Claus Gittinger <cg@exept.de>
Fri, 28 Feb 1997 21:25:03 +0100
changeset 316 f6214d6f484d
parent 315 eab866497e0e
child 323 61fe6bb4b5ee
permissions -rw-r--r--
redraw if orientation changes

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"


SimpleView subclass:#Separator
	instanceVariableNames:'orientation'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Layout'
!

!Separator class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

!

documentation 
"
    a simple widget for a separating line. 
    To be placed between groups of other widgets.

    See examples.

    [See also:] 
        FramedBox VariableVerticalPanel VariableHorizontalPanel

    [author:]
        Claus Gittinger
"
!

examples
"
  a separator between two button-panels:
                                                                        [exBegin]
    |top p1 p2 sep|

    top := StandardSystemView new.
    top extent:300@300.

    p1 := VerticalPanelView origin:0.0@0.0 corner:1.0@0.5 in:top.
    p1 bottomInset:5; borderWidth:0.
    p2 := VerticalPanelView origin:0.0@0.5 corner:1.0@1.0 in:top.
    p2 topInset:5; borderWidth:0.

    (Button label:'one' in:p1) width:0.2.
    (Button label:'two' in:p1) width:0.2.
    (Button label:'three' in:p1) width:0.2.

    sep := Separator in:top.
    sep orientation:#horizontal.
    sep origin:0.0@0.5 extent:1.0@10.
    sep topInset:-5; bottomInset:-5.

    (Button label:'four' in:p2) width:0.2.
    (Button label:'five' in:p2) width:0.2.
    (Button label:'six' in:p2) width:0.2.

    top open
                                                                        [exEnd]


  vertical:
                                                                        [exBegin]
    |top p1 p2 sep|

    top := StandardSystemView new.
    top extent:300@300.

    p1 := VerticalPanelView origin:0.0@0.0 corner:0.5@1.0 in:top.
    p1 rightInset:5; borderWidth:0.
    p2 := VerticalPanelView origin:0.5@0.0 corner:1.0@1.0 in:top.
    p2 leftInset:5; borderWidth:0.

    (Button label:'one' in:p1) width:0.4.
    (Button label:'two' in:p1) width:0.4.
    (Button label:'three' in:p1) width:0.4.

    sep := Separator in:top.
    sep orientation:#vertical.
    sep origin:0.5@0.0 extent:10@1.0.
    sep leftInset:-5; rightInset:-5.

    (Button label:'four' in:p2) width:0.4.
    (Button label:'five' in:p2) width:0.4.
    (Button label:'six' in:p2) width:0.4.

    top open
                                                                        [exEnd]


  with multiple horizontal seps in a panel:
                                                                        [exBegin]
    |top p sep|

    top := StandardSystemView new.
    top extent:300@300.

    p := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    p verticalLayout:#spreadSpace.
    p horizontalLayout:#center.

    (Button label:'one' in:p).
    (Button label:'two' in:p).
    (Button label:'three' in:p).

    sep := Separator in:p.
    sep orientation:#horizontal.
    sep extent:0.9@10.

    (Button label:'four' in:p).
    (Button label:'five' in:p).

    sep := Separator in:p.
    sep orientation:#horizontal.
    sep extent:0.9@10.

    (Button label:'six' in:p).

    top open
                                                                        [exEnd]
"
! !

!Separator methodsFor:'accessing'!

orientation
    "return the orientation (one of #horizontal or #vertical)"

    ^ orientation
!

orientation:aSymbol
    "set the orientation to one of #horizontal or #vertical"

    orientation := aSymbol.
    shown ifTrue:[
        self invalidate
    ]

    "Modified: 28.2.1997 / 21:24:38 / cg"
! !

!Separator methodsFor:'drawing'!

redraw
    |vCenter hCenter is3D|

    self clear.
    is3D := styleSheet is3D.

    self paint:shadowColor.
    orientation == #vertical ifTrue:[
	hCenter := self width // 2.
	self displayLineFromX:hCenter y:0 toX:hCenter y:height-1.
	is3D ifTrue:[
	    self paint:lightColor.
	    self displayLineFromX:hCenter+1 y:0 toX:hCenter+1 y:height-1.
	]
    ] ifFalse:[
	vCenter := self height // 2.
	self displayLineFromX:0 y:vCenter toX:width-1 y:vCenter.
	is3D ifTrue:[
	    self paint:lightColor.
	    self displayLineFromX:0 y:vCenter+1 toX:width-1 y:vCenter+1.
	]
    ]
! !

!Separator methodsFor:'initialization'!

initialize
    super initialize.
    borderWidth := 0.
    orientation := #horizontal.

    "Modified: 28.2.1997 / 21:23:02 / cg"
! !

!Separator methodsFor:'queries'!

specClass
    self class == Separator ifTrue:[^ DividerSpec].
    ^ super specClass


! !

!Separator class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg2/Separator.st,v 1.14 1997-02-28 20:25:03 cg Exp $'
! !