summaryrefslogtreecommitdiffstats
path: root/test/tests/test_buttons.rb
blob: 90075063227b1d6c25803703b08bbcb4a9763750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
module Tests
    #
    class TestBg < Efl::Elm::ElmWin
        def initialize name, title, fct
            super nil, name
            self.title = title
            self.autodel = true
            @bg = Elm::ElmBg.new self do |bg|
                bg.size_hint_weight_expand
                self.resize_object_add bg
                bg.show
            end
            self.send fct
            self.resize 320, 480
            self.show
        end
        #
        def __create_butt_ico txt=nil, do_icon=true
            if do_icon
                ico = Elm::ElmIcon.new self
                ico.file = "#{PACKAGE_DATA_DIR}/images/logo_small.png", nil
            else
                ico = nil
            end
            bt = Efl::Elm::ElmButton.new self
            bt.text = txt unless txt.nil?
            bt.icon = ico if ico
            bt.smart_callback_add "clicked", method(:bt_clicked_cb)
            bt.smart_callback_add "unpressed", method(:bt_unpressed_cb)
            @bx.pack_end bt
            @buttons << bt
            ico.show if ico
            bt.show
            [bt,ico]
        end
        #
        def buttons
            @scr = Efl::Elm::ElmScroller.new self do |scr|
                scr.bounce = false, true
                scr.policy = :elm_scroller_policy_off, :elm_scroller_policy_auto
                self.resize_object_add scr
                scr.size_hint_weight_expand
                scr.show
            end
            @bx = Efl::Elm::ElmBox.new self do |bx|
                bx.size_hint_weight_expand
                @scr.content = bx
                bx.show
            end
            #
            @buttons = []
            #
            bt,ico = __create_butt_ico "Icon sized to button"
            ico.size_hint_aspect = :evas_aspect_control_vertical, 1, 1
            #
            bt,ico = __create_butt_ico "Icon no scale"
            ico.scale = false, false
            #
            bt,ico = __create_butt_ico "Disabled Button"
            bt.disabled = true
            ico.size_hint_aspect = :evas_aspect_control_vertical, 1, 1
            #
            bt,ico = __create_butt_ico
            bt.disabled = true
            ico.size_hint_aspect = :evas_aspect_control_vertical, 1, 1
            #
            bt,ico = __create_butt_ico "Label Only", false
            bt.smart_callback_add "repeated", method(:bt_repeated_cb)
            bt.autorepeat = true
            bt.autorepeat_gap_timeout = 0.5
            bt.autorepeat_initial_timeout = 2.0
            #
            bt,ico = __create_butt_ico
            ico.scale = false, false
            #
            bt,ico = __create_butt_ico "Anchor style", false
            bt.style = "anchor"
            #
            bt,ico = __create_butt_ico
            ico.size_hint_aspect = :evas_aspect_control_vertical, 1, 1
            bt.style = "anchor"
            #
            bt,ico = __create_butt_ico
            ico.size_hint_aspect = :evas_aspect_control_vertical, 1, 1
            bt.style = "anchor"
            bt.disabled = true
            bt.access_info_set "This is some custom text describing this widget"
        end
        #
        def bt_clicked_cb data, evas_obj, event_info
            idx = @buttons.index @buttons.find { |b| b.to_ptr==evas_obj }
            puts "clicked event on Button: #{idx+1}"
        end
        #
        def bt_unpressed_cb data, evas_obj, event_info
            idx = @buttons.index @buttons.find { |b| b.to_ptr==evas_obj }
            puts "unpressed event on Button: #{idx+1}"
        end
        #
        def bt_repeated_cb data, evas_obj, event_info
            @count = ((@count||=0)+1)%1000
            Efl::Elm::ElmButton.new(evas_obj).text = "count = #{@count}"
        end
    end
    #
    def self.test_button
        TestBg.new 'buttons', 'Buttons', :buttons
    end
end
#
# EOF