It is currently Wed Oct 23, 2019 8:08 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: StringGadget Centered Hal & Val cross platform
PostPosted: Tue Jun 11, 2019 5:27 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3429
It should be cross platform
Using only native commands
Tested with Windows only

Code:
Global sh,cw,ch

Procedure type()
  Text$ = GetGadgetText(1)
  StartDrawing(WindowOutput(0))
    DrawingFont(FontID(0))
    w = TextWidth(text$)
  StopDrawing()     
  ResizeGadget(1,cw/2-w/2,ch/2-sh/2-2,w,sh)
EndProcedure

LoadFont(0,"Tahoma",24)
OpenWindow(0, 0, 0, 600, 400, "StringGadget ", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowColor(0,#White)
StartDrawing(WindowOutput(0))
  DrawingFont(FontID(0))
  sh = TextHeight("Q")+2
  sw = TextWidth(" ")
StopDrawing()

ContainerGadget(0,10,10,580,60,#PB_Container_Flat)
  SetGadgetColor(0,#PB_Gadget_BackColor,$FFFFFF)
  cw = GadgetWidth(0)
  ch = GadgetHeight(0)
  StringGadget(1, cw/2,10,sw,sh," ",#PB_String_BorderLess)
  SetGadgetFont(1,FontID(0))
  SetGadgetColor(1,#PB_Gadget_FrontColor,$0000FF) 
CloseGadgetList()

SetGadgetFont(1,FontID(0))

SetActiveGadget(1)

BindGadgetEvent(1,@type())
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()
         Case 1
         
      EndSelect
  EndSelect
Until Quit = 1


Edit : Modified #1

_________________
Egypt my love


Last edited by RASHAD on Tue Jun 11, 2019 7:43 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: StringGadget Centered Hal & Val cross platform
PostPosted: Tue Jun 11, 2019 7:03 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1651
Location: Germany
The vertical centering is indeed working cross-platform. But the first input character is not fully visible on Linux (Linux Mint 19.1 'Tessa' x64 with Cinnamon and GTK3)

Image

and on MacOS (MacOS 10.13.6 'High Sierra'):

Image


Top
 Profile  
Reply with quote  
 Post subject: Re: StringGadget Centered Hal & Val cross platform
PostPosted: Tue Jun 11, 2019 7:45 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3429
Thanks Shardik
Previous post updated but I do things blindly

Played around with the other post maybe it will be OK with Mac
Code:
LoadFont(0,"Tahoma",24)

OpenWindow(0, 0, 0, 600, 400, "StringGadget ", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
SetWindowColor(0,#White)
StringGadget(1, 10,10,580,40,"ABCDEJQ")
SetGadgetFont(1,FontID(0))
dummy = TextGadget(#PB_Any,0,0,0,0,"ABCDEJQ")
  SetGadgetFont(dummy,FontID(0))
  h = GadgetHeight(dummy,#PB_Gadget_RequiredSize)
FreeGadget(dummy)
ResizeGadget(1,10,10,#PB_Ignore,h+2)

Repeat

Until WaitWindowEvent() = #PB_Event_CloseWindow

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: StringGadget Centered Hal & Val cross platform
PostPosted: Wed Jun 12, 2019 3:36 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 4:41 am
Posts: 673
Location: Canada
I'm not sure I follow here, RASHAD.
Why the detour through a dummy TextGadget() to get the fitted height since GadgetHeight(#gadget,#PB_Gadget_RequiredSize) works perfectly with StringGadget() ?

It's the fitted width that is a problem with StringGadget().

_________________
"That's not a bug..." said the programmer. "...It's a feature! "
"Oh! I see..." replied the blind man.


Top
 Profile  
Reply with quote  
 Post subject: Re: StringGadget Centered Hal & Val cross platform
PostPosted: Wed Jun 12, 2019 4:37 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3429
Hi Blue
Shardik in other thread reported that GadgetHeight() for StringGasget() did not work with Mac
So I am trying an alternative maybe you know :P
Sorry mate :wink:

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: StringGadget Centered Hal & Val cross platform
PostPosted: Wed Jun 12, 2019 6:37 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 4:41 am
Posts: 673
Location: Canada
Thanks RASHAD.
Oh, yes, now I understand.
I had skipped that part of the question.

(I was the same in the army : always a step behind.
It must be genetic.)

But your suggestion to him led me to rewrite the code I posted last night in that other topic about a related question. This time I made use of the simple but effective idea you presented above (taking measurements via a dummy TextGadget()) and discovered that it is very effective. but it has its peculiarities too.

I'll erase my useless code of last night and post this more efficient one. And, as usual, i'll have a question or two for you. So don't go out tonight and don't fall asleep. You're needed at the shop.

_________________
"That's not a bug..." said the programmer. "...It's a feature! "
"Oh! I see..." replied the blind man.


Top
 Profile  
Reply with quote  
 Post subject: Re: StringGadget Centered Hal & Val cross platform
PostPosted: Wed Jun 12, 2019 9:14 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4511
Location: Lyon - France
Works great here W7 x86 // v5.70 X86
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: StringGadget Centered Hal & Val cross platform
PostPosted: Wed Jun 12, 2019 12:08 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 24, 2005 4:02 pm
Posts: 913
Location: Germany
StringEx - Module
(I have added support for centring and right-justification)

_________________
Sorry for my English. My language is German.
(Translated with http://www.DeepL.com/Translator)

Download of PureBasic - Modules (GitHub)

[Windows 10 x64] [PB V5.7x]


Top
 Profile  
Reply with quote  
 Post subject: Re: StringGadget Centered Hal & Val cross platform
PostPosted: Wed Jun 12, 2019 2:54 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3429
@KCC
Thanks buddy

@Thorsten1867
Your modules and RSBasic also are very much appreciated
Good work indeed
Thanks

_________________
Egypt my love


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye