How to use gs:menu() as a pop-up inside a frame/canvas?

Gunilla Arendt gunilla@REDACTED
Mon Jan 28 09:49:33 CET 2002


A popup menu can have a menubutton, window or frame as parent, but not
a canvas. Below is a simple example of using a popup menu inside a

/ Gunilla

-export([start/0, init/0]).

start() -> spawn(?MODULE, init, []).

init() ->
    GS = gs:start(),
    Win = gs:window(GS, [{width,200}, {height,100}, {buttonpress,true},
    Frm = gs:frame(Win, [{x,0}, {y,0}, {width,200}, {height,100}]),
    Menu = gs:menu(Frm),
    gs:menuitem(Menu, [{label,{text,"Item 1"}}]),
    gs:menuitem(Menu, [{label,{text,"Item 2"}}]),
    gs:menuitem(Menu, [{label,{text,"Item 3"}}]),

loop(Menu) ->
	{gs, _Obj, buttonpress, _Data, [_Button,X,Y|_]} ->
	    gs:config(Menu, {post_at, {X,Y}}),
	_ ->

Ed Landa wrote:
> I've been trying to come up with the solution to this problem all day.
> Unfortunately, the docs only seem to hint at this feature being available and I
> can't find any similar contributed code anywhere.
> How can I create a pop-up menu inside of a frame?  I have a canvas with several
> items on it, and I would like to bring up a menu when a user right-clicks on an
> item.  I can build the menu just fine, but it never displays.  I've tried
> config'ing the object with {map, true}, {active,true} and {post_at,{X,Y}} in
> all different combinations, but nothing happens.
> While looking thru the gs source, I noticed some comments about comments about
> some config options being "not implemented".  Could it be that the pop-up stuff
> was never quite completed?
> Any assistance would be greatly appreciated.  I can provide my test code if
> needed.
> Thanks,
> Ed

More information about the erlang-questions mailing list