iup-ffi 0.13.0-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENCE.md +21 -0
- data/README.md +139 -0
- data/lib/iup-ffi-plain.rb +51 -0
- data/lib/iup-ffi.rb +70 -0
- data/lib/library/linux/libcd.so +0 -0
- data/lib/library/linux/libim.so +0 -0
- data/lib/library/linux/libiup.so +0 -0
- data/lib/library/linux/libiup_scintilla.so +0 -0
- data/lib/library/linux/libiupcd.so +0 -0
- data/lib/library/linux/libiupcontrols.so +0 -0
- data/lib/library/linux/libiupim.so +0 -0
- data/lib/library/linux/libiupimglib.so +0 -0
- data/lib/plain/iupcdlib.rb +158 -0
- data/lib/plain/iupcontrolslib.rb +28 -0
- data/lib/plain/iupimglib.rb +15 -0
- data/lib/plain/iupimlib.rb +18 -0
- data/lib/plain/iuplib.rb +354 -0
- data/lib/plain/scintilla-lib.rb +17 -0
- data/lib/wrapped/attribute-builders.rb +93 -0
- data/lib/wrapped/attribute-reference.rb +27 -0
- data/lib/wrapped/background-box.rb +37 -0
- data/lib/wrapped/button.rb +152 -0
- data/lib/wrapped/callback-setter.rb +78 -0
- data/lib/wrapped/canvas.rb +698 -0
- data/lib/wrapped/colorbar.rb +212 -0
- data/lib/wrapped/colordialog.rb +121 -0
- data/lib/wrapped/common-attributes.rb +34 -0
- data/lib/wrapped/constants.rb +504 -0
- data/lib/wrapped/dial.rb +129 -0
- data/lib/wrapped/dialog.rb +309 -0
- data/lib/wrapped/drag-drop-attributes.rb +98 -0
- data/lib/wrapped/dynamic-fill-methods.rb +22 -0
- data/lib/wrapped/expander.rb +128 -0
- data/lib/wrapped/filedialog.rb +168 -0
- data/lib/wrapped/fill.rb +29 -0
- data/lib/wrapped/fontdialog.rb +71 -0
- data/lib/wrapped/frame.rb +70 -0
- data/lib/wrapped/gridbox.rb +188 -0
- data/lib/wrapped/hbox.rb +90 -0
- data/lib/wrapped/image-attributes.rb +58 -0
- data/lib/wrapped/image.rb +178 -0
- data/lib/wrapped/iup-global.rb +46 -0
- data/lib/wrapped/label.rb +110 -0
- data/lib/wrapped/link.rb +54 -0
- data/lib/wrapped/list.rb +567 -0
- data/lib/wrapped/matrix.rb +575 -0
- data/lib/wrapped/menu.rb +91 -0
- data/lib/wrapped/menuitem.rb +150 -0
- data/lib/wrapped/messagedialog.rb +127 -0
- data/lib/wrapped/progressbar.rb +91 -0
- data/lib/wrapped/progressdialog.rb +85 -0
- data/lib/wrapped/radio.rb +74 -0
- data/lib/wrapped/scintilla.rb +1112 -0
- data/lib/wrapped/scrollbar-attributes.rb +178 -0
- data/lib/wrapped/scrollbox.rb +40 -0
- data/lib/wrapped/separator.rb +24 -0
- data/lib/wrapped/splitbox.rb +114 -0
- data/lib/wrapped/stretchbox.rb +70 -0
- data/lib/wrapped/submenu.rb +58 -0
- data/lib/wrapped/tabs.rb +223 -0
- data/lib/wrapped/text.rb +382 -0
- data/lib/wrapped/timer.rb +82 -0
- data/lib/wrapped/toggle.rb +150 -0
- data/lib/wrapped/tree.rb +612 -0
- data/lib/wrapped/val.rb +162 -0
- data/lib/wrapped/vbox.rb +93 -0
- data/lib/wrapped/widget.rb +282 -0
- data/lib/wrapped/zbox.rb +80 -0
- metadata +131 -0
data/lib/wrapped/text.rb
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# A text control is one of the more complex controls, because it can be
|
|
4
|
+
# displayed in a variety of ways:
|
|
5
|
+
#
|
|
6
|
+
# (1) a single line, for inputting a single line of text.
|
|
7
|
+
#
|
|
8
|
+
# Iup::Text.new do |t|
|
|
9
|
+
# t.expand = 'horizontal'
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# (2) a multi-line control, to act more like an editor.
|
|
13
|
+
#
|
|
14
|
+
# Iup::Text.new do |t|
|
|
15
|
+
# t.multiline = 'yes'
|
|
16
|
+
# t.expand = 'yes'
|
|
17
|
+
# t.size = '200x100'
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# (3) a spin box, for selecting one of several values: this
|
|
21
|
+
# example supports the range 10 to 20 and reports the current
|
|
22
|
+
# value as it changes.
|
|
23
|
+
#
|
|
24
|
+
# Iup::Text.new do |t|
|
|
25
|
+
# t.spin = 'yes'
|
|
26
|
+
# t.spinmax = 20
|
|
27
|
+
# t.spinmin = 10
|
|
28
|
+
# t.expand = 'horizontal'
|
|
29
|
+
# t.spin_cb = ->(v){
|
|
30
|
+
# puts "spin control is now #{v}"
|
|
31
|
+
# Iup::DEFAULT
|
|
32
|
+
# }
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
class Text < Iup::Widget
|
|
36
|
+
include DragDropAttributes
|
|
37
|
+
|
|
38
|
+
# Creates a new instance.
|
|
39
|
+
# If a block is given, the new instance is yielded to it.
|
|
40
|
+
def initialize
|
|
41
|
+
@handle = IupLib.IupText(nil)
|
|
42
|
+
|
|
43
|
+
# run any provided block on instance, to set up further attributes
|
|
44
|
+
yield self if block_given?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# -- attributes
|
|
48
|
+
|
|
49
|
+
##
|
|
50
|
+
# :attr: alignment
|
|
51
|
+
# Sets the alignment of text within control, options 'ALEFT' / 'ACENTER' / 'ARIGHT'.
|
|
52
|
+
define_attribute :alignment
|
|
53
|
+
|
|
54
|
+
##
|
|
55
|
+
# :attr_writer: append
|
|
56
|
+
# Appends given string to end of text.
|
|
57
|
+
define_writer :append
|
|
58
|
+
|
|
59
|
+
##
|
|
60
|
+
# :attr: autohide
|
|
61
|
+
# If set, scrollbars are only shown if necessary, values 'yes' / 'no'.
|
|
62
|
+
define_attribute :autohide
|
|
63
|
+
|
|
64
|
+
##
|
|
65
|
+
# :attr: border
|
|
66
|
+
# Sets border around text, values 'yes' / 'no'.
|
|
67
|
+
define_attribute :border
|
|
68
|
+
|
|
69
|
+
##
|
|
70
|
+
# :attr: canfocus
|
|
71
|
+
# If set, the control can gain focus, values 'yes' / 'no'.
|
|
72
|
+
define_attribute :canfocus
|
|
73
|
+
|
|
74
|
+
##
|
|
75
|
+
# :attr: caret
|
|
76
|
+
# Character position of insertion point:
|
|
77
|
+
# + 'col' in single-line mode, sets column number of caret;
|
|
78
|
+
# + 'lin,col' in multi-line mode, sets line and column number of caret.
|
|
79
|
+
define_attribute :caret
|
|
80
|
+
|
|
81
|
+
##
|
|
82
|
+
# :attr: caretpos
|
|
83
|
+
# Index of character of the insertion point: uses a 0-based index of entire text value.
|
|
84
|
+
define_attribute :caretpos
|
|
85
|
+
|
|
86
|
+
##
|
|
87
|
+
# :attr_writer: clipboard
|
|
88
|
+
# 'clear' / 'copy' / 'cut' / 'paste', access the clipboard with the current selection.
|
|
89
|
+
define_writer :clipboard
|
|
90
|
+
|
|
91
|
+
##
|
|
92
|
+
# :attr_reader: count
|
|
93
|
+
# Number of characters and line-breaks in text.
|
|
94
|
+
define_reader :count
|
|
95
|
+
|
|
96
|
+
##
|
|
97
|
+
# :attr: expand
|
|
98
|
+
# Allows control to fill available space in indicated direction.
|
|
99
|
+
# Values 'no' / 'horizontal' / 'vertical' / 'yes'.
|
|
100
|
+
define_attribute :expand
|
|
101
|
+
|
|
102
|
+
##
|
|
103
|
+
# :attr: formatting
|
|
104
|
+
# Set to 'yes' in multi-line mode, to allow control to use formatting of text.
|
|
105
|
+
define_attribute :formatting
|
|
106
|
+
|
|
107
|
+
##
|
|
108
|
+
# :attr_writer: insert
|
|
109
|
+
# Places a given string at current caret position, overwriting any current selection.
|
|
110
|
+
define_writer :insert
|
|
111
|
+
|
|
112
|
+
##
|
|
113
|
+
# :attr_reader: linecount
|
|
114
|
+
# Returns number of lines of text.
|
|
115
|
+
define_reader :linecount
|
|
116
|
+
|
|
117
|
+
##
|
|
118
|
+
# :attr_reader: linevalue
|
|
119
|
+
# Returns line of text where the caret is.
|
|
120
|
+
define_reader :linevalue
|
|
121
|
+
|
|
122
|
+
##
|
|
123
|
+
# :attr: mask
|
|
124
|
+
# Defines a mask to filter text input.
|
|
125
|
+
# See {pre-defined masks}[../Iup.html#Masks].
|
|
126
|
+
define_attribute :mask
|
|
127
|
+
|
|
128
|
+
##
|
|
129
|
+
# :attr: multiline
|
|
130
|
+
# Set multiline text input, values 'no' / 'yes'.
|
|
131
|
+
define_attribute :multiline
|
|
132
|
+
|
|
133
|
+
##
|
|
134
|
+
# :attr: nc
|
|
135
|
+
# Maximum number of characters allowed for keyboard input (0 allows an indefinite number).
|
|
136
|
+
define_attribute :nc
|
|
137
|
+
|
|
138
|
+
##
|
|
139
|
+
# :attr: overwrite
|
|
140
|
+
# 'off' / 'on', used when formatting=yes.
|
|
141
|
+
define_attribute :overwrite
|
|
142
|
+
|
|
143
|
+
##
|
|
144
|
+
# :attr: padding
|
|
145
|
+
# Margin in x and y directions, value as "mxn".
|
|
146
|
+
define_attribute :padding
|
|
147
|
+
|
|
148
|
+
##
|
|
149
|
+
# :attr: password
|
|
150
|
+
# 'yes' / 'no', if set, masks the input text as "*".
|
|
151
|
+
define_attribute :password
|
|
152
|
+
|
|
153
|
+
##
|
|
154
|
+
# :attr_reader: position
|
|
155
|
+
# Returns position in pixels within client window as "x,y".
|
|
156
|
+
define_reader :position
|
|
157
|
+
|
|
158
|
+
##
|
|
159
|
+
# :attr: rastersize
|
|
160
|
+
# Size in pixels within client window, value as "widthxheight".
|
|
161
|
+
define_attribute :rastersize
|
|
162
|
+
|
|
163
|
+
##
|
|
164
|
+
# :attr: readonly
|
|
165
|
+
# User cannot change the contents, values 'yes' / 'no'.
|
|
166
|
+
define_attribute :readonly
|
|
167
|
+
|
|
168
|
+
##
|
|
169
|
+
# :attr_reader: screenposition
|
|
170
|
+
# Returns position in pixels on screen as "x,y".
|
|
171
|
+
define_reader :screenposition
|
|
172
|
+
|
|
173
|
+
##
|
|
174
|
+
# :attr: scrollbar
|
|
175
|
+
# In multi-line mode, selects 'no' / 'horizontal' / 'vertical' / 'yes' (for both) scrollbars.
|
|
176
|
+
define_attribute :scrollbar
|
|
177
|
+
|
|
178
|
+
##
|
|
179
|
+
# :attr_writer: scrollto
|
|
180
|
+
# * 'col' Scrolls to make given column number visible, in single-line mode.
|
|
181
|
+
# * 'lin/col' Scrolls to make line and column number visible, in multi-line mode.
|
|
182
|
+
define_writer :scrollto
|
|
183
|
+
|
|
184
|
+
##
|
|
185
|
+
# :attr_writer: scrolltopos
|
|
186
|
+
# Scrolls to make character 'number' visible.
|
|
187
|
+
define_writer :scrolltopos
|
|
188
|
+
|
|
189
|
+
##
|
|
190
|
+
# :attr: selectedtext
|
|
191
|
+
# Reads or overwrites the current selection.
|
|
192
|
+
# Does nothing if no text is selected.
|
|
193
|
+
define_attribute :selectedtext
|
|
194
|
+
|
|
195
|
+
##
|
|
196
|
+
# :attr: selection
|
|
197
|
+
# Selects text as 'col1:col2' (single-line) / 'lin1,col1:lin2,col2' (multi-line) / 'all' / 'none'.
|
|
198
|
+
define_attribute :selection
|
|
199
|
+
|
|
200
|
+
##
|
|
201
|
+
# :attr: selectionpos
|
|
202
|
+
# Selects text between character positions: 'pos1:pos2' / 'all' / 'none'.
|
|
203
|
+
define_attribute :selectionpos
|
|
204
|
+
|
|
205
|
+
##
|
|
206
|
+
# :attr: spin
|
|
207
|
+
# 'no' / 'yes', attaches a spin control to the text box.
|
|
208
|
+
define_attribute :spin
|
|
209
|
+
|
|
210
|
+
##
|
|
211
|
+
# :attr: spinalign
|
|
212
|
+
# 'right' / 'left', with respect to the text (GTK always 'right').
|
|
213
|
+
define_attribute :spinalign
|
|
214
|
+
|
|
215
|
+
##
|
|
216
|
+
# :attr: spinauto
|
|
217
|
+
# 'yes' / 'no', updates value of control when spin buttons used.
|
|
218
|
+
# When 'no', "spin_cb" must adjust the value.
|
|
219
|
+
define_attribute :spinauto
|
|
220
|
+
|
|
221
|
+
##
|
|
222
|
+
# :attr: spininc
|
|
223
|
+
# Increment value, defaults to 1.
|
|
224
|
+
define_attribute :spininc
|
|
225
|
+
|
|
226
|
+
##
|
|
227
|
+
# :attr: spinmax
|
|
228
|
+
# Maximum spin value, defaults to 100.
|
|
229
|
+
define_attribute :spinmax
|
|
230
|
+
|
|
231
|
+
##
|
|
232
|
+
# :attr: spinmin
|
|
233
|
+
# Minimum spin value, defaults to 1.
|
|
234
|
+
define_attribute :spinmin
|
|
235
|
+
|
|
236
|
+
##
|
|
237
|
+
# :attr: spinvalue
|
|
238
|
+
# Current value of spin, defaults to 1.
|
|
239
|
+
define_attribute :spinvalue
|
|
240
|
+
|
|
241
|
+
##
|
|
242
|
+
# :attr: spinwrap
|
|
243
|
+
# 'no' / 'yes', automatically wraps spin at ends of range, when set.
|
|
244
|
+
define_attribute :spinwrap
|
|
245
|
+
|
|
246
|
+
##
|
|
247
|
+
# :attr: tabsize
|
|
248
|
+
# In multi-line mode, controls number of spaces used for a tab, defaults to 8.
|
|
249
|
+
define_attribute :tabsize
|
|
250
|
+
|
|
251
|
+
##
|
|
252
|
+
# :attr: tip
|
|
253
|
+
# Tooltip string.
|
|
254
|
+
define_attribute :tip
|
|
255
|
+
|
|
256
|
+
##
|
|
257
|
+
# :attr: value
|
|
258
|
+
# Retrieves or sets the text.
|
|
259
|
+
define_attribute :value
|
|
260
|
+
|
|
261
|
+
##
|
|
262
|
+
# :attr_writer: valuemasked
|
|
263
|
+
# Retrieves or sets the text, applying +MASK+ when setting.
|
|
264
|
+
define_writer :valuemasked
|
|
265
|
+
|
|
266
|
+
##
|
|
267
|
+
# :attr: visiblecolumns
|
|
268
|
+
# The minimum number of visible columns, defaults to 5.
|
|
269
|
+
define_attribute :visiblecolumns
|
|
270
|
+
|
|
271
|
+
##
|
|
272
|
+
# :attr: visiblelines
|
|
273
|
+
# The minimum number of visible lines, when dropdown=no.
|
|
274
|
+
define_attribute :visiblelines
|
|
275
|
+
|
|
276
|
+
##
|
|
277
|
+
# :attr: wordwrap
|
|
278
|
+
# Forces a word wrap of lines longer than width of control.
|
|
279
|
+
# Values 'no' / 'yes', when multiline=yes.
|
|
280
|
+
define_attribute :wordwrap
|
|
281
|
+
|
|
282
|
+
# :section: Callbacks
|
|
283
|
+
|
|
284
|
+
##
|
|
285
|
+
# :attr_writer: action
|
|
286
|
+
#
|
|
287
|
+
# Callback called when the text is edited, but before its value is actually changed.
|
|
288
|
+
# Callback must respond to +call+ and takes a 2-argument callback: (character, new_value)
|
|
289
|
+
# * +character+ - the character typed
|
|
290
|
+
# * +new_value+ - the new text value
|
|
291
|
+
# Return Iup::IGNORE to ignore the new_value and allow the character to be
|
|
292
|
+
# added to the text.
|
|
293
|
+
|
|
294
|
+
# --
|
|
295
|
+
def action= callback
|
|
296
|
+
unless callback.arity == 2
|
|
297
|
+
raise ArgumentError, 'action callback must take 2 argument: (character, new-text)'
|
|
298
|
+
end
|
|
299
|
+
cb = Proc.new do |ih, c, text|
|
|
300
|
+
callback.call c, text
|
|
301
|
+
end
|
|
302
|
+
define_callback cb, 'ACTION', :is_i
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
include ButtonCallback
|
|
306
|
+
|
|
307
|
+
##
|
|
308
|
+
# :attr_writer: caret_cb
|
|
309
|
+
#
|
|
310
|
+
# Callback called when the caret/cursor position is changed.
|
|
311
|
+
# Callback must respond to +call+ and takes a callback which accepts 3
|
|
312
|
+
# arguments (line, column, position) of caret
|
|
313
|
+
# * +line+ - line number (1-indexed)
|
|
314
|
+
# * +column+ - column number (1-indexed)
|
|
315
|
+
# * +position+ - character position (0-indexed)
|
|
316
|
+
|
|
317
|
+
# --
|
|
318
|
+
def caret_cb= callback
|
|
319
|
+
unless callback.arity == 3
|
|
320
|
+
raise ArgumentError, 'caret_cb callback must take 3 arguments: (line, column, position)'
|
|
321
|
+
end
|
|
322
|
+
cb = Proc.new do |ih, lin, col, pos|
|
|
323
|
+
callback.call lin, col, pos
|
|
324
|
+
end
|
|
325
|
+
define_callback cb, 'CARET_CB', :iii_i
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
##
|
|
329
|
+
# :attr_writer: motion_cb
|
|
330
|
+
# Callback called when the mouse is moved.
|
|
331
|
+
# Callback must respond to +call+ and takes 3 arguments: (x, y, state)
|
|
332
|
+
# * +x+ - x position of mouse
|
|
333
|
+
# * +y+ - y position of mouse
|
|
334
|
+
# * +state+ - status of mouse buttons and certain keyboard keys at the moment the event was generated.
|
|
335
|
+
|
|
336
|
+
#--
|
|
337
|
+
def motion_cb= callback
|
|
338
|
+
unless callback.arity == 3
|
|
339
|
+
raise ArgumentError, 'motion_cb callback must take 3 arguments: (x, y, state)'
|
|
340
|
+
end
|
|
341
|
+
cb = Proc.new do |ih, x, y, state|
|
|
342
|
+
callback.call x, y, state
|
|
343
|
+
end
|
|
344
|
+
define_callback cb, 'MOTION_CB', :iis_i
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
##
|
|
348
|
+
# :attr_writer: spin_cb
|
|
349
|
+
#
|
|
350
|
+
# Callback called when a spin button is pressed. Valid only when SPIN=YES.
|
|
351
|
+
# Callback must respond to +call+ and take a 1-argument callback: (value)
|
|
352
|
+
# * +value+ - the value of spin control.
|
|
353
|
+
|
|
354
|
+
# --
|
|
355
|
+
def spin_cb= callback
|
|
356
|
+
unless callback.arity == 1
|
|
357
|
+
raise ArgumentError, 'spin_cb callback must take 1 argument, the value'
|
|
358
|
+
end
|
|
359
|
+
cb = Proc.new do |ih, val|
|
|
360
|
+
callback.call val
|
|
361
|
+
end
|
|
362
|
+
define_callback cb, 'SPIN_CB', :i_i
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
##
|
|
366
|
+
# :attr_writer: valuechanged_cb
|
|
367
|
+
#
|
|
368
|
+
# Sets callback called after the value was interactively changed by the user.
|
|
369
|
+
# Callback must respond to +call+ and take no arguments.
|
|
370
|
+
|
|
371
|
+
# --
|
|
372
|
+
def valuechanged_cb= callback
|
|
373
|
+
unless callback.arity.zero?
|
|
374
|
+
raise ArgumentError, 'valuechanged_cb callback must take 0 arguments'
|
|
375
|
+
end
|
|
376
|
+
cb = Proc.new do |ih|
|
|
377
|
+
callback.call
|
|
378
|
+
end
|
|
379
|
+
define_callback cb, 'VALUECHANGED_CB', :plain
|
|
380
|
+
end
|
|
381
|
+
end
|
|
382
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# The timer is used to trigger a callback function at
|
|
4
|
+
# regular intervals without interrupting the application's
|
|
5
|
+
# main event loop. It can be used to safely update the
|
|
6
|
+
# user interface.
|
|
7
|
+
#
|
|
8
|
+
# For example, the following creates a timer which counts down
|
|
9
|
+
# from 10, updating a label's title. When the count reaches 0,
|
|
10
|
+
# the application will close.
|
|
11
|
+
#
|
|
12
|
+
# count = 10
|
|
13
|
+
# timer = Iup::Timer.new do |t|
|
|
14
|
+
# t.time = 1000
|
|
15
|
+
#
|
|
16
|
+
# t.action_cb = ->{
|
|
17
|
+
# if count.zero?
|
|
18
|
+
# Iup::CLOSE
|
|
19
|
+
# else
|
|
20
|
+
# count -= 1
|
|
21
|
+
# label.title = "Time remaining: #{count}"
|
|
22
|
+
# Iup::DEFAULT
|
|
23
|
+
# end
|
|
24
|
+
# }
|
|
25
|
+
# end
|
|
26
|
+
class Timer
|
|
27
|
+
extend AttributeBuilders
|
|
28
|
+
include CallbackSetter
|
|
29
|
+
|
|
30
|
+
# Unique reference to widget.
|
|
31
|
+
attr_reader :handle
|
|
32
|
+
|
|
33
|
+
def initialize &block
|
|
34
|
+
@handle = IupLib.IupTimer
|
|
35
|
+
|
|
36
|
+
# run any provided block on instance, to set up further attributes
|
|
37
|
+
yield self if block_given?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# must be called when Timer is finished with
|
|
41
|
+
def destroy
|
|
42
|
+
IupLib.IupDestroy @handle
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# -- attributes
|
|
46
|
+
|
|
47
|
+
##
|
|
48
|
+
# :attr: time
|
|
49
|
+
# The time interval before the action_cb is called, in milliseconds.
|
|
50
|
+
define_attribute :time
|
|
51
|
+
|
|
52
|
+
##
|
|
53
|
+
# :attr: run
|
|
54
|
+
# Values 'yes' / 'no' to start or stop the timer.
|
|
55
|
+
define_attribute :run
|
|
56
|
+
|
|
57
|
+
##
|
|
58
|
+
# :attr_reader: wid
|
|
59
|
+
# The native serial number of the timer: -1 if not running.
|
|
60
|
+
define_reader :wid
|
|
61
|
+
|
|
62
|
+
# :section: Callbacks
|
|
63
|
+
|
|
64
|
+
##
|
|
65
|
+
# :attr_writer: action_cb
|
|
66
|
+
# Callback called when the time is up.
|
|
67
|
+
# Return Iup::CLOSE to end application.
|
|
68
|
+
# Callback must respond to +call+ and take no arguments.
|
|
69
|
+
|
|
70
|
+
# --
|
|
71
|
+
def action_cb= callback
|
|
72
|
+
unless callback.arity.zero?
|
|
73
|
+
raise ArgumentError, 'action_cb must take 0 arguments'
|
|
74
|
+
end
|
|
75
|
+
cb = Proc.new do |ih|
|
|
76
|
+
callback.call
|
|
77
|
+
end
|
|
78
|
+
define_callback(cb, 'ACTION_CB', :plain)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# A control that can have two or three states, and displays either some
|
|
4
|
+
# text or an image.
|
|
5
|
+
#
|
|
6
|
+
# === Example
|
|
7
|
+
#
|
|
8
|
+
# (1) with text label
|
|
9
|
+
#
|
|
10
|
+
# Iup::Toggle.new('click to change')
|
|
11
|
+
#
|
|
12
|
+
# (2) with a standard image, reporting changes to value
|
|
13
|
+
#
|
|
14
|
+
# Iup::Toggle.new do |t|
|
|
15
|
+
# t.image = "IUP_MessageHelp"
|
|
16
|
+
# t.valuechanged_cb = ->{ puts "button 1 state #{toggle1.value}" }
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
class Toggle < Iup::Widget
|
|
20
|
+
include ImageAttributes
|
|
21
|
+
|
|
22
|
+
# Creates a new instance.
|
|
23
|
+
# If a block is given, the new instance is yielded to it.
|
|
24
|
+
# * +title+ - optional text to display
|
|
25
|
+
def initialize(title=nil)
|
|
26
|
+
@handle = IupLib.IupToggle(title, '')
|
|
27
|
+
|
|
28
|
+
# run any provided block on instance, to set up further attributes
|
|
29
|
+
yield self if block_given?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# -- attributes
|
|
33
|
+
|
|
34
|
+
##
|
|
35
|
+
# :attr: alignment
|
|
36
|
+
# Sets the horizontal and vertical alignment.
|
|
37
|
+
# The value is a string "horizontal:vertical", with
|
|
38
|
+
# horizontal options ALEFT, ACENTER, ARIGHT and
|
|
39
|
+
# vertical options ATOP, ACENTER, ABOTTOM.
|
|
40
|
+
# Partial values also accepted, e.g. "ARIGHT", ":ATOP".
|
|
41
|
+
define_attribute :alignment
|
|
42
|
+
|
|
43
|
+
##
|
|
44
|
+
# :attr: canfocus
|
|
45
|
+
# Enables the control to gain focus. Values 'yes' / 'no'.
|
|
46
|
+
define_attribute :canfocus
|
|
47
|
+
|
|
48
|
+
##
|
|
49
|
+
# :attr: expand
|
|
50
|
+
# Allows control to fill available space in indicated direction.
|
|
51
|
+
# Values 'no' / 'horizontal' / 'vertical' / 'yes'.
|
|
52
|
+
define_attribute :expand
|
|
53
|
+
|
|
54
|
+
##
|
|
55
|
+
# :attr: flat
|
|
56
|
+
# If set, hides the control's border until mouse enters the button area.
|
|
57
|
+
# Values 'yes' / 'no'.
|
|
58
|
+
define_attribute :flat
|
|
59
|
+
|
|
60
|
+
##
|
|
61
|
+
# :attr: padding
|
|
62
|
+
# Margin in x and y directions, value as "mxn".
|
|
63
|
+
define_attribute :padding
|
|
64
|
+
|
|
65
|
+
##
|
|
66
|
+
# :attr_reader: position
|
|
67
|
+
# Returns position in pixels within client window as "x,y".
|
|
68
|
+
define_reader :position
|
|
69
|
+
|
|
70
|
+
##
|
|
71
|
+
# :attr_reader: radio
|
|
72
|
+
# Returns 'yes' / 'no', if toggle is within a radio control.
|
|
73
|
+
define_reader :radio
|
|
74
|
+
|
|
75
|
+
##
|
|
76
|
+
# :attr: rastersize
|
|
77
|
+
# Size of the control, in pixels, value as "widthxheight".
|
|
78
|
+
define_attribute :rastersize
|
|
79
|
+
|
|
80
|
+
##
|
|
81
|
+
# :attr_reader: screenposition
|
|
82
|
+
# returns position in pixels on screen as "x,y".
|
|
83
|
+
define_reader :screenposition
|
|
84
|
+
|
|
85
|
+
##
|
|
86
|
+
# :attr: three_state
|
|
87
|
+
# 'no' / 'yes', 3-state only for text labels, and not in a radio control.
|
|
88
|
+
|
|
89
|
+
# --
|
|
90
|
+
def three_state
|
|
91
|
+
IupLib.IupGetAttribute(@handle, '3STATE').first
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def three_state= val # :nodoc:
|
|
95
|
+
IupLib.IupGetAttribute(@handle, '3STATE', val).first
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
##
|
|
99
|
+
# :attr: tip
|
|
100
|
+
# Tooltip string.
|
|
101
|
+
define_attribute :tip
|
|
102
|
+
|
|
103
|
+
##
|
|
104
|
+
# :attr: title
|
|
105
|
+
# text to display.
|
|
106
|
+
define_attribute :title
|
|
107
|
+
|
|
108
|
+
##
|
|
109
|
+
# :attr: value
|
|
110
|
+
# Toggle's state, value one of
|
|
111
|
+
# 'on' / 'off' / 'toggle' / 'notdef' (for 3-state toggles).
|
|
112
|
+
define_attribute :value
|
|
113
|
+
|
|
114
|
+
# :section: Callbacks
|
|
115
|
+
|
|
116
|
+
##
|
|
117
|
+
# :attr_writer: action
|
|
118
|
+
# Callback called when the toggle's state (on/off) was changed.
|
|
119
|
+
# Callback must respond to +call+ and takes a 1-argument callback: (state_change)
|
|
120
|
+
# * +state_change+ - state changed to 'on' or 'off' gives value 1 or 0
|
|
121
|
+
|
|
122
|
+
# --
|
|
123
|
+
def action= callback
|
|
124
|
+
unless callback.arity == 1
|
|
125
|
+
raise ArgumentError, 'action callback must take 1 argument, the state_change'
|
|
126
|
+
end
|
|
127
|
+
cb = Proc.new do |ih, state_change|
|
|
128
|
+
callback.call state_change.to_i
|
|
129
|
+
end
|
|
130
|
+
define_callback cb, 'ACTION', :i_i
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
##
|
|
134
|
+
# :attr_writer: valuechanged_cb
|
|
135
|
+
# Callback called after the value was interactively changed by the user.
|
|
136
|
+
# Callback must respond to +call+ and take no arguments.
|
|
137
|
+
|
|
138
|
+
# --
|
|
139
|
+
def valuechanged_cb= callback
|
|
140
|
+
unless callback.arity.zero?
|
|
141
|
+
raise ArgumentError, 'valuechanged_cb callback must take 0 arguments'
|
|
142
|
+
end
|
|
143
|
+
cb = Proc.new do |ih|
|
|
144
|
+
callback.call
|
|
145
|
+
end
|
|
146
|
+
define_callback cb, 'VALUECHANGED_CB', :plain
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|