diff --git a/.gitignore b/.gitignore index 369ba8e..57fe491 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ *.gem -Gemfile.lock \ No newline at end of file +Gemfile.lock +.ruby-version +.ruby-gemset +# Gladiator (Glimmer Editor) +.gladiator diff --git a/ci_ui/Gemfile b/ci_ui/Gemfile index 663bfe0..19b3b86 100644 --- a/ci_ui/Gemfile +++ b/ci_ui/Gemfile @@ -3,4 +3,4 @@ source 'https://rubygems.org' gem 'ci_uy' -gem 'libui' +gem 'glimmer-dsl-libui' diff --git a/ci_ui/Gemfile.lock b/ci_ui/Gemfile.lock index 8dedff2..1684732 100644 --- a/ci_ui/Gemfile.lock +++ b/ci_ui/Gemfile.lock @@ -1,15 +1,27 @@ GEM remote: https://rubygems.org/ specs: + array_include_methods (1.4.0) ci_uy (1.0.1) - libui (0.0.6) + color (1.8) + facets (3.1.0) + glimmer (2.3.0) + array_include_methods (~> 1.4.0) + facets (>= 3.1.0, < 4.0.0) + glimmer-dsl-libui (0.2.10) + color (~> 1.8) + glimmer (~> 2.3.0) + libui (~> 0.0.11) + os (>= 1.0.0, < 2.0.0) + libui (0.0.11) + os (1.1.1) PLATFORMS ruby DEPENDENCIES ci_uy - libui + glimmer-dsl-libui BUNDLED WITH - 2.1.4 + 2.2.28 diff --git a/ci_ui/ci_ui.rb b/ci_ui/ci_ui.rb index 81ac84a..f23c628 100644 --- a/ci_ui/ci_ui.rb +++ b/ci_ui/ci_ui.rb @@ -1,63 +1,47 @@ # frozen_string_literal: true -require 'libui' +require 'glimmer-dsl-libui' require 'ci_uy' -UI = LibUI -UI.init - -MAIN_WINDOW = UI.new_window('Validador de cédulas de identidad 🇺🇾', 400, 90, 1) - -# Elements in first tab -vbox = UI.new_vertical_box -UI.box_set_padded(vbox, 3) -UI.window_set_child(MAIN_WINDOW, vbox) - -lbl_result = UI.new_label('') - -# Callback for validating the number when text is entered -text_changed_callback = proc do |ptr| - input = UI.entry_text(ptr) - valid = CiUY.validate(input.to_s) - UI.label_set_text(lbl_result, valid ? '✅ - Número Válido' : '❌ - Número no válido') -end - -txt_validate = UI.new_entry -UI.entry_on_changed(txt_validate, text_changed_callback, nil) - -hbox1 = UI.new_vertical_box -UI.box_append(hbox1, UI.new_label('Ingrese un número de cédula'), 0) -UI.box_append(hbox1, txt_validate, 1) -UI.box_append(hbox1, lbl_result, 1) - -# Elements in second tab -hbox2 = UI.new_vertical_box -btn_random = UI.new_button('Obtener número de cédula al azar') -txt_random_number = UI.new_entry -button_clicked_callback = proc do - number = CiUY.random.to_s - UI.entry_set_text(txt_random_number, number) - 0 -end -UI.button_on_clicked(btn_random, button_clicked_callback, nil) -UI.box_append(hbox2, btn_random, 0) -UI.box_append(hbox2, txt_random_number, 0) - -# Create tab menu and append elements -tab = UI.new_tab -UI.tab_append(tab, 'Validador', hbox1) -UI.tab_append(tab, 'Cédula al azar', hbox2) -UI.box_append(vbox, tab, 1) - -# Show main window -UI.control_show(MAIN_WINDOW) - -# Cleanup when closing -UI.window_on_closing(MAIN_WINDOW) do - UI.control_destroy(MAIN_WINDOW) - UI.quit - 0 -end - -UI.main -UI.quit +include Glimmer + +window('Validador de cédulas de identidad 🇺🇾', 400, 90) { + vertical_box { + tab { + tab_item('Validador') { + vertical_box { + label('Ingrese un número de cédula') { + stretchy false + } + + @text_validate = entry { + on_changed do + input = @text_validate.text + valid = CiUY.validate(input.to_s) + @lbl_result.text = valid ? '✅ - Número Válido' : '❌ - Número no válido' + end + } + + @lbl_result = label + } + } + + tab_item('Cédula al azar') { + vertical_box { + button('Obtener número de cédula al azar') { + stretchy false + + on_clicked do + number = CiUY.random.to_s + @txt_random_number.text = number + end + } + + @txt_random_number = entry { + stretchy false + } + } + } + } + } +}.show