Skip to content

package document

import "kaiju/engine/ui/markup/document"

Variables

Debug

struct {
    ReloadStylesEvent events.Event
}{}

Functions

TransformHTML

func TransformHTML(htmlStr string, withData any) (string, error)

Types

Document

struct

type Document struct {
    Elements     []*Element
    TopElements  []*Element
    HeadElements []*Element

    Debug struct {
        ReloadEventId events.Id
}

// Has unexported fields. }

DocumentFromHTMLString

func DocumentFromHTMLString(uiMan *ui.Manager, htmlStr string, withData any, funcMap map[string]func(*Element)) *Document

Document.Activate

func (d *Document) Activate()

Document.AddChildElement

func (d *Document) AddChildElement(parent *Element, elm *Element)

Document.ApplyStyles

func (d *Document) ApplyStyles()

Document.Clean

func (d *Document) Clean()

Document.Deactivate

func (d *Document) Deactivate()

Document.Destroy

func (d *Document) Destroy()

Document.DupicateElement

func (d *Document) DupicateElement(elm *Element) *Element

DupicateElement will create a duplicate of a given element, nesting it under the same parent as the given element (at the end). If you wish to just duplicate an element and use one of the Insert functions, then use Element.Clone followed by an Insert function instead

Document.GetElementById

func (h *Document) GetElementById(id string) (*Element, bool)

Document.GetElementsByClass

func (h *Document) GetElementsByClass(class string) []*Element

Document.GetElementsByGroup

func (h *Document) GetElementsByGroup(group string) []*Element

Document.GetElementsByTagName

func (h *Document) GetElementsByTagName(tag string) []*Element

Document.InsertElementAfter

func (d *Document) InsertElementAfter(elm *Element, after *Element)

InsertElementAfter inserts the given element elm into the document after the specified element after. It handles the removal of elm from its current parent if it has one, and then inserts it into the children of after's parent at the correct position. The function ensures that elm is properly added to the document's element list and updates all necessary caches and styles after the insertion.

Parameters: - elm: the element to be inserted - after: the element after which elm should be inserted

Preconditions: - Both elm and after must not be nil (enforced by debug.Ensure)

Document.InsertElementBefore

func (d *Document) InsertElementBefore(elm *Element, before *Element)

InsertElementBefore inserts the given element elm into the document before the specified element before. It handles the removal of elm from its current parent if it has one, and then inserts it into the children of before's parent at the correct position. The function ensures that elm is properly added to the document's element list and updates all necessary caches and styles after the insertion.

Parameters: - elm: the element to be inserted - before: the element before which elm should be inserted

Preconditions: - Both elm and before must not be nil (enforced by debug.Ensure)

Document.IsActive

func (d *Document) IsActive() bool

Document.RemoveElement

func (d *Document) RemoveElement(elm *Element)

RemoveElement removes the specified element from the document by first recursively removing all child elements, then removing the element from its parent's children list, destroying the UI entity, and updating the document's element caches. Finally, it reapplies all document styles.

Parameters: - elm: pointer to the Element to be removed from the document

The function performs the following operations: 1. Recursively removes all child elements starting from the last child 2. Removes the element from its parent's Children list if it has a parent 3. Destroys the UI entity associated with the element 4. Updates the parent's layout dirty flag 5. Removes the element from document's indexed elements 6. Applies all document styles to reflect changes

Document.SetElementClasses

func (d *Document) SetElementClasses(elm *Element, classes ...string)

SetElementClasses updates the class list of the given element and applies style changes to the entire document. It calls SetElementClassesWithoutApply to update classes, then applies all styles in the document.

Parameters: - elm: pointer to the Element whose classes will be updated - classes: variadic string parameters representing the new class names

Document.SetElementClassesWithoutApply

func (d *Document) SetElementClassesWithoutApply(elm *Element, classes ...string)

SetElementClassesWithoutApply updates the class list of the given element without applying styles. It removes the element from its previous class lists, sets the new classes, and updates the document's classElements map to reflect the new class assignments.

Parameters: - elm: pointer to the Element whose classes will be updated - classes: variadic string parameters representing the new class names

The function performs the following operations: 1. Sorts both the input classes and existing element classes 2. Returns early if classes are identical 3. Removes element from previous class lists in classElements map 4. Sets the new class list on the element 5. Adds element to the appropriate class lists in classElements map

Document.SetupStylizer

func (d *Document) SetupStylizer(style rules.StyleSheet, host *engine.Host, stylizer Stylizer)

Element

struct

type Element struct {
    Type html.NodeType
    Data string

    UI       *ui.UI
    UIPanel  *ui.Panel
    Parent   weak.Pointer[Element]
    Children []*Element

    StyleRules []rules.Rule
    UIEventIds [ui.EventTypeEnd][]events.Id
    // Has unexported fields.
}

NewHTML

func NewHTML(htmlStr string) *Element

Element.Attribute

func (e *Element) Attribute(key string) string

Element.Body

func (e *Element) Body() *Element

Element.ClassList

func (e *Element) ClassList() []string

Element.Clone

func (e *Element) Clone(parent *Element) *Element

Element.EnforceColor

func (d *Element) EnforceColor(color matrix.Color)

Element.FindElementById

func (e *Element) FindElementById(id string) *Element

Element.FindElementByTag

func (e *Element) FindElementByTag(tag string) *Element

Element.FindElementLabelById

func (e *Element) FindElementLabelById(id string) *ui.Label

Element.FindElementsByTag

func (e *Element) FindElementsByTag(tag string) []*Element

Element.HasClass

func (e *Element) HasClass(class string) bool

Element.Head

func (e *Element) Head() *Element

Element.Html

func (e *Element) Html() *Element

Element.IndexOfChild

func (d *Element) IndexOfChild(child *Element) int

Element.InnerLabel

func (d Element) InnerLabel() *ui.Label

Element.IsButton

func (e *Element) IsButton() bool

Element.IsImage

func (e *Element) IsImage() bool

Element.IsInput

func (e *Element) IsInput() bool

Element.IsSelect

func (e *Element) IsSelect() bool

Element.IsSelectOption

func (e *Element) IsSelectOption() bool

Element.IsText

func (e *Element) IsText() bool

Element.Root

func (e *Element) Root() *Element

Element.SetAttribute

func (e *Element) SetAttribute(key, value string)

SetAttribute sets an attribute on the HTML element. If the attribute key is "class", it parses the value as space-separated class names and sets them using SetClasses. Otherwise, it updates the existing attribute or adds a new one to the element's attribute list.

Element.SetClasses

func (e *Element) SetClasses(classes ...string)

Element.UnEnforceColor

func (d *Element) UnEnforceColor()

Stylizer

interface

type Stylizer interface {
    ApplyStyles(s rules.StyleSheet, doc *Document, host *engine.Host)
}

TemplateIndexedAny

struct

type TemplateIndexedAny struct {
    Idx   int
    Value any
}