Skip to content

Commit

Permalink
feat: add support for dynamic fontSize management
Browse files Browse the repository at this point in the history
split also Mode and Theme in file separated extensions

work on issue #22
  • Loading branch information
bsorrentino committed Aug 21, 2023
1 parent caece40 commit bdb9205
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 223 deletions.
22 changes: 17 additions & 5 deletions PlantUMLEditor/Sources/CodeViewer/CodeViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public struct CodeViewer: ViewRepresentable {
private let darkTheme: CodeWebView.Theme
private let lightTheme: CodeWebView.Theme
private let isReadOnly: Bool
private let fontSize: Int
private let fontSize: CGFloat

public init(
content: Binding<String>,
mode: CodeWebView.Mode = .json,
darkTheme: CodeWebView.Theme = .solarized_dark,
lightTheme: CodeWebView.Theme = .solarized_light,
isReadOnly: Bool = false,
fontSize: Int = 12,
fontSize: CGFloat = 12,
textDidChanged: ((String) -> Void)? = nil
) {
self._content = content
Expand All @@ -41,12 +41,12 @@ public struct CodeViewer: ViewRepresentable {
}

public func makeCoordinator() -> Coordinator {
Coordinator(content: $content, colorScheme: colorScheme)
Coordinator(content: $content, colorScheme: colorScheme, fontSize: fontSize )
}

private func getWebView(context: Context) -> CodeWebView {
let codeView = CodeWebView()

codeView.setReadOnly(isReadOnly)
codeView.setMode(mode)
codeView.setFontSize(fontSize)
Expand All @@ -69,6 +69,13 @@ public struct CodeViewer: ViewRepresentable {
colorScheme == .dark ? webview.setTheme(darkTheme) : webview.setTheme(lightTheme)
context.coordinator.set(colorScheme: colorScheme)
}

print( "fontSize: \(fontSize)" )

if context.coordinator.fontSize != fontSize {
context.coordinator.fontSize = fontSize
webview.setFontSize(fontSize)
}
}

// MARK: macOS
Expand All @@ -91,13 +98,17 @@ public struct CodeViewer: ViewRepresentable {
}

public extension CodeViewer {

class Coordinator: NSObject {
@Binding private(set) var content: String

private(set) var colorScheme: ColorScheme
var fontSize: CGFloat

init(content: Binding<String>, colorScheme: ColorScheme) {
init(content: Binding<String>, colorScheme: ColorScheme, fontSize: CGFloat ) {
_content = content
self.colorScheme = colorScheme
self.fontSize = fontSize
}

func set(content: String) {
Expand All @@ -111,6 +122,7 @@ public extension CodeViewer {
self.colorScheme = colorScheme
}
}

}
}

Expand Down
189 changes: 189 additions & 0 deletions PlantUMLEditor/Sources/CodeViewer/CodeWebView+Mode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
//
// File.swift
//
//
// Created by Bartolomeo Sorrentino on 21/08/23.
//

import Foundation


extension CodeWebView {

public enum Mode: String {
case abap = "abap"
case abc = "abc"
case actionscript = "actionscript"
case ada = "ada"
case alda = "alda"
case apache_conf = "apache_conf"
case apex = "apex"
case applescript = "applescript"
case aql = "aql"
case asciidoc = "asciidoc"
case asl = "asl"
case assembly_x86 = "assembly_x86"
case autohotkey = "autohotkey"
case batchfile = "batchfile"
case c9search = "c9search"
case c_cpp = "c_cpp"
case cirru = "cirru"
case clojure = "clojure"
case cobol = "cobol"
case coffee = "coffee"
case coldfusion = "coldfusion"
case crystal = "crystal"
case csharp = "csharp"
case csound_document = "csound_document"
case csound_orchestra = "csound_orchestra"
case csound_score = "csound_score"
case csp = "csp"
case css = "css"
case curly = "curly"
case d = "d"
case dart = "dart"
case diff = "diff"
case django = "django"
case dockerfile = "dockerfile"
case dot = "dot"
case drools = "drools"
case edifact = "edifact"
case eiffel = "eiffel"
case ejs = "ejs"
case elixir = "elixir"
case elm = "elm"
case erlang = "erlang"
case forth = "forth"
case fortran = "fortran"
case fsharp = "fsharp"
case fsl = "fsl"
case ftl = "ftl"
case gcode = "gcode"
case gherkin = "gherkin"
case gitignore = "gitignore"
case glsl = "glsl"
case gobstones = "gobstones"
case golang = "golang"
case graphqlschema = "graphqlschema"
case groovy = "groovy"
case haml = "haml"
case handlebars = "handlebars"
case haskell = "haskell"
case haskell_cabal = "haskell_cabal"
case haxe = "haxe"
case hjson = "hjson"
case html = "html"
case html_elixir = "html_elixir"
case html_ruby = "html_ruby"
case ini = "ini"
case io = "io"
case jack = "jack"
case jade = "jade"
case java = "java"
case javascript = "javascript"
case json = "json"
case json5 = "json5"
case jsoniq = "jsoniq"
case jsp = "jsp"
case jssm = "jssm"
case jsx = "jsx"
case julia = "julia"
case kotlin = "kotlin"
case latex = "latex"
case less = "less"
case liquid = "liquid"
case lisp = "lisp"
case livescript = "livescript"
case logiql = "logiql"
case logtalk = "logtalk"
case lsl = "lsl"
case lua = "lua"
case luapage = "luapage"
case lucene = "lucene"
case makefile = "makefile"
case markdown = "markdown"
case mask = "mask"
case matlab = "matlab"
case maze = "maze"
case mediawiki = "mediawiki"
case mel = "mel"
case mixal = "mixal"
case mushcode = "mushcode"
case mysql = "mysql"
case nginx = "nginx"
case nim = "nim"
case nix = "nix"
case nsis = "nsis"
case nunjucks = "nunjucks"
case objectivec = "objectivec"
case ocaml = "ocaml"
case pascal = "pascal"
case perl = "perl"
case perl6 = "perl6"
case pgsql = "pgsql"
case php = "php"
case php_laravel_blade = "php_laravel_blade"
case pig = "pig"
case plain_text = "plain_text"
case plantuml = "plantuml"
case powershell = "powershell"
case praat = "praat"
case prisma = "prisma"
case prolog = "prolog"
case properties = "properties"
case protobuf = "protobuf"
case puppet = "puppet"
case python = "python"
case qml = "qml"
case r = "r"
case razor = "razor"
case rdoc = "rdoc"
case red = "red"
case redshift = "redshift"
case rhtml = "rhtml"
case rst = "rst"
case ruby = "ruby"
case rust = "rust"
case sass = "sass"
case scad = "scad"
case scala = "scala"
case scheme = "scheme"
case scss = "scss"
case sh = "sh"
case sjs = "sjs"
case slim = "slim"
case smarty = "smarty"
case snippets = "snippets"
case soy_template = "soy_template"
case space = "space"
case sparql = "sparql"
case sql = "sql"
case sqlserver = "sqlserver"
case stylus = "stylus"
case svg = "svg"
case swift = "swift"
case tcl = "tcl"
case terraform = "terraform"
case tex = "tex"
case text = "text"
case textile = "textile"
case toml = "toml"
case tsx = "tsx"
case turtle = "turtle"
case twig = "twig"
case typescript = "typescript"
case vala = "vala"
case vbscript = "vbscript"
case velocity = "velocity"
case verilog = "verilog"
case vhdl = "vhdl"
case visualforce = "visualforce"
case wollok = "wollok"
case xml = "xml"
case xquery = "xquery"
case yaml = "yaml"
case zeek = "zeek"
}


}
55 changes: 55 additions & 0 deletions PlantUMLEditor/Sources/CodeViewer/CodeWebView+Theme.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// File.swift
//
//
// Created by Bartolomeo Sorrentino on 21/08/23.
//

import Foundation


extension CodeWebView {

public enum Theme: String {

case ambiance = "ambiance"
case chrome = "chrome"
case clouds = "clouds"
case clouds_midnight = "clouds_midnight"
case cobalt = "cobalt"
case crimson_editor = "crimson_editor"
case dawn = "dawn"
case dracula = "dracula"
case dreamweaver = "dreamweaver"
case chaos = "chaos"
case eclipse = "eclipse"
case github = "github"
case gob = "gob"
case gruvbox = "gruvbox"
case idle_fingers = "idle_fingers"
case iplastic = "iplastic"
case katzenmilch = "katzenmilch"
case kr_theme = "kr_theme"
case kuroir = "kuroir"
case merbivore = "merbivore"
case merbivore_soft = "merbivore_soft"
case mono_industrial = "mono_industrial"
case monokai = "monokai"
case nord_dark = "nord_dark"
case pastel_on_dark = "pastel_on_dark"
case solarized_dark = "solarized_dark"
case solarized_light = "solarized_light"
case sqlserver = "sqlserver"
case terminal = "terminal"
case textmate = "textmate"
case tomorrow = "tomorrow"
case tomorrow_night = "tomorrow_night"
case tomorrow_night_blue = "tomorrow_night_blue"
case tomorrow_night_bright = "tomorrow_night_bright"
case tomorrow_night_eighties = "tomorrow_night_eighties"
case twilight = "twilight"
case vibrant_ink = "vibrant_ink"
case xcode = "xcode"
}

}
Loading

0 comments on commit bdb9205

Please sign in to comment.