Skip to content

Commit

Permalink
Hello, Sash Form! Sample and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyObtiva committed Oct 21, 2020
1 parent d27f24b commit b0ebc4a
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 456 deletions.
538 changes: 100 additions & 438 deletions README.md

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ Here is a list of tasks to do (moved to [CHANGELOG.md](CHANGELOG.md) once done).

## Next

- Document code_text in README
- Document sash_form in README
- Update documentation with regards to how to run samples (removing references to sample:run)
- Document a third way of creating custom widgets (extending a standard WidgetProxy)

## Soon

- Optimize code_text line style listener algorithm or avoid setting code_text style via listener for performance reasons
- Optimize code_text syntax highlighting by not lexing except when content changes (e.g. during scrolling, do not lex)
- Make code_text custom widget support multiple languages
- Make code_text custom widget auto-detect current language
- Have `glimmer samples` show the code of sample models too outside the main view just like `glimmer sample:code` did in the past

- Support radio data-binding similar to combo (spawning radio buttons automatically based on options)
- Support a clean way of specifying different widget properties per OS (e.g. taking a hash of OS mappings instead of raw property values or supporting mac, windows, linux Glimmer keywords that wrap blocks around platform specific logic, perhaps make a web equivalent in opal)
- Add preferences dialog/menu-items to desktopify app
- Remove default margins from composites/layouts. They are not as helpful as they seemed.
Expand All @@ -20,9 +22,6 @@ Here is a list of tasks to do (moved to [CHANGELOG.md](CHANGELOG.md) once done).
- Support glimmer list:gems (listing all types of gems together)
- glimmer webify task, which generates a Glimmer DSL for Opal Rails app for a desktop app and publishes it on Heroku
- Make glimmer meta samples editable for experimentation before launching a sample
- Make code_text custom widget support multiple languages
- Make code_text custom widget auto-detect current language
- Remove dependencies on gems that are only needed for Glimmer tasks (loading them at the time of running those tasks only)

- Log exceptions that occur in event listener blocks
# - Log exceptions that happen in CustomWidget body, before_body, and after_body blocks
Expand All @@ -40,6 +39,7 @@ Here is a list of tasks to do (moved to [CHANGELOG.md](CHANGELOG.md) once done).
- Add FillLayout default style if not passed in
- Make GitHub username optional for Scaffolding
- Have scaffolding of custom widget and custom shell within app match the namespace when inside a custom shell gem (or app if namespace is used), and reference APP_ROOT correctly
- Remove dependencies on gems that are only needed for Glimmer tasks (loading them at the time of running those tasks only)

- Add shortcuts for password (adding :border as default style) and other text widget types
- Add shortcuts for error_box, information_box, etc... message_box variations based on style (e.g. SWT::ICON_INFORMATION)
Expand Down
2 changes: 1 addition & 1 deletion glimmer-dsl-swt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Gem::Specification.new do |s|
"samples/elaborate/contact_manager/contact_manager_presenter.rb",
"samples/elaborate/contact_manager/contact_repository.rb",
"samples/elaborate/login.rb",
"samples/elaborate/meta_sample.rb",
"samples/elaborate/tic_tac_toe.rb",
"samples/elaborate/tic_tac_toe/board.rb",
"samples/elaborate/tic_tac_toe/cell.rb",
Expand All @@ -131,7 +132,6 @@ Gem::Specification.new do |s|
"samples/hello/hello_pop_up_context_menu.rb",
"samples/hello/hello_tab.rb",
"samples/hello/hello_world.rb",
"samples/meta_sample.rb",
"vendor/swt/linux/swt.jar",
"vendor/swt/mac/swt.jar",
"vendor/swt/windows/swt.jar"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glimmer-hello-sash-form-red-maximized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glimmer-hello-sash-form-resized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glimmer-hello-sash-form-vertical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glimmer-hello-sash-form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glimmer-meta-sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions lib/glimmer/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ module RakeTask
end
end

desc 'Brings up the Glimmer Meta-Sample app to allow browsing, running, and viewing code of Glimmer samples (including samples in installed Glimmer gems)'
desc 'Brings up the Glimmer Meta-Sample app to allow browsing, running, and viewing code of Glimmer samples'
task :samples do
Glimmer::Launcher.new([File.expand_path('../../../samples/meta_sample.rb', __FILE__)]).launch
Glimmer::Launcher.new([File.expand_path('../../../samples/elaborate/meta_sample.rb', __FILE__)]).launch
end

namespace :package do
Expand Down
1 change: 1 addition & 0 deletions lib/glimmer/swt/custom/code_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def syntax_highlighting
hash[:token_index] = code_size
code_size += hash[:token_text].size
end
# TODO consider grouping by line to optimize performance for line get style listener
end

before_body {
Expand Down
11 changes: 4 additions & 7 deletions samples/meta_sample.rb → samples/elaborate/meta_sample.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'rouge'

# TODO include meta-sample's code in code to display but not launch
class Sample
attr_accessor :sample_directory, :file, :selected

Expand Down Expand Up @@ -106,7 +103,7 @@ def launch
text 'Glimmer Meta-Sample (The Sample of Samples)'

on_swt_show {
SampleDirectory.selected_sample = SampleDirectory.all_samples.first
SampleDirectory.selected_sample = SampleDirectory.all_samples.first
}

sash_form {
Expand Down Expand Up @@ -143,15 +140,15 @@ def launch
}

button {
layout_data(:center, :center, true, true) {
layout_data(:center, :center, false, false) {
height_hint 150
}
text 'Launch Sample'
font height: 45
on_widget_selected {
SampleDirectory.selected_sample.launch
}
}
}
}

code_text {
Expand All @@ -161,7 +158,7 @@ def launch
}

weights 1, 2
}
}
}.open
end
end
Expand Down
137 changes: 137 additions & 0 deletions samples/hello/hello_sash_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Copyright (c) 2007-2020 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class SashFormPresenter
include Glimmer

attr_accessor :sash_width, :orientation, :orientation_style

def initialize
@sash_width = 10
self.orientation = 'horizontal'
end

def orientation_options
['horizontal', 'vertical']
end

def orientation=(value)
@orientation = value
self.orientation_style = swt(@orientation)
end
end

@presenter = SashFormPresenter.new

include Glimmer

shell {
grid_layout 1, false
minimum_size 740, 0
text 'Hello, Sash Form!'

@sash_form = sash_form {
layout_data(:fill, :fill, true, true) {
height_hint 200
}
sash_width bind(@presenter, :sash_width)
orientation bind(@presenter, :orientation_style)
weights 1, 2

@green_label = label {
text 'Hello, (resize >>)'
background :dark_green
foreground :white
font height: 30
}

@red_label = label {
text '(<< resize) Sash Form!'
background :red
foreground :white
font height: 30
}
}

composite {
layout_data(:fill, :fill, true, true)
grid_layout 2, true

label {
layout_data(:right, :center, true, false)
text 'Sash Width:'
font height: 16
}
spinner {
layout_data(:fill, :center, true, false) {
width_hint 100
}
selection bind(@presenter, :sash_width)
font height: 16
}

label {
layout_data(:right, :center, true, false)
text 'Orientation:'
font height: 16
}
combo(:read_only, :border) {
layout_data(:fill, :center, true, false) {
width_hint 100
}
selection bind(@presenter, :orientation)
font height: 16
}

button {
layout_data(:fill, :center, true, false)
text 'Maximize Green Label'
foreground :dark_green
font height: 16

on_widget_selected {
@sash_form.maximized_control = @green_label.swt_widget
}
}
button {
layout_data(:fill, :center, true, false)
text 'Maximize Red Label'
foreground :red
font height: 16

on_widget_selected {
@sash_form.maximized_control = @red_label.swt_widget
}
}

button {
layout_data(:fill, :center, true, false) {
horizontal_span 2
}
text 'Maximize None'
font height: 16

on_widget_selected {
@sash_form.maximized_control = nil
}
}
}
}.open

0 comments on commit b0ebc4a

Please sign in to comment.