Alexya.Controls
— TypeA controls
object contains a list of options object
and a GtkGrid
containing each option's widget.
Alexya.Option
— Type mutable struct Option{W, T} <: AbstractOption{W, T}
Represents an option
object.
An option is a value of type T
associated with a GtkWidget
.
The option's value can be accessed with the empty bracket notation: option[]
The option.set
function sets a new value for the option. The option's value can also be setted with the empty bracket notation: option[] = newvalue
Each option type defines the get
and set
functions.
Alexya.:→
— Method widget → N::Int
Returns CellSpan
object for widget
that spans N
columns.
Examples
julia> label"I span 4 columns" → 4
CellSpan(GtkSlider..., 1, 4)
Alexya.:→
— Method widget → r:c
Returns a GridCell
object for widget
that spans r
rows and c
columns.
Examples
julia> Box((), :h) → 3:4
CellSpan(GtkBox..., 3, 4)
Alexya.:↓
— Method widget ↓ N::Int
Returns CellSpan
object for widget
that spans N
rows.
Examples
julia> Slider(1:100) ↓ 2
CellSpan(GtkSlider..., 2, 1)
Alexya.:⟶
— Method s ⟶ [a₁ a₂; b₁ b₂]
Return the value s
linearly mapped from the a
interval to the b
interval.
Examples
julia> 1 ⟶ [0 1; 0 10]
10.0
julia> 0.5 ⟶ [0 1; 0 10]
5.0
julia> -2 ⟶ [-5 5; 0 5]
1.5
Alexya.Grid
— Method Grid(rows::Matrix)
Creates a new GtkGrid
widget.
The rows
parameter is a Matrix
that contains the GridCells
. A GridCell
can be either a GtkWidget
, a CellSpan
object or a empty tuple ()
.
The position of each element in the rows
matrix will determine its position on the Grid
.
An CellSpan
object represents a cell that spans multiple rows or/and columns. An empty tuple indicates an empty cell.
Examples
grid = Grid(@margin(10), [
button slider
() label
])
grid = Grid(@margin(10), [
# the button will span 2 rows
CellSpan(button, 2, 1) slider
() label
])
grid = Grid(@margin(10), [
# the button will span 2 rows
button ↓ 2 slider
# the label will span 2 columns
label → 2
])
grid = Grid(@margin(10)) do
[
# the textarea will span 3 rows and 2 columns
textarea → 3:2 switch
() () ()
() () ()
toolbar → 2 button
]
end
Alexya.addwidget
— Method addwidget(widget::GtkWidget)
Adds the widget widget
in the current window.
Examples
julia> slider = Slider(1:100)
GtkSlider...
julia> addwidget(slider)
GtkSlider...
Alexya.framerate
— Method framerate(fps::Real)
Sets the current framerate
.
The default framerate
is approximaly 60
frames/second.
The framerate is dynamic, wich means that you can set the framerate inside the update
function or anywhere else.
Alexya.getprop
— Method getprop(widget, key)
Returns the Gtk property key
from widget
.
Examples
julia> getprop(window, :title)
"My window"
Alexya.getprop
— Method getprop(widget, key, T)
Returns the Gtk property key
with type T
from widget
.
Examples
julia> getprop(window, :title, String)
"My window"
Alexya.init
— Function init(title [, width = 400, height = 400])
Initialize Alexya
by creating a new AlexyaApp
global object.
The title
parameter is the title of the window
, the width
and height
parameters are not necessarily the same as the window, but they determine the size of the canvas. The size of the window and canvas can be controlled by the current layout
, and the behavior of the addwidget
function or @create
macro are also controlled by the layout
.
The default layout
is canvasonly
, wich means that the canvas will be the only widget on the window and uses of the addwidget
function or @create
macro will not work.
You can set the current layout
by calling the uselayout
function or the @layout
macro. The layout
is a just a function that determines how the widgets (including the canvas) are added to the window. You can also create your own layouts.
Examples
julia> init("My beautiful animation", 800, 600)
AlexyaApp...
julia> @layout aside(:h, 200)
julia> @layout aside(:v, 300)
julia> @layout MyLayout
julia> uselayout() do canvas, widgets
Box(:v) do
canvas,
widgets...
end # Box
end
Alexya.keyboard
— Method keyboard(key)
Returns a number that represents a key
of the keyboard.
Alexya.mag
— Method mag(v::Vector{<:Real})
Returns the magnitude
of v
.
Alexya.mag2
— Method mag2(v::Vector{<:Real})
Returns the magnitude
squared of v
.
Alexya.mag²
— Method mag²(v::Vector{<:Real})
Returns the magnitude
squared of v
.
Alexya.mapr
— Method mapr(s::Real, intervals::Matrix)
Return the value s
linearly mapped from the intervals in intervals
.
Examples
julia> mapr(1, [0 1; 0 10])
10.0
julia> mapr(0.5, [0 1; 0 10])
5.0
julia> mapr(-2, [-5 5; 0 5])
1.5
Alexya.noLoop
— Method noLoop()
This function will prevent the drawing loop from start, wich will call the update
function just one time (or zero if you call on the setup
function).
Alexya.offevent
— Method offevent(widget, eventid)
Disconnect the event of id eventid
from widget
.
Examples
julia> id = onevent(:destroy, window) do
println("The window has been closed")
end
julia> destroy(window)
The window has been closed
julia> offevent(window, id)
julia> show(window)
GtkWindow...
julia> destroy(window)
Alexya.onevent
— Method onevent(callback, event, widget)
Adds a event listener for widget
. The callback
is called when the event
is fired.
Examples
julia> onevent(:destroy, window) do
println("The window has been closed")
end
Alexya.point
— MethodAlexya.random
— Methodrandom(len [, T = Float64])
Returns a random number between 0
and len
. The result is converted to the type T
.
Alexya.random
— Methodrandom(a, b [, T = Float64])
Returns a random number between a
and b
. The result is converted to the type T
.
Alexya.randv
— Method randv()
Returns a vector of magnitude 1
pointing in a random direction.
Alexya.rot
— Method rot(v::Vector{<:Real}, φ)
Returns a new vector where its magnitude
is the same as v
, but its angle is the sum of φ
and the angle of v
.
Alexya.set!
— Method set!(widget, props::Dict)
Sets a Gtk property of widget
for each key-value pair in props
.
Alexya.set!
— Method set!(widget, props::NamedTuple)
Sets a Gtk property of widget
for each key-value pair in props
.
Examples
julia> set!(button, (label = "Click-me"))
julia> set!(color_btn, (color = colorant"#f1a"))
Alexya.set!
— Method set!(widget, prop, values::NamedTuple)
Sets a Gtk property of widget
for each key-value pair in values
.
The name of the final property will be prop-key
where key is a key of values
.
For example, instead of setting the margins of a widget
each time, like this:
set!(mywidget, :margin_top, 10)
set!(mywidget, :margin_bottom, 20)
set!(mywidget, :margin_left, 15)
set!(mywidget, :margin_right, 10)
We can simple do:
set!(mywidget, :margin, (
top = 10,
bottom = 20,
left = 15,
right = 10
))
Alexya.set!
— Method set!(widget; props...)
Sets a Gtk property of widget
for each key-value pair in props
.
Alexya.set!
— Method set!(widget, prop, value)
Sets the value
of the Gtk property prop
of widget
.
Examples
julia> set!(window, :title, "My window")
julia> set!(entry, :text, "Foo bar")
Alexya.span
— Method span(widget, r, c)
Creates a GridCell
containing widget
that spans r
rows and c
columns.
Examples
julia> span(mybutton, 2, 2)
CellSpan(GtkButton..., 2, 2)
Alexya.start
— Method start(; [ async = false])
Starts the current AlexyaApp
.
This function will setup all the events, apply the current layout
and start the canvas drawing loop. The async
parameter determines if the loop should be asynchronous.
Alexya.use
— Method use(type::Symbol, func::Function)
Alexya
works with events, and event listeners can be attached to the current application
with the use
function or the @use
macro.
Each event has a unique type (a symbol
) that determines how it is fired.
The @use
macro automatically determines the type of event by the name of the function that is passed as argument.
Event | Is fired when | Usage |
---|---|---|
setup | The app starts | Do something when the app is starting |
update | Every frame | Draw every frame on the canvas using Luxor |
appclosed | Window closed | Do something when the window is closed |
keypress | Keyboard key pressed | Do something when a key is pressed |
mousepress | Canvas is clicked | Do something when the canvas is clicked |
mouserelease | Canvas is clicked | Do something after the canvas is clicked |
mousemotion | Mouse is moving | Do something when the mouse is moving inside the canvas |
Examples
@use function setup()
println("My application has started!")
end
@use function update()
background("black")
# Luxor drawing here
end
@use function keypress(event)
@info "Key press event" key=event.keyval
end
@use function mousepress(event)
@info "Mouse clicked" pos=event.pos
end
@use function mouserelease(event)
@info "Mouse button release" pos=event.pos
end
@use function mousemotion(event)
@info "Cursor moving" pos=event.pos
end
@use function appclosed()
@info "Window closed"
end
Alexya.withangle
— Function withangle(angle [, abs = 1])
Returns a vector of magnitude abs
and angle angle
.
Alexya.withmag
— Method withmag(v, m)
Returns a vector with the same direction as v
, but with magnitude m
.
Base.angle
— Method angle(v::Vector{<:Real})
Returns the angle
(in radians) that a 2D vector v
makes with the positive x-axis.
Alexya.@align
— Macro @align v h
Sets the vertical and horizontal alignment of Gtk widget.
Examples
julia> Button("Foo", @align(:center)) # Sets both alignments to center
GtkButton...
julia> Button("Foo", @align(:center, :end))
GtkButton...
Alexya.@canvas
— Macro @canvas
Returns the current canvas.
Alexya.@create
— Macro @create widget
Adds a widget
in the current application
.
Alexya.@framecount
— Macro @framecount
Returns the current frame count
.
Alexya.@framerate
— Macro @framerate
Returns the current framerate
.
Alexya.@height
— Macro @height
Returns the current canvas height
.
Alexya.@init
— Macro @init title width height
Shorthand macro for the init
function.
Alexya.@init
— Macro @init title [width = 400, height = 400]
Shorthand macro for the init
function.
Alexya.@margin
— Macro @margin values...
Useful macro for setting the margins
of a widget.
Example | Behavior |
---|---|
@margin(s) | Sets all margins to s |
@margin(v, h) | Sets top-bottom and left-right margins respectively |
@margin(t, b, h) | Sets top , bottom and left-right margins respectively |
@margin(t, r, b, l) | Sets top , right , bottom and left margins respectively |
Examples
julia> Button(:Foo, @margin(10)) # Sets all margins to 10
GtkButton...
julia> Button(:Foo, @margin(10, 20)) # Sets top-bottom margins to 10 and left-right margins to 20
GtkButton...
Alexya.@spacing
— Macro @spacing r c
Sets the row
and column
spacing of a GtkGrid
widget.
Examples
julia> Grid(@spacing(10)) # sets both row and column spacing.
GtkGrid...
julia> Grid(@spacing(10, 20))
GtkGrid...
Alexya.@use
— Macro @use event
Adds a event
listener on the current application
.
The @use
macro should be use in a function declaration expression.
The event type
is automatically determined by the name of the function.
Alexya.@width
— Macro @width
Returns the current canvas width
.
Alexya.@window
— Macro @window
Returns the current window
.