Hide and show subviews

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

Hide and show subviews

Sergei Gnezdov
Hi,

I am trying to hide and show views dynamically.  I execute the
following code and it hides and shows data just fine.  The problem is
that after view is hidden an empty space is displayed.  I'd like
parent view to reposition its subviews using current layout manager.

shell := Shell show.
shell view layoutManager: ProportionalLayout new.
shell view
    addSubView: (ContainerView new
        backcolor: Color red;
        yourself)
    name: 'left'.
shell view addSubView: Splitter new.
shell view
    addSubView: (ContainerView new
        backcolor: Color blue;
        layoutManager: BorderLayout new;
        yourself)
    name: 'right'.
(shell view viewNamed: 'right') hide.


Reply | Threaded
Open this post in threaded view
|

Re: Hide and show subviews

Louis Sumberg-2
Hi Sergei,

In taking a quick look at what the layout managers do, it seems they don't
take into account whether the subviews are showing or hidden, so I don't
think there's an easy way to do what you want.  However, there do seem
several ways to accomplish what you're trying to do in the little example
you gave, though I don't know if this'll do it for your actual app.

One way is to hide the subview AND the splitter and change the arrangement
of the remaining subview to some large number.  This will effectively force
the subview that's showing to take up almost all of the parent view's space.
I say "almost" because the splitter is still there, even though hidden and
even if you set its width to 0.  You can compensate for this by coloring the
background of the view the same as the subview that's showing.  E.g., at the
end of your example code, add:

    (shell view viewNamed: 'right') hide.
    (shell view viewNamed: 'left') arrangement: 999999.
    shell view subViews second hide; width: 0. "splitter"
    shell view backcolor: Color red.

Hope this helps.

-- Louis

> I am trying to hide and show views dynamically.  I execute the
> following code and it hides and shows data just fine.  The problem is
> that after view is hidden an empty space is displayed.  I'd like
> parent view to reposition its subviews using current layout manager.
>
> shell := Shell show.
> shell view layoutManager: ProportionalLayout new.
> shell view
>     addSubView: (ContainerView new
>         backcolor: Color red;
>         yourself)
>     name: 'left'.
> shell view addSubView: Splitter new.
> shell view
>     addSubView: (ContainerView new
>         backcolor: Color blue;
>         layoutManager: BorderLayout new;
>         yourself)
>     name: 'right'.
> (shell view viewNamed: 'right') hide.


Reply | Threaded
Open this post in threaded view
|

Re: Hide and show subviews

Sergei Gnezdov
In reply to this post by Sergei Gnezdov
On Mon, 09 Jun 2003 10:33:29 -0700, Sergei Gnezdov
<[hidden email]> wrote:

>Hi,
>
>I am trying to hide and show views dynamically.  I execute the
>following code and it hides and shows data just fine.  The problem is
>that after view is hidden an empty space is displayed.  I'd like
>parent view to reposition its subviews using current layout manager.
>
>shell := Shell show.
>shell view layoutManager: ProportionalLayout new.
>shell view
>    addSubView: (ContainerView new
>        backcolor: Color red;
>        yourself)
>    name: 'left'.
>shell view addSubView: Splitter new.
>shell view
>    addSubView: (ContainerView new
>        backcolor: Color blue;
>        layoutManager: BorderLayout new;
>        yourself)
>    name: 'right'.
>(shell view viewNamed: 'right') hide.

I found a solution with one strange behavior:

shell := Shell show.
shell view rectangle: (Rectangle origin: 9@60 corner: 336@200).
shell view layoutManager: ProportionalLayout new.
shell view
    addSubView: (ContainerView new
        backcolor: Color red;
        yourself)
    name: 'left'.
blueContainer := ContainerView new
        backcolor: Color blue;
        layoutManager: BorderLayout new;
        yourself.
shell view
    addSubView: (blueContainer)
    name: 'right'.
shell view removeSubView: (blueContainer).
shell view
    addSubView: (blueContainer)
    name: 'right'.
shell view invalidate.

The last line is required in order for the blue container to show up.
At the same adding blueConainer for the first time does not require
invalidate call.


Reply | Threaded
Open this post in threaded view
|

Re: Hide and show subviews

Sergei Gnezdov
On Tue, 10 Jun 2003 10:26:47 -0700, Sergei Gnezdov
<[hidden email]> wrote:

>On Mon, 09 Jun 2003 10:33:29 -0700, Sergei Gnezdov
><[hidden email]> wrote:
>
>>Hi,
>>
>>I am trying to hide and show views dynamically.  I execute the
>>following code and it hides and shows data just fine.  The problem is
>>that after view is hidden an empty space is displayed.  I'd like
>>parent view to reposition its subviews using current layout manager.
>>
[snip]

>
>I found a solution with one strange behavior:
>
>shell := Shell show.
>shell view rectangle: (Rectangle origin: 9@60 corner: 336@200).
>shell view layoutManager: ProportionalLayout new.
>shell view
>    addSubView: (ContainerView new
>        backcolor: Color red;
>        yourself)
>    name: 'left'.
>blueContainer := ContainerView new
>        backcolor: Color blue;
>        layoutManager: BorderLayout new;
>        yourself.
>shell view
>    addSubView: (blueContainer)
>    name: 'right'.
>shell view removeSubView: (blueContainer).
>shell view
>    addSubView: (blueContainer)
>    name: 'right'.
>shell view invalidate.
>
>The last line is required in order for the blue container to show up.
>At the same adding blueConainer for the first time does not require
>invalidate call.

It does not work on a more complex example which uses ViewComposer.

I created a simple view with center panel and south panel controlled
by BorderLayout.  Here is a class:

"Filed out from Dolphin Smalltalk XP"!

Shell subclass: #LearnUI
        instanceVariableNames: 'southPanelPresenter'
        classVariableNames: ''
        poolDictionaries: ''
        classInstanceVariableNames: ''!
LearnUI guid: (GUID fromString:
'{10D1834E-E410-43E3-A319-9FCD62C871D9}')!
LearnUI comment: 'LearnUI show.'!
!LearnUI categoriesForClass!Unclassified! !
!LearnUI methodsFor!

createComponents
        "Create the presenters contained by the receiver"

        super createComponents.
        southPanelPresenter := self add: ListPresenter new name:
'southPanel'.!

hideSouthPanel
        self view removeSubView: (southPanelPresenter view)
!

showSouthPanel
        self view addSubView: (southPanelPresenter view) name:
'southPanel'.
        self view invalidate.! !
!LearnUI categoriesFor: #createComponents!public! !
!LearnUI categoriesFor: #hideSouthPanel!public! !
!LearnUI categoriesFor: #showSouthPanel!public! !


Reply | Threaded
Open this post in threaded view
|

Re: Hide and show subviews

Sergei Gnezdov
In reply to this post by Louis Sumberg-2
I've read comment about arrangement call and I have no clue what
View>>arrangement method is supposed to do.  Hence, I don't understand
how
>    (shell view viewNamed: 'left') arrangement: 999999.
works.

>From Dolphin comment:

arrangement: anObject
"Set the arrangement parameter for the receiver in its parent's
layout manager to be anObject. If the parent has no layout manager
then a walkback will result"

self parentView arrangementOf: self put: anObject.


On Mon, 9 Jun 2003 22:14:23 -0700, "Louis Sumberg"
<[hidden email]> wrote:

>Hi Sergei,
>
>In taking a quick look at what the layout managers do, it seems they don't
>take into account whether the subviews are showing or hidden, so I don't
>think there's an easy way to do what you want.  However, there do seem
>several ways to accomplish what you're trying to do in the little example
>you gave, though I don't know if this'll do it for your actual app.
>
>One way is to hide the subview AND the splitter and change the arrangement
>of the remaining subview to some large number.  This will effectively force
>the subview that's showing to take up almost all of the parent view's space.
>I say "almost" because the splitter is still there, even though hidden and
>even if you set its width to 0.  You can compensate for this by coloring the
>background of the view the same as the subview that's showing.  E.g., at the
>end of your example code, add:
>
>    (shell view viewNamed: 'right') hide.
>    (shell view viewNamed: 'left') arrangement: 999999.
>    shell view subViews second hide; width: 0. "splitter"
>    shell view backcolor: Color red.
>
>Hope this helps.
>
>-- Louis
>
>> I am trying to hide and show views dynamically.  I execute the
>> following code and it hides and shows data just fine.  The problem is
>> that after view is hidden an empty space is displayed.  I'd like
>> parent view to reposition its subviews using current layout manager.
>>
>> shell := Shell show.
>> shell view layoutManager: ProportionalLayout new.
>> shell view
>>     addSubView: (ContainerView new
>>         backcolor: Color red;
>>         yourself)
>>     name: 'left'.
>> shell view addSubView: Splitter new.
>> shell view
>>     addSubView: (ContainerView new
>>         backcolor: Color blue;
>>         layoutManager: BorderLayout new;
>>         yourself)
>>     name: 'right'.
>> (shell view viewNamed: 'right') hide.
>


Reply | Threaded
Open this post in threaded view
|

Re: Hide and show subviews

Louis Sumberg-2
Sergei,

> I've read comment about arrangement call and I have no clue what
> View>>arrangement method is supposed to do.

The class comment for ProportionalLayout describes how that type of layout
manager works, how a Splitter is used, how the arrangement aspect controls
the relative sizes of subviews, and what an arrangement value of 0 does.
Maybe this will help:

(shell view viewNamed: 'right')  "blue subview"
    hide;  "hide it"
    arrangement: 0;    "tell its ProportionalLayoutManager not to resize it"
    width: 0.    "change its width to 0, so that red subview fills the
screen"
shell view subViews second  "hide the splitter bar too"
    hide;
    width: 0.

-- Louis


Reply | Threaded
Open this post in threaded view
|

Re: Hide and show subviews

Chris Uppal-3
In reply to this post by Sergei Gnezdov
Sergei Gnezdov wrote:
> I've read comment about arrangement call and I have no clue what
> View>>arrangement method is supposed to do.  Hence, I don't understand
> how
> >    (shell view viewNamed: 'left') arrangement: 999999.
> works.

Just to add to what Louis said.

The #arrangement aspect is interpreted by the LayoutManager, and each type of
LayoutManager has its own kinds of arrangements.  So for a View that had an
arrangement of 2 in a ProportionalLayoutManager (where the 2 is an indication
of what fraction of the whole width/height of the containing View it takes up),
the same View under a BorderLayout might have an #arrangement of #north or
#center (indicating which part of the containing View it is shown in).

    -- chris