Skip to content

Commit

Permalink
Hello, Checkbox Group! Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyObtiva committed Oct 29, 2020
1 parent b749dfd commit c6c22ee
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 124 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,8 +2,11 @@

### 4.17.7.0

- `checkbox_group` built-in custom widget
- Hello, Checkbox Group! Sample
- Refactor `radio_group` to render labels instead of relying on radio button text since they are better stylable
- Refactor Glimmer Meta-Sample to use `radio_group` instead of `radio`
- Fix issue with ExpandBar fill_layout with the extra element at the end (remove it)

### 4.17.6.0

Expand Down
3 changes: 0 additions & 3 deletions TODO.md
Expand Up @@ -5,9 +5,6 @@ Here is a list of tasks to do (moved to [CHANGELOG.md](CHANGELOG.md) once done).
## Next

- Fix minor visual issues with Glimmer Meta-Sample on Linux
- `checkbox_group` built-in custom widget
- Hello, Checkbox Group! Sample
- Fix issue with ExpandBar fill_layout with the extra element at the end (remove it)

## Soon

Expand Down
12 changes: 7 additions & 5 deletions lib/glimmer/swt/custom/checkbox_group.rb
Expand Up @@ -123,7 +123,7 @@ def build_checkboxes
margin_height 0
horizontal_spacing 0
vertical_spacing 0
}
}
checkboxes << checkbox { |checkbox_proxy|
on_widget_selected {
self.selection_indices = checkboxes.each_with_index.map {|cb, i| i if cb.selection}.to_a.compact
Expand All @@ -133,12 +133,14 @@ def build_checkboxes
layout_data :fill, :center, true, false
text item
on_mouse_up { |event|
found_index = labels.each_with_index.detect {|l, i| event.widget == l.swt_widget}[1]
if self.selection_indices.include?(found_index)
self.selection_indices.delete(found_index)
found_text = labels.each_with_index.detect {|l, i| event.widget == l.swt_widget}[0]&.text
selection_values = self.selection
if selection_values.include?(found_text)
selection_values.delete(found_text)
else
self.selection_indices << found_index
selection_values << found_text
end
self.selection = selection_values
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/elaborate/meta_sample.rb
Expand Up @@ -20,7 +20,7 @@ def name
end

def content
@content ||= File.read(file)
@content = File.read(file)
end

def launch
Expand Down
28 changes: 14 additions & 14 deletions samples/hello/hello_checkbox.rb
Expand Up @@ -19,22 +19,22 @@
# 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 Person
attr_accessor :skiing, :snowboarding, :snowmobiling, :snowshoeing

def initialize
reset_activities
class HelloCheckbox
class Person
attr_accessor :skiing, :snowboarding, :snowmobiling, :snowshoeing

def initialize
reset_activities
end

def reset_activities
self.skiing = false
self.snowboarding = true
self.snowmobiling = false
self.snowshoeing = false
end
end

def reset_activities
self.skiing = false
self.snowboarding = true
self.snowmobiling = false
self.snowshoeing = false
end
end

class HelloCheckbox
include Glimmer

def launch
Expand Down
68 changes: 68 additions & 0 deletions samples/hello/hello_checkbox_group.rb
@@ -0,0 +1,68 @@
# 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 HelloCheckboxGroup
class Person
attr_accessor :activities

def initialize
reset_activities
end

def activities_options
['Skiing', 'Snowboarding', 'Snowmobiling', 'Snowshoeing']
end

def reset_activities
self.activities = ['Snowboarding']
end
end

include Glimmer

def launch
person = Person.new

shell {
text 'Hello, Checkbox!'
row_layout :vertical

label {
text 'Check all snow activities you are interested in:'
font style: :bold
}

checkbox_group {
selection bind(person, :activities)
}

button {
text 'Reset Activities'

on_widget_selected do
person.reset_activities
end
}
}.open
end
end

HelloCheckboxGroup.new.launch
24 changes: 12 additions & 12 deletions samples/hello/hello_combo.rb
Expand Up @@ -19,20 +19,20 @@
# 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 Person
attr_accessor :country, :country_options

def initialize
self.country_options = ['', 'Canada', 'US', 'Mexico']
reset_country
end

def reset_country
self.country = 'Canada'
class HelloCombo
class Person
attr_accessor :country, :country_options

def initialize
self.country_options = ['', 'Canada', 'US', 'Mexico']
reset_country
end

def reset_country
self.country = 'Canada'
end
end
end

class HelloCombo
include Glimmer

def launch
Expand Down
46 changes: 23 additions & 23 deletions samples/hello/hello_list_multi_selection.rb
Expand Up @@ -19,30 +19,30 @@
# 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 Person
attr_accessor :provinces, :provinces_options

def initialize
self.provinces_options=[
"",
"Quebec",
"Ontario",
"Manitoba",
"Saskatchewan",
"Alberta",
"British Columbia",
"Nova Skotia",
"Newfoundland"
]
self.provinces = ["Quebec", "Manitoba", "Alberta"]
end

def reset_provinces
self.provinces = ["Quebec", "Manitoba", "Alberta"]
end
end

class HelloListMultiSelection
class Person
attr_accessor :provinces, :provinces_options

def initialize
self.provinces_options=[
"",
"Quebec",
"Ontario",
"Manitoba",
"Saskatchewan",
"Alberta",
"British Columbia",
"Nova Skotia",
"Newfoundland"
]
self.provinces = ["Quebec", "Manitoba", "Alberta"]
end

def reset_provinces
self.provinces = ["Quebec", "Manitoba", "Alberta"]
end
end

include Glimmer

def launch
Expand Down
27 changes: 14 additions & 13 deletions samples/hello/hello_list_single_selection.rb
Expand Up @@ -19,21 +19,22 @@
# 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 Person
attr_accessor :country, :country_options

def initialize
self.country_options=["", "Canada", "US", "Mexico"]
self.country = "Canada"
end

def reset_country
self.country = "Canada"
end
end

class HelloListSingleSelection
class Person
attr_accessor :country, :country_options

def initialize
self.country_options=["", "Canada", "US", "Mexico"]
self.country = "Canada"
end

def reset_country
self.country = "Canada"
end
end

include Glimmer

def launch
person = Person.new

Expand Down
34 changes: 17 additions & 17 deletions samples/hello/hello_radio.rb
Expand Up @@ -19,25 +19,25 @@
# 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 Person
attr_accessor :male, :female, :child, :teen, :adult, :senior

def initialize
reset
class HelloRadio
class Person
attr_accessor :male, :female, :child, :teen, :adult, :senior

def initialize
reset
end

def reset
self.male = nil
self.female = nil
self.child = nil
self.teen = nil
self.adult = true
self.senior = nil
end
end

def reset
self.male = nil
self.female = nil
self.child = nil
self.teen = nil
self.adult = true
self.senior = nil
end
end

class HelloRadio
include Glimmer
include Glimmer

def launch
person = Person.new
Expand Down
40 changes: 20 additions & 20 deletions samples/hello/hello_radio_group.rb
Expand Up @@ -19,28 +19,28 @@
# 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 Person
attr_accessor :gender, :age_group

def initialize
reset
end

def gender_options
['Male', 'Female']
end

def age_group_options
['Child', 'Teen', 'Adult', 'Senior']
end

def reset
self.gender = nil
self.age_group = 'Adult'
class HelloRadioGroup
class Person
attr_accessor :gender, :age_group

def initialize
reset
end

def gender_options
['Male', 'Female']
end

def age_group_options
['Child', 'Teen', 'Adult', 'Senior']
end

def reset
self.gender = nil
self.age_group = 'Adult'
end
end
end

class HelloRadioGroup
include Glimmer

def launch
Expand Down

0 comments on commit c6c22ee

Please sign in to comment.