Bootstrap for FiveWin is a concept based on the grid system used in modern web frameworks like Bootstrap. It enables the creation of user-friendly and responsive user interfaces (UI) in FiveWin applications. The grid system divides the window into a specific number of columns, allowing for simple and consistent positioning and sizing of controls (such as buttons, text fields, labels, etc.).
Main features:
Grid system: The window is divided into 12 columns, with the spacing between columns (gutter) being definable.
Responsive design: The controls automatically adjust to the size of the window when it is resized.
Easy positioning: Controls can be positioned based on rows and columns, similar to HTML/CSS with Bootstrap.
Flexibility: Controls can span across multiple columns (ColSpan) to create complex layouts.
Code: Select all | Expand
#include "FiveWin.ch"
// Farben für Dark Mode
#DEFINE DARK_BACKGROUND RGB( 40, 40, 40 )
#DEFINE DARK_TEXT RGB( 255, 255, 255 )
#DEFINE DARK_BUTTON_BG RGB( 60, 60, 60 )
#DEFINE DARK_BUTTON_FG RGB( 255, 255, 255 )
// Hauptprogramm
FUNCTION Main()
LOCAL oDlg, oGrid
LOCAL oBtnOk, oBtnCancel
// Dialogfenster erstellen
DEFINE DIALOG oDlg ;
TITLE "FiveWin Bootstrap Test" ;
SIZE 800, 600 ;
TRUEPIXEL ;
STYLE WS_THICKFRAME
oDlg:SetColor( DARK_TEXT, DARK_BACKGROUND )
// Grid-System erstellen (12 Spalten, 10 Pixel Abstand)
oGrid := FWGrid():New( 12, 10 )
// Buttons hinzufügen
oBtnOk := FWButton():New( "&Ok", { || MsgInfo("Ok clicked!") }, oDlg, 1, 1, 3 )
oBtnOk:SetColor( DARK_BUTTON_FG, DARK_BUTTON_BG )
oGrid:AddControl( oBtnOk:oButton, 1, 1, 3 )
oBtnCancel := FWButton():New( "&Cancel", { || oDlg:End() }, oDlg, 1, 4, 3 )
oBtnCancel:SetColor( DARK_BUTTON_FG, DARK_BUTTON_BG )
oGrid:AddControl( oBtnCancel:oButton, 1, 4, 3 )
// Grid-System dem Dialog zuweisen
oDlg:bResized := { || oGrid:Resize( oDlg:nWidth(), oDlg:nHeight() ) }
// Dialogfenster anzeigen
ACTIVATE DIALOG oDlg ;
CENTERED
RETURN NIL
// Grid-System
CLASS FWGrid
DATA aControls
DATA nColumns
DATA nGutter
METHOD New( nColumns, nGutter )
METHOD AddControl( oControl, nRow, nCol, nColSpan )
METHOD Resize( nWidth, nHeight )
ENDCLASS
METHOD New( nColumns, nGutter ) CLASS FWGrid
::aControls := {}
::nColumns := nColumns
::nGutter := nGutter
RETURN Self
METHOD AddControl( oControl, nRow, nCol, nColSpan ) CLASS FWGrid
AAdd( ::aControls, { oControl, nRow, nCol, nColSpan } )
RETURN Self
METHOD Resize( nWidth, nHeight ) CLASS FWGrid
LOCAL nColWidth := (nWidth - (::nColumns + 1) * ::nGutter) / ::nColumns
LOCAL nControlWidth, nControlHeight, nX, nY
LOCAL aControl
FOR EACH aControl IN ::aControls
IF aControl[1] != NIL
nControlWidth := nColWidth * aControl[4] + (aControl[4] - 1) * ::nGutter
nControlHeight := 32 // Standardhöhe
nX := ::nGutter + (aControl[3] - 1) * (nColWidth + ::nGutter)
nY := ::nGutter + (aControl[2] - 1) * (nControlHeight + ::nGutter)
aControl[1]:SetPos( nY, nX )
aControl[1]:SetSize( nControlWidth, nControlHeight )
ENDIF
NEXT
RETURN Self
// Vordefinierte Klassen
CLASS FWButton
DATA oButton
METHOD New( cCaption, bAction, oWnd, nRow, nCol, nColSpan )
METHOD SetColor( nTextColor, nBgColor )
ENDCLASS
METHOD New( cCaption, bAction, oWnd, nRow, nCol, nColSpan ) CLASS FWButton
::oButton := TButton():New( 0, 0, cCaption, oWnd, bAction, 100, 32 )
RETURN Self
METHOD SetColor( nTextColor, nBgColor ) CLASS FWButton
::oButton:SetColor( nTextColor, nBgColor )
RETURN Self
But I still have problems here.
Best regards,
Otto
class
Code: Select all | Expand
CLASS TWindow
// ... (vorhandene Daten und Methoden)
// Neue Eigenschaften für das Grid-System
DATA nColumns AS NUMERIC INIT 12 // Anzahl der Spalten im Grid
DATA nGutter AS NUMERIC INIT 5 // Abstand zwischen den Steuerelementen
DATA oGrid AS ARRAY INIT {} // Array zur Speicherung der Steuerelemente im Grid
// Neue Methoden für das Grid-System
METHOD AddToGrid( oControl, nRow, nCol, nColSpan )
METHOD ResizeControls( nWidth, nHeight )
METHOD _NCOLUMNS( nNewValue ) SETGET
// ... (restliche vorhandene Methoden)
ENDCLASS
//----------------------------------------------------------------------------//
METHOD AddToGrid( oControl, nRow, nCol, nColSpan ) CLASS TWindow
// Fügt ein Steuerelement zum Grid hinzu
IF !EMPTY( ::oGrid )
AAdd( ::oGrid, { oControl, nRow, nCol, nColSpan } )
ENDIF
RETURN Self
//----------------------------------------------------------------------------//
METHOD ResizeControls( nWidth, nHeight ) CLASS TWindow
// Berechnet die Größe und Position der Steuerelemente basierend auf dem Grid
LOCAL nColWidth := (nWidth - (::nColumns + 1) * ::nGutter) / ::nColumns
LOCAL nControlWidth, nControlHeight, nX, nY
LOCAL aControl
IF !EMPTY( ::oGrid )
FOR EACH aControl IN ::oGrid
IF aControl[1] != NIL
nControlWidth := nColWidth * aControl[4] + (aControl[4] - 1) * ::nGutter
nControlHeight := 32 // Standardhöhe
nX := ::nGutter + (aControl[3] - 1) * (nColWidth + ::nGutter)
nY := ::nGutter + (aControl[2] - 1) * (nControlHeight + ::nGutter)
aControl[1]:SetPos( nY, nX )
aControl[1]:SetSize( nControlWidth, nControlHeight )
ENDIF
NEXT
ENDIF
RETURN Self
//----------------------------------------------------------------------------//
METHOD _NCOLUMNS( nNewValue ) CLASS TWindow
IF PCount() > 0
::nColumns := nNewValue
ENDIF
RETURN ::nColumns
prg
Code: Select all | Expand
FUNCTION Main()
LOCAL oDlg
LOCAL oSayName, oGetName
LOCAL oSayAge, oGetAge
LOCAL oBtnOk, oBtnCancel
// Create the dialog
oDlg := TDialog():New(,,,, "FiveWin Bootstrap Test",,, .F., 262144,,,,, .F.,,,, 800, 600, .F.,, "oDlg", nil, .T., )
// Initialize grid system
oDlg:nColumns := 12
oDlg:nGutter := 5
oDlg:oGrid := {}
// SAY (Label) for Name
oSayName := TSay():New( 0, 0, "Name:", oDlg )
oDlg:AddToGrid( oSayName, 2, 1, 2 )
// GET (Input field) for Name
oGetName := TGet():New( 0, 0, 100, 32, "", oDlg )
oDlg:AddToGrid( oGetName, 2, 3, 4 )
// SAY (Label) for Age
oSayAge := TSay():New( 0, 0, "Alter:", oDlg )
oDlg:AddToGrid( oSayAge, 3, 1, 2 )
// GET (Input field) for Age
oGetAge := TGet():New( 0, 0, 100, 32, "", oDlg )
oDlg:AddToGrid( oGetAge, 3, 3, 4 )
// Buttons
oBtnOk := TButton():New( 0, 0, "&Ok", oDlg, { || MsgInfo("Ok clicked!") }, 100, 32 )
oDlg:AddToGrid( oBtnOk, 4, 1, 3 )
oBtnCancel := TButton():New( 0, 0, "&Cancel", oDlg, { || oDlg:End() }, 100, 32 )
oDlg:AddToGrid( oBtnCancel, 4, 4, 3 )
// Assign grid system to the dialog
oDlg:bResized := { || oDlg:ResizeControls( oDlg:nWidth(), oDlg:nHeight() ) }
// Show the dialog
ACTIVATE DIALOG oDlg CENTERED
RETURN NIL