Tuesday, December 22, 2020

Glimmer DSL for Opal v0.9.0 Menu Support

Glimmer DSL for Opal (Pure Ruby Web GUI & Auto-Webifier of Desktop Apps via Opal On Rails) just had a couple of exciting new releases (0.9.0 and 0.8.0) that bring menu bar and context menu support. 




# From Glimmer DSL for Opal: https://github.com/AndyObtiva/glimmer-dsl-opal#hello-menu-bar
include Glimmer
COLORS = [:white, :red, :yellow, :green, :blue, :magenta, :gray, :black]
shell {
grid_layout {
margin_width 0
margin_height 0
}
text 'Hello, Menu Bar!'
@label = label(:center) {
font height: 50
text 'Check Out The Menu Bar Above!'
}
menu_bar {
menu {
text '&File'
menu_item {
text '&New'
accelerator :command, :N
on_widget_selected {
message_box {
text 'New'
message 'New file created.'
}.open
}
}
menu_item {
text '&Open...'
accelerator :command, :O
on_widget_selected {
message_box {
text 'Open'
message 'Opening File...'
}.open
}
}
menu {
text 'Open &Recent'
menu_item {
text 'File 1'
on_widget_selected {
message_box {
text 'File 1'
message 'File 1 Contents'
}.open
}
}
menu_item {
text 'File 2'
on_widget_selected {
message_box {
text 'File 2'
message 'File 2 Contents'
}.open
}
}
}
menu_item(:separator)
menu_item {
text 'E&xit'
on_widget_selected {
exit(0)
}
}
}
menu {
text '&Edit'
menu_item {
text 'Cut'
accelerator :command, :X
}
menu_item {
text 'Copy'
accelerator :command, :C
}
menu_item {
text 'Paste'
accelerator :command, :V
}
}
menu {
text '&Options'
menu_item(:radio) {
text '&Enabled'
on_widget_selected {
@select_one_menu.enabled = true
@select_multiple_menu.enabled = true
}
}
@select_one_menu = menu {
text '&Select One'
enabled false
menu_item(:radio) {
text 'Option 1'
}
menu_item(:radio) {
text 'Option 2'
}
menu_item(:radio) {
text 'Option 3'
}
}
@select_multiple_menu = menu {
text '&Select Multiple'
enabled false
menu_item(:check) {
text 'Option 4'
}
menu_item(:check) {
text 'Option 5'
}
menu_item(:check) {
text 'Option 6'
}
}
}
menu {
text '&Format'
menu {
text '&Background Color'
COLORS.each { |color_style|
menu_item(:radio) {
text color_style.to_s.split('_').map(&:capitalize).join(' ')
on_widget_selected {
@label.background = color_style
}
}
}
}
menu {
text 'Foreground &Color'
COLORS.each { |color_style|
menu_item(:radio) {
text color_style.to_s.split('_').map(&:capitalize).join(' ')
on_widget_selected {
@label.foreground = color_style
}
}
}
}
}
menu {
text '&View'
menu_item(:radio) {
text 'Small'
on_widget_selected {
@label.font = {height: 25}
@label.parent.pack
}
}
menu_item(:radio) {
text 'Medium'
selection true
on_widget_selected {
@label.font = {height: 50}
@label.parent.pack
}
}
menu_item(:radio) {
text 'Large'
on_widget_selected {
@label.font = {height: 75}
@label.parent.pack
}
}
}
menu {
text '&Help'
menu_item {
text '&Manual'
accelerator :command, :shift, :M
on_widget_selected {
message_box {
text 'Manual'
message 'Manual Contents'
}.open
}
}
menu_item {
text '&Tutorial'
accelerator :command, :shift, :T
on_widget_selected {
message_box {
text 'Tutorial'
message 'Tutorial Contents'
}.open
}
}
menu_item(:separator)
menu_item {
text '&Report an Issue...'
on_widget_selected {
message_box {
text 'Report an Issue'
message 'Reporting an issue...'
}.open
}
}
}
}
}.open



# From Glimmer DSL for Opal: https://github.com/AndyObtiva/glimmer-dsl-opal#hello-pop-up-context-menu
include Glimmer
shell {
grid_layout {
margin_width 0
margin_height 0
}
text 'Hello, Pop Up Context Menu!'
label {
text "Right-Click on the Text to\nPop Up a Context Menu"
font height: 50
menu {
menu {
text '&History'
menu {
text '&Recent'
menu_item {
text 'File 1'
on_widget_selected {
message_box {
text 'File 1'
message 'File 1 Contents'
}.open
}
}
menu_item {
text 'File 2'
on_widget_selected {
message_box {
text 'File 2'
message 'File 2 Contents'
}.open
}
}
}
menu {
text '&Archived'
menu_item {
text 'File 3'
on_widget_selected {
message_box {
text 'File 3'
message 'File 3 Contents'
}.open
}
}
menu_item {
text 'File 4'
on_widget_selected {
message_box {
text 'File 4'
message 'File 4 Contents'
}.open
}
}
}
}
}
}
}.open

No comments:

Post a Comment