Created
August 23, 2022 01:51
-
-
Save AndyObtiva/794654be543035062df2993ff997012c to your computer and use it in GitHub Desktop.
Glimmer DSL for SWT (JRuby Desktop Development GUI Framework) - Hello, Code Text! Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From: https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_SAMPLES.md#hello-code-text | |
require 'glimmer-dsl-swt' | |
class HelloCodeText | |
include Glimmer::UI::CustomShell | |
attr_accessor :ruby_code, :js_code, :html_code | |
before_body do | |
self.ruby_code = <<~RUBY | |
greeting = 'Hello, World!' | |
include Glimmer | |
shell { | |
text 'Glimmer' | |
label { | |
text greeting | |
font height: 30, style: :bold | |
} | |
}.open | |
RUBY | |
self.js_code = <<~JS | |
function greet(greeting) { | |
alert(greeting); | |
} | |
var greetingString = 'Hello, World!'; | |
greet(greetingString); | |
var moreGreetings = ['Howdy!', 'Aloha!', 'Hey!'] | |
for(var greeting of moreGreetings) { | |
greet(greeting) | |
} | |
JS | |
self.html_code = <<~HTML | |
<html> | |
<body> | |
<section class="accordion"> | |
<form method="post" id="name"> | |
<label for="name"> | |
Name | |
</label> | |
<input name="name" type="text" /> | |
<input type="submit" /> | |
</form> | |
</section> | |
</body> | |
</html> | |
HTML | |
end | |
body { | |
shell { | |
minimum_size 640, 480 | |
text 'Hello, Code Text!' | |
tab_folder { | |
tab_item { | |
fill_layout | |
text 'Ruby (glimmer theme)' | |
# Note: code_text theme is currently ignored in dark mode | |
code_text(language: 'ruby', theme: 'glimmer', lines: true) { # theme is currently ignored in dark mode | |
text <=> [self, :ruby_code] | |
} | |
} | |
tab_item { | |
fill_layout | |
text 'JavaScript (pastie theme)' | |
# Note: code_text theme is currently ignored in dark mode | |
code_text(:multi, :h_scroll, :v_scroll, language: 'javascript', theme: 'pastie', lines: {width: 2}) { | |
root { | |
grid_layout(2, false) { | |
margin_width 2 | |
} | |
background Display.system_dark_theme? ? :black : :white | |
} | |
line_numbers { | |
background Display.system_dark_theme? ? :black : :white | |
} | |
text <=> [self, :js_code] | |
} | |
} | |
tab_item { | |
fill_layout | |
text 'HTML (github theme)' | |
# Note: code_text theme is currently ignored in dark mode | |
code_text(language: 'html', theme: 'github') { # default is lines: false | |
text <=> [self, :html_code] | |
} | |
} | |
} | |
} | |
} | |
end | |
HelloCodeText.launch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment