Skip to content

Reference Canvas

ddbnl edited this page Sep 2, 2022 · 2 revisions

The canvas is a widget that allows custom content. It can load its graphic content from a text file, or it can be set programmatically.

Properties

from_file

File path to a text file from which to load visual context. Empty string means don't load from file. The file content will be merged into your binary, so you do not need to ship the text file with your binary. The file path you use must be relative to the folder specified in your EZ_FOLDER environment variable.

Property type:

String

Possible values:

Any valid file path.

Default value:

Empty string.

Usage examples:

In EzLang files:

- Canvas:
    from_file: ./canvas_content.txt

In code:

use ez_term::*;
let (root_widget, mut state_tree, mut scheduler) = load_ui();
let state = state_tree.get_mut("my_canvas").as_canvas_mut();

state.set_from_file("./canvas_content.txt");

run(root_widget, state_tree, scheduler);

Setting content from code

The alternative to loading content from a text file is setting content from code. You have to manually create the pixels and use them to construct a PixelMap (Vec<Vec>) Here is an example to create a square like this:

S S S
S S S
S S S

The code:

use ez_term::*;
let (root_widget, mut state_tree, mut scheduler) = load_ui();
let state = state_tree.get_mut("my_canvas").as_canvas_mut();

// We create a single pixel
let pixel = Pixel::new("S".to_string(), Color::White, Color::Black);

// We create a row of three pixels
let row = vec!(pixel.clone(); 3);

// We create a pixelmap of three rows (we now have a square)
let content = vec!(row.clone(); 3);

state.set_contents(content);

run(root_widget, state_tree, scheduler);

Default callbacks implementations

The Canvas widget does not have any default callback implementations.

Available callbacks

  • on_scroll_up
  • on_scroll_down
  • on_hover
  • on_drag
  • on_left_click
  • on_right_click

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