Skip to content

Instantly share code, notes, and snippets.

View MoAlyousef's full-sized avatar

Mohammed Alyousef MoAlyousef

View GitHub Profile
@MoAlyousef
MoAlyousef / main.rs
Last active August 25, 2025 21:18
Compact packed expandable multiple tree
use fltk::{prelude::*, *};
static COFACTOR: utils::oncelock::Lazy<i32> = utils::oncelock::Lazy::new(|| (app::font_size() as f64 * 2.0) as i32);
fn prep_tree(t: &mut tree::Tree) {
if let Some(root) = t.next(&t.first().unwrap()) {
if root.is_open() {
let elems = root.children();
t.resize(t.x(), t.y(), t.w(), (elems + 1) * *COFACTOR);
} else {
@MoAlyousef
MoAlyousef / main.rs
Created September 23, 2021 16:27
fltk-sys example
#![feature(concat_idents)]
use fltk_sys::{fl::*, frame::*, window::*, group::*, button::{self, *}};
use std::os::raw::*;
macro_rules! fstr {
($s:literal) => {
concat!($s, "\0").as_ptr() as _
}
}
@MoAlyousef
MoAlyousef / custom_dialog.rs
Last active August 25, 2025 21:15
custom dialog using fltk-rs
use fltk::{
app, button,
enums::{Color, Font, FrameType},
frame, group, input,
prelude::*,
window,
};
fn style_button(btn: &mut button::Button) {
btn.set_color(Color::Cyan);
@MoAlyousef
MoAlyousef / counter.cpp
Last active March 8, 2024 22:52
FLTK flutter-like using C++
#include <FL/Enumerations.H>
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Window.H>
#include <FL/fl_draw.H>
#include <cstdio>
#include <functional>
@MoAlyousef
MoAlyousef / hover_button.rs
Created April 22, 2021 17:28
Example of Hover support for buttons, it basically requires handling the Event::Enter and Event::Leave events.
use fltk::{
app, button,
enums::{Color, Event, FrameType},
prelude::*,
window,
};
const COLOR: u32 = 0xB39DDB;
const SELECTION_COLOR: u32 = 0x9575CD;
const HOVER_COLOR: u32 = 0xD1C4E9;
@MoAlyousef
MoAlyousef / resize_override.rs
Created April 22, 2021 17:06
Override FLTK's resizing defaults
#![allow(unused_variables)]
use fltk::{
app::App,
button::Button,
enums::Event,
group::Group,
prelude::{GroupExt, WidgetBase, WidgetExt, WindowExt},
window::Window,
};
@MoAlyousef
MoAlyousef / rtl_input.rs
Created April 22, 2021 16:26
Right to Left input (for RTL languages).
use fltk::{enums::*, prelude::*, *};
use std::ops::{Deref, DerefMut};
pub struct RtlInput {
inp: input::Input,
}
impl RtlInput {
pub fn new(x: i32, y: i32, w: i32, h: i32, label: &'static str) -> Self {
let mut inp = input::Input::new(x, y, w, h, label).with_align(Align::Right);
@MoAlyousef
MoAlyousef / popup_hack.rs
Last active August 25, 2025 21:00
A popup hack allowing to use dynamic strings, basically by creating a hidden Choice widget then getting the MenuItem using the `MenuExt::at(0)` method.
use fltk::{prelude::*, *};
fn main() {
let mut choice = menu::Choice::default();
choice.add_choice("File/New");
choice.add_choice(&format!("{}\t", "Edit/Cut"));
choice.add_choice("File/Open");
choice.add_choice(&format!("Edit/{}", "Copy"));
choice.add_choice("Other|Option");
@MoAlyousef
MoAlyousef / expand_button.rs
Last active August 25, 2025 20:59
Expandable button animation using fltk-rs
use fltk::{prelude::*, *};
fn main() {
let app = app::App::default();
app::set_visible_focus(false);
let mut win = window::Window::default().with_size(400, 300);
win.set_color(enums::Color::White);
let mut but = button::Button::default()
.with_size(80, 40)
.with_label("Expand!")