Extending Editor Example Code, Adding a File List Pane

75 views
Skip to first unread message

Robin Rowe

unread,
Apr 24, 2015, 1:00:51 PM4/24/15
to fltkg...@googlegroups.com
I'd like to add a file list pane to the FLTK code editor example code,
to look like geany. I tried adapting from the Tile example code, but the
editor pane looks shredded. It's fine when I try putting a box in the
pane instead like the Tile example does. Why does the editor pane look
crazy?

I've tried several variations on the code below. None of them work if I
put the editor in the pane instead of a box. With some variations the
editor pops out of the pane into its own window. Some it never draws,
just has whatever is underneath the window frozen in the pane. It never
gains focus so I can type in the editor.

How do I get it to work?

Thanks!

Robin


int main(int argc, char **argv)
{ enum
{ dx0=600,
dx1=100,
border=20,
height=400,
width=dx0+border+dx1
};
Fl_Window mainWindow(width,height);
mainWindow.box(FL_NO_BOX);
mainWindow.resizable(mainWindow);

Fl_Tile tile(0,0,width,height,"TabNote");

textbuf = new Fl_Text_Buffer;
style_init();
fl_open_callback(cb);
Fl_Window* textWindow = new_view(dx0,height);
textWindow->box(FL_NO_BOX);
Fl_Box box0(0,0,dx0,height,"0\nThis is a child window");
box0.box(FL_DOWN_BOX);
box0.color(19);
// box0.labelsize(18);
// box0.align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
textWindow->resizable(box0);
textWindow->end();

Fl_Double_Window w1(dx0,0,dx0,height,"1");
w1.box(FL_NO_BOX);
Fl_Box box1(0,0,dx0,height,"1\nThis is a child window");
box1.box(FL_DOWN_BOX);
box1.color(19);
box1.labelsize(18);
box1.align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
w1.resizable(box1);
w1.end();

Fl_Box
r(tile.x()+border,tile.y()+border,tile.w()-2*border,tile.h()-2*border);
tile.resizable(r);
tile.end();

mainWindow.end();

textWindow->show();
mainWindow.show(argc,argv);

return Fl::run();
}


Greg Ercolano

unread,
Apr 24, 2015, 1:18:03 PM4/24/15
to fltkg...@googlegroups.com
On 04/24/15 09:56, Robin Rowe wrote:
> [code snipped]

Hmm, it doesn't build, so kinda hard to follow.
Can you change it up so we can build it?

I'd suggest indenting 2 spaces each time you create
a new parent widget, and then un-indent with each end()
so that you can catch parenting issues.

For instance, when I did that, I noticed the tile.end()
and textWindow->end() needed their orders switched;
the parent is end()ed before the child, which is out of sequence.

I tried adding the necessary #include's just to get it to build,
but it seems to refer to other stuff that seems possibly relevant.
Messed around a bit to get it to build 'something', but I don't think
the result is what's intended.

Anyway, try restructuring the program so we can build it,
including the #include's and any other classes (new_view?)
it might need, or replace the custom classes with regular FLTK
classes if that doesn't affect the issue, to keep the code example simple.

Message has been deleted

joe63074

unread,
Apr 26, 2015, 1:21:48 PM4/26/15
to fltkg...@googlegroups.com
I deleted my previous post, this should get you closer to what you want I think. (This puts an extra text editor on the left, but it could be any widget.)

Starting at line 795:

Fl_Window* new_view() {
  EditorWindow* w = new EditorWindow(660, 400, title);
    w->begin();
    Fl_Menu_Bar* m = new Fl_Menu_Bar(0, 0, 660, 30);
    m->copy(menuitems, w);

    // start tile here
    new Fl_Tile(0, 30, 660, 370, 0);

    // add a new text editor on the left
    Fl_Text_Buffer *filebuf = new Fl_Text_Buffer();
    Fl_Text_Editor *file_pane = new Fl_Text_Editor(0, 30, 128, 370, 0);
    file_pane->buffer(filebuf);

    // the original editor goes on the right
    w->editor = new Fl_Text_Editor(file_pane->w(), 30, 660, 370);
    w->editor->textfont(FL_COURIER);
    w->editor->textsize(TS);
  //w->editor->wrap_mode(Fl_Text_Editor::WRAP_AT_BOUNDS, 250);
    w->editor->buffer(textbuf);
    w->editor->highlight_data(stylebuf, styletable,
                              sizeof(styletable) / sizeof(styletable[0]),
                              'A', style_unfinished_cb, 0);
  w->end();
  w->resizable(w->editor);
  w->callback((Fl_Callback *)close_cb, w);

  textbuf->add_modify_callback(style_update, w->editor);
  textbuf->add_modify_callback(changed_cb, w);
  textbuf->call_modify_callbacks();
  num_windows++;
  return w;
}



This gives the following result:

-Joe

Greg Ercolano

unread,
Apr 26, 2015, 1:39:30 PM4/26/15
to fltkg...@googlegroups.com
On 04/26/15 10:21, joe63074 wrote:
> I deleted my previous post..

Note to all: while you can delete a post from google,
the deleted post will remain on the fltk.org webforum archive,
NNTP archive, and of course the mailing list.

Robin Rowe

unread,
May 10, 2015, 9:39:09 PM5/10/15
to fltkg...@googlegroups.com
Joe's code example helped a lot, thanks.

The code I have below works, but has a couple little issues. The Add
button gets cut off and the buttons pack vertical scrollbar appears even
though there's only one item and nowhere to scroll. What do I do to fix?

While a pack of buttons is a good start, what I want is a widget that
works like Qt QListWidget. How to do in FLTK?

Robin

// Added to editor.cxx

Fl_Widget* MakeFilePane(Fl_Window* w)
{ Fl_Scroll* scroll = new Fl_Scroll(0,30,100,370);
scroll->type(Fl_Scroll::VERTICAL);
Fl_Pack* pack = new Fl_Pack(0, 30, 120, 370);
pack->box(FL_DOWN_FRAME);
new Fl_Button(0, 0, 10, 30, "+ Add File");
pack->end();
w->resizable(pack);
return pack;
}

Fl_Window* new_view() {
EditorWindow* w = new EditorWindow(660, 400, title);
w->begin();
Fl_Menu_Bar* m = new Fl_Menu_Bar(0, 0, 660, 30);
m->copy(menuitems, w);
#ifdef ORIGINAL_CODE
w->editor = new Fl_Text_Editor(0, 30, 660, 370);
#else
Fl_Widget* file_pane=MakeFilePane(w);
w->editor = new Fl_Text_Editor(file_pane->w(), 30, 660, 370);
#endif
.
.
.

MacArthur, Ian (Selex ES, UK)

unread,
May 11, 2015, 4:55:56 AM5/11/15
to fltkg...@googlegroups.com
> The code I have below works, but has a couple little issues. The Add
> button gets cut off and the buttons pack vertical scrollbar appears
> even
> though there's only one item and nowhere to scroll. What do I do to
> fix?
>
> While a pack of buttons is a good start,

I'm not as big fan of Fl_Pack to be honest...

> what I want is a widget that
> works like Qt QListWidget. How to do in FLTK?

I think I'd start with an Fl_Tree and use that; it is very configurable, and can be used to make a list too, so might work for you.

Or some variation of Fl_Choice I suppose might work.






Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Reply all
Reply to author
Forward
0 new messages