membrane.ui
bordered
(bordered elem)
(bordered pad elem)
Graphical elem that will draw drawable with a gray border. Also allows a specified padding.
;; Add a border without padding (bordered elem)
;; Add border with 5 px padding around elem (bordered 5 elem)
;; Add border ;; Add 3 pixels of padding to the left and right ;; and 5 pixels to the top and bottom (bordered 3 5 elem)
;; Add border ;; 1 px to the top ;; 2 pixels to the right ;; 3 pixels to the bottom ;; 4 pixels to the left. (bordered 1 2 3 4 elem)
bounds
(bounds elem)
Returns a 2 element vector with the width, height of an element's bounds with respect to its origin
box-contains?
(box-contains? [x y width height] [px py])
Tests whether px py is within x y width height.
button
(button text)
(button text on-click)
(button text on-click hover?)
Graphical elem that draws a button. Optional on-click function may be provided that is called with no arguments when button has a mouse-down event.
clipboard-copy
(clipboard-copy elem)
Returns the intents of a clipboard copy event on elem.
clipboard-paste
(clipboard-paste elem s)
Returns the intents of a clipboard paste event on elem.
fill-bordered
(fill-bordered color pad drawable)
Graphical elem that will draw elem with filled border.
filled-rectangle
(filled-rectangle color width height)
font
(font name size)
Creates a font.
name
: Should be the path to a font file on desktop. If nil, use the default font.
size
: Size of the font. If nil, use the default font size.
horizontal-layout
(horizontal-layout & elems)
Returns a graphical elem of elems layed out next to eachother.
IBounds
protocol
members
-bounds
(-bounds elem)
Returns a 2 element vector with the width, height of an element's bounds with respect to its origin
IBubble
protocol
Allows an element add, remove, modify intents emitted from its children.
members
-bubble
(-bubble _ intents)
Called when an intent is being emitted by a child element. The parent element can either return the same intents or allow them to continue to bubble.
IChildren
protocol
members
-children
(-children elem)
Returns sub elements of elem. Useful for traversal.
IHandleEvent
protocol
members
-can-handle?
(-can-handle? this event-type)
-handle-event
(-handle-event this event-type event-args)
image
(image image-path)
(image image-path [width height :as size])
(image image-path [width height :as size] opacity)
Graphical element that draws an image.
image-path
: using the skia backend, image-path
can be one of
- a string filename
- a java.net.URL
- a byte array containing the bytes of supported image format
This is useful for drawing images included in a jar. Simply put your image in your resources folder, typically resources.
Draw the images in the jar with
(ui/image (clojure.java.io/resource "filename.png"))
The image can be drawn at a different size by supplying a size. Supply a nil size will use the the original image size.
The image can be aspect scaled by supply a size with one of the dimensions as nil.
For example, to draw an image with width 30 with aspect scaling, (image "path.png" [30 nil])
opacity is a float between 0 and 1.
Allowable image formats may vary by platform, but will typically include png and jpeg.
IOrigin
protocol
members
-origin
(-origin elem)
Specifies the top left corner of a component's bounds
The origin is vector or 2 numbers x, y
key-event
(key-event elem key scancode action mods)
Returns the intents of a key event on elem.
label
(label text)
(label text font)
Graphical elem that can draw text.
label will use the default line spacing for newline. font should be a membrane.ui.Font
maybe-key-event
macro
(maybe-key-event test body)
Only respond to key events when test
is true.
maybe-key-press
macro
(maybe-key-press test body)
Only respond to key press events when test
is true.
memoize-var
added in 1.0
(memoize-var f)
Returns a memoized version of a referentially transparent function. The memoized version of the function keeps a cache of the mapping from arguments to results and, when calls with the same arguments are repeated often, has higher performance at the expense of higher memory use.
mouse-down
(mouse-down elem [mx my :as pos])
Returns the intents of a mouse down event on elem.
mouse-enter-global
(mouse-enter-global elem enter?)
Returns the intents of an event representing when the mouse enters or leaves the window.
Note: This event is new and is not implemented for all backends.
mouse-move-global
(mouse-move-global elem global-pos)
Returns the intents of a mouse move event on elem. Will -mouse-move-global for all elements and their children.
on
(on & events)
Wraps an elem with event handlers.
events are pairs of events and event handlers and the last argument should be an elem.
example:
Adds do nothing event handlers for mouse-down and mouse-up events on a label that says "Hello!" (on :mouse-down (fn mx my nil) :mouse-up (fn mx my nil) (label "Hello!"))
on-bubble
(on-bubble on-bubble & drawables)
Wraps drawables and adds a handler for bubbling
on-bubble should take seq of intents
on-click
(on-click on-click & drawables)
Wrap an element with a mouse down event handler, on-click.
on-click must accept 0 arguments and should return a sequence of intents.
on-clipboard-copy
(on-clipboard-copy on-clipboard-copy & drawables)
Wraps drawables and adds a handler for clipboard copy events.
on-clipboard-copy should take 0 arguments and return a sequence of intents.
on-clipboard-cut
(on-clipboard-cut on-clipboard-cut & drawables)
Wraps drawables and adds a handler for clipboard cut events.
on-clipboard-copy should take 0 arguments and return a sequence of intents.
on-clipboard-paste
(on-clipboard-paste on-clipboard-paste & drawables)
Wraps drawables and adds a handler for clipboard paste events.
on-clipboard-paste should take 1 arguments s and return a sequence of intents.
on-drop
(on-drop on-drop & drawables)
Wraps drawables and adds an event handler for drop events.
on-drop should take 2 arguments paths pos and return a sequence of intents.
on-key-event
(on-key-event on-key-event & drawables)
Wraps drawables and adds a handler for key events.
on-key-event should take 4 arguments key, scancode, action, mods and return a sequence of intents.
on-key-press
(on-key-press on-key-press & drawables)
Wraps drawables and adds an event handler for key-press events.
on-key-press should take 1 argument key and return a sequence of intents.
on-mouse-down
(on-mouse-down on-mouse-down & drawables)
Wraps drawables and adds an event handler for mouse-down events.
on-mouse-down should take 1 argument mx my of the mouse position in local coordinates and return a sequence of intents.
on-mouse-down-raw
(on-mouse-down-raw on-mouse-down-raw & drawables)
Wraps drawables and adds an event handler for mouse-down events.
Unlike on-mouse-down
, does not ignore events outside the bounds of drawables
.
on-mouse-down-raw should take 1 argument mx my of the mouse position in local coordinates and return a sequence of intents.
on-mouse-enter-global
(on-mouse-enter-global on-mouse-enter-global & drawables)
Wraps drawables and adds an event handler for mouse-enter-global events.
on-mouse-enter-global down should take 1 argument enter?
that represents the mouse entering or leaving
the window.
Returns a sequence of intents.
on-mouse-event
(on-mouse-event on-mouse-event & drawables)
Wraps drawables and adds an event handler for mouse events.
on-mouse-event should take 4 arguments pos button mouse-down? mods and return a sequence of intents.
on-mouse-move
(on-mouse-move on-mouse-move & drawables)
Wraps drawables and adds an event handler for mouse-move events.
on-mouse-move down should take 1 argument mx my of the mouse position in local coordinates and return a sequence of intents.
on-mouse-move-global
(on-mouse-move-global on-mouse-move-global & drawables)
Wraps drawables and adds an event handler for mouse-move-global events.
on-mouse-move-global down should take 1 argument mx my of the mouse position in global coordinates and return a sequence of intents.
on-mouse-move-raw
(on-mouse-move-raw on-mouse-move-raw & drawables)
Wraps drawables and adds an event handler for mouse-move events.
Unlike on-mouse-move
, does not ignore events outside the bounds of drawables
.
on-mouse-move down should take 1 argument mx my of the mouse position in local coordinates and return a sequence of intents.
on-mouse-up
(on-mouse-up on-mouse-up & drawables)
Wraps drawables and adds an event handler for mouse-up events.
on-mouse-up should take 1 argument mx my of the mouse position in local coordinates and return a sequence of intents.
on-mouse-up-raw
(on-mouse-up-raw on-mouse-up-raw & drawables)
Wraps drawables and adds an event handler for mouse-up events.
Unlike on-mouse-up
, does not ignore events outside the bounds of drawables
.
on-mouse-up should take 1 argument mx my of the mouse position in local coordinates and return a sequence of intents.
on-scroll
(on-scroll on-scroll & drawables)
Wraps drawables and adds an event handler for scroll events.
on-scroll should take 1 argument offset-x offset-y of the scroll offset and return a sequence of intents.
origin
(origin elem)
Specifies the top left corner of a component's bounds
The origin is vector or 2 numbers x, y
origin-x
(origin-x elem)
Convience function for returning the x coordinate of elem's origin
origin-y
(origin-y elem)
Convience function for returning the y coordinate of elem's origin
padding
(padding p elem)
(padding px py elem)
(padding top right bottom left elem)
Adds empty space around an element. The bounds of the returned element will include the padding.
;; Add 5 pixels of empty space around all 4 sides of elem
(padding 5 elem)
;; Add 3 pixels of padding to the left and right ;; and 5 pixels to the top and bottom (padding 3 5 elem)
;; 1 px to the top ;; 2 pixels to the right ;; 3 pixels to the bottom ;; 4 pixels to the left. (padding 1 2 3 4 elem)
path
(path & points)
A graphical element that will draw lines connecting points.
See with-style, with-stroke-width, and with-color for more options.
rectangle
(rectangle width height)
Graphical elem that draws a rectangle.
See with-style, with-stroke-width, and with-color for more options.
rounded-rectangle
(rounded-rectangle width height border-radius)
Graphical elem that draws a rounded rectangle.
scissor-view
(scissor-view offset bounds drawable)
Graphical elem to only draw drawable within bounds with an offset.
All other drawing will be clipped.
scrollview
(scrollview bounds offset drawable)
Graphical elem that will draw drawable offset by offset and clip its drawings to bounds.
spacer
(spacer x)
(spacer x y)
An empty graphical element with width x and height y.
Useful for layout.
text-cursor
(text-cursor text cursor)
(text-cursor text cursor font)
Graphical elem that can draw a text cursor
font should be a membrane.ui.Font
text-selection
(text-selection text [selection-start selection-end :as selection])
(text-selection text [selection-start selection-end :as selection] font)
Graphical elem for drawing a selection of text.
translate
(translate x y drawable)
A graphical elem that will shift drawable's origin by x and y and draw it at its new origin.
try-draw
(try-draw body error-draw)
Tries to draw body. If an exception occurs, calls error-draw with draw
and the exception
Example: (ui/try-draw error-body (fn draw e (draw (ui/label e))))
vertical-layout
(vertical-layout & elems)
Returns a graphical elem of elems stacked on top of each other
with-color
(with-color color & drawables)
with-stroke-width
(with-stroke-width stroke-width & drawables)
Set the stroke width for drawables.
with-style
(with-style style & drawables)
Style for drawing paths and polygons
style is one of: :membrane.ui/style-fill :membrane.ui/style-stroke :membrane.ui/style-stroke-and-fill
wrap-on
(wrap-on & events)
Wraps an elem with event handlers.
events are pairs of events and event handlers and the last argument should be an elem. The event handlers should accept an extra first argument to the event which is the original event handler.
example:
Wraps a button with a mouse-down handler that only returns an intent when the x coordinate is even. (on :mouse-down (fn [handler mx my] (when (even? mx) (handler mx my))) (button "Hello!" (fn [] :hello!)))