How to dynamically reposition groups on a dialog

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

How to dynamically reposition groups on a dialog

#1 Post by rdonnay »

The below code shows how to use the eXpress++ RESIZE system to dynamically move around groups of objects on the screen when the screen size changes. This technique is handy when there is a large difference in aspect ratio from screen to screen and it is desirable to manage the real estate of the screen to best fit the aspect.

Compile and run the below code and watch what happens when the screen is resized horizontally and vertically.

Press the F9 key several times to see how the screen can be controlled by the user or by the programmer depending on monitor resolution.

This is similar to the <div> tag and style sheets used in HTML for managing real estate based on the device.
After some feedback I tend to take this further and simplify the process for the programmer.
The underlying code would not change, only the STYLE syntax.

Code: Select all

#INCLUDE "dcdialog.ch"
#INCLUDE "appevent.CH"

FUNCTION Main()

LOCAL GetList[0], GetOptions, oGroup1, oGroup2, oGroup3, i, oDlg

@ 0,0 DCSAY 'Press F9 to change screen size' SAYSIZE 0 ;
      RESIZE DCGUI_RESIZE_REPOSONLY_Y

DCHOTKEY xbeK_F9 ACTION {||ScreenSize(oDlg)}

@ 20,0 DCGROUP oGroup1 SIZE 210,210 CAPTION 'Group 1' ;
      RESIZE { {|x,y,o|ResizeGroup1(x,y,o,oDlg)}, nil }

FOR i := 1 TO 8
  @ i*20,20 DCSAY 'This is ' + Alltrim(Str(i)) SAYSIZE 0 ;
     PARENT oGroup1
NEXT

@ 240,0 DCGROUP oGroup2 SIZE 210,210 CAPTION 'Group 2' ;
       RESIZE { {|x,y,o|ResizeGroup2(x,y,o,oDlg,oGroup1)}, nil }

FOR i := 1 TO 8
  @ i*20,20 DCSAY 'This is ' + Alltrim(Str(i)) SAYSIZE 0 ;
     PARENT oGroup2
NEXT

@ 460,0 DCGROUP oGroup3 SIZE 210,210 CAPTION 'Group 3' ;
       RESIZE { {|x,y,o|ResizeGroup3(x,y,o,oDlg,oGroup2)}, nil }

FOR i := 1 TO 8
  @ i*20,20 DCSAY 'This is ' + Alltrim(Str(i)) SAYSIZE 0 ;
     PARENT oGroup3
NEXT

DCGETOPTIONS RESIZE PIXEL

DCREAD GUI FIT TITLE 'Group Relocate Test' OPTIONS GetOptions ;
   PARENT @oDlg

RETURN nil

* ----------

STATIC FUNCTION ResizeGroup1( x,y,o, oDlg )

LOCAL aRepos

aRepos := { o:currentPos()[1],o:CurrentPos()[2]+y }

RETURN aRepos

* ----------

STATIC FUNCTION ResizeGroup2( x,y,o, oDlg, oGroup1 )

LOCAL aRepos

IF oDlg:currentSize()[1] < 450
  aRepos := { oGroup1:currentPos()[1], ;
              oGroup1:CurrentPos()[2]-o:currentSize()[2]-10 }
ELSE
  aRepos := { oGroup1:currentPos()[1]+oGroup1:currentSize()[1]+10, ;
              oGroup1:CurrentPos()[2]}
ENDIF

RETURN aRepos

* ----------

STATIC FUNCTION ResizeGroup3( x,y,o, oDlg, oGroup2 )

LOCAL aRepos

IF oDlg:currentSize()[1] < 690
  aRepos := { oGroup2:currentPos()[1], ;
              oGroup2:CurrentPos()[2]-o:currentSize()[2]-10 }
ELSE
  aRepos := { oGroup2:currentPos()[1]+oGroup2:currentSize()[1]+10, ;
              oGroup2:CurrentPos()[2]}
ENDIF

RETURN aRepos

* ----------

STATIC FUNCTION ScreenSize( oDlg )

IF oDlg:currentSize()[1] >= 690
  oDlg:setSize({250,730})
ELSEIF oDlg:currentSize()[1] >= 470
  oDlg:setSize({690,290})
ELSEIF oDlg:currentSize()[1] < 300
  oDlg:setSize({470,510})
ENDIF

RETuRN nil

* ----------

PROC appsys ; RETURN
screen1.JPG
screen1.JPG (35.21 KiB) Viewed 12169 times
screen2.jpg
screen2.jpg (36.3 KiB) Viewed 12169 times
screen3.jpg
screen3.jpg (36.01 KiB) Viewed 12169 times
The eXpress train is coming - and it has more cars.

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to dynamically reposition groups on a dialog

#2 Post by skiman »

Hi Roger,

I tried this to see if I could use the idea in my application, but this is crashing if you do the following. Take the right bottom corner, and resize the window some times. On my system it crashes within a few seconds.
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to dynamically reposition groups on a dialog

#3 Post by rdonnay »

On my system it crashes within a few seconds.
I cannot make it crash.
What version of eXpress++ and Xbase++ are you using?

What is the crash? Do you get an error screen? Is it an XPPFATAL?

I need more information.
The eXpress train is coming - and it has more cars.

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to dynamically reposition groups on a dialog

#4 Post by skiman »

Hi Roger,

xppfatal.log
FATAL ERROR LOG
Stack Overflow
SYS Thread-ID: 632
Module: EH
Error Codes: EH: 12 Sub: 0(0) OS: 0 XPP: 16
Call Stack of Thread 1 (632):
(B)@DC_GETLIST@I@INIT(776)
DC_COMPLETEEVENTS(176)
(B)@DC_GETLIST@I@INIT(776)
DC_COMPLETEEVENTS(176)
(B)@DC_GETLIST@I@INIT(776)
DC_COMPLETEEVENTS(176)
(B)@DC_GETLIST@I@INIT(776)
DC_COMPLETEEVENTS(176)
(B)@DC_GETLIST@I@INIT(776)
DC_COMPLETEEVENTS(176)
(B)@DC_GETLIST@I@INIT(776)
DC_COMPLETEEVENTS(176)
... some hundred lines
(B)@DC_GETLIST@I@INIT(776)
DC_COMPLETEEVENTS(176)
(B)@DC_GETLIST@I@INIT(776)
DC_COMPLETEEVENTS(176)
(B)@DC_GETLIST@I@INIT(776)
@DC_GETLIST@I@EVENTLOOP(4404)
@DC_GETLIST@I@READGUI(3663)
DC_READGUI(105)
MAIN(164)
Call Stack of GUI Thread (824):
File: C:\customers\Robca\testmove.EXE
TimeStamp: 20150429 12:24
End of FATAL ERROR LOG.

Xbase++ 1.9 355
eXpress++ 254. Sorry, don't be angry at me. :oops:
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to dynamically reposition groups on a dialog

#5 Post by rdonnay »

eXpress++ 254. Sorry, don't be angry at me. :oops:
I won't be angry if you have some of that Pear Liquor when I come out to the European Devcon in November. :naughty:

Here is your fix. Line 767 of _DCGETBX.PRG (build 254) :

Was:

Code: Select all

 ELSEIF ::isResize
    ::parentDlg:resize := {|a,b,o,x|x := SetAppFocus(), ;
                                    ;//o:drawingArea:hide(), ;
                                    DC_ReSize(a,b,o,aGetList,self), ;
                                    ;//o:drawingArea:show(), ;
                                    SetAppFocus(x), ;
                                    DC_CompleteEvents(), ;
                                    nil }
Is:

Code: Select all

  ELSEIF ::isResize
    ::parentDlg:resize := {|a,b,o,x|x := SetAppFocus(), ;
                                    ;//o:drawingArea:hide(), ;
                                    DC_ReSize(a,b,o,aGetList,self), ;
                                    ;//o:drawingArea:show(), ;
                                    SetAppFocus(x), ;
                                    :// DC_CompleteEvents(), ;
                                    nil }
The eXpress train is coming - and it has more cars.

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to dynamically reposition groups on a dialog

#6 Post by skiman »

Thanks for the fix. I will test it again.

Do you know how they put that pear in a bottle? It's growing in it.
Image

I bring a bottle with me in November. The real French stuff.
Best regards,

Chris.
www.aboservice.be

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to dynamically reposition groups on a dialog

#7 Post by skiman »

Roger,

It's working without crash after the modification.

With Windows 8 and xBase++ a dialog will scroll when swiping. Maybe it would be a good idea to dynamically add scrollbars.

If you hit the F9 untill the three groups are besides each other. As in screen3.
Image

Now if you resize the dialog, make it smaller. The group3 moves down. Would it be possible that at that moment, a vertical scrollbar appears?
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to dynamically reposition groups on a dialog

#8 Post by rdonnay »

Add this to the DCGETOPTIONS command:

SCROLLBARS XBP_SCROLLBAR_VERT + XBP_SCROLLBAR_HORIZ
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to dynamically reposition groups on a dialog

#9 Post by Eugene Lutsenko »

Pear in a bottle - it's very cool. But Roger Express and such tricks shows :clap:

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to dynamically reposition groups on a dialog

#10 Post by skiman »

Code: Select all

SCROLLBARS XBP_SCROLLBAR_VERT + XBP_SCROLLBAR_HORIZ
Scrollbars are working perfectly.
Best regards,

Chris.
www.aboservice.be

Post Reply