Markup Structure

Display

The <display> tag holds the styles for an element. Display styles are object oriented and acts on the element the display tag is directly within.

<container>
    <display>
        :this{
            width: 30px ;
            height: 30px;
            background: color(grey);
        }
    </display>
</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>

Code

The <code> tag holds the code for an element. Code is object oriented and event driven and acts on the element the code tag is directly within.

<container>
    <code>
        this.count = 0;
        this.registerEvent(this.PRESSED,()=>{
            console.log(`element pressed ${this.count++} times.`);
        });
    </code>
</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>

Display

Overview

Modkit Design Language provides an Object Oriented means of styling elements. How an element is styled can either be Defined within the element itself, Composed from styles defined outside the element, or Inherited from the element’s definition (in case of a custom widget).

Defining Styles

The most straightforward way to define a style is do so within the element itself. Defining style rules along with the element they affect is the clearest way to connect where style rules are defined and where they are applied.

While basic style rules are scoped to the element they are defined within, they

This also forms the basis for style Composition and Inheritance.

Composing Styles

Inheriting Styles

(from the elements definition in case of a widget), or

Precedence

A word about order of precedence…​

Just like modifying data within an object (in an object oriented programming language) uses a reference to the object itself before referencing its functions/methods/data (e.g. this.value or self.func()), all rules are anchored to the element they are defined within.

Note

While Modkit Design Language’s styles often resemble CSS styles, there are a number of subtle differences in the styles themselves and how they are applied. Most noteably MKDL provides a simplified set of style properties, does not have any notion of a "cascade" and determining which styles will be applied is often much more straightforward than with CSS.

Style Rules

XML Tag

<display>

When working with Modkit Design language’s XML format (i.e. in an .mkdl file), styles are authored in a <display> tag within the target element. Styles are defined with CSS-like rules consisting of selectors and a list of declarations (properties and values).

Selectors

Selectors are anchored to the element they are defined within through the use of the :this selector. Due to the object oriented nature of MKDL’s design styles, every rule’s selector begins with (or only contains) :this.

An element’s default rules (:this) are always applied for the element unless overridden (see precedence) but any number of states can be chosesn such as :this:selected or :this:selected:hover.

Body

Following a rule’s selector is its body, which consists of curly braces {} surrounding any number of style declarations.

Declaration

Each declaration consists of a property and value separated by : and ending with ; e.g. width: 30px;

Property

Declaration properties include many items that would be familiar to those with knowledge of CSS such as:

  • width

  • height

  • border-width

but also include some items that aren’t available or have different meaning from those in CSS such as:

  • layout-content

Value

Examples

<container>
    <display>
        <state name="selected" condition="this.selected"></state>
        :this{
            width: 30px;
            height: 30px;
            background: color(grey);
        }
    </display>
</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>
  1. name

  2. condition

  3. selected

  4. this.selected

Display Styles

Overview

===

===

===

Examples

<container>
	<display>
		<state name="selected" condition="this.selected"></state>
		:this{
			width: 30px;
			height: 30px;
			background: color(grey);
		}

    </display>

</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>

Display State

Overview

Separation of Code and Style is a core feature of the Modkit Design Language and one way this is accomplished is with its declarative state system. The designer simply referencds a builtin state or declares a new state along with the condition that will cause the state to be applied, and can then use the state to trigger changes to the element’s display styles.

Built-in states

Hover

The built-in hover state is applied to an element whenever a user’s pointing device (e.g. mouse) is directly over the element.

Declaring custom states

XML Tag

<state>

When working with Modkit Design language’s XML format (i.e. in an .mkdl file), custom states are declared in a <state> tag within an element’s <display> tag.

Attributes

name (required)

The name attribute specifies the name for the state which is used in a selector when writing display styles for the state.

condition (required)

The condition attribute specifies the javascript condition that must be met for the state to be applied.

Note that the condition is automatically checked using a watcher and any variable used in the condition must begin with this. e.g. this.selected.

Using a state

Display Style Selector

When working with Modkit Design language’s CSS-like format (i.e. in a <display> tag within an .mkdl file), custom states are used in selectors by adding a : to its name so that a state named selected would become :selected. Multiple states can be strung together such as :selected:error.

Note that because display styles are "object oriented", they will begin with :this so the simplest selector that will use the selected state would be :this:selected and applying both selected and error states would use the selector :this:selected:error.

Examples

New states are set up in the state tag within the display tag. The following example declares a state named selected which is applied when the condition this.selected is met for the enclosing container element. The state selector :selected is used in the display style to change the element’s background color. Finally the state is toggled between true and false when the element’s PRESSED event is triggered.

<<container>
    <display>
        <state  name="selected" condition = "this.selected" ></state >
        :this{
            width: 30px ;
            height: 30px;
            background: color(grey);
        }
        :this:selected{
            background: color(green);
        }
    </display>
    <code>
        this.registerEvent(this.PRESSED,()=>{
            if(this.selected){
                this.selected = false;
            }
            else{
                this.selected = true;
            }
            /*test comment
            on two lines      */
        });
    </code>
</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>
  1. selected is the name of the state. When used in a selector a : is appended, becoming :selected.

  2. this.selected being true on the enclosing element is the condition that triggers the state

  3. :selected is used in the display style to change the element’s background color

  4. this.selected is set to true when the element’s PRESSED event is triggered and it was previously false

  5. this.selected is set to false when the element’s PRESSED event is triggered and it was previously true

  6. the this.PRESSED event causes the state to update

  7. the element’s styles are put in the <display> tag.

  8. the encolosing element is the root where the <display> and <code> tags are placed.

  9. states are set up in the <state> tag within the <display> tag.

<container>  
    <code id="code-content">
        <import name="mkmlEditor" from="./mkml-editor-class.mjs"></import> 
        <import name="default" as="ModkitEnvironment" from="./ModkitEnvironment/js/modkitEnvironment.mjs"></import>

        this.registerEvent(this.LOADED,()=>{
            this.app.editor = new mkmlEditor('raw'); 
            if(window.chrome){
            
            window.fs = new ModkitEnvironment()
            }
            
        });
    </code>
    <display>
        :this {
            layout-content:column;
            height: 100%;
            width: 100%;
        }

    </display>
</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>
<container>
    <display>
        :this {
            layout-content: stack;
            height: 270px;
            width:  270px;
            border-color: black;
            border-width: 1px;
            border-style: solid;
            border-radius: 4px;
            padding-left: 5px;
            padding-bottom: 5px;
            padding-right: 5px;
        }
    </display>
    <box>
        <display>
          :this{
             left: 120px;
             top: 120px;
          }
        </display>
        1
    </box>
    <box>
       <display>
          :this{
             left:60px;
             top: 60px;
          }
        </display>
        2
    </box>
    <box>
       <display>
          :this{
             left:0px;
             top: 0px;
          }
       </display>
       3
     </box>
</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>
<container>
    <display>
        :this {
            layout-content:row;
            height: 200px;
            width: stretch;
            padding-top: 5px;
            padding-bottom: 5px;
            padding-right: 5px;
            border-color: black;
            border-width: 1px;
            border-style: solid;
            border-radius: 4px;
        }
    </display>
    <box>1</box>
    <box>2</box>
    <box>3</box>
</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>
<container>
    <display>
        :this {
            layout-content:column;
            height: stretch;
            width:  300px;
            border-color: black;
            border-width: 1px;
            border-style: solid;
            border-radius: 4px;
            padding-left: 5px;
            padding-bottom: 5px;
            padding-right: 5px;
        }
    </display>
    <box>1</box>
    <box>2</box>
    <box>3</box>
</container>
<html> <script src="fastdom.min.js"></script> </html> <modkit> <assets> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/window.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/container.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/app.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/text.mkml"></component> <component url="node_modules/@modkit/modkit-mockup-language/assets/components/screen.mkml"></component> <behavior url="node_modules/@modkit/modkit-mockup-language/assets/behaviors/capture-input.mkml"></behavior> <component tag="box" extends="container"> <display> :this { height: 100px; width: 100px; border-color: black; border-width: 1px; border-style: solid; margin-top: 5px; align-content-vertical: center; background: color(rgb(170,170,170)); layout-content: column; } </display> <children></children> </component> </assets> <app title="test" behavior="capture-input"> <screen> <window> <display> :this{ layout-content:stack; } </display> <container> <display> :this { layout-content: stack; height: 270px; width: 270px; border-color: black; border-width: 1px; border-style: solid; border-radius: 4px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; } </display> <box> <display> :this{ left: 120px; top: 120px; } </display> 1 </box> <box> <display> :this{ left:60px; top: 60px; } </display> 2 </box> <box> <display> :this{ left:0px; top: 0px; } </display> 3 </box> </container> </window> </screen> </app> </modkit>