PureBasic Forum

 It is currently Sat May 18, 2013 10:19 am

 All times are UTC + 1 hour

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Submenus / family tree / multidim array / subitemsPosted: Tue Oct 11, 2011 5:00 pm
 Enthusiast

Joined: Mon Feb 16, 2009 10:42 am
Posts: 531
Location: sweden
I have a project where you click on one thing which opens up another sets of buttons or keywords - and by clicking those another set opens up etc etc.
All my values are semicolon separated. I have put the submenu in [ ]
Took me an hour to do, so now hopefully I save someone else that hour. Maybe someone like to use it - go ahead to whatever you want to. Works cross platform, but as always it works best on a Mac.
Code:
original.s="Fruit[Red[Apple;Plum];Green[Apple[Granny Smith;Winterfresh];Pear;Cactus];Yellow[Banana;Corn]];"
original.s+"Vegetable[Round[Tomato[Baby;Plum;Flat;Beef];Potato];Long[Cucumber]];"
original.s+"Others[Diary[Milk;Cream;Butter];Flour[Wheat;Whole grain]]"
For i=1 To Len(result)
If Mid(result,i,1)="["
inbracks+1
ElseIf Mid(result,i,1)="]"
inbracks-1
ElseIf inbracks=0
realresult.s+Mid(result,i,1)
EndIf
Next
For i=1 To CountString(realresult.s,";")+1
Next
ProcedureReturn result
EndProcedure
inbacks.b=0
For i=1 To Len(result)
If counter=subresult
realresult.s+Mid(result,i,1)
EndIf
If Mid(result,i,1)="["
inbracks+1
ElseIf Mid(result,i,1)="]"
inbracks-1
ElseIf Mid(result,i,1)=";" And inbracks=0
counter+1
EndIf
Next
If FindString(realresult,"[")
For i=Len(realresult) To 1 Step -1
If Mid(realresult,i,1)="]"
Break
EndIf
Next
realresult=Mid(realresult,FindString(realresult,"[")+1,i-FindString(realresult,"[")-1)
Else
realresult=""
EndIf
ProcedureReturn realresult
EndProcedure
OpenWindow(0,0,0,640,480,"")
result.s=clean_result(0,original.s)
Repeat
eventid=WaitWindowEvent()
EndIf
EndIf
Until eventid=#PB_Event_CloseWindow

Top

 Post subject: Re: Submenus / family tree / multidim array / subitemsPosted: Tue Oct 11, 2011 5:04 pm
 Enthusiast

Joined: Tue Mar 02, 2004 1:20 pm
Posts: 683
Location: Cologne / Germany
Nice! Thanks for sharing!

jesperbrannmark wrote:
[...] but as always it works best on a Mac.

Greetings ... Kiffi

_________________
Sorry for my weird english

Top

 Post subject: Re: Submenus / family tree / multidim array / subitemsPosted: Wed Oct 12, 2011 2:54 pm
 Enthusiast

Joined: Fri Apr 25, 2003 11:08 pm
Posts: 398
jesper,

Thank you for the handy nested submenus code.

I would suggest adding a couple of "ClearGadgetItems()" statements as shown below
to clear out previous results when clicking on higher-level menu items.

For example, choose "Fruit -> Green -> Apple" to fill all four lists.
When you click on "Vegetable" in the first list, the second list is filled
and the third and fourth lists are cleared, removing the older entries.

Regards,
Eric

Code:
Repeat
EventID=WaitWindowEvent()
EndIf
EndIf
Until EventID=#PB_Event_CloseWindow

Top

 Post subject: String speed issuePosted: Mon Apr 30, 2012 4:31 pm
 Enthusiast

Joined: Mon Feb 16, 2009 10:42 am
Posts: 531
Location: sweden
I am using my code and some people are really getting larger lists (64KB and bigger).
Is there any cleaver options to speed up string handling? It takes like 10-20 seconds per click with that size...

Top

 Post subject: Re: Submenus / family tree / multidim array / subitemsPosted: Mon Apr 30, 2012 5:15 pm
 Enthusiast

Joined: Mon Feb 16, 2009 10:42 am
Posts: 531
Location: sweden
Ok.
I replaced MID(string,start.l,1) with PeekB(@string+start.l-1) instead and now there is fast as lighting

Top

 Post subject: Re: Submenus / family tree / multidim array / subitemsPosted: Mon Apr 30, 2012 5:18 pm
 User

Joined: Tue Aug 10, 2010 3:17 pm
Posts: 82
use list with a structure containing list, it should be pretty instaneous

_________________
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed )

Top

 Post subject: Re: Submenus / family tree / multidim array / subitemsPosted: Mon Apr 30, 2012 5:28 pm

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
jesperbrannmark wrote:
Ok.
I replaced MID(string,start.l,1) with PeekB(@string+start.l-1) instead and now there is fast as lighting

Does not work with Unicode. Requires PeekC() and * SizeOf(Character)
Code:
string.s = "abcdefg"
start.l  = 3

Debug Mid( string,start.l,1 )

; wrong
Debug Chr( PeekB(@string+start.l-1) )

; right
Debug Chr( PeekC( @string+( (start.l-1)*SizeOf(Character) ) ) )

Top

 Post subject: Re: Submenus / family tree / multidim array / subitemsPosted: Mon Apr 30, 2012 7:02 pm
 User

Joined: Tue Aug 10, 2010 3:17 pm
Posts: 82
Here try this code :

Tell me if this is quicker than yours with big Menu...

Code:
;{ Structure

Name.s
EndStructure

EndStructure

;}

;{ Procedure

EndIf

EndProcedure

Next

EndProcedure

EndProcedure

; on nettoie les menus avant

pos = 1

For i = 1 To Len(List_Nested_Menu)

If char = "["

;          Debug "Niveau : " + Str(ListIndex(*menu())) + " : " + *Old_menu\Name

pos = i + 1

ElseIf no = #True
no = #False
pos = i + 1

If char = "]"
pos = i + 1
no = #True

EndIf

ElseIf char = ";"

pos = i + 1

ElseIf char = "]"

pos = i + 1

no = #True

EndIf

Next

EndProcedure

Protected level, i, state

If gadget = -1 ; Initialization
Next

ProcedureReturn
EndIf

; we first find in which level the modification was
Break
EndIf
Next

If i <= level

state = 0
level = i
EndIf

ElseIf i = level + 1

Next

Else

EndIf
Next

EndProcedure

Debug "Level : " + Str(level) + " : " + *menu\Menu()\Name

Next
EndProcedure

;}

;{ Exemple

original.s = "Fruit[Red[Apple;Plum];Green[Apple[Granny Smith;Winterfresh];Pear;Cactus];Yellow[Banana;Corn]];"
original.s + "Vegetable[Round[Tomato[Baby;Plum;Flat;Beef];Potato];Long[Cucumber]];"
original.s + "Others[Diary[Milk;Cream;Butter];Flour[Wheat;Whole grain]]"

ListIconGadget(1, 120, 0, 100, 480, "Go", 95, #PB_ListIcon_AlwaysShowSelection)
ListIconGadget(2, 240, 0, 100, 480, "Go", 95, #PB_ListIcon_AlwaysShowSelection)
ListIconGadget(3, 360, 0, 100, 480, "Go", 95, #PB_ListIcon_AlwaysShowSelection)

; We init the nested menu

For a = 0 To 3
Next

Repeat
event = WaitWindowEvent()

Case 0, 1, 2, 3

EndSelect

EndIf

Until event = #PB_Event_CloseWindow

;}

_________________
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed )

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 8 posts ]

 All times are UTC + 1 hour

Who is online

Users browsing this forum: No registered users and 4 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite