### Midi Player Setup Instructions Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Instructions for setting up and running the Midi Player example, including installing TiMidity and using different Ruby commands. ```shell ruby -r './lib/glimmer-dsl-libui' examples/midi_player.rb ``` ```shell ruby -r glimmer-dsl-libui -e "require 'examples/midi_player'" ``` -------------------------------- ### Run 'hello_world' Installed Application Gem Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Example of running the 'hello_world' application after it has been installed as a gem. ```bash hello_world ``` -------------------------------- ### Run GPT2 Notepad Example (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the GPT2 notepad example when the glimmer-dsl-libui gem is installed. Requires additional gems. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/gpt2_notepad'" ``` -------------------------------- ### Run Form Table Example (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the form table example when the glimmer-dsl-libui gem is installed. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/form_table'" ``` -------------------------------- ### Complete Glimmer DSL LibUI Setup Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/configuration.md A full example demonstrating the setup of Glimmer DSL LibUI, including requiring the library, optional configuration for infinite loop processing, and a basic application window. ```ruby require 'glimmer-dsl-libui' # Optionally configure Glimmer Glimmer::Config.loop_max_count = -1 # Infinite loop include Glimmer # Application code window('My App', 300, 200) { label('Hello') }.show ``` -------------------------------- ### Run Dynamic Form Example (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the dynamic form example when the glimmer-dsl-libui gem is installed. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/dynamic_form'" ``` -------------------------------- ### Run Basic Table Selection Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-BASIC-EXAMPLES.md Provides commands to run the basic table selection example. Use the first command if you cloned the project, and the second if you installed the Glimmer DSL for LibUI gem. ```bash ruby -r './lib/glimmer-dsl-libui' examples/basic_table_selection.rb ``` ```bash ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_selection'" ``` -------------------------------- ### Run Editable Table Example (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the editable table example when the glimmer-dsl-libui gem is installed. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/editable_table'" ``` -------------------------------- ### Run Class-Based Custom Controls Example (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the class-based custom controls example after installing the glimmer-dsl-libui gem. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/class_based_custom_controls'" ``` -------------------------------- ### Run Editable Column Table Example (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the editable column table example when the glimmer-dsl-libui gem is installed. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/editable_column_table'" ``` -------------------------------- ### Run Class-Based Custom Control Slots Example (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the class-based custom control slots example directly after installing the gem. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/class_based_custom_control_slots'" ``` -------------------------------- ### Run Paginated Refined Table Example (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the paginated refined table example when the glimmer-dsl-libui gem is installed. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/paginated_refined_table'" ``` -------------------------------- ### Run GPT2 Notepad Example (Project) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the GPT2 notepad example when the project is cloned. Requires additional gems. ```bash ruby -r './lib/glimmer-dsl-libui' examples/gpt2_notepad.rb ``` -------------------------------- ### Run Form Table Example (Project) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the form table example when the project is cloned. ```bash ruby -r './lib/glimmer-dsl-libui' examples/form_table.rb ``` -------------------------------- ### Run Basic Area Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-BASIC-EXAMPLES.md Provides commands to run the basic area example. Use the first command if you cloned the project, and the second if you installed the Glimmer DSL for LibUI gem. ```bash ruby -r './lib/glimmer-dsl-libui' examples/basic_area.rb ``` ```bash ruby -r glimmer-dsl-libui -e "require 'examples/basic_area'" ``` -------------------------------- ### Run Basic Table Color Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-BASIC-EXAMPLES.md Provides commands to run the basic table color example. Use the first command if you cloned the project, and the second if you installed the Glimmer DSL for LibUI gem. ```bash ruby -r './lib/glimmer-dsl-libui' examples/basic_table_color.rb ``` ```bash ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_color'" ``` -------------------------------- ### Run Lazy Table Example (Ruby Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the lazy table example after installing the glimmer-dsl-libui gem. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/lazy_table'" ``` -------------------------------- ### Run Class-Based Custom Control Slots Example (Glimmer CLI) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the class-based custom control slots example using the glimmer CLI after installing the gem. ```bash glimmer examples ``` -------------------------------- ### Run Dynamic Form Example (Project) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the dynamic form example when the project is cloned. ```bash ruby -r './lib/glimmer-dsl-libui' examples/dynamic_form.rb ``` -------------------------------- ### Run Editable Table Example (Project) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the editable table example when the project is cloned. ```bash ruby -r './lib/glimmer-dsl-libui' examples/editable_table.rb ``` -------------------------------- ### Run Class-Based Custom Controls Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the class-based custom controls example from the project root. ```bash ruby -r "./lib/glimmer-dsl-libui" examples/class_based_custom_controls.rb ``` -------------------------------- ### Run a Specific Glimmer Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Launch a specific Glimmer example file, such as 'basic_window.rb', from the command line. This is helpful for testing and demonstrating Glimmer's capabilities. ```bash glimmer examples/basic_window.rb ``` -------------------------------- ### Run Meta-Example with Ruby Gem Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Command to run the meta-example after installing the glimmer-dsl-libui Ruby gem. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/meta_example'" ``` -------------------------------- ### Run Class-Based Custom Control Slots Example (Project Root) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the class-based custom control slots example from the project root. ```bash bin/glimmer examples/class_based_custom_control_slots.rb ``` -------------------------------- ### Run Editable Column Table Example (Project) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the editable column table example when the project is cloned. ```bash ruby -r './lib/glimmer-dsl-libui' examples/editable_column_table.rb ``` -------------------------------- ### Run 'hello_world' Application Directly Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Example of running the 'hello_world' scaffolded application using its specific executable script. ```bash bin/hello_world ``` -------------------------------- ### Run Paginated Refined Table Example (Project) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the paginated refined table example when the project is cloned. ```bash ruby -r './lib/glimmer-dsl-libui' examples/paginated_refined_table.rb ``` -------------------------------- ### Integrate with Database and Display Data in a Table Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/INDEX.md This example demonstrates how to connect to a SQLite database using Sequel, fetch user data, and display it in a table within a Glimmer DSL LibUI window. Ensure you have the 'sequel' gem installed. ```ruby require 'glimmer-dsl-libui' require 'sequel' # Database class UserList include Glimmer def launch @db = Sequel.connect('sqlite://users.db') window('Users', 600, 400) { table { text_column('Name') text_column('Email') cell_rows @db[:users].all } }.show end end UserList.new.launch ``` -------------------------------- ### Run Tetris with Glimmer DSL (Gem) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the Tetris example after installing the Glimmer DSL for LibUI gem. It requires Ruby and the gem to be installed. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/tetris'" ``` -------------------------------- ### Launch Example with Code Editing Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md This snippet demonstrates launching an example with interactive code editing capabilities. It includes functionality to select examples, manage versions, save changes, and run the application. It also includes error handling for file operations. ```ruby require 'fileutils' class MetaExample include Glimmer attr_accessor :code_text def initialize @examples = [ 'Hello World', 'Button', 'Checkbox', 'Color Button', 'Date Picker', 'Dropdown List', 'Entry', 'Grid', 'Image', 'Label', 'Menu', 'Radio Button', 'Spinner', 'Tabbed Panel', 'Table', 'Text Area', 'Window' ] @advanced_examples = [ 'Advanced Grid', 'Advanced Table' ] @examples_with_versions = @examples.map { |e| [e] }.flatten @advanced_examples_with_versions = @advanced_examples.map { |e| [e, "#{e}v2", "#{e}v3" ] }.flatten @selected_example_index = 0 @advanced_example_radio_buttons = radio_buttons @advanced_example_radio_buttons.value = @advanced_examples_with_versions[0] @version_spinbox = spinbox @code_entry = multiline_entry end def file_path_for(example) File.join(__dir__, 'examples', "#{example.gsub(' ', '_').downcase}.rb") end def version_count_for(example) case example when 'Hello World' 2 when 'Entry' 2 when 'Advanced Grid' 3 when 'Advanced Table' 3 else 1 end end def selected_example if @advanced_example_radio_buttons.selected @advanced_examples_with_versions[@advanced_example_radio_buttons.selected] else @examples_with_versions[@selected_example_index] end end def launch window('Glimmer DSL Libui Examples', 800, 600) { scroll_pane { vertical_box { @example_radio_buttons = radio_buttons { @examples.each_with_index do |example, index| radio_button(example) { on_selected do @selected_example_index = index @advanced_example_radio_buttons.value = nil example = selected_example self.code_text = File.read(file_path_for(example)) @version_spinbox.value = 1 end } end } @advanced_example_radio_buttons = radio_buttons { @advanced_examples.each do |example| radio_button(example) { on_selected do @selected_example_index = nil example = selected_example self.code_text = File.read(file_path_for(example)) @version_spinbox.value = 1 end } end } on_selected do @selected_example_index = examples_with_versions.index(advanced_examples_with_versions[@advanced_example_radio_buttons.selected]) example = selected_example self.code_text = File.read(file_path_for(example)) @version_spinbox.value = 1 end } label # filler label # filler } } horizontal_box { label('Version') { stretchy false } @version_spinbox = spinbox(1, 100) { value 1 on_changed do example = selected_example if @version_spinbox.value > version_count_for(example) @version_spinbox.value -= 1 else version_number = @version_spinbox.value == 1 ? '' : @version_spinbox.value example = "#{selected_example}#{version_number}" self.code_text = File.read(file_path_for(example)) end end } } horizontal_box { stretchy false button('Launch') { on_clicked do begin parent_dir = File.join(Dir.home, '.glimmer-dsl-libui', 'examples') FileUtils.mkdir_p(parent_dir) example_file = File.join(parent_dir, "#{selected_example.underscore}.rb") File.write(example_file, code_text) example_supporting_directory = File.expand_path(selected_example.underscore, __dir__) FileUtils.cp_r(example_supporting_directory, parent_dir) if Dir.exist?(example_supporting_directory) FileUtils.cp_r(File.expand_path('../icons', __dir__), File.dirname(parent_dir)) FileUtils.cp_r(File.expand_path('../sounds', __dir__), File.dirname(parent_dir)) run_example(example_file) rescue => e puts e.full_message puts 'Unable to write code changes! Running original example...' run_example(file_path_for(selected_example)) end end } button('Reset') { on_clicked do self.code_text = File.read(file_path_for(selected_example)) end } } } @code_entry = non_wrapping_multiline_entry { text <=> [self, :code_text] } } }.show end MetaExample.new.launch ``` -------------------------------- ### Run Lazy Table Example (Project Clone) Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the lazy table example when the project is cloned locally. ```bash ruby -r "./lib/glimmer-dsl-libui" examples/lazy_table.rb ``` -------------------------------- ### Dashboard Grid Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/api-reference/container-controls.md A complete example demonstrating the use of the grid container to build a dashboard layout with labels and buttons. ```ruby require 'glimmer-dsl-libui' class Dashboard include Glimmer def launch window('Dashboard', 600, 400) { grid { left_margin 10 top_margin 10 x_padding 5 y_padding 5 label('Dashboard') { left 0; top 0; x_span 2 } label('Status:') { left 0; top 1 } label('Running') { left 1; top 1 } button('Start') { left 0; top 2 } button('Stop') { left 1; top 2 } } }.show end end Dashboard.new.launch ``` -------------------------------- ### LibUI Procedural App Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md An example of an application written using LibUI's procedural imperative syntax. Requires initialization and manual control management. ```ruby require 'libui' UI = LibUI UI.init main_window = UI.new_window('hello world', 300, 200, 1) button = UI.new_button('Button') UI.button_on_clicked(button) do UI.msg_box(main_window, 'Information', 'You clicked the button') end UI.window_on_closing(main_window) do puts 'Bye Bye' UI.control_destroy(main_window) UI.quit 0 end UI.window_set_child(main_window, button) UI.control_show(main_window) UI.main UI.quit ``` -------------------------------- ### Install Glimmer DSL for LibUI Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/INDEX.md Install the Glimmer DSL for LibUI gem using Bundler or as a standalone gem. ```ruby gem 'glimmer-dsl-libui' ``` ```ruby gem install glimmer-dsl-libui ``` -------------------------------- ### Scaffold a Custom Window with Name Only Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Example of scaffolding a custom window with only a name, assuming a 'hello_world' application context. ```bash glimmer "scaffold:cw[greeting_window]" ``` -------------------------------- ### Complete Glimmer Application Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/api-reference/window-proxy.md A full example of a Glimmer application demonstrating window creation, data binding for the title, event handling for closing, and basic UI elements like buttons and multiline entries. ```ruby require 'glimmer-dsl-libui' class AppModel attr_accessor :name end class App include Glimmer def launch @model = AppModel.new @model.name = 'Untitled' window('Text Editor', 600, 400) { title <= [@model, :name] # Bind title to model vertical_box { horizontal_box { stretchy false button('Save') { on_clicked do @model.name = "Saved: #{Time.now}" end } } multiline_entry { stretchy true # text <=> [@model, :content] } } on_closing do puts "Goodbye!" end }.show end end App.new.launch ``` -------------------------------- ### Scaffold Custom Shape Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Example command to scaffold a 'heart' custom shape within the 'hello_world' application namespace. ```bash glimmer "scaffold:cs[heart]" ``` -------------------------------- ### Example Usage of Custom Window Gem Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md This Ruby code demonstrates how to require and show a custom window gem. ```ruby require 'glimmer-libui-cw-greeter-acme' ... greeter.show ... ``` -------------------------------- ### Complete Form Event Handling Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/api-reference/listeners-and-events.md A comprehensive example demonstrating various event listeners within a form, including `on_changed` for entries, `on_toggled` for checkboxes, `on_clicked` for buttons, and `on_closing` for the window. ```ruby require 'glimmer-dsl-libui' class FormApp include Glimmer attr_accessor :name, :email, :agree def launch window('Form with Events', 400, 300) { form { entry_label('Name:') entry { text <=> [self, :name] on_changed do validate_name end } entry_label('Email:') entry { text <=> [self, :email] on_changed do validate_email end } checkbox('I agree to terms') { checked <=> [self, :agree] on_toggled do |item| if item.checked puts "User agreed to terms" end end } } horizontal_box { stretchy false padded true button('Submit') { on_clicked do if valid? submit_form msg_box('Success', 'Form submitted!') else msg_box('Error', 'Please fill all fields') end end } button('Reset') { on_clicked do self.name = '' self.email = '' self.agree = false end } } on_closing do if name.empty? false # Allow close else msg_box('Confirm', 'Discard changes?') end end }.show end def validate_name puts "Name: #{name}" if !name.empty? end def validate_email puts "Email: #{email}" if email.include?('@') end def valid? !name.empty? && email.include?('@') && agree end def submit_form puts "Submitting: #{name}, #{email}" end end FormApp.new.launch ``` -------------------------------- ### Histogram Example with Data Binding Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md This example demonstrates how to create a histogram visualization using Glimmer DSL for LibUI. It includes data binding for spinboxes and color buttons, allowing interactive updates to the histogram. ```ruby require 'glimmer-dsl-libui' class Histogram include Glimmer X_OFF_LEFT = 20 Y_OFF_TOP = 20 X_OFF_RIGHT = 20 Y_OFF_BOTTOM = 20 POINT_RADIUS = 5 COLOR_BLUE = Glimmer::LibUI.interpret_color(0x1E90FF) attr_accessor :datapoints, :histogram_color def initialize @datapoints = 10.times.map {Random.new.rand(90)} @histogram_color = COLOR_BLUE end def graph_size(area_width, area_height) graph_width = area_width - X_OFF_LEFT - X_OFF_RIGHT graph_height = area_height - Y_OFF_TOP - Y_OFF_BOTTOM [graph_width, graph_height] end def point_locations(width, height) xincr = width / 9.0 # 10 - 1 to make the last point be at the end yincr = height / 100.0 @datapoints.each_with_index.map do |value, i| val = 100 - value [xincr * i, yincr * val] end end # method-based custom control representing a graph path def graph_path(width, height, should_extend, &block) locations = point_locations(width, height).flatten path { if should_extend polygon(locations + [width, height, 0, height]) else polyline(locations) end # apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph transform { translate X_OFF_LEFT, Y_OFF_TOP } block.call } end def launch window('histogram example', 640, 480) { margined true horizontal_box { vertical_box { stretchy false 10.times do |i| spinbox(0, 100) { |sb| stretchy false value <=> [self, "datapoints[#{i}]", after_write: -> { @area.queue_redraw_all }] } end color_button { |cb| stretchy false color <=> [self, :histogram_color, after_write: -> { @area.queue_redraw_all }] } } @area = area { on_draw do |area_draw_params| rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height]) { fill 0xFFFFFF } graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height]) figure(X_OFF_LEFT, Y_OFF_TOP) { line(X_OFF_LEFT, Y_OFF_TOP + graph_height) line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height) stroke 0x000000, thickness: 2, miter_limit: 10 } # now create the fill for the graph below the graph line graph_path(graph_width, graph_height, true) { fill @histogram_color.merge(a: 0.5) } # now draw the histogram line graph_path(graph_width, graph_height, false) { stroke @histogram_color.merge(thickness: 2, miter_limit: 10) } end } } }.show end end Histogram.new.launch ``` -------------------------------- ### Advanced Table Example with Data Binding and Events Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/api-reference/table-proxy.md This example demonstrates a Task Manager application using glimmer-dsl-libui, featuring data binding for tasks, editable cells, selection management, and event handling for cell changes. ```ruby require 'glimmer-dsl-libui' class TaskManager include Glimmer attr_accessor :tasks Task = Struct.new(:name, :priority, :completed) def initialize @tasks = [ Task.new('Buy groceries', 'High', false), Task.new('Write documentation', 'Medium', false), Task.new('Fix bug #123', 'High', true), ] end def launch window('Task Manager', 600, 400) { vertical_box { padded true horizontal_box { stretchy false padded true button('Add Task') { on_clicked do @tasks << Task.new('New Task', 'Medium', false) end } button('Delete Selected') { on_clicked do # Remove selected task end } } table { stretchy true editable true selection_mode :zero_or_one text_column('Task Name') text_column('Priority') checkbox_column('Completed') cell_rows <=> [self, :tasks, { after_write: ->(val) { save_tasks }, }] on_changed do |row, column| puts "Task changed: #{tasks[row].name}" end } } }.show end def save_tasks puts "Tasks saved: #{tasks.map(&:name)}" end end TaskManager.new.launch ``` -------------------------------- ### About Menu Item Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/api-reference/container-controls.md Adds a standard about menu item. Use `on_clicked` to display application information. ```ruby menu('Help') { about_menu_item { on_clicked do msg_box('About', 'MyApp v1.0') end } } ``` -------------------------------- ### Form Layout Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/INDEX.md Demonstrates a form layout with labels and entry fields for two properties, linked to a model. ```ruby form { entry_label('Field 1:') entry { text <=> [model, :field1] } entry_label('Field 2:') entry { text <=> [model, :field2] } } ``` -------------------------------- ### Scaffold a 'hello_world' Application Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Demonstrates scaffolding a specific application named 'hello_world'. The command output lists all generated files and directories. ```bash glimmer "scaffold[hello_world]" ``` -------------------------------- ### Run Meta-Example from Project Root Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Command to run the meta-example directly from the project's root directory after cloning. ```bash ruby -r './lib/glimmer-dsl-libui' examples/meta_example.rb ``` -------------------------------- ### Run Glimmer Meta-Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Test the Glimmer DSL for LibUI installation by running the meta-example. This can be done via the glimmer command or explicit Ruby execution. ```bash glimmer examples ``` ```ruby ruby -r glimmer-dsl-libui -e "require 'examples/meta_example'" ``` -------------------------------- ### Hello World Application Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/INDEX.md Create a basic 'Hello World' application with a window and a button that displays a message box when clicked. Requires Glimmer DSL for LibUI to be included. ```ruby require 'glimmer-dsl-libui' include Glimmer window('Hello World', 300, 200) { button('Click Me') { on_clicked do msg_box('Info', 'Hello, World!') end } }.show ``` -------------------------------- ### Menu System Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/api-reference/container-controls.md Creates a menu bar with File, Edit, and Help menus, including menu items with click handlers and standard separators. Demonstrates menu creation and item definition. ```ruby require 'glimmer-dsl-libui' include Glimmer window('Application', 500, 400) { vertical_box { label('Content goes here') } menu('File') { menu_item('New') { on_clicked do msg_box('New', 'Creating new document') end } menu_item('Open') { on_clicked do # Handle open end } separator_menu_item quit_menu_item } menu('Edit') { menu_item('Undo') { on_clicked { puts 'Undo' } } menu_item('Redo') { on_clicked { puts 'Redo' } } } menu('Help') { about_menu_item { on_clicked do msg_box('About', 'My Application v1.0') end } } }.show ``` -------------------------------- ### Basic Scrolling Area Example Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-BASIC-EXAMPLES.md This example demonstrates how to create a scrolling area with a dynamic graph that updates in real-time. It includes setup for axes and a figure to draw lines on. The timer updates the graph and scrolls the view. ```ruby require 'glimmer-dsl-libui' class BasicScrollingArea include Glimmer SCROLLING_AREA_WIDTH = 800 SCROLLING_AREA_HEIGHT = 400 SCROLLING_AREA_PADDING_X = 20 SCROLLING_AREA_PADDING_Y = 20 def initialize @x = SCROLLING_AREA_PADDING_X @y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y create_gui Glimmer::LibUI.timer(0.01) do @x += SCROLLING_AREA_PADDING_X @y = [[@y + rand(SCROLLING_AREA_PADDING_Y*4)*(rand(2) == 0 ? -1 : 1), SCROLLING_AREA_PADDING_Y].max, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y].min @graph.content { # re-open @graph's content and add a line line(@x, @y) } # if there is a need to enlarge scrolling area, call `@scrolling_area.set_size(new_width, new_height)` @scrolling_area.scroll_to(@x - (SCROLLING_AREA_WIDTH/2), @y) # 3rd and 4th arguments for width and height are assumed as those of main window by default if not supplied # return false to stop timer once @x exceeds scrolling area width - padding false if @x >= (SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2) end end def launch @main_window.show end def x_axis polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) { stroke :black, thickness: 3 } ((SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*4) / SCROLLING_AREA_PADDING_X).times do |x_multiplier| x = x_multiplier*SCROLLING_AREA_PADDING_X + SCROLLING_AREA_PADDING_X*2 y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y polyline(x, y, x, y + SCROLLING_AREA_PADDING_Y/2) { stroke :black, thickness: 2 } end end def y_axis polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) { stroke :black, thickness: 3 } ((SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y*3) / SCROLLING_AREA_PADDING_Y).times do |y_multiplier| x = SCROLLING_AREA_PADDING_X y = y_multiplier*SCROLLING_AREA_PADDING_Y + SCROLLING_AREA_PADDING_Y*2 polyline(x, y, x - SCROLLING_AREA_PADDING_X/2, y) { stroke :black, thickness: 2 } end end def create_gui @main_window = window('Basic Scrolling Area', SCROLLING_AREA_WIDTH / 2, SCROLLING_AREA_HEIGHT) { resizable false @scrolling_area = scrolling_area(SCROLLING_AREA_WIDTH, SCROLLING_AREA_HEIGHT) { x_axis y_axis @graph = figure(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) { stroke :blue, thickness: 2 } } } end end BasicScrollingArea.new.launch ``` -------------------------------- ### Get All X11 Color Names Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/configuration.md Retrieves a list of all available X11 color names as Symbols. Requires the 'color' gem to be installed. ```ruby colors = LibUI.x11_colors colors.include?(:red) colors.include?(:alice_blue) ``` -------------------------------- ### Timer without Data Binding Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md A countdown timer example for Glimmer DSL for LibUI that does not use data binding. It includes alarm functionality but requires manual UI updates. Timidity++ must be installed for alarm sounds. ```ruby require 'glimmer-dsl-libui' class Timer include Glimmer SECOND_MAX = 59 MINUTE_MAX = 59 HOUR_MAX = 23 def initialize @pid = nil @alarm_file = File.expand_path('../sounds/AlanWalker-Faded.mid', __dir__) at_exit { stop_alarm } setup_timer create_gui end def stop_alarm if @pid Process.kill(:SIGKILL, @pid) if @th.alive? @pid = nil end end def play_alarm stop_alarm if @pid.nil? begin @pid = spawn "timidity -G 0.0-10.0 #{@alarm_file}" @th = Process.detach @pid ``` -------------------------------- ### Histogram Example with LibUI Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md This Ruby code demonstrates how to create a histogram visualization using the LibUI library. It includes setup for drawing areas, handling user input for color selection, and custom drawing logic for the histogram graph. ```ruby # https://github.com/jamescook/libui-ruby/blob/master/example/histogram.rb require 'libui' UI = LibUI X_OFF_LEFT = 20 Y_OFF_TOP = 20 X_OFF_RIGHT = 20 Y_OFF_BOTTOM = 20 POINT_RADIUS = 5 init = UI.init handler = UI::FFI::AreaHandler.malloc histogram = UI.new_area(handler) brush = UI::FFI::DrawBrush.malloc color_button = UI.new_color_button blue = 0x1E90FF datapoints = [] def graph_size(area_width, area_height) graph_width = area_width - X_OFF_LEFT - X_OFF_RIGHT graph_height = area_height - Y_OFF_TOP - Y_OFF_BOTTOM [graph_width, graph_height] end matrix = UI::FFI::DrawMatrix.malloc def point_locations(datapoints, width, height) xincr = width / 9.0 # 10 - 1 to make the last point be at the end yincr = height / 100.0 data = [] datapoints.each_with_index do |dp, i| val = 100 - UI.spinbox_value(dp) data << [xincr * i, yincr * val] i += 1 end data end def construct_graph(datapoints, width, height, should_extend) locations = point_locations(datapoints, width, height) path = UI.draw_new_path(0) # winding first_location = locations[0] # x and y UI.draw_path_new_figure(path, first_location[0], first_location[1]) locations.each do |loc| UI.draw_path_line_to(path, loc[0], loc[1]) end if should_extend UI.draw_path_line_to(path, width, height) UI.draw_path_line_to(path, 0, height) UI.draw_path_close_figure(path) end UI.draw_path_end(path) path end handler_draw_event = Fiddle::Closure::BlockCaller.new( 0, [1, 1, 1] ) do |_area_handler, _area, area_draw_params| area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params) path = UI.draw_new_path(0) # winding UI.draw_path_add_rectangle(path, 0, 0, area_draw_params.AreaWidth, area_draw_params.AreaHeight) UI.draw_path_end(path) set_solid_brush(brush, 0xFFFFFF, 1.0) # white UI.draw_fill(area_draw_params.Context, path, brush.to_ptr) UI.draw_free_path(path) dsp = UI::FFI::DrawStrokeParams.malloc dsp.Cap = 0 # flat dsp.Join = 0 # miter dsp.Thickness = 2 dsp.MiterLimit = 10 # DEFAULT_MITER_LIMIT dashes = Fiddle::Pointer.malloc(8) dsp.Dashes = dashes dsp.NumDashes = 0 dsp.DashPhase = 0 # draw axes set_solid_brush(brush, 0x000000, 1.0) # black graph_width, graph_height = *graph_size(area_draw_params.AreaWidth, area_draw_params.AreaHeight) path = UI.draw_new_path(0) # winding UI.draw_path_new_figure(path, X_OFF_LEFT, Y_OFF_TOP) UI.draw_path_line_to(path, X_OFF_LEFT, Y_OFF_TOP + graph_height) UI.draw_path_line_to(path, X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height) UI.draw_path_end(path) UI.draw_stroke(area_draw_params.Context, path, brush, dsp) UI.draw_free_path(path) # now transform the coordinate space so (0, 0) is the top-left corner of the graph UI.draw_matrix_set_identity(matrix) UI.draw_matrix_translate(matrix, X_OFF_LEFT, Y_OFF_TOP) UI.draw_transform(area_draw_params.Context, matrix) # now get the color for the graph itself and set up the brush # uiColorButtonColor(colorButton, &graphR, &graphG, &graphB, &graphA) graph_r = Fiddle::Pointer.malloc(8) # double graph_g = Fiddle::Pointer.malloc(8) # double graph_b = Fiddle::Pointer.malloc(8) # double graph_a = Fiddle::Pointer.malloc(8) # double UI.color_button_color(color_button, graph_r, graph_g, graph_b, graph_a) brush.Type = 0 # solid brush.R = graph_r[0, 8].unpack1('d') brush.G = graph_g[0, 8].unpack1('d') brush.B = graph_b[0, 8].unpack1('d') # now create the fill for the graph below the graph line path = construct_graph(datapoints, graph_width, graph_height, true) brush.A = graph_a[0, 8].unpack1('d') / 2.0 UI.draw_fill(area_draw_params.Context, path, brush) UI.draw_free_path(path) # now draw the histogram line path = construct_graph(datapoints, graph_width, graph_height, false) brush.A = graph_a[0, 8].unpack1('d') UI.draw_stroke(area_draw_params.Context, path, brush, dsp) UI.draw_free_path(path) end handler.Draw = handler_draw_event # Assigning to local variables # This is intended to protect Fiddle::Closure from garbage collection. ``` -------------------------------- ### Draw Alternating Color Text in Area Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-BASIC-EXAMPLES.md This example demonstrates how to draw text with alternating colors within an area. It defines a helper method to manage color changes and text content for each line. Ensure the Glimmer DSL for LibUI is installed. ```ruby class BasicDrawText include Glimmer def alternating_color_string(initial: false, &block) @index = 0 if initial @index += 1 string { if @index.odd? color r: 0.5, g: 0, b: 0.25, a: 0.7 else color r: 0, g: 0.5, b: 0, a: 0.7 end block.call + "\n\n" } end def launch window('Michael Ende (1929-1995) The Neverending Story', 600, 400) { margined true area { on_draw do |area_draw_params| text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width]) # align :left # default alignment default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal alternating_color_string(initial: true) { ' At last Ygramul sensed that something was coming toward ' \ 'her. With the speed of lightning, she turned about, confronting ' \ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' } alternating_color_string { ' A cry of fear escaped Bastian. ' } alternating_color_string { ' A cry of terror passed through the ravine and echoed from ' \ 'side to side. Ygramul turned her eye to left and right, to see if ' \ 'someone else had arrived, for that sound could not have been ' \ 'made by the boy who stood there as though paralyzed with ' \ 'horror. ' } alternating_color_string { ' Could she have heard my cry? Bastion wondered in alarm. ' \ "But that's not possible. " } alternating_color_string { ' And then Atreyu heard Ygramuls voice. It was very high ' \ 'and slightly hoarse, not at all the right kind of voice for that ' \ 'enormous face. Her lips did not move as she spoke. It was the ' \ 'buzzing of a great swarm of hornets that shaped itself into ' \ 'words. ' } } end } }.show end end BasicDrawText.new.launch ``` -------------------------------- ### Run Installed Application Gem Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Execute an installed application gem using its executable script. This command is available after the gem has been installed (e.g., 'gem install hello_world'). ```bash app_name ``` -------------------------------- ### Install Glimmer DSL for LibUI Gem Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/README.md Provides the command to install the Glimmer DSL for LibUI gem using RubyGems. Ensure you have Ruby and RubyGems installed. ```bash gem install glimmer-dsl-libui ``` -------------------------------- ### Paginated Refined Table Example Link Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Link to the source code for the paginated refined table example. ```ruby # New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version: # [examples/paginated_refined_table.rb](/examples/paginated_refined_table.rb) ``` -------------------------------- ### Create a Basic Window with a Button Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/README.md This example demonstrates how to create a simple window with a button that triggers a message box when clicked. It requires the 'glimmer-dsl-libui' gem and includes the main DSL module. ```ruby require 'glimmer-dsl-libui' include Glimmer # Real working example window('My App', 300, 200) { button('Click Me') { on_clicked do msg_box('Success', 'Button was clicked!') end } }.show ``` -------------------------------- ### Instantiate and Run Application Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Creates an instance of the TinyMidiPlayer class to start the application. This is the entry point for the Glimmer DSL Libui application. ```ruby TinyMidiPlayer.new ``` -------------------------------- ### Example Usage of Custom Shape Gem Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Example of how a consumer would include and use a custom shape gem in their project. ```ruby require 'glimmer-libui-cs-heart-acme' ... window { area { heart } } ... ``` -------------------------------- ### Create a Basic Window Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md This snippet shows the simplest way to create and display a window using Glimmer DSL LibUI. It requires including the Glimmer module and calling the window and show methods. ```ruby require 'glimmer-dsl-libui' include Glimmer window('hello world').show ``` -------------------------------- ### Create a Main Application Window Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/_autodocs/api-reference/glimmer-dsl-module.md Use the `window` keyword to create the main application window with a title, dimensions, and content defined in a block. The `show` method is called to display the window. ```ruby require 'glimmer-dsl-libui' include Glimmer window('Hello World', 400, 300) { label('Welcome to Glimmer') button('Say Hello') { on_clicked do msg_box('Greeting', 'Hello, World!') end } }.show ``` -------------------------------- ### Create GUI with Menu and Controls Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Constructs the main graphical user interface, including a help menu, a window with playback controls (play/stop buttons), and a combobox for selecting MIDI files. This sets up the application's visual elements and basic interactions. ```ruby def create_gui menu('Help') { menu_item('Version') { on_clicked do show_version end } } window('Tiny Midi Player', 200, 50) { horizontal_box { vertical_box { stretchy false button('▶') { on_clicked do play_midi end } button('■') { on_clicked do stop_midi end } } combobox { |c| items @midi_files.map { |path| File.basename(path) } on_selected do @selected_file = @midi_files[c.selected] play_midi if @th&.alive? end } } }.show end ``` -------------------------------- ### Run Snake Game with Installed Glimmer DSL LibUI Gem Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/docs/examples/GLIMMER-DSL-LIBUI-ADVANCED-EXAMPLES.md Command to run the Snake game after installing the Glimmer DSL LibUI Ruby gem. ```bash ruby -r glimmer-dsl-libui -e "require 'examples/snake'" ``` -------------------------------- ### Create a Window with a Button Source: https://github.com/andyobtiva/glimmer-dsl-libui/blob/master/README.md Demonstrates how to create a window with a button and handle click events. When the button is clicked, a message box is displayed. ```ruby require 'glimmer-dsl-libui' include Glimmer window('hello world', 300, 200) { button('Button') { on_clicked do msg_box('Information', 'You clicked the button') end } }.show ```