Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored GUI code with Glimmer DSL for LibUI #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.gem
Gemfile.lock
Gemfile.lock
.ruby-version
.ruby-gemset
# Gladiator (Glimmer Editor)
.gladiator
2 changes: 1 addition & 1 deletion ci_ui/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source 'https://rubygems.org'

gem 'ci_uy'
gem 'libui'
gem 'glimmer-dsl-libui'
18 changes: 15 additions & 3 deletions ci_ui/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
102 changes: 43 additions & 59 deletions ci_ui/ci_ui.rb
Original file line number Diff line number Diff line change
@@ -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