StringGadget right alignment

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
ken_anthony
User
User
Posts: 77
Joined: Thu Jun 20, 2013 5:41 am
Location: Springerville AZ USA

StringGadget right alignment

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: StringGadget right alignment

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: StringGadget right alignment

Post by davido »

@skywalk:

Very easy to miss: It doesn't appear to be in the manual!
DE AA EB
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: StringGadget right alignment

Post 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.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: StringGadget right alignment

Post 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!
DE AA EB
ken_anthony
User
User
Posts: 77
Joined: Thu Jun 20, 2013 5:41 am
Location: Springerville AZ USA

Re: StringGadget right alignment

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: StringGadget right alignment

Post by Fred »

Using other gadget flags is not supported, use SetWindowLong_() on Windows if you want to change the style
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: StringGadget right alignment

Post 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.
DE AA EB
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: StringGadget right alignment

Post 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?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
ken_anthony
User
User
Posts: 77
Joined: Thu Jun 20, 2013 5:41 am
Location: Springerville AZ USA

Re: StringGadget right alignment

Post by ken_anthony »

Running that code snippet I get 3 password balls.

Linux Mint 15rc.
ken_anthony
User
User
Posts: 77
Joined: Thu Jun 20, 2013 5:41 am
Location: Springerville AZ USA

Re: StringGadget right alignment

Post by ken_anthony »

Also I forgot to mention 32bit.
Zach
Addict
Addict
Posts: 1675
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: StringGadget right alignment

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: StringGadget right alignment

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
ken_anthony
User
User
Posts: 77
Joined: Thu Jun 20, 2013 5:41 am
Location: Springerville AZ USA

Re: StringGadget right alignment

Post 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.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: StringGadget right alignment

Post 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
Last edited by Shardik on Tue Jun 25, 2013 1:46 pm, edited 1 time in total.
Post Reply