FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Nueva clase TLayout
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Nueva clase TLayout
Posted: Sun Sep 22, 2013 06:43 PM
Saludos,

les dejo una nueva clase para crear layout en ventanas, esto nos permite autoajustar los controles contenidos, con esta clase podriamos olvidar el uso de @ x,y y el tamaño de los controles

para ver el efecto redimencionen la ventana

dejo un zip con 2 ejemplos ejecutable y todas las fuentes

http://sitasoft.net/fivewin/samples/layout_1.zip

para correr los ejemplos por favor copiarlos en la carpeta de samples de fivewin

aqui el codigo de uno de los ejemplos

Code (fw): Select all Collapse
#include "fivewin.ch"
#include "ribbon.ch"
#include "gif.ch"


function main()
    local oWnd
    local oMainLay
    local hLays := {=>}
    local hButtons := {=>}
    local hBrowses := {=>}
    local oRBar, oFld

    define window oWnd title "testing layout"


    USE CUSTOMER NEW SHARED ALIAS "CUST1"
    USE CUSTOMER NEW SHARED ALIAS "CUST2"

    hLays["MAIN"] = TLayout():new( oWnd )

    hLays["H1"] = hLays["MAIN"]:addHLayout(75)
    hLays["H2"] = hLays["MAIN"]:addHLayout()

    //add 4 layout in H1, will use for 4 buttons
    hLays["H1"]:addVLayout()
    hLays["H1"]:addVLayout()
    hLays["H1"]:addVLayout()
    hLays["H1"]:addVLayout()

    @ 0,0 button hButtons["ONE"] prompt "btn1" of hLays["H1"]:aVLayout[1]
    hLays["H1"]:aVLayout[1]:oClient = hButtons["ONE"]

    @ 0,0 button hButtons["TWO"] prompt "btn2" of hLays["H1"]:aVLayout[2]
    hLays["H1"]:aVLayout[2]:oClient = hButtons["TWO"]

    @ 0,0 button hButtons["THREE"] prompt "btn3" of hLays["H1"]:aVLayout[3]
    hLays["H1"]:aVLayout[3]:oClient = hButtons["THREE"]

    @ 0,0 button hButtons["FOUR"] prompt "btn4" of hLays["H1"]:aVLayout[4]
    hLays["H1"]:aVLayout[4]:oClient = hButtons["FOUR"]

/*
IN THIS POINT THE DISTRIBUTION IS
----------------------------------
|     |                          |
|btn1 |                          |
|-----|                          |
|     |                          |
|btn2 |                          |
|-----|                          |
|     |                          |
|btn3 |                          |
|-----|                          |
|     |                          |
|btn4 |                          |
----------------------------------
->75<-|->REST OF WIDTH         <-|
*/
    
    //add 3 layout in H2, will use for 3 xbrowse
    hLays["H2"]:addVLayout()
    hLays["H2"]:addVLayout()
    hLays["H2"]:addVLayout()


    @ 0,0 XBROWSE hBrowses["ONE"] OF hLays["H2"]:aVLayout[1] ALIAS "CUST1"
    hBrowses["ONE"]:CreateFromCode()
    hLays["H2"]:aVLayout[1]:oClient = hBrowses["ONE"]

    
    @ 0, 0 FOLDEREX oFld PIXEL PROMPT "Gifs", "xbrowse", "layout" of hLays["H2"]:aVLayout[2]
    hLays["H2"]:aVLayout[2]:oClient = oFld

    @ 1,   1 GIF FILE "..\gifs\matrix4.gif" OF oFld:aDialogs[ 1 ] 

    @ 0,0 XBROWSE hBrowses["ONE"] OF oFld:aDialogs[2] ALIAS "CUST2"
    hBrowses["ONE"]:CreateFromCode()
    oFld:aDialogs[2]:oClient = hBrowses["ONE"]

    //WORKING INSIDE FOLDERS
    hLays["FOLDER"] = TLayout():new( oFld:aDialogs[3] )

    hLays["FOLDER_H1"] = hLays["FOLDER"]:addHLayout()

    //add 4 layout in FOLDER_H1, will use for 4 buttons
    hLays["FOLDER_H1"]:addVLayout()
    hLays["FOLDER_H1"]:addVLayout()
    hLays["FOLDER_H1"]:addVLayout()
    hLays["FOLDER_H1"]:addVLayout()

    @ 0,0 button hButtons["FOLDER_ONE"] prompt "btn1" of hLays["FOLDER_H1"]:aVLayout[1]
    hLays["FOLDER_H1"]:aVLayout[1]:oClient = hButtons["FOLDER_ONE"]

    @ 0,0 button hButtons["FOLDER_TWO"] prompt "btn2" of hLays["FOLDER_H1"]:aVLayout[2]
    hLays["FOLDER_H1"]:aVLayout[2]:oClient = hButtons["FOLDER_TWO"]

    @ 0,0 button hButtons["FOLDER_THREE"] prompt "btn3" of hLays["FOLDER_H1"]:aVLayout[3]
    hLays["FOLDER_H1"]:aVLayout[3]:oClient = hButtons["FOLDER_THREE"]

    @ 0,0 button hButtons["FOLDER_FOUR"] prompt "btn4" of hLays["FOLDER_H1"]:aVLayout[4]
    hLays["FOLDER_H1"]:aVLayout[4]:oClient = hButtons["FOLDER_FOUR"]




    DEFINE RIBBONBAR oRBar WINDOW  hLays["H2"]:aVLayout[3] PROMPT "One", "Two", "Three" HEIGHT 133 TOPMARGIN 25 2010

/*
IN THIS POINT THE DISTRIBUTION IS
----------------------------------
|     |                          |
|btn1 |                          |
|-----| xbrowse                  |
|     |--------------------------|
|btn2 |                          |
|-----|                          |
|     | folderex                 |
|btn3 |--------------------------|
|-----|                          |
|     |                          |
|btn4 | ribbonbar                |
----------------------------------
->75<-|->REST OF WIDTH         <-|
*/

    activate window oWnd

return nil


Code (fw): Select all Collapse
#include "fivewin.ch"

#define LAYOUT_TYPE_MAIN       0
#define LAYOUT_TYPE_HORIZONTAL 1
#define LAYOUT_TYPE_VERTICAL   2


class TLayout from TPanel
    
    data bOnResize
    data aHLayout, aVLayout
    data nType
    data nTop, nLeft, nWidth, nHeight
    data lFixed

    data nSumHFix, nHFix, nSumVFix, nVFix HIDDEN

    method new( oWnd )
    method addHLayout()
    method addVLayout()

    method calculeHorizontal( nWidth, nHeight ) HIDDEN
    method calculeVertical( nWidth, nHeight ) HIDDEN

    method onResized( nWidth, nHeight )


endclass


//----------------------------------------------------//

method TLayout:new( oWnd )

    local bOnResize

    ::aHLayout  = {}
    ::aVLayout  = {}

    ::nTop      = 0
    ::nLeft     = 0
    ::nWidth    = 0
    ::nHeight   = 0

    ::lFixed  = .F.
    ::nSumHFix = 0
    ::nHFix    = 0  
    ::nSumVFix = 0
    ::nVFix    = 0

    ::nId = ::GetNewId()

    ::bOnResize = oWnd:bResized

    oWnd:bResized = {| nType, nWidth, nHeight | ::onResized( nType, nWidth, nHeight ) }

    if ! oWnd:isKindOf("TLAYOUT")
        ::nType = LAYOUT_TYPE_MAIN
        oWnd:oClient = self
    endif

return ::Super:new(0,0, oWnd:nHeight, oWnd:nWidth, oWnd)

//----------------------------------------------------//

method TLayout:addVLayout( nHeight )

    local oChild

    DEFAULT nHeight := 0

    oChild = TLayout():new( self )

    oChild:nType = LAYOUT_TYPE_VERTICAL
    oChild:lFixed = nHeight > 0
    oChild:nHeight = nHeight
    
    if oChild:lFixed
        ::nSumVFix++
        ::nVFix += nHeight
    endif

    aadd( ::aVLayout, oChild )

return oChild

//----------------------------------------------------//

method TLayout:addHLayout( nWidth )

    local oChild

    DEFAULT nWidth := 0

    oChild = TLayout():new( self )

    oChild:nType = LAYOUT_TYPE_HORIZONTAL
    oChild:lFixed = nWidth > 0
    oChild:nWidth = nWidth
    
    if oChild:lFixed
        ::nSumHFix++
        ::nHFix += nWidth
    endif

    aadd( ::aHLayout, oChild )

return oChild

//----------------------------------------------------//

method TLayout:calculeVertical( nWidth, nHeight )
    local nLen
    local nNewHeight
    local nAuxHeight, nCalcHeight
    local nItem, nCountNotFixed := 0
    local nTop, nLeft
    local oItem
    local nAcum := 0

    nLen = Len( ::oWnd:aVLayout )
    nCalcHeight := ( nHeight - ::oWnd:nVFix ) / Max( 1, ( nLen - ::oWnd:nSumVFix ) )
    nNewHeight = nCalcHeight
    nTop = 0
    nLeft = 0
    for nItem = 1 to nLen
        oItem = ::oWnd:aVLayout[ nItem ]
        if oItem:nId == ::nId
            if oItem:lFixed
                nAuxHeight = nNewHeight
                nNewHeight = oItem:nHeight
            else
                nCountNotFixed++
                nNewHeight = Round( nCalcHeight * nCountNotFixed, 0 ) - nAcum
                nAuxHeight = nNewHeight
            endif
            ::Move( nTop, nLeft, nWidth, nNewHeight )
            nNewHeight = nAuxHeight                                             
            exit
        else
            if oItem:lFixed
                nTop += oItem:nHeight
            else
                nCountNotFixed++
                nNewHeight = Round( nCalcHeight * nCountNotFixed, 0 ) - nAcum
                nAcum += nNewHeight
                nTop += nNewHeight
            endif           
        endif   
    next
return nil

//----------------------------------------------------//

method TLayout:calculeHorizontal( nWidth, nHeight )
    local nLen
    local nNewWidth
    local nAuxWidth, nCalcWidth
    local nItem, nCountNotFixed := 0
    local nTop, nLeft
    local oItem
    local nAcum := 0

    nLen = Len( ::oWnd:aHLayout )
    nCalcWidth := ( nWidth - ::oWnd:nHFix ) / Max( 1, ( nLen - ::oWnd:nSumHFix ) )
    nNewWidth = nCalcWidth
    nTop = 0
    nLeft = 0
    for nItem = 1 to nLen
        oItem = ::oWnd:aHLayout[ nItem ]
        if oItem:nId == ::nId
            if oItem:lFixed
                nAuxWidth = nNewWidth
                nNewWidth = oItem:nWidth
            else
                nCountNotFixed++
                nNewWidth = Round( nCalcWidth * nCountNotFixed, 0 ) - nAcum
                nAuxWidth = nNewWidth
            endif
            ::Move( nTop, nLeft, nNewWidth, nHeight )
            nNewWidth = nAuxWidth                                               
            exit
        else
            if oItem:lFixed
                nLeft += oItem:nWidth
            else
                nCountNotFixed++
                nNewWidth = Round( nCalcWidth * nCountNotFixed, 0 ) - nAcum
                nAcum += nNewWidth
                nLeft += nNewWidth
            endif           
        endif   
    next
return nil

//----------------------------------------------------//

method TLayout:onResized( nType, nWidth, nHeight )
    if ::nType != LAYOUT_TYPE_MAIN
        if ::oWnd:isKindOf( "TLAYOUT" )
            switch ::nType
                case LAYOUT_TYPE_HORIZONTAL
                    ::calculeHorizontal( nWidth, nHeight )
                    exit
                case LAYOUT_TYPE_VERTICAL
                    ::calculeVertical( nWidth, nHeight )
                    exit
            endswitch
        endif
    end

    if ! ( ::bOnResize == NIL )
        Eval( ::bOnResize, nType, nWidth, nHeight )
    endif

return 0


//----------------------------------------------------//





Posts: 401
Joined: Thu Oct 06, 2005 10:15 PM
Re: Nueva clase TLayout
Posted: Sun Sep 22, 2013 06:57 PM

EXELENTE APORTACION !!! GRACIAS DANIEL


:):):):):lol::lol::lol::):):)

Saludos,



Pablo Alberto Vidal

/*

------------------------------------------------------

Harbour 3.2.0, Fivewin 17.02, BCC7

------------------------------------------------------

*/
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: Nueva clase TLayout
Posted: Sun Sep 22, 2013 10:25 PM

Excelente, era una funcionalidad que faltaba en FWH. Gracias Daniel !!!

Posts: 328
Joined: Fri May 19, 2006 04:08 PM
Re: Nueva clase TLayout
Posted: Mon Sep 23, 2013 01:11 AM

Espectacular !!!
Daniel gracias por este gran aporte !!!

Un gran abrazo

FWH 32/64 14.04

Harbour 3.2.0 (r1306211258)

PellesC
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: Nueva clase TLayout
Posted: Mon Sep 23, 2013 02:43 PM

Oooooooooooooooooooooooooooooooooooooooooooooooh
Fantastico..

Arreglo mis ventanas de venta inmediatamente, con esto me despreocupo de la resolucion de los monitores...

Buena.

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Nueva clase TLayout
Posted: Mon Sep 23, 2013 02:54 PM

Excelente, Gracias Daniel

Saludos,

Adhemar

Saludos,



Adhemar C.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Nueva clase TLayout
Posted: Mon Sep 23, 2013 02:55 PM

Solo nuestro querido mago de los números (y de muchas mas cosas) podia hacer una clase tan buena :-)

Gracias!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: Nueva clase TLayout
Posted: Mon Sep 23, 2013 10:41 PM

Oraleeee !!
como siempre Maestro Daniel,
Felicidades !!

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 392
Joined: Tue Jul 29, 2008 01:55 PM
Re: Nueva clase TLayout
Posted: Mon Sep 23, 2013 11:59 PM

Daniel.

FANTASTICO

Gracias

Saludos

Visite Chiapas, el paraiso de México.
Posts: 880
Joined: Fri Jan 12, 2007 08:35 PM
Re: Nueva clase TLayout
Posted: Tue Sep 24, 2013 03:15 AM

Super increíble genio ! :shock:

Saluditos :wink:

Que es mejor que programar? creo que nada :)
Atropellada pero aqui ando :P

I love Fivewin

séʌǝɹ ןɐ ɐʇsǝ opunɯ ǝʇsǝ
Posts: 1380
Joined: Fri Oct 14, 2005 01:28 PM
Re: Nueva clase TLayout
Posted: Tue Sep 24, 2013 11:22 AM

Daniel;
como siempre muchisimas gracias por tu nuevo y desinteresado aporte

Resistencia - "Ciudad de las Esculturas"

Chaco - Argentina
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Nueva clase TLayout
Posted: Tue Sep 24, 2013 01:29 PM

Daniel,
Muchas gracias.
Este es un aporte de primera magnitud que aumenta el nivel de profesionalismo de los programas desarrollados con FWH.

Saludos,

George

Posts: 593
Joined: Sat May 12, 2007 11:47 AM
Re: Nueva clase TLayout
Posted: Tue Sep 24, 2013 07:58 PM

Buenísimo Daniel, muchas gracias.

Saludos.

Rolando :D

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Nueva clase TLayout
Posted: Wed Oct 23, 2013 06:27 PM

Daniel,
Se podria aplicar tu magnifica clase a este ejemplo?

viewtopic.php?f=3t=27505#p153384

&

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Nueva clase TLayout
Posted: Fri Oct 25, 2013 03:41 AM
Hola

si, de hecho iba a responder el post con un ejemplo usando layout, pero veo que funciona bien como lo presentaron, al parecer no es necesario

la clase TLayout es bastante buena tiene un potencial inmenso

aqui dejo un ejemplo, habria que copiarlo en la carpeta de samples de fivewin para que tome las ruta de las imagenes de forma correcta

Code (fw): Select all Collapse
#include "fivewin.ch"
#xcommand DEFINE LAYOUT <oLayout> <of:OF, WINDOW, DIALOG, LAYOUT> <oDlg> ;
    => ;
    <oLayout> := TLayout():new(<oDlg>) 

#xcommand DEFINE VERTICAL LAYOUT [<oLayout>] OF <oMainLay> [ SIZE <nSize> ]  ;
    => ;
    [<oLayout> :=] <oMainLay>:addVLayout([<nSize>]) 

#xcommand DEFINE HORIZONTAL LAYOUT  [<oLayout>] OF <oMainLay> [ SIZE <nSize> ]  ;
    => ;
    [<oLayout> :=] <oMainLay>:addHLayout([<nSize>]) 

#xcommand SET LAYOUT CONTROL <oControl> OF <oLayout>;
    =>;
    <oLayout>:oClient := <oControl>


function main()

    local oWnd
    local xLay := {=>}
    local oBar1, oBar2


    define window oWnd

    define LAYOUT xLay["main"] of oWnd

    define VERTICAL LAYOUT of xLay["main"] size 32
    define VERTICAL LAYOUT of xLay["main"] size 32

    define buttonbar oBar1 of xLay["main"]:aVLayout[1] size 32,32 2010
    define buttonbar oBar2 of xLay["main"]:aVLayout[2] size 32,32 2007

    DEFINE BUTTON OF oBar1 FILENAME "..\bitmaps\alphabmp\bs_close.bmp" 
    DEFINE BUTTON OF oBar2 FILENAME "..\bitmaps\alphabmp\bs_open.bmp"

    DEFINE BUTTON OF oBar1 FILENAME "..\bitmaps\alphabmp\bs_exit.bmp" 
    DEFINE BUTTON OF oBar2 FILENAME "..\bitmaps\alphabmp\bs_options.bmp" 

    activate window oWnd

return nil