about summary refs log blame commit diff stats
path: root/src/layout/box.nim
blob: a9cc74dd58c04b923e09b1fdca546fad2ff34c39 (plain) (tree)
1
2
3
4
5
6
7
8

              
                 
               
              

    
                  


           

                         
                          
 

                                     
                       
                                
               
                     
 







                                              









                                                                     
 
                                     
                   
               
                
                                
 
                              



                                      
               
 






                                           


                                         

                           
                   
               
                
                                          
 
                             
                   


                         
 
                       
                  
                       
               
                 
                           
 
                                       
                          
                              
                                
                       
                   

                

                       





                        
 
                   

                   
                            
                 
 

                                        
import options

import css/values
import html/dom
import io/term

type
  Offset* = object
    x*: int
    y*: int

  Viewport* = ref object
    term*: TermAttributes
    root*: BlockBoxBuilder

  BoxBuilder* = ref object of RootObj
    children*: seq[BoxBuilder]
    inlinelayout*: bool
    computed*: CSSComputedValues
    node*: Node
    element*: Element

  InlineBoxBuilder* = ref object of BoxBuilder
    text*: seq[string]
    ictx*: InlineContext
    newline*: bool

  BlockBoxBuilder* = ref object of BoxBuilder
    bctx*: BlockContext

  InlineBlockBoxBuilder* = ref object of BoxBuilder
    content*: BlockBoxBuilder # iblock.bctx is equivalent to box.bctx

  MarkerBoxBuilder* = ref object of InlineBoxBuilder
    ordinalvalue*: int
    inside*: bool

  ListItemBoxBuilder* = ref object of BoxBuilder
    marker*: MarkerBoxBuilder
    content*: BlockBoxBuilder

  InlineAtom* = ref object of RootObj
    offset*: Offset
    width*: int
    height*: int
    vertalign*: CSSVerticalAlign

  ComputedFormat* = ref object
    fontstyle*: CSSFontStyle
    fontweight*: int
    textdecoration*: CSSTextDecoration
    color*: CSSColor
    node*: Node

  InlineSpacing* = ref object of InlineAtom
    format*: ComputedFormat

  InlineWord* = ref object of InlineAtom
    str*: string
    format*: ComputedFormat

  InlineBlock* = ref object of InlineAtom
    bctx*: BlockContext

  InlineRow* = ref object
    atoms*: seq[InlineAtom]
    offset*: Offset
    width*: int
    height*: int
    lineheight*: int #line-height property

  InlineContext* = ref object
    offset*: Offset
    height*: int
    rows*: seq[InlineRow]
    thisrow*: InlineRow

    whitespacenum*: int
    maxwidth*: int
    viewport*: Viewport
    node*: Node
    shrink*: bool
    format*: ComputedFormat

  BlockContext* = ref object of RootObj
    inline*: InlineContext
    nested*: seq[BlockContext]
    computed*: CSSComputedValues
    viewport*: Viewport
    offset*: Offset
    width*: int
    height*: int
    margin_top*: int
    margin_bottom*: int
    margin_left*: int
    margin_right*: int
    padding_top*: int
    padding_bottom*: int
    padding_left*: int
    padding_right*: int

    compwidth*: int
    maxwidth*: int
    nocenter*: bool
    compheight*: Option[int]
    shrink*: bool

  ListItem* = ref object of BlockContext
    marker*: InlineContext