Add lhs_dialog.pbi a GUI Library/Module

Initial state with some Bugs
This commit is contained in:
René Linder 2019-05-20 13:19:02 +02:00
parent 9d6def2132
commit a7d3ed5432

174
GUI/lhs_dialog.pbi Normal file
View file

@ -0,0 +1,174 @@
;************************************************
;*
;* Advanced Dialog V0.1
;*
;*
;*
DeclareModule lhs_lib_adv_diag
Enumeration Dialogtypes
#lhs_adv_dialog_text
#lhs_adv_dialog_string
#lhs_adv_dialog_edit
EndEnumeration
Declare dialog() ;Dialog darstellen und abwarten
Declare init(Titel.s)
Declare add(Descrition.s, UID.s, Type.i, Lines.i, Content.s="") ;Element zum Dialog hinzufügen
Declare reset() ;dialog Liste leeren.
Declare.s get_explizit(UID.s) ;Respronse exlpizit zurückgeben
Declare get_init() ;get() Initilaiseren beim ersten element
Declare.s get() ;gibt das Aktuelle element zurück
EndDeclareModule
Module lhs_lib_adv_diag
Structure lhs_adv_dialog
Lines.i
Id.i
Text_Id.i
UID.s
Description.s
Type.i
Response.s
EndStructure
Global NewList lhs_adv_diag_content.lhs_adv_dialog()
Global Current_Element, Total_Elements
Procedure reset()
ClearList(lhs_adv_diag_content())
EndProcedure
Procedure add(Descrition.s, UID.s, Type.i, Lines.i, Content.s="")
AddElement(lhs_adv_diag_content())
lhs_adv_diag_content()\Description = Descrition
lhs_adv_diag_content()\UID = UID
lhs_adv_diag_content()\Type= Type
lhs_adv_diag_content()\Lines = Lines
lhs_adv_diag_content()\Response = Content
EndProcedure
Procedure init(Titel.s)
reset()
AddElement(lhs_adv_diag_content())
lhs_adv_diag_content()\Description = Titel
Total_Elements = 0
Current_Element = 0
EndProcedure
Procedure dialog()
Define Dialog, Dialog_Height, Event, PosY, Lines_curr, Current, Button_Ok, Button_Cancel
ResetList(lhs_adv_diag_content())
NextElement(lhs_adv_diag_content())
Current_Element = 0
PosY = 0
Lines_curr = 0
Height = 0
Dialog_Height = 50
Dialog = OpenWindow(#PB_Any, 0,0, 400, Dialog_Height, lhs_adv_diag_content()\Description, #PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
While NextElement(lhs_adv_diag_content())
Current_Element + 1
If lhs_adv_diag_content()\Lines = 1
Lines_curr + 1
PoSY = (Lines_curr * 50) - 45
Height = 40
Dialog_Height + 50
Else
Lines_curr + lhs_adv_diag_content()\Lines
Height = (lhs_adv_diag_content()\Lines * 50)
Dialog_Height + Height
Height - 15
PosY = (Lines_curr * 50) - Height
EndIf
ResizeWindow(Dialog, #PB_Ignore, #PB_Ignore, #PB_Ignore, Dialog_Height)
WindowBounds(Dialog, 400, Dialog_Height, 400, Dialog_Height)
Select lhs_adv_diag_content()\Type
Case #lhs_adv_dialog_text
lhs_adv_diag_content()\Id = TextGadget(#PB_Any, 5, PoSY , 390, Height, lhs_adv_diag_content()\Description)
Case #lhs_adv_dialog_string
lhs_adv_diag_content()\Text_Id = TextGadget(#PB_Any, 5, PoSY , 90, Height, lhs_adv_diag_content()\Description)
lhs_adv_diag_content()\Id = StringGadget(#PB_Any, 100, PoSY , 290, Height, lhs_adv_diag_content()\Response)
Case #lhs_adv_dialog_edit
lhs_adv_diag_content()\Text_Id = TextGadget(#PB_Any, 5, PoSY , 90, Height, lhs_adv_diag_content()\Description)
lhs_adv_diag_content()\Id = EditorGadget(#PB_Any, 100, PoSY , 290, Height)
SetGadgetText(lhs_adv_diag_content()\Id, lhs_adv_diag_content()\Response)
Default
;Reines Text Element
EndSelect
Wend
; Ok und Cancel Button
PosY + Height + 10
Button_Ok = ButtonGadget(#PB_Any, 5, PosY, 190, 40, "Ok")
Button_Cancel = ButtonGadget(#PB_Any, 205, PosY, 190, 40, "Cancel")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit=1
Case #PB_Event_Gadget
Select EventGadget()
Case Button_Cancel
CloseWindow(dialog)
ProcedureReturn #False
Case Button_Ok
ResetList(lhs_adv_diag_content())
NextElement(lhs_adv_diag_content())
While NextElement(lhs_adv_diag_content())
lhs_adv_diag_content()\Response = GetGadgetText(lhs_adv_diag_content()\Id)
Wend
CloseWindow(dialog)
ProcedureReturn #True
EndSelect
EndSelect
Until Quit=1
EndProcedure
Procedure.s get_explizit(UID.s)
ResetList(lhs_adv_diag_content())
While NextElement(lhs_adv_diag_content())
If lhs_adv_diag_content()\UID = UID
ProcedureReturn lhs_adv_diag_content()\Response
EndIf
Wend
ProcedureReturn UID
EndProcedure
Procedure get_init()
Current_Element = 1
EndProcedure
Procedure.s get()
EndProcedure
EndModule
; lhs_lib_adv_diag::init("Test Dialog")
; lhs_lib_adv_diag::add("Test", "test", lhs_lib_adv_diag::#lhs_adv_dialog_edit, 2)
; lhs_lib_adv_diag::add("Test2", "test2", lhs_lib_adv_diag::#lhs_adv_dialog_string, 1)
; lhs_lib_adv_diag::add("Test3", "test3", lhs_lib_adv_diag::#lhs_adv_dialog_edit, 1)
; lhs_lib_adv_diag::add("Test4", "test4", lhs_lib_adv_diag::#lhs_adv_dialog_string, 1)
; If lhs_lib_adv_diag::dialog()
; MessageRequester("Info", "Ok")
; Else
; MessageRequester("Info", "Cancel")
; EndIf
; MessageRequester("Test", lhs_lib_adv_diag::get_explizit("test"))
; IDE Options = PureBasic 5.71 beta 1 LTS (Linux - x64)
; CursorPosition = 95
; FirstLine = 67
; Folding = --
; EnableXP
; SubSystem = qt