Page 1 of 2

StringGadget right alignment

Posted: Sun Jun 23, 2013 5:17 am
by ken_anthony
Now that I've bought the compiler I must make it work regardless of what it takes. Customers don't care about the programmers problems. /Preface over.

Apparently StringGadget is what former VB programmers would call a textbox. How can you have a textbox without the ability to right align numbers in it? My workaround will be to pad spaces (assuming I can find a suitable event to tie it to.)

But a right alignment option is almost essential for anything I would give my customers. I will make do until that day.

How do you guys do it? Be of good cheer.

ken.

Re: StringGadget right alignment

Posted: Sun Jun 23, 2013 6:27 am
by skywalk
Use the forum search padawan... :wink:

Code: Select all

If OpenWindow(0, 0, 0, 322, 205, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(0, 8,  10, 306, 20, "Normal StringGadget...", #PB_Text_Right)
  StringGadget(1, 8,  35, 306, 20, "1234567", #PB_String_Numeric|#PB_Text_Right)
  StringGadget(2, 8,  60, 306, 20, "Read-only StringGadget", #PB_String_ReadOnly|#PB_Text_Right)
  StringGadget(3, 8,  85, 306, 20, "lowercase...", #PB_String_LowerCase|#PB_Text_Right)
  StringGadget(4, 8, 110, 306, 20, "uppercase...", #PB_String_UpperCase|#PB_Text_Right)
  StringGadget(5, 8, 140, 306, 20, "Borderless StringGadget", #PB_String_BorderLess|#PB_Text_Right)
  StringGadget(6, 8, 170, 306, 20, "Password", #PB_String_Password|#PB_Text_Right)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: StringGadget right alignment

Posted: Sun Jun 23, 2013 8:30 am
by davido
@skywalk:

Very easy to miss: It doesn't appear to be in the manual!

Re: StringGadget right alignment

Posted: Sun Jun 23, 2013 9:02 am
by eesau
davido wrote:It doesn't appear to be in the manual!
It's not officially supported: #PB_Text_Right is a flag for TextGadget, not StringGadget, that's why it's missing in the manual.

Re: StringGadget right alignment

Posted: Sun Jun 23, 2013 11:06 am
by davido
@eesau: Thank you very much for your explanation. :D

I thought that there was something strange as it is not listed in the 'changelogs' either.
No wonder it is difficult to locate!

Re: StringGadget right alignment

Posted: Sun Jun 23, 2013 11:47 am
by ken_anthony
Didn't work.

Code: Select all

    txtMMUnitPrice = StringGadget(#PB_Any, 770, 150, 80, 50, "0.00",#PB_String_Numeric | #PB_Text_Right)
    txtMMTotalPrice = StringGadget(#PB_Any, 860, 150, 80, 50, "0.00",#PB_String_ReadOnly | #PB_Text_Right)
Both fields became password fields only showing little balls.

Re: StringGadget right alignment

Posted: Sun Jun 23, 2013 12:01 pm
by Fred
Using other gadget flags is not supported, use SetWindowLong_() on Windows if you want to change the style

Re: StringGadget right alignment

Posted: Sun Jun 23, 2013 12:03 pm
by davido
Hi ken_anthony,

Thank you for asking the question. Nice to learn something new. :D

I did try the code skywalk quoted and it worked just fine.

I injected your code into the aforementioned code, enlarged the window and it worked with your code, too.
Then changed the second of your string gadgets to show centre and that worked, too.

I'm using 64 bit PureBasic with Windows 7-64 bit. I assume you are using windows, from reading your first post.
From what eesau posted, it might not work with other OS's.

Re: StringGadget right alignment

Posted: Sun Jun 23, 2013 12:04 pm
by PB
> txtMMUnitPrice = StringGadget(#PB_Any, 770, 150, 80, 50, "0.00",#PB_String_Numeric | #PB_Text_Right)
> became password fields only showing little balls.

Works fine here on Win7 64-bit (the "0.00" is right-aligned):

Code: Select all

If OpenWindow(0,200,250,450,200,"test",#PB_Window_SystemMenu)
  sg=StringGadget(#PB_Any,20,20,100,21,"0.00",#PB_String_Numeric|#PB_Text_Right)
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
When you run my snippet above on your PC, what happens?

Re: StringGadget right alignment

Posted: Mon Jun 24, 2013 1:31 am
by ken_anthony
Running that code snippet I get 3 password balls.

Linux Mint 15rc.

Re: StringGadget right alignment

Posted: Mon Jun 24, 2013 1:32 am
by ken_anthony
Also I forgot to mention 32bit.

Re: StringGadget right alignment

Posted: Mon Jun 24, 2013 3:24 am
by Zach
Maybe this is one of those interoperability shortfalls that people sometimes gripe about (Windows being the most maintained version, and Linux/MacOS suffering)

Are you using GTK? (I know nothing about PB on Linix) Maybe you can do this via API? If its a cross-platform app you can just section that bit of code off with a CompilerIF flag to only compile for Linux and use a different solution for your other targets.

Also, when you post a thread like this it would be good to preface it with your PB [PB Linux X.xx] version so people don't get confused and give answers for the wrong OS :mrgreen:
Most of us here use Windows I think, so people naturally give windows oriented answers by default

edit: does this help ? (again, assuming GTK)

https://developer.gnome.org/gtk3/3.4/Gt ... -alignment

http://www.mail-archive.com/gtk-list@gn ... 15523.html

http://ubuntuforums.org/showthread.php?t=1206616

This may also be relevant for porting-in unrecognized API
http://www.purebasic.fr/english/viewtop ... it=GTK+API

Re: StringGadget right alignment

Posted: Mon Jun 24, 2013 6:32 am
by ts-soft
The RightAlignment works under Windows only because has #ES_RIGHT the same value, how #PB_Text_Right.

Code: Select all

Debug #PB_Text_Right
Debug #SS_RIGHT
Debug #ES_RIGHT
Better use #ES_RIGHT on Stringgadget or as Fred suggest, change the Style to make sure it works.

Greetings - Thomas

Re: StringGadget right alignment

Posted: Mon Jun 24, 2013 6:38 am
by ken_anthony
Thanks for the info. I was very productive today meaning I'm pretty fried right now. I need to get it out of my mind for a while (I code in my sleep. You would not believe how often I wake up with solutions.) I've got most of my forms done except for a few issues and now have to connect to a SQL db. I was going to go MySQL but now I'm leaning toward PostgreSQL (in the old days my VB data object connected to all of them with the selection of a single enum.) I'm in discussion with some hosts now and need to make a decision. But sleep first.

Re: StringGadget right alignment

Posted: Mon Jun 24, 2013 9:58 am
by Shardik
Fred wrote:Using other gadget flags is not supported, use SetWindowLong_() on Windows if you want to change the style
Unfortunately it's a little bit more complicated. In Windows XP the alignment is only possible on creation of the StringGadget. Beginning with Windows Vista it's possible to change the alignment of a StringGadget's content dynamically:
http://forum.purebasic.com/english/view ... 13&t=36853

Try the following cross-platform code which I tested on Windows XP x86 SP3, Windows 7 x86 SP1, Kubuntu 13.04 x86 and Linux Mint 15 x86 Cinnamon. It redefines the StringGadget on Windows XP with the attribute #ES_RIGHT and changes the alignment dynamically on Windows Vista, Windows 7, Linux and MacOS X:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ImportC ""
    gtk_entry_set_alignment(Entry.I, XAlign.F)
  EndImport
CompilerEndIf

OpenWindow(0, 100, 100, 280, 70, "Right-aligned StringGadget", #PB_Window_SystemMenu)
StringGadget(0, 60, 20, 150, 21, "123")

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    gtk_entry_set_alignment(GadgetID(0), 1)
  CompilerCase #PB_OS_MacOS
    CocoaMessage(0, GadgetID(0), "setAlignment:", 1)
  CompilerCase #PB_OS_Windows
    If OSVersion() > #PB_OS_Windows_XP
      SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) & $FFFFFFFC | #ES_RIGHT) 
    Else
      StringGadget(0, 60, 20, 150, 21, "123", #ES_RIGHT)
    EndIf
CompilerEndSelect

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow