Murga-Projects Forums
Keep tabs from resizing - Printable Version

+- Murga-Projects Forums (http://www.murga-projects.com/forum)
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: Keep tabs from resizing (/showthread.php?tid=310)


Keep tabs from resizing - jpjacobs - 03-31-2008 04:16 AM

Hi!
I wrote a little ui, but i'm stuck with a problem.
I have a bunch of tabs in a group that is resizable, but i can't stop the tabs and buttons from resizing...
the code is:

Code:
--!/usr/local/bin/murgaLua
-- Tabber: A little scripty thing, to keep track of found tabs, search them, rate them, compress them, autoscroll, print them...
function tabber_exit()
  local confirm=fltk.fl_choice("sure you want to quit?","stay","quit",NULL)
    if confirm == 1 then os.exit(0) else tabber:show() end
end

tabber = fltk:Fl_Double_Window(510, 410)
    tabber:callback(tabber_exit)

menubar = fltk:Fl_Menu_Bar(0, 0, 510, 25)

do tabsGroup = fltk:Fl_Group(10,50,490,350)
        tabber:resizable(tabsGroup)
        tabs  = fltk:Fl_Tabs(5, 25, 500, 380)
            do local editorTab = fltk:Fl_Group(10, 50, 490, 350, "Editor")
                textbuffer = fltk.Fl_Text_Buffer()
                textEditor = fltk:Fl_Text_Editor(10, 55, 485, 315)
                    textEditor:buffer(textbuffer)
                    textEditor:textfont(fltk.FL_COURIER);
                    textEditor:textsize(10);
                editButton = fltk:Fl_Light_Button(335, 375, 50, 25, "Edit")
                    editButton:selection_color(Fl_Color1)
                newButton = fltk:Fl_Button(390, 375, 50, 25, "New")
                saveButton = fltk:Fl_Button(445, 375, 50, 25, "Save")
                    saveButton:deactivate()
            fltk.Fl_End()
            end
            
            do local searchTab = fltk:Fl_Group(10, 50, 490, 350, "Search")
                 pattern = fltk:Fl_Input(90, 65, 400, 25, "Search for")
                 fieldChoice = fltk:Fl_Choice(90, 90, 400, 25, "for")
                        local choices = {"Artist","Title","Chord"}
                        for i = 1,table.getn(choices) do
                                fieldChoice:add(choices[i])
                        end
                        fieldChoice:value(0)
                 searchButton = fltk:Fl_Return_Button(415, 375, 85, 25, "Search!")
                 clearButton = fltk:Fl_Button(355, 375, 55, 25, "Clear")
                 helpButton = fltk:Fl_Button(295, 375, 55, 25, "Help")
                 exact = fltk:Fl_Check_Button(90, 115, 400, 25, "exact")
            
            fltk.Fl_End()
            end
            
            do local browseTab = fltk:Fl_Group(10, 50, 490, 350, "Browse")
            fltk.Fl_End()
            end
            fltk.Fl_End()   -- end of tabs
        fltk.Fl_End()       -- end of TabsGroup
end
Fl:scheme("gtk+")
tabber:show();
Fl:run();

-- vim:ft=murga


Thanks,

Jan-Pieter


RE: Keep tabs from resizing - mikshaw - 03-31-2008 12:26 PM

I haven't succeeded in doing it with your script, but I think it may have something to do with the localization of every widget....never could understand why that was so important when it generally causes more problems than it solves in small applications.

The resize takes some work if you want to have complete control of it. It seems that you need to set every widget you want to resize from the specific widget up to the top level.
toplevel:resizable(second_level)
second_level:resizable(third_level)
third_level:resizable(fourth_level)


RE: Keep tabs from resizing - mikshaw - 04-01-2008 05:25 AM

Try this:

Code:
-- Tabber: A little scripty thing, to keep track of found tabs, search them, rate them, compress them, autoscroll, print them...
function tabber_exit()
  local confirm=fltk.fl_choice("sure you want to quit?","stay","quit",NULL)
    if confirm == 1 then os.exit(0) else tabber:show() end
end

tabber = fltk:Fl_Double_Window(510, 410)
    tabber:callback(tabber_exit)

menubar = fltk:Fl_Menu_Bar(0, 0, 510, 25)

--do tabsGroup = fltk:Fl_Group(10,25,490,350)
        tabs  = fltk:Fl_Tabs(5, 25, 500, 380)
            do editorTab = fltk:Fl_Group(10, 50, 490, 350, "Editor")
                textbuffer = fltk.Fl_Text_Buffer()
                textEditor = fltk:Fl_Text_Editor(10, 55, 485, 315)
                    textEditor:buffer(textbuffer)
                    textEditor:textfont(fltk.FL_COURIER);
                    textEditor:textsize(10);
                editButton = fltk:Fl_Light_Button(335, 375, 50, 25, "Edit")
                    editButton:selection_color(Fl_Color1)
                newButton = fltk:Fl_Button(390, 375, 50, 25, "New")
                saveButton = fltk:Fl_Button(445, 375, 50, 25, "Save")
                    saveButton:deactivate()
            fltk.Fl_End()
            end
            
textbuffer:text([[
One problem was the relative sizes of the tabs group (tabs, not tabsGroup)
and its contents. The tabs widget automatically scales its tabs according
to the amount of space between the position of the tabs group and the
position of the group inside it. which ever end has the wider space gets
the tabs, and their scale is determined by the amount of that space.
I changed the y position of tabs to 25, which gives them a 25px size
because the group inside has a y position of 50.

Also I commented out tabsGroup because it is redundant in this case.
Fl_Tabs is already a group itself, so unless you plan to have something
adjacent to tabs and also contained by tabsGroup, there's no need for it.

The resizable does still affect the tabs and everything else in a window.
You have to be explicit about the widget(s) you want to allow to resize,
starting with the top level window and working down through each group:

tabber:resizable(tabs)
tabs:resizable(editorTab)
tabs:resizable(searchTab)
tabs:resizable(browseTab)
editorTab:resizable(textEditor)
searchTab:resizable(slug1)
browseTab:resizable(slug2)

I had to globalize some of those widgets in order for this to work.
If you're working on a small application that doesn't need to call
or be called from another script, there is little harm in using
global objects for most things. In many cases it is necessary, in
order for the various objects to communicate with each other.

The second and third tabs contain a slug which gets the resize, to
show how setting a particular widget in a particular way can affect
the resize and prevent other objects in that group from resizing.
Resizable is a big pain, though. I still have difficulty determining
how to organize widgets sometimes in order to get the correct behavior.
]])

            do searchTab = fltk:Fl_Group(10, 50, 490, 350, "Search")
slug1=fltk:Fl_Box(10,200,10,100); slug1:box(fltk.FL_BORDER_BOX); slug1:align(fltk.FL_ALIGN_WRAP) -- DEBUGGING
slug1:label("note the initial scale and position of this box. It is between the non-scaling objects")
                 pattern = fltk:Fl_Input(90, 65, 400, 25, "Search for")
                 fieldChoice = fltk:Fl_Choice(90, 90, 400, 25, "for")
                        local choices = {"Artist","Title","Chord"}
                        for i = 1,table.getn(choices) do
                                fieldChoice:add(choices[i])
                        end
                        fieldChoice:value(0)
                 searchButton = fltk:Fl_Return_Button(415, 375, 85, 25, "Search!")
                 clearButton = fltk:Fl_Button(355, 375, 55, 25, "Clear")
                 helpButton = fltk:Fl_Button(295, 375, 55, 25, "Help")
                 exact = fltk:Fl_Check_Button(90, 115, 400, 25, "exact")
            
            fltk.Fl_End()
            end
            
            do browseTab = fltk:Fl_Group(10, 50, 490, 350, "Browse")
slug2=fltk:Fl_Box(10,350,490,1); slug2:box(fltk.FL_BORDER_BOX) -- DEBUGGING
            fltk.Fl_End()
            end
            fltk.Fl_End()   -- end of tabs
  --      fltk.Fl_End()       -- end of TabsGroup
--end
Fl:scheme("gtk+")
tabber:resizable(tabs)
tabs:resizable(editorTab)
tabs:resizable(searchTab)
tabs:resizable(browseTab)
editorTab:resizable(textEditor)
searchTab:resizable(slug1)
browseTab:resizable(slug2)
tabber:show();
Fl:run();




RE: Keep tabs from resizing - jpjacobs - 04-01-2008 08:53 PM

this was just the info i was looking for...
I wonder why my interface in fluid acted like it should (in live mode) but not the murgaLua'd thing.
Well thanks a lot for explaining this to me!

Jan-Pieter


RE: Keep tabs from resizing - mikshaw - 04-01-2008 11:54 PM

I'm guessing there are differences between FLTK in C++ and in murgaLua. It might be in the translation between the two, or it might be actual differences in the way murgaLua behaves. I suppose there is always going to be changes in behavior when you translate something from C++ to Lua.