News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.

Post Reply  Post Thread 
another menu thing
Author Message
Senior Member

Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
another menu thing

Playing around with homemade menu options again. This one is kinda visually similar to the collapsable browser I was working on earlier. It makes use of a pack of buttons that "expand" when clicked. This example only changes the label text and size a little, but it could be easily modified to load a thumbnail image or other such thing. It's heavily commented, so that should help in customizing. I haven't yet added the ability for the buttons to actually DO anything other than change their own appearance =o)

Screenshot attached.

EDIT: added a conditional placeholder for a subsequent click on the expanded button.

#!/usr/bin/env murgaLua

-- Creates a vertical scroll containing an arbitrary number of
-- buttons which grow and change labels when clicked, and collapse
-- when another button is clicked
-- Additional button behavior, such as secondary action by clicking
-- the active button (a logical next step), is not implemented yet

mbw=64 -- menu button width
mbnh=30 -- button normal height
mbeh=200 -- expanded height

-- These labels are displayed on buttons in their inactive state.
-- Another table of equal size could be created to store info for
-- active state, or tables of arbitrary size could be generated
-- and used for data in both the build_menu() loop and butt_cb()
menu_labels={"one", "two", "three", "four",
"five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen",
"nineteen", "twenty", "twenty-one", "twenty-two"}

-- Notes on customizing this function:
-- active_butt = previously selected button
-- self = currently selected button
-- (1) This line is auxiliary and disposable
-- (2) Try setting the label to an image or text from a table/file
-- (3) See (1)
function butt_cb(self)
if self:h()==mbeh then -- if self is already expanded
-- put stuff to do on second click here
-- expand new button
  active_butt:size(mbw,mbnh) -- collapse previous button
  active_butt:label(prev_label) -- reset to initial label
  active_butt:labelsize(def_sz) -- reset to initial label size (1)
  prev_label=self:label() -- backup the initial label of current button
  self:label("BIG\n"..prev_label) -- change the label text of current button (2)
  self:labelsize(def_sz*2) -- increase label size of current button (3)
  self:size(mbw,mbeh) -- expand current button
  active_butt=self -- let everyone know which button to collapse next time
  menu_scroll:redraw() -- visual clean up

function build_menu(x,y,w,h)
menu_scroll:type(2) -- FL_VERTICAL doesn't seem to work
menu_scroll:box(fltk.FL_DOWN_BOX) -- just for looks
menu_pack=fltk:Fl_Pack(x,y,w-20,h-20) -- note 20 pixel space for scrollbar
fltk:Fl_End() -- end pack
fltk:Fl_End() -- end scroll
-- create buttons from menu_labels table
-- This could be made dynamic by, for example,
-- populating the table with a list of files
for i,v in pairs(menu_labels) do

w=fltk:Fl_Window(300,600,"menu test 2")
-- x,y,w,h (note: w doesn't need to be mbeh)
-- set a default font size (needed only if butt_cb uses it)
-- set first button active
-- initialize a prev_label for first use in butt_cb
--active_butt:do_callback() -- optional

Attached File(s) Thumbnail(s)

This post was last modified: 05-02-2010 08:29 AM by mikshaw.

05-02-2010 01:47 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: