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 >
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 >
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 >
-
name
-
condition
-
selected
-
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 >
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 >
-
selected
is the name of the state. When used in a selector a:
is appended, becoming:selected
. -
this.selected
being true on the enclosing element is the condition that triggers the state -
:selected
is used in the display style to change the element’s background color -
this.selected
is set totrue
when the element’sPRESSED
event is triggered and it was previouslyfalse
-
this.selected
is set tofalse
when the element’sPRESSED
event is triggered and it was previouslytrue
-
the
this.PRESSED
event causes the state to update -
the element’s styles are put in the
<display>
tag. -
the encolosing element is the root where the
<display>
and<code>
tags are placed. -
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 >
<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 >
<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 >
<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 >