Skip to content

Tutorial Callback On Drag

ddbnl edited this page Sep 7, 2022 · 2 revisions

This callback is activated when a widget is left mouse clicked and the click is not released. As long as the click is not released, the widget will receive a new event every time the mouse cursor changes position.

The callback receives two extra arguments: one is the previous drag position, and one is the current drag position. The previous drag position argument is an Option; on the very first drag event, the previous drag position will be None. This is how you know the drag is new. Subsequently, the previous drag position will contain IsizeCoordinates. Because you have both the current and the previous IsizeCoordinates, you know which direction the drag is going.

The coordinates are relative to the widget. So if the coordinates are (3, 2), it means the click was located in the widget on the third pixel from the left and the second pixel from the top. It is possible for drag coordinates to be negative, which means the drag is occurring to the left of, or above, the widget. The coordinates can also be larger than the widget, which means the drag is occurring to the right of, or below, the widget. You can access the coordinates through 'mouse_pos.x' and 'mouse_pos.y'.

To set this callback with a closure:

use ez_term::*;
let (root_widget, mut state_tree, mut scheduler) = load_ui();

let my_callback = move |context: Context, previous_mouse_pos: Option<IsizeCoordinates>,
                        mouse_pos: IsizeCoordinates| {

    true
};
let new_callback_config = CallbackConfig::from_on_drag(Box::new(my_callback));
scheduler.update_callback_config("my_label", new_callback_config);

To set this callback with a function:

use ez_term::*;
let (root_widget, mut state_tree, mut scheduler) = load_ui();

fn my_callback(context: Context, previous_mouse_pos: Option<IsizeCoordinates>,
               mouse_pos: IsizeCoordinates) -> bool {

    true
};
let new_callback_config = CallbackConfig::from_on_drag(Box::new(my_callback));
scheduler.update_callback_config("my_label", new_callback_config);

Continue

The general tutorial continues with: Callback: On Scroll up.

Tutorial Tutorial-Project-Structure
  Minimal example
EzLang
  EzLang basics
  EzLang Templates
  Ezlang Layout modes
   EzLang Box mode layouts
   EzLang Stack mode layouts
   EzLang Table mode layouts
   EzLang Float mode layouts
   EzLang Tab mode layouts
   EzLang Screen mode layouts
   EzLang Layout Scrolling
   EzLang Layout Views
  EzLang Widget overview
   EzLang Label
   EzLang Text Input
   EzLang Button
   EzLang Checkbox
   EzLang Radio button
   EzLang Dropdown
   EzLang Slider
   EzLang Canvas
  EzLang Property Binding
  EzLang Sizing
   EzLang Size hints
   EzLang Auto scaling
   EzLang Maths Sizing
   EzLang Manual Sizing
  EzLang Positioning
   EzLang Layout Mode Positioning
   EzLang Position Hints
   EzLang Position Maths
   EzLang Manual Position
   EzLang Adjusting Position
  EzLang Keyboard Selection
Scheduler
  Widget States and the State Tree
  The Scheduler Object
  Managing callbacks
   Callback Structure
   Callback Configs
   Callback: On keyboard enter
   Callback: On Left Mouse Click
   Callback: On Press
   Callback: On Select
   Callback: On Deselect
   Callback: On Right Mouse Click
   Callback: On Hover
   Callback: On Drag
   Callback: On Scroll Up
   Callback: On Scroll Down
   Callback: On Value Change
   Callback: Custom Key Binds
   Callback: Global Key Binds
   Callback: Property Binds
  Tasks
   Scheduled Single Exectution Tasks
   Scheduled Recurring Tasks
   Threaded Tasks
  Custom Properties
  Modals
  Programmatic Widgets
  Updating widgets
  Managing selection
Default global (key)binds
Performance
ExamplesLayout: Box Mode Nested
Layout: Box Mode Size Hints
Layout: Stack Mode
Layout: Table Mode Dynamic
Layout: Table Mode Static
Layout: Float Mode Manual
Layout: Float Mode Position hints
Layout: Screen Mode
Layout: Tab Mode
Layout: Scrolling
Layout: Views
Widget: Label
Widget: Text input
Widget: Button
Widget: Checkbox
Widget: Radio Button
Widget: Dropdown
Widget: Slider
Widget: Progress Bar
Widget: Canvas
Scheduler: Schedule Once
Scheduler: Schedule Once Callback
Scheduler: Schedule Recurring
Scheduler: Schedule Recurring Callback
Scheduler: Threaded Task State Tree
Scheduler: Threaded Task Custom Property
Scheduler: Create Widgets
Scheduler: Modal Popup
Reference Widgets
  Common Properties
  Label
  Text Input
  Button
  Checkbox
  Radio button
  Dropdown
  Slider
  Canvas
Scheduler
  Schedule once
  Schedule Recurring
  Schedule Threaded
  Cancel Task
  Cancel Recurring Task
  Create Widget
  Remove Widget
  Select Widget
  Deselect Widget
  Update Widget
  Force Redraw
  Open Modal
  Dismiss Modal
  Bind Global Key
  Remove Global Key
  Clear Global Keys
  Bind Property
  Create Custom Properties
  Get Property
  Get Property Mut
  Overwrite Callback Config
  Update Callback Config
  Exit
Clone this wiki locally