23 April 2016, 13:55 | #1 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
How to change a gadtools button's text?
I am trying to find a way to change the text of a button.
I've tried to find anything on the internet and failed I got 29 gadgets. The first one is of STRING_KIND and all the others of BUTTON_KIND. I've tried updating the text without removing the gadget and failed. I've tried updating the text after removing the gadget and then readding the gadget and failed. (full source here: https://github.com/alexalkis/acalc/blob/master/acalc.c ) Relevant snippet Code:
case GD_SIN: #ifdef USEMPFR mpfr_sin(res, res, MPFR_RNDN); #else res = sin(res); #endif RemoveGadget(wp, gadgets[1]); gadgets[1]->GadgetText->IText = "Ok"; Gadgetdata[1].ng_GadgetText = "shit"; int pos = AddGadget(wp, gadgets[1], 0); RefreshGList(gadgets[1], wp, NULL, 1); GT_RefreshWindow(wp, NULL); printf("new gadget pos: %d\n", pos); Thanks. |
24 April 2016, 11:29 | #2 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
I am trying to change a button from saying "sin" on the button to anything else. (for example "ok")
The above snippet gets executed, but the button's text stays the same. |
24 April 2016, 11:55 | #3 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
gadget[1] is a pointer to a "Gadget"
Code:
struct Gadget { struct Gadget *NextGadget; WORD LeftEdge, TopEdge; WORD Width, Height; UWORD Flags; UWORD Activation; UWORD GadgetType; APTR GadgetRender; APTR SelectRender; struct IntuiText *GadgetText; LONG MutualExclude; APTR SpecialInfo; UWORD GadgetID; APTR UserData; }; Code:
struct IntuiText { UBYTE FrontPen, BackPen; /* the pen numbers for the rendering */ UBYTE DrawMode; /* the mode for rendering the text */ WORD LeftEdge; /* relative start location for the text */ WORD TopEdge; /* relative start location for the text */ struct TextAttr *ITextFont; /* if NULL, you accept the default */ UBYTE *IText; /* pointer to null-terminated text */ struct IntuiText *NextText; /* pointer to another IntuiText to render */ }; |
24 April 2016, 12:09 | #4 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Code:
RemoveGadget(wp, gadgets[1]); gadgets[1]->GadgetText->IText = "Ok"; Gadgetdata[1].ng_GadgetText = "shit"; int pos = AddGadget(wp, gadgets[1], 0); RefreshGList(gadgets[0], wp, NULL, -1); GT_RefreshWindow(wp, NULL); printf("new gadget pos: %d with text \"%s\"\n", pos, gadgets[1]->GadgetText->IText); Code:
new gadget pos: 0 with text "Ok" Further, if I comment out the whole block except the RemoveGadget() then the button is "dead" (i.e. you can't press it) but it is still there!!! [EDIT] if I just comment out the AddGadget it has the same behavior. Button still visible but dead. |
24 April 2016, 12:15 | #5 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
|
24 April 2016, 12:25 | #6 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
What about GT_SetGadgetAttrs? It's used to change all attributes of gadgets, so if it's doable it should be in there.
|
24 April 2016, 12:29 | #7 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Only GA_DISABLED is supported on BUTTON_KIND. (http://amigadev.elowar.com/read/ADCD.../node03F6.html)
PS: I've tried GT_SetGadgetAttrs(gadgets[1], wp, NULL, GTTX_Text ,"Ok", TAG_END); and failed anyways |
24 April 2016, 21:15 | #8 |
Registered User
Join Date: Oct 2012
Location: Germany
Posts: 585
|
I'm not sure, but are you trying to change the text by just assigning a new string?
|
25 April 2016, 00:22 | #9 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
|
25 April 2016, 00:46 | #10 |
Registered User
Join Date: Oct 2012
Location: Germany
Posts: 585
|
Create two strings at the start of the program, remove the gadget, set pointer to 2nd string and add it again.
Or copy new string over old text with strcpy or sprintf, after removing the gadget. |
25 April 2016, 19:30 | #11 | |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Quote:
Although the second idea is mega-hack, I've tried it. Still doesn't work. |
|
25 April 2016, 19:44 | #12 |
Registered User
Join Date: Oct 2012
Location: Germany
Posts: 585
|
Hrm...I am tempted to try it myself. Maybe at the weekend.
|
25 April 2016, 20:19 | #13 |
Registered User
Join Date: Oct 2012
Location: Germany
Posts: 585
|
If I am interpreting the RKM correctly, gadget data is allocated (and thus copied) when calling CreateGadget(). You cannot modify gadget text via SetGadgetAttr(), as you already found out.
Only way is to remove all gadgets, call FreeGadgets() and create a new gadget list. Alternative: create your own gadget with pure Intuition or BOOPSI. |
26 April 2016, 06:08 | #14 | |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Quote:
Oh well, will give it a shot. Thanks. |
|
26 April 2016, 07:41 | #15 |
Registered User
Join Date: Oct 2012
Location: Germany
Posts: 585
|
GadTools gadgets have been implemented as an easy, "no hassle"-framework for the most common UI-tasks. That's why you hit the wall quickly if you try something the developers didn't regard as common.
I'm currently struggling with a BOOPSI-class for a button-gadget displaying changing imagery. Believe me, it's not getting any better |
26 April 2016, 19:11 | #16 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Indeed removing all and readding worked! (Yay)
so this does work Code:
Gadgetdata[1].ng_GadgetText = "new"; ReAddGadgets(); Code:
void ReAddGadgets(void) { struct Gadget *pgad; int i; if (glist) { RemoveGList(wp, glist, -1); FreeGadgets(glist); } pgad = CreateContext(&glist); /* ContextData ! */ for (i=0; i < 29; i++) { if (gadgets[i] = pgad = CreateGadgetA( (i == 0) ? STRING_KIND : BUTTON_KIND, pgad, &Gadgetdata[i], (i == 0) ? (struct TagItem *)&GadgetTags[i]: NULL)) { if (i == 0) { display = pgad; } } else { printf("Failed to create gadget %d.\n", i); } } AddGList(wp, glist, -1, -1, NULL); RefreshGList(glist, wp, NULL, -1); GT_RefreshWindow(wp, NULL); } |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
gadtools | zharn | Coders. C/C++ | 6 | 21 February 2014 20:26 |
change the config with a button click ? | turrican3 | support.WinUAE | 4 | 08 December 2013 09:54 |
Change Scalos Icon Text color | TronPlayer | support.Hardware | 3 | 05 January 2011 23:03 |
Any way to change Radboot Left Mouse Button? | fitzsteve | project.ClassicWB | 8 | 20 January 2010 22:53 |
Change text colors | frikilokooo | project.ClassicWB | 6 | 08 March 2008 21:26 |
|
|