How to place a StringGadget on the Toolbar?
How to place a StringGadget on the Toolbar?
How to place a StringGadget on the Toolbar?
Re: How to place a StringGadget on the Toolbar?
You can't.
Programs doing this don't use toolbars, but Ribbons or other custom things.
Programs doing this don't use toolbars, but Ribbons or other custom things.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: How to place a StringGadget on the Toolbar?
You can!

With:
Code: Select all
SetParent_(GadgetID(#StringGadget), ToolBarID(#ToolBar))
Simple example:
Code: Select all
Enumeration
#Window
#ToolBar
#ToolBarImageButton
#StringGadget
EndEnumeration
OpenWindow(#Window, 0, 0, 150, 50, "ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateToolBar(#ToolBar, WindowID(#Window))
UsePNGImageDecoder()
Path$ = #PB_Compiler_Home + "Examples" + #PS$ + "Sources" + #PS$ + "Data" + #PS$ + "ToolBar" + #PS$ + ""
ToolBarImageButton(#ToolBarImageButton, LoadImage(0, Path$ + "New.png"))
StringGadget(#StringGadget, 30, 2, 100, 20, "Hello!")
SetParent_(GadgetID(#StringGadget), ToolBarID(#ToolBar))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Hygge
Re: How to place a StringGadget on the Toolbar?
Great, but I need it for Linux! 

Re: How to place a StringGadget on the Toolbar?
I have modified Kiffi's example to also work on Linux and MacOS. I have tested it successfully with PB 6.20 x64 on these operating systems:
- Linux Mint 21.3 'Virginia' with Cinnamon
- MacOS 13.7.4 'Ventura'
- RaspberryPi OS 64-Bit (Debian 12.9 'Bookworm')
- Windows 10 23H2
Code: Select all
Enumeration
#Window
#ToolBar
#ToolBarImageButton
#StringGadget
EndEnumeration
OpenWindow(#Window, 0, 0, 170, 50, "ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateToolBar(#ToolBar, WindowID(#Window))
UsePNGImageDecoder()
Path$ = #PB_Compiler_Home + "examples" + #PS$ + "sources" + #PS$ + "Data" +
#PS$ + "ToolBar" + #PS$ + ""
ToolBarImageButton(#ToolBarImageButton, LoadImage(0, Path$ + "New.png"))
StringGadget(#StringGadget, 30, 2, 100, 20, "Hello!")
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
ToolItem = gtk_tool_item_new_()
gtk_tool_item_set_visible_horizontal_(ToolItem, #True)
gtk_toolbar_insert_(ToolBarID(#ToolBar), ToolItem, -1)
gtk_widget_reparent_(GadgetID(#StringGadget), ToolItem)
gtk_widget_show_all_(WindowID(#Window))
CompilerCase #PB_OS_MacOS
Define Size.NSSize
Size\width = GadgetWidth(#StringGadget)
Size\height = GadgetHeight(#StringGadget)
CreateImage(0, 24, 24)
ToolBarImageButton(#StringGadget, ImageID(0))
ItemArray = CocoaMessage(0, ToolBarID(#ToolBar), "items")
Item = CocoaMessage(0, ItemArray, "objectAtIndex:", 1)
CocoaMessage(0, Item, "setView:", GadgetID(#StringGadget))
CocoaMessage(0, Item, "setMaxSize:@", @Size)
CocoaMessage(0, Item, "setMinSize:@", @Size)
CompilerCase #PB_OS_Windows
SetParent_(GadgetID(#StringGadget), ToolBarID(#ToolBar))
CompilerEndSelect
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Re: How to place a StringGadget on the Toolbar?
Ok, you can.
This is not intended by M$.

Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD