1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- class EXAMPLE3
- -- A small app to convert inches to centimeters and viceversa.
- inherit
- IUP_INTERFACE
- create {ANY}
- make
- feature {ANY}
-
- t1, t2: IUP_TEXT
- rd: IUP_RADIO
-
- make
- local
- gui: IUP
- i: STRING
- op1, op2: IUP_TOGGLE
- l: IUP_LABEL
- b: IUP_BUTTON
- h1, h2: IUP_HBOX
- v: IUP_VBOX
- w: IUP_DIALOG
- a, b2, c: ARRAY[IUP_WIDGET]
- do
- gui := iup_open
- -- Create two toggle buttons and associate names with these.
- create op1.toggle("in to cm")
- op1.set_widget_name("in/cm")
- create op2.toggle("cm to in")
- op2.set_widget_name("cm/in")
- -- Put toggle buttons inside a radio container.
- a := {ARRAY[IUP_WIDGET]} << op1, op2 >>
- create h1.hbox(a)
- create rd.radio(h1)
- -- Create two text field, one for the user entry and other for the
- -- result.
- create t1.text
- t1.set_mask("IUP_MASK_FLOAT") -- Only allow float numbers.
- create t2.text
- t2.set_readonly(True)
- t2.set_can_focus(False)
- -- A label
- create l.label("=")
- -- Put these inside an horizontal box.
- b2 := {ARRAY[IUP_WIDGET]} << t1, l, t2 >>
- create h2.hbox(b2)
- h2.set_gap(10)
- -- Create a button and connect the callback.
- create b.button("Convert")
- b.set_cb_action(agent convert_units)
- -- Fill available horizontal space
- b.expand_horizontal_free
- -- Put all the widgets inside a vertical box.
- c := {ARRAY[IUP_WIDGET]} << rd, h2, b >>
- create v.vbox(c)
- v.set_alignment("ACENTER")
- v.set_gap(10)
- v.set_margin(10, 10)
- -- Create the window.
- create w.dialog(v)
- w.set_title("Convert units")
- i := w.show
- gui.main_loop
- gui.close
- end
- convert_units (widget: IUP_BUTTON): STRING
- local
- str, tgl: STRING
- rst: REAL_64
- do
- str := t1.get_value
- tgl := rd.get_value
- if tgl.is_equal("in/cm") then
- rst := 2.54*str.to_real
- else
- rst := 0.393701*str.to_real
- end
-
- t2.set_value(rst.out)
- Result := "IUP_DEFAULT"
- end
- end -- class EXAMPLE3
|