Skip to main content

Module canvas

Module canvas 

Source
Expand description

Immediate-mode game interface for scripts: every frame a script describes what is on screen (panels, text in any font, images, buttons, sliders, toggles) and the shell paints it over the game. Clicks and slider changes come back on the next frame, so menus are plain ifs:

use kvas_engine::canvas::{Canvas, Align};
let ui = Canvas::default();
ui.panel([0.0, 0.0, 1280.0, 720.0], [0.0, 0.0, 0.0, 0.6], 0.0);
ui.text("LAST SERVICE", [640.0, 200.0], 64.0, [1.0; 4], "fonts/terminal.ttf", Align::Center);
if ui.button("new", [540.0, 360.0, 200.0, 44.0], "NEW SHIFT") { /* start */ }
assert_eq!(ui.commands().len(), 3);

Coordinates are in a virtual screen 720 units high whose width follows the window’s aspect ratio (ctx.ui_width()); [x, y, w, h] rectangles start at the top-left corner.

Structs§

ButtonStyle
Look of buttons and sliders.
Canvas
The interface of one frame plus what the player did with the previous one.

Enums§

Align
Horizontal text alignment.
UiCmd
One drawing command of the interface (fields as in the matching Canvas methods).

Constants§

UI_HEIGHT
Height of the virtual interface screen.