ruddfawcett / Notepad

[iOS] A fully themeable markdown editor with live syntax highlighting.
http://rudd.fyi/notepad
MIT License
881 stars 106 forks source link

Programatic themes #59

Closed rivera-ernesto closed 4 years ago

rivera-ernesto commented 4 years ago

With this changes it is now possible both to create Theme objects fully programmatically, or also adjust themes read from json files.

Sample fully programatic theme that handles iOS 13 dark mode:

var theme = Theme()
theme.body.attributes = [.font :  UIFont.inter(), .foregroundColor : UIColor.secondaryLabel]
theme.styles.append(Style(element: .h1, attributes: [.font : UIFont.inter(size: 24), .foregroundColor : UIColor.label]))
theme.styles.append(Style(element: .h2, attributes: [.font : UIFont.inter(size: 18), .foregroundColor : UIColor.label]))
theme.styles.append(Style(element: .h3, attributes: [.font : UIFont.inter(size: 16), .foregroundColor : UIColor.label]))
theme.styles.append(Style(element: .bold, attributes: [.font : UIFont.inter(weight: .bold)]))
theme.styles.append(Style(element: .italic, attributes: [.font : UIFont.inter(italic: true)]))
theme.styles.append(Style(element: .boldItalic, attributes: [.font : UIFont.inter(weight: .bold, italic: true)]))
theme.styles.append(Style(element: .code, attributes: [.font : UIFont(name: "CourierNewPSMT", size: 15)!, .foregroundColor : UIColor.label, .backgroundColor : UIColor.secondarySystemBackground]))
theme.styles.append(Style(element: .image, attributes: [.foregroundColor : UIColor.appTint]))
theme.styles.append(Style(element: .url, attributes: [.foregroundColor : UIColor.appTint]))