problem with MenuMorph like morphs

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

problem with MenuMorph like morphs

Ralph Boland
I have a Morph subclass, say M, that contains a collection of
"ItemMorph", say, as submorphs.
When an M is displayed the ItemMorph submorphs are displayed in a
column.  An ItemMorph
can act as a display of data but can also act as a button.  This code
all works as expected.

I sometimes need an M morph to act similar to a MenuMorph;  that is
the  M  morph
can be made to display on command, say from pressing some button.  Then once the
user presses on one of the M morph submorphs (ItemMorphs)  the pressed upon
submorph is to like a button invoking some action.   Once the
selection is made the
entire  M  morph is to be deleted from the screen, like for a MenuMorph.

Except in my case the button action never occurs and the M morph is not deleted.

To get to the root of the problem I made copies of Classes  MenuMorph
and MenuItemMorph
and was able to get menus to work using these classes. Once I got
these copied morphs to
work like regular menus I was able to set breakpoints without getting
unwanted call stacks.

I then made the changes to  M and  "ItemMorph" based upon what I
learned about MenuMorph
and MenuItemMorph.   I then made a call stack occur when using the
copied Morphs by having the
method to invoke when a selection is made not exist.  My classes  M
and ItemMorph have
every  method that is a mehod of  MenuMorph or  MenuItemMorph on the
call stack.  But none
of them are called when I try to create a menu using M.

It seems that some code that handles focus invokes a new process to
handle the click by
the mouse on a MenuItemMorph  but doesn't do so or does so such that
nothing happens
when I click on a ItemMorph submorph of an  M morph on my screen.

Where can I set a breakpoint so that I can investigate why nothing
happens when I click
on a ItemMorph instance submorph of an M morph on the screen?

Notes:
1) When my M morph is first displayed there is at the top a balloon that says:

                   Enter text to narrow selection
                   down to matching items

I didn't intend for this balloon to occur but it got picked up somehow.
It would be useful to know how to change its text or remove it.  I
point it out here only because
it may help explain what is happening.

2)  On mouseUp this balloon disappears.

3) after the second mouseDown the  M morph gains a shadow and can be
picked up and moved.

This is an open source project for teaching math/science to young kids.
I have problems with the MIT license though so not sure what license I will use.

Any help much appreciated and sorry about the post length.

Ralph Boland

Reply | Threaded
Open this post in threaded view
|

Re: problem with MenuMorph like morphs

K K Subbu
On 27/03/20 10:02 AM, Ralph Boland wrote:
> I sometimes need an M morph to act similar to a MenuMorph;  that is
> the  M  morph
> can be made to display on command, say from pressing some button.

Every Morph can have its own event handler (see on:send:to).

MenuMorph manages a collection of such MenuItems (a button or a sub-menu).

If your button is rectangular with border and string label, use
SimpleButtonMorph (comments has examples).

If the label is an icon (Form), look at IconicButton. You can create
your own icon by using Do->Form fromUser bitEdit.

Use PluggableButtonMorph if you building a tool pane.

> Where can I set a breakpoint so that I can investigate why nothing
> happens when I click
> on a ItemMorph instance submorph of an M morph on the screen?

The foreground process that handles UI events can be observed using
Tools->Process Browser. This process uses HandMorph to direct events to
specific morphs on the screen. You can use HandMorph>>showEvents to turn
on/off events tracing. See

  http://forum.world.st/Button-tracking-Morph-td63492.html

> Notes:
> 1) When my M morph is first displayed there is at the top a balloon that says:
>
>                     Enter text to narrow selection
>                     down to matching items
>
> I didn't intend for this balloon to occur but it got picked up somehow.
> It would be useful to know how to change its text or remove it.  I
> point it out here only because
> it may help explain what is happening.

See http://wiki.squeak.org/squeak/2332 for a well-written example of an
interactive morph.

HTH .. Subbu


Reply | Threaded
Open this post in threaded view
|

Re: problem with MenuMorph like morphs

Karl Ramberg
In reply to this post by Ralph Boland
Hi,
Can you post a link to the code?

Cheers,
Karl

On Fri, Mar 27, 2020 at 5:33 AM Ralph Boland <[hidden email]> wrote:
I have a Morph subclass, say M, that contains a collection of
"ItemMorph", say, as submorphs.
When an M is displayed the ItemMorph submorphs are displayed in a
column.  An ItemMorph
can act as a display of data but can also act as a button.  This code
all works as expected.

I sometimes need an M morph to act similar to a MenuMorph;  that is
the  M  morph
can be made to display on command, say from pressing some button.  Then once the
user presses on one of the M morph submorphs (ItemMorphs)  the pressed upon
submorph is to like a button invoking some action.   Once the
selection is made the
entire  M  morph is to be deleted from the screen, like for a MenuMorph.

Except in my case the button action never occurs and the M morph is not deleted.

To get to the root of the problem I made copies of Classes  MenuMorph
and MenuItemMorph
and was able to get menus to work using these classes. Once I got
these copied morphs to
work like regular menus I was able to set breakpoints without getting
unwanted call stacks.

I then made the changes to  M and  "ItemMorph" based upon what I
learned about MenuMorph
and MenuItemMorph.   I then made a call stack occur when using the
copied Morphs by having the
method to invoke when a selection is made not exist.  My classes  M
and ItemMorph have
every  method that is a mehod of  MenuMorph or  MenuItemMorph on the
call stack.  But none
of them are called when I try to create a menu using M.

It seems that some code that handles focus invokes a new process to
handle the click by
the mouse on a MenuItemMorph  but doesn't do so or does so such that
nothing happens
when I click on a ItemMorph submorph of an  M morph on my screen.

Where can I set a breakpoint so that I can investigate why nothing
happens when I click
on a ItemMorph instance submorph of an M morph on the screen?

Notes:
1) When my M morph is first displayed there is at the top a balloon that says:

                   Enter text to narrow selection
                   down to matching items

I didn't intend for this balloon to occur but it got picked up somehow.
It would be useful to know how to change its text or remove it.  I
point it out here only because
it may help explain what is happening.

2)  On mouseUp this balloon disappears.

3) after the second mouseDown the  M morph gains a shadow and can be
picked up and moved.

This is an open source project for teaching math/science to young kids.
I have problems with the MIT license though so not sure what license I will use.

Any help much appreciated and sorry about the post length.

Ralph Boland