Graphic on Button - how?

Linux specific forum
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Graphic on Button - how?

Post by Straker »

How can I get the graphic on the button without using the ButtonImageGadget? Basically I want them just like the GTK defaults:

Image

Thanks
Image Image
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Try gtk_button_set_image_().
I'm not sure if that works if the button had no image when it was created though.
The docs say nothing about that.

The alternative is to simply remove the label widget from the button and put an
image and a new label inside (with a packing widget)

Use gtk_image_new_from_stock_() to get the default images.
quidquid Latine dictum sit altum videtur
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

Ok thanks. I'll give it a shot. I saw the examples in C relating packing but it seems like a lot of code to do it...

I'll post my results here.

Thanks
Image Image
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

Hi,

this can be achieved like this:

Code: Select all

IncludeFile "/media/sda2/pb_source/glade2pb/missing_functions.pb"
*hwnd=OpenWindow(0,0,0,400,300,"Test",#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
    *button1=ButtonGadget(#PB_Any,10,10,100,30,"")
    *buttonp=PeekL(*button1)
    
    *image1 = gtk_image_new_from_stock_("gtk-cancel", #GTK_ICON_SIZE_BUTTON);
    gtk_button_set_image_(*buttonp,*image1)
    gtk_button_set_label_(*buttonp,"MyText")
    CloseGadgetList()
EndIf

Repeat
ev = WaitWindowEvent()
ForEver
you need either the "missing_functions.pb" found here:http://home.arcor.de/x-linux/pure/missing_functions.pb
or you have to declare the gtk_button_set_image() funktion by yourself (Openlibrary())

It seems that the #PB_Any returns a pointer to a pointer to a structure and not the pointer to the structure (gtk_button) itself...?? :shock:
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> It seems that the #PB_Any returns a pointer to a pointer to a structure and not the pointer to the structure (gtk_button) itself...??

It returns the internal PB gadget structure, just like on windows.
Simply use GadgetID(). It returns the GtkButton pointer.
quidquid Latine dictum sit altum videtur
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

...gmmpf... sometimes I'm thinking to complicated... didn't thought about GadgetID()... anyway... :D
Post Reply