Tabs - Elements - Hag GUI for Cobra
Tabs allow the user to switch between several forms, making good use of screen space. Each tab belongs to a "Tab Group", and only one tab can be selected per group at any time.
Tab Groups expose the following read-only variables:
tabGroup.x: Integer - Tab group x position
tabGroup.y: Integer - Tab group y position
tabGroup.enabled: Boolean - If tab group is enabled
tabGroup.visible: Boolean - If tab group is visible
Tabs expose the following read-only variables:
tab.x: Integer - Tab x position
tab.y: Integer - Tab y position
tab.w: Integer - Tab width
tab.h: Integer - Tab height
tab.enabled: Boolean - If tab is enabled
tab.visible: Boolean - If tab is visible
For a ready-to-run example, see Example_Tabs or Example2D in the Examples download.
Example:
Uses
hagC2D,
cobra2D,
keyset
Const
EXAMPLES_PER_TAB = 4
Procedure UpdateMyControls()
Var
selTab : ^tabs
lastSelTab : Static ^tabs
Begin
{ Tabs }
selTab = SelectedTab(tabGroup1)
If selTab <> lastSelTab then
lastSelTab = selTab
HideForm(frm1a)
HideForm(frm1b)
HideForm(frm1c)
HideForm(frm1d)
If selTab = tab1a then ShowForm(frm1a)
If selTab = tab1b then ShowForm(frm1b)
If selTab = tab1c then ShowForm(frm1c)
If selTab = tab1d then ShowForm(frm1d)
Endif
If selTab = tab1a then UpdateForm1a()
If selTab = tab1b then UpdateForm1b()
If selTab = tab1c then UpdateForm1c()
If selTab = tab1d then UpdateForm1d()
End
Procedure UpdateForm1a()
Begin
If ButtonClicked(frm1a_btnClose) then RequestExit
End
Procedure UpdateForm1b()
Begin
If ButtonClicked(frm1b_btnClose) then RequestExit
End
Procedure UpdateForm1c()
Begin
If ButtonClicked(frm1c_btnClose) then RequestExit
End
Procedure UpdateForm1d()
Begin
If ButtonClicked(frm1d_btnClose) then RequestExit
End
Var
i: Integer
frmMain: ^forms
frameMain : ^frames
tabGroup1: ^tabGroups
tab1a: ^tabs
frm1a: ^forms
frm1a_btnButtons: Array[EXAMPLES_PER_TAB] of ^buttons
frm1a_btnClose: ^buttons
tab1b: ^tabs
frm1b: ^forms
frm1b_sliSliders: Array[EXAMPLES_PER_TAB] of ^sliders
frm1b_btnClose: ^buttons
tab1c: ^tabs
frm1c: ^forms
frm1c_prgProgress: Array[EXAMPLES_PER_TAB] of ^progressBars
frm1c_btnClose: ^buttons
tab1d: ^tabs
frm1d: ^forms
frm1d_btnButtons: Array[EXAMPLES_PER_TAB] of ^buttons
frm1d_btnClose: ^buttons
background: Element
Begin
SetAppName("Tabs example")
OpenScreen(320, 240, 32, FALSE, COB_SHOWBORDER+COB_SHOWCLOSE)
Randomize(Millisecs)
background = CreateSprite(320,240)
Cls(ToRGBA(235,233,237),background) ; Flip
// Init GUI
HagBaseDir("hag\")
HagInit(320, 240, 1) // Start at sprite index 1 because of the background sprite
HagLoadGuiTheme("xp")
// Set up GUI Elements
frmMain = CreateForm()
frameMain = CreateFrame(frmMain,20,20,280,170,FRAME_STYLE_TAB)
tabGroup1 = CreateTabGroup(frmMain)
tab1a = CreateTab(tabGroup1,20,20,60,"Tab 1",TRUE)
tab1b = CreateTab(tabGroup1,80,20,60,"Tab 2")
tab1c = CreateTab(tabGroup1,140,20,60,"Tab 3")
tab1d = CreateTab(tabGroup1,200,20,60,"Tab 4")
// Tab 1a
frm1a = CreateForm("Form 1a")
frm1a_btnClose = CreateButton(frm1a, 240, 200, 50, "Close")
For i = 0 to (EXAMPLES_PER_TAB-1)
frm1a_btnButtons[i] = CreateButton(frm1a, 40, 60 + (i*30), 100, "Button "+(i+1))
Next
FocusButton(frm1a_btnClose)
// Tab 1b
frm1b = CreateForm("Form 1b")
frm1b_btnClose = CreateButton(frm1b, 240, 200, 50, "Close")
For i = 0 to (EXAMPLES_PER_TAB-1)
frm1b_sliSliders[i] = CreateSlider(frm1b, 40, 60 + (i*30), 100)
SliderSetPercent(frm1b_sliSliders[i], Rand(0,100))
Next
FocusButton(frm1b_btnClose)
// Tab 1c
frm1c = CreateForm("Form 1c")
frm1c_btnClose = CreateButton(frm1c, 240, 200, 50, "Close")
For i = 0 to (EXAMPLES_PER_TAB-1)
frm1c_prgProgress[i] = CreateProgressBar(frm1c, 40, 60 + (i*30), 100)
ProgressBarPercent(frm1c_prgProgress[i], Rand(0,100))
Next
FocusButton(frm1c_btnClose)
// Tab 1d
frm1d = CreateForm("Form 1d")
frm1d_btnClose = CreateButton(frm1d, 240, 200, 50, "Close")
For i = 0 to (EXAMPLES_PER_TAB-1)
frm1d_btnButtons[i] = CreateButton(frm1d, 40, 60 + (i*30), 100, "More "+(i+1))
Next
FocusButton(frm1d_btnClose)
HagUpdateOnce()
While ExitRequested = FALSE
HagUpdateAll_AutoKeys()
UpdateMyControls()
If KeyHits(VK_ESCAPE) > 0 then RequestExit
Flip
Pause(1)
Wend
HagFreeAll()
CloseScreen()
End
Stay Subscribed
RSS feed or get updates by e-mail.
, subscribe to theYou can also contact me directly - I make an effort to reply to every e-mail.