#debounce #events #fltk #control #throttling #frequency #tokio

debounce_fltk

A simple debounce and throttling tool suitable for FLTK applications. Can be used to control the frequency of UI event processing or the frequency of function calls for other non UI events. Non macro processing, pure code control. Relying on tokio implementation.

8 releases (4 breaking)

0.5.0 Mar 28, 2024
0.4.2 Mar 1, 2024
0.3.0 Mar 1, 2024
0.2.2 Feb 25, 2024
0.1.0 Feb 24, 2024

#358 in GUI

Download history 391/week @ 2024-02-24 173/week @ 2024-03-02 15/week @ 2024-03-09 1/week @ 2024-03-16 114/week @ 2024-03-23 42/week @ 2024-03-30 8/week @ 2024-04-06

167 downloads per month
Used in fltkrs-richdisplay

MIT license

36KB
403 lines

debounce_fltk

A simple debounce and throttling tool suitable for FLTK applications. Can be used to control the frequency of UI event processing or the frequency of function calls for other non UI events. It also supports executing a task at once or repeatedly after the preset timer expires. Non macro processing, pure code control. Relying on tokio implementation.

Usage examples:

    let mut debounce_update = TokioDebounce::new_debounce({
        let vp = version_package.clone();
        let mut script_editor = script_editor.clone();
        let tree = tree.clone();
        let editor_window = editor_window.clone();
        move |_| {
            // debug!("tree callback, {:?}", tree.first_selected_item());
            update_level_record(tree.clone(), vp.clone(), script_editor.clone(), editor_window.clone());
            update_tree_stat(tree.clone(), &mut script_editor);
        }
    }, Duration::from_millis(100), true);

    tree.set_callback({
        let mut script_editor = script_editor.clone();
        move |tree| {
            // debug!("tree callback, {:?}", tree.first_selected_item());

            if let Some(sel) = tree.first_selected_item() {
                let depth = sel.depth();
                if depth == 2 {
                    if let Err(_e) = script_editor.config_tabs.set_value(&script_editor.config_trigger_flex) {
                        // error!("切换触发器标签页时出错:{:?}", e);
                    }
                } else if depth == 3 {
                    if let Err(_e) = script_editor.config_tabs.set_value(&script_editor.config_expr_flex) {
                        // error!("切换触发器标签页时出错:{:?}", e);
                    }
                }
            }

            /*
            当鼠标点选某个树节点时,Changed事件会连续发生两次:第一次取消选择状态,第二次选中某个节点。
            因此这里需要做防抖处理,只处理有限时段内最后一次事件即可。
             */
            debounce_update.update_param(());
        }
    });

Dependencies

~17–25MB
~378K SLoC