charlesroddie / MathAtom

Structural representations of visual mathematics expressions for use in .Net rendering libraries
MIT License
7 stars 0 forks source link

How to manage styles and colors #3

Open charlesroddie opened 5 years ago

charlesroddie commented 5 years ago

Can we discuss the best way to describe styles (colors, italics, fonts, ...) in the Atom type?

Currently:

wpf-math CSharpMath Comment
Char of char * textStyle: string option
FixedChar of c:char * fontId:int
Styled of RowAtom* background: Brush * foreground: Brush Styled of Atom * Style

Color of Atom * colorString: string

Should we have a single Atom case Styled of Atom * Style to give style information?

type Style = System.Drawing.Color option * italic: bool option * bold: bool option * font: string option

Where inner styles take precedence over outer styles, and there is a default style which is the most outer style? Would this work?

Happypig375 commented 5 years ago

Inner styles completely taking over outer ones is a problem. For example, setting text yellow inside bold text would un-bold the text.

Happypig375 commented 5 years ago

I prefer different atoms for different style settings.

charlesroddie commented 5 years ago

Inner styles completely taking over outer ones is a problem. For example, setting text yellow inside bold text would un-bold the text.

Of course inner colors take precedence over outer colors etc.. So combining styles would go:

type Style =
    {   Color: System.Drawing.Color option
        Italic: bool option
        ... }
    static member Combine (outer:Style) (inner:Style) =
        {   Color = if inner.Color.IsSome then inner.Color else outer.Color
            Italic = if inner.Italic.IsSome then inner.Italic else outer.Italic
            ... }

So a single style atom vs separate color/bold/italic/etc. atoms vs anything inbetween shouldn't prevent correct behaviour here.