c++11 - How does one use FLTK library using Bjarne's GUI's header file in his book Programming principles and practices? - TagMerge
3How does one use FLTK library using Bjarne's GUI's header file in his book Programming principles and practices?How does one use FLTK library using Bjarne's GUI's header file in his book Programming principles and practices?

How does one use FLTK library using Bjarne's GUI's header file in his book Programming principles and practices?

Asked 1 years ago
0
3 answers

I can't tell you exactly how to compile the given code and I don't think your problem is related to FLTK or building (and optionally installing) FLTK. It is a well-known problem that Bjarne Stroustrup's files as posted by him are broken and need several fixes to be compileable. I can only give some links which may help you to fix your copies of the files.

  1. You may want to download the original files from Dr. B.'s GitHub repository (if you didn't): https://github.com/BjarneStroustrup/Programming-_Principles_and_Practice_Using_Cpp

  2. Someone posted a long guide on how to fix the files and (at the end of the original post) a zip file with his fixed files. There are several more comments with additional minor fixes. If you follow the thread you may be successful, but I don't know for sure: https://groups.google.com/g/ppp-public/c/BtlzdWGuQpQ/m/KuDN4u-SPKgJ

As a FLTK developer I see such questions frequently but since I don't have the book I can't really say how to compile the examples of the book.

I'd appreciate if you could confirm that the link(s) above helped so we can redirect further questions here.

Source: link

0

Here's an example:
use fltk::{
    prelude::*,
    app::App,
    enums::Color,
    frame::Frame,
    window::DoubleWindow,
    button::Button,
};

fn main() {
    let a = App::default();
    
    let mut sub_win = DoubleWindow::default()
        .with_size(128, 128)
        .with_pos(64, 64);
    sub_win.set_border(false);
    sub_win.set_color(Color::Magenta); // So you can see it clearly.
    let _ = Frame::default().with_label("Sub Window")
        .with_size(128, 128)
        .with_pos(0, 0);
    sub_win.end();
    sub_win.show();
    
    let mut main_win = DoubleWindow::default().with_label("Main Window")
        .with_size(256, 128)
        .with_pos(0, 0);
    let mut b0 = Button::default().with_label("won't work")
        .with_size(96, 64)
        .with_pos(20, 32);
    let mut b1 = Button::default().with_label("is hacky")
        .with_size(96, 64)
        .with_pos(130, 32);
    main_win.end();
    main_win.show();
    
    b0.set_callback({
        let mut sub_win = sub_win.clone();
        move |_| {
            sub_win.show();          // The FLTK docs suggest this should work.
            sub_win.platform_show(); // This also disappoints.
        }
    });

    b1.set_callback(move |_| {
        sub_win.hide();          // This combination is what
        sub_win.show();          // actually works.
    });
    
    a.run().unwrap();
}
For example, the following C++ program exhibits the exact same behavior as the Rust one above:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>

Fl_Window *SUB_WIN;

void b_zero_cb(Fl_Widget *b) {
    SUB_WIN->show();
    SUB_WIN->redraw();
}

void b_one_cb(Fl_Widget *b) {
    SUB_WIN->hide();
    SUB_WIN->show();
    SUB_WIN->redraw();
}

int main(int argc, char **argv) {
    SUB_WIN = new Fl_Window(64, 64, 128, 128);
    Fl_Box *sub_label = new Fl_Box(0, 0, 128, 128, "Sub Window");
    SUB_WIN->color(FL_DARK_MAGENTA);
    SUB_WIN->border(false);
    SUB_WIN->xclass("Floating");
    SUB_WIN->end();
    SUB_WIN->show();
    
    Fl_Window *win = new Fl_Window(0, 0, 256, 128, "Main Window");
    Fl_Button *b0 = new Fl_Button(20, 32, 96, 64, "won't work");
    Fl_Button *b1 = new Fl_Button(130, 32, 96, 64, "hacky?");
    win->end();
    win->xclass("Floating");
    win->show();
    
    b0->callback(b_zero_cb);
    b1->callback(b_one_cb);
    
    return Fl::run();
}
On the C++ end, Fl_Widget::show() is a virtual function that should raise the window, if the variable points to a top-level window (a window with no parent). On the Rust side, I see these lines:
extern "C" {
    pub fn Fl_Window_show(arg1: *mut Fl_Window);
}

Source: link

0

Add platform-independent Fl_Screen_Driver::print_or_copy_window().
This member function is available for all platforms to print or copy the front window
with or without its titlebar.
WHAT IS FLTK?
The Fast Light Tool Kit ("FLTK", pronounced "fulltick") is a
a cross-platform C++ GUI toolkit for UNIX(r)/Linux(r) (X11),
Microsoft(r) Windows(r), and MacOS(r) X. FLTK provides
modern GUI functionality without the bloat and supports 3D
graphics via OpenGL(r) and its built-in GLUT emulation. It
was originally developed by Mr. Bill Spitzak and is
currently maintained by a small group of developers across
the world with a central repository in the US.

For more information see README.txt:
https://github.com/fltk/fltk/blob/master/README.txt

Source: link

Recent Questions on c++11

    Programming Languages