[Solved] ButtonGadget text alignment at runtime?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [Solved] ButtonGadget text alignment at runtime?

Post by Shardik »

BorisTheOld wrote:In the great scheme of things, customers don't worry about a few extra machine cycles or how pretty the screen looks.
BorisTheOld wrote:But never have I found it desirable to make API calls from high-level languages.
Do your applications use windows and gadgets to communicate with your users or are they only doing calculations in the background? As soon as you present PB gadgets in your forms you might run into trouble. Did you never need some pretty elementary tasks like to justify text in table columns (ListIconGadget), center text in a StringGadget or display tree items with icons or check boxes (in PB's MacOS version icons and check boxes can only be displayed at the left edge of the TreeGadget: API-workaround) and many more (take a look into my cross-platform examples). For these tasks I needed to use API functions on some or all of the 3 OS platforms and in most cases there doesn't exist a non-API way. Or do you sacrifice a user friendly GUI only in order to not having to use API?

You have already presented examples of your code which consists of thousands of modules. Why should it be so hard to also put API code into modules and change these modules as soon as the missing functionality is implemented natively in PureBasic?

Sorry for hijacking this thread. As a compensation I have taken PB's example code and added the API parts for Linux and MacOS... :twisted:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ImportC ""
    gtk_button_set_alignment(*Button.GtkButton, xAlign.F, yAlign.F)
  EndImport
CompilerEndIf

OpenWindow(0,200,200,200,100,"test")
ButtonGadget(0,10,10,180,80,"Click for left")
bg=GadgetID(0)
t=1

Repeat
  ev=WaitWindowEvent()
  If ev=#PB_Event_Gadget
    t=1-t
    If t=0
      SetGadgetText(0,"Click for center")
    Else
      SetGadgetText(0,"Click for left")
    EndIf

    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Linux
        gtk_button_get_alignment_(bg, @xAlign.F, @yAlign.F)
        gtk_button_set_alignment(bg, Abs(xAlign - 0.5), yAlign)
      CompilerCase #PB_OS_MacOS
        CocoaMessage(0, bg, "setAlignment:", CocoaMessage(0, bg, "alignment") ! 1) 
      CompilerCase #PB_OS_Windows
        SetWindowLongPtr_(bg,#GWL_STYLE,GetWindowLongPtr_(bg,#GWL_STYLE)!#BS_LEFT)
    CompilerEndSelect
  EndIf
Until ev=#PB_Event_CloseWindow
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: [Solved] ButtonGadget text alignment at runtime?

Post by BorisTheOld »

Shardik wrote:Do your applications use windows and gadgets to communicate with your users.......
Yes
Shardik wrote:Did you never need some pretty elementary tasks like to justify text in table columns (ListIconGadget), center text in a StringGadget......
Yes, we do all those things, but with custom gadgets. Such as the custom Button/ButtonBar example that I posted two months ago: http://www.purebasic.fr/english/viewtop ... 40&t=57143

Using the Canvas control, we can create just about any custom gadget we need with the functionality that we need. Be it List gadgets that can handle millions of items, or gadgets that have absolute control over contents, text position, text selection, and cursor position. The possibilities are endless, and it's all done without needing any API code.

It's just a matter of thinking outside the box, and using PB's standard, but powerful, features.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Post Reply