Lesson 26 of 50 · Layout language

Native apps

A page can run in a native window instead of a browser. You write the same page language, with the same style properties, and Salam draws the window itself. This lesson starts with a hello window and then lists what only the web build has.

A hello window

Any page is a native program. Save this as hello.salam:

native-hello.salam
page:
    title = "Hello"
    box:
        align = center
        justify = center
        gap = 12
        padding = 32
        heading: size = 1 content = "Hello, window" end
        paragraph: color = #4b5563 content = "This is drawn by Salam, not by a browser." end
        button:
            padding = 8, 20
            radius = 6
            background = #2563eb
            color = white
            hover background = #1d4ed8
            content = "Close"
        end
    end
end
salam run hello.salam --ui=native
salam build hello.salam --ui=native

run opens the window. build makes an executable that you can give to someone else; it needs no browser. The layout, the colours, the hover state and the text are the ones the web build would draw, because they come from the same style vocabulary.

What is the same

  • The tree of elements, component, if and each.
  • Every style property: layout, gap, align, sizes, colours, radius, shadow, text properties and states such as hover.
  • State declared with name := value and event handlers such as click. The window redraws only what a change touched.
  • Persian and English source, and right to left text.

What is web only

Things that only make sense in a browser are ignored or refused in a native window. salam check page.salam --ui=native lists them. Web metadata gives a warning and is skipped: SEO tags, meta, head link, base, noscript, srcset, loading, rel, target, data attributes, and form action and method. Elements that need a browser engine are errors: script, iframe, embed, object, template, svg, math, contenteditable and popover.

One page for both

Wrap the web only part in if SALAM_UI_WEB:. The compiler folds it away in a native build. SALAM_UI_NATIVE is the opposite.

native-both.salam
page:
    title = "One page, two targets"
    if SALAM_UI_WEB:
        meta: name = "description" content = "A page for the browser." end
    end
    box:
        padding = 24
        heading: size = 2 content = "Same page" end
        paragraph: content = "The meta tag above exists only in the web build." end
    end
end

Other desktop paths

If you want a browser engine inside a window, gui.webview hosts HTML, CSS and JS. That is a different path from the native page language, which has no browser inside.

For browser output, see Layout on the web. The next lessons cover each element and the style vocabulary.