FixGUI Documentation

Back to summary

import "gui/view";

Canvas class

The Canvas class is used for creation of custom views.

You can use it directly but it is better to use the hierarchy of SubViews. The easiest way is to use the as_view method of any SubView which creates a Canvas with all the events handled automatically. You can also add any SubView directly to container Views as it internally calls this method for SubViews.

The canvas supports ability to scroll the content. However in many cases it is better to use PureScrollView to have a full control of the scrolling capability as the native support varies a lot between platforms.

Inherits from View.

Initialization

static function create(): Canvas
static function create(flags: Integer): Canvas
Creates a new canvas. You can also optionally pass the flags:

CANVAS_SCROLLABLE - enables scrollbar
CANVAS_BORDER - shows a border

Properties

function set_scroll_state(type: Integer, pos: Integer, max: Integer, page_size: Integer, always_show: Boolean)
Sets the scroll state. The type is either SCROLL_HORIZ or SCROLL_VERT, the scroll position is in pixels, the maximum position is excluding the size and the page size. You can choose if to always show scrollbars or hide them when not needed (may not work on all platforms or both directions are affected).
function set_scroll_position(type: Integer, pos: Integer)
Sets the scroll position in pixels. The type is either SCROLL_HORIZ or SCROLL_VERT.
function get_scroll_position(type: Integer)
Returns the scroll position in pixels. The type is either SCROLL_HORIZ or SCROLL_VERT.
function set_active_rendering(enable: Boolean)
Sets the active rendering. When enabled the canvas is continuously repainted at a maximum rate in an efficient way. It might be limited by the refresh rate of the monitor depending on the platform and the settings of the OS.
function get_active_rendering(): Boolean
Returns true when the active rendering is enabled.
function set_relative_mode(enable: Boolean)
Sets the relative mode for mouse events. In this mode the mouse cursor is hidden and the mouse is captured by the canvas. Relative movements are reported instead of regular mouse positions (using the EVENT_MOUSE_RELATIVE event type).
function get_relative_mode(): Boolean
Returns true when the relative mode is enabled.
function set_overdraw_size(amount: Integer)
Sets the overdraw size in pixels. This is used when repainting the canvas. Every redrawing is internally enlarged by this amount in every direction and then the extra area is discarded when putting it into a screen. This allows to provide the required pixels for non-local effects such as blurs.
function get_overdraw_size(): Integer
Returns the overdraw size in pixels.
function set_focusable(enable: Boolean)
Sets the canvas focusable.
function is_focusable(): Boolean
Returns true when the canvas is focusable.
function repaint()
function repaint(x: Integer, y: Integer, width: Integer, height: Integer)
function repaint(r: Rect)
Schedules a repaint of either the whole canvas or it's part. The repainting will be done after other events are processed. The area from multiple calls is combined to do a single repainting at once. This is not needed to be called when the active rendering is enabled.

Web platform: You can force an immediate repaint to get a better performance.

Event handlers

virtual function handle_destroy()
Override to handle destruction of the canvas.
virtual function handle_resize()
Override to handle resizing of the canvas.
virtual function handle_paint(p: Painter)
Override to handle painting of the canvas.