1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
//! # fltk-rs //! //! [![Documentation](https://docs.rs/fltk/badge.svg)](https://docs.rs/fltk) //! [![Crates.io](https://img.shields.io/crates/v/fltk.svg)](https://crates.io/crates/fltk) //! [![License](https://img.shields.io/crates/l/fltk.svg)](https://github.com/MoAlyousef/fltk-rs/blob/master/LICENSE) //! [![Build](https://github.com/MoAlyousef/fltk-rs/workflows/Build/badge.svg?branch=master)](https://github.com/MoAlyousef/fltk-rs/actions) //! //! //! //! Rust bindings for the FLTK Graphical User Interface library. //! //! The FLTK crate is a crossplatform lightweight gui library which can be statically linked to produce small, self-contained (no dependencies) and fast gui applications. //! //! Tutorials: //! - [Video](https://github.com/MoAlyousef/fltk-rs#tutorials) //! - [Written](https://github.com/MoAlyousef/fltk-rs/wiki) //! //! Here is a [list](https://en.wikipedia.org/wiki/FLTK#Use) of software using FLTK. //! //! - [Link](https://github.com/fltk/fltk) to the official FLTK repository. //! - [Link](https://www.fltk.org/doc-1.3/index.html) to the official documentation. //! //! ## Usage //! //! Just add the following to your project's Cargo.toml file: //! //! ```toml //! [dependencies] //! fltk = "^0.13" //! ``` //! The library is automatically built and statically linked to your binary. //! //! For faster builds you can enable ninja builds for the C++ source using the "use-ninja" feature. //! //! An example hello world application: //! //! ```no_run //! use fltk::{app::*, window::*}; //! //! let app = App::default(); //! let mut wind = Window::new(100, 100, 400, 300, "Hello from rust"); //! wind.end(); //! wind.show(); //! app.run().unwrap(); //! ``` //! //! Another example showing the basic callback functionality: //! ```no_run //! use fltk::{app::*, button::*, frame::*, window::*}; //! //! let app = App::default(); //! let mut wind = Window::new(100, 100, 400, 300, "Hello from rust"); //! let mut frame = Frame::new(0, 0, 400, 200, ""); //! let mut but = Button::new(160, 210, 80, 40, "Click me!"); //! wind.end(); //! wind.show(); //! but.set_callback(move || frame.set_label("Hello World!")); //! app.run().unwrap(); //! ``` //! Please check the examples directory for more examples. //! You will notice that all widgets are instantiated with a new() method, taking the x and y coordinates, the width and height of the widget, as well as a label which can be left blank if needed. Another way to initialize a widget is using the builder pattern: (The following buttons are equivalent) //! //! ```ignored //! let but1 = Button::new(10, 10, 80, 40, "Button 1"); //! //! let but2 = Button::default() //! .with_pos(10, 10) //! .with_size(80, 40) //! .with_label("Button 2"); //! ``` //! //! An example of a counter showing use of the builder pattern: //! ```ignored //! let app = app::App::default(); //! let mut wind = Window::default() //! .with_size(160, 200) //! .center_screen() //! .with_label("Counter"); //! let mut frame = Frame::default() //! .with_size(100, 40) //! .center_of(&wind) //! .with_label("0"); //! let mut but_inc = Button::default() //! .size_of(&frame) //! .above_of(&frame, 0) //! .with_label("+"); //! let mut but_dec = Button::default() //! .size_of(&frame) //! .below_of(&frame, 0) //! .with_label("-"); //! wind.make_resizable(true); //! wind.end(); //! wind.show(); //! /* Event handling */ //! ``` //! //! ### Events //! //! Events can be handled using the set_callback method (as above) or the available fltk::app::set_callback() free function, which will handle the default trigger of each widget(like clicks for buttons): //! ```ignored //! /* previous hello world code */ //! but.set_callback(move || frame.set_label("Hello World!")); //! app.run().unwrap(); //! ``` //! Another way is to use message passing: //! ```ignored //! /* previous counter code */ //! let (s, r) = app::channel::<Message>(); //! //! but_inc.emit(s, Message::Increment); //! but_dec.emit(s, Message::Decrement); //! //! while app.wait() { //! let label: i32 = frame.label().parse().unwrap(); //! match r.recv() { //! Some(Message::Increment) => frame.set_label(&(label + 1).to_string()), //! Some(Message::Decrement) => frame.set_label(&(label - 1).to_string()), //! None => (), //! } //! } //! ``` //! For the remainder of the code, check the full example here: //! https://github.com/MoAlyousef/fltk-rs/blob/master/examples/counter2.rs //! //! For custom event handling, the handle() method can be used: //! ```ignored //! some_widget.handle(move |ev: Event| { //! match ev { //! /* handle ev */ //! } //! }); //! ``` //! Handled or ignored events using the handle method should return true, unhandled events should return false. //! More examples are available in the examples directory. //! //! ### Theming //! //! FLTK offers 4 application themes (called schemes): //! - Base //! - Gtk //! - Gleam //! - Plastic //! //! These can be set using the App::with_scheme() function. //! ```ignored //! let app = App::default().with_scheme(AppScheme::Gleam); //! ``` //! Themes of individual widgets can be optionally modified using the provided methods in the WidgetBase trait, //! such as set_color(), set_label_font(), set_frame() etc: //! ```ignored //! some_button.set_color(Color::Light1); //! You can use one of the provided colors in the fltk enums //! some_button.set_color(Color::from_rgb(255, 0, 0)); //! Or you can specify a color by rgb or hex/u32 value //! some_button.set_color(Color::from_u32(0xffebee)); //! some_button.set_frame(FrameType::RoundUpBox); //! some_button.set_font(Font::TimesItalic); //! ``` //! //! ## Features //! //! The following are the features offered by the crate: //! - use-ninja: If you have ninja build installed, it builds faster than make or VS //! - system-libpng: Uses the system libpng //! - system-libjpeg: Uses the system libjpeg //! - system-zlib: Uses the system zlib //! - fltk-bundled: Support for bundled versions of cfltk and fltk on selected platforms (requires curl and tar) //! - no-pango: Build without pango support on Linux/BSD. //! - enable-glwindow: Support for drawing using OpenGL functions. //! //! ## Dependencies //! //! Rust (version > 1.38), CMake (version > 3.0), Git and a C++11 compiler need to be installed and in your PATH for a crossplatform build from source. This crate also offers a bundled form of fltk on selected platforms, this can be enabled using the fltk-bundled feature flag (which requires curl and tar to download and unpack the bundled libraries). //! //! - Windows: No dependencies. //! - MacOS: No dependencies. //! - Linux: X11 and OpenGL development headers need to be installed for development. The libraries themselves are available on linux distros with a graphical user interface. //! //! For Debian-based GUI distributions, that means running: //! ```ignored //! $ sudo apt-get install libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpango1.0-dev libpng-dev libgl1-mesa-dev libglu1-mesa-dev //! ```ignored //! For RHEL-based GUI distributions, that means running: //! ```ignored //! $ sudo yum groupinstall "X Software Development" && yum install pango-devel libXinerama-devel libpng-devel //! ``` //! For Arch-based GUI distributions, that means running: //! ```ignored //! $ sudo pacman -S libx11 libxext libxft libxinerama libxcursor libxrender libxfixes libpng pango cairo libgl mesa --needed //! ``` //! For Alpine linux: //! ```ignored //! $ apk add pango-dev fontconfig-dev libxinerama-dev libxfixes-dev libxcursor-dev libpng-dev mesa-gl //! ``` //! For NixOS (Linux distribution) this `nix-shell` environment can be used: //! ```ignored //! $ nix-shell --packages rustc cmake git gcc xorg.libXext xorg.libXft xorg.libXinerama xorg.libXcursor xorg.libXrender xorg.libXfixes libpng libcerf pango cairo libGL mesa pkg-config //! ``` //! - Android: Android Studio, Android Sdk, Android Ndk. //! //! ## FAQ //! //! please check the [FAQ](https://github.com/MoAlyousef/fltk-rs/blob/master/FAQ.md) page for frequently asked questions, encountered issues, guides on deployment, and contribution. #![allow(non_upper_case_globals)] /// Application related methods and functions pub mod app; /// Browser widgets pub mod browser; /// Button widgets pub mod button; /// Dialog widgets pub mod dialog; /// Drawing primitives pub mod draw; /// Fltk defined enums: Color, Font, CallbackTrigger etc pub mod enums; /// Basic fltk box/frame widget pub mod frame; /// Group widgets pub mod group; /// Image types supported by fltk pub mod image; /// Input widgets pub mod input; /// Menu widgets pub mod menu; /// Miscellaneous widgets not fitting a certain group pub mod misc; /// Output widgets pub mod output; /// All fltk widget traits and flt error types pub mod prelude; /// Widget surface to image functions pub mod surface; /// Table widgets pub mod table; /// Text display widgets pub mod text; /// Tree widgets pub mod tree; /// General utility functions pub mod utils; /// Valuator widgets pub mod valuator; /// Basic empty widget pub mod widget; /// Window widgets pub mod window; /// Printing related functions #[cfg(not(target_os = "android"))] pub mod printer; pub use enums::*; pub use prelude::*; #[macro_use] extern crate fltk_derive; #[macro_use] extern crate lazy_static; #[macro_use] extern crate bitflags;