{"id":16753442,"url":"https://github.com/thbar/magic","last_synced_at":"2025-04-10T16:06:39.222Z","repository":{"id":512867,"uuid":"140678","full_name":"thbar/magic","owner":"thbar","description":"IronRuby sugar for WPF, Silverlight and Windows Forms.","archived":false,"fork":false,"pushed_at":"2010-04-17T08:53:14.000Z","size":272,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-24T13:51:19.180Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thbar.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-03-01T21:08:10.000Z","updated_at":"2025-02-06T16:00:36.000Z","dependencies_parsed_at":"2022-07-04T21:31:03.949Z","dependency_job_id":null,"html_url":"https://github.com/thbar/magic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thbar%2Fmagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thbar%2Fmagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thbar%2Fmagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thbar%2Fmagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thbar","download_url":"https://codeload.github.com/thbar/magic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248250743,"owners_count":21072682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T02:50:08.637Z","updated_at":"2025-04-10T16:06:39.205Z","avatar_url":"https://github.com/thbar.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Magic is a gem making it easier to develop UI:\n- Windows Forms, WPF/Silverlight with IronRuby\n- Swing with JRuby\n\nh1. USAGE\n\nHere are quick starters (some of these are under samples/):\n\nh2. Windows Forms\n\n\u003cpre\u003e\u003ccode\u003eform = Magic.build do\n  @menu = main_menu do\n    menu_item(\"\u0026File\") do\n      menu_item(\"\u0026New\")\n      menu_item(\"\u0026Quit\").click { Application.Exit }\n      menu_item(\"\u0026Other Quit\", :click =\u003e lambda { Application.Exit })\n    end\n  end\n  form(:text =\u003e \"Title\", :menu =\u003e @menu) do\n    flow_layout_panel(:dock =\u003e :fill) do\n      button(:text =\u003e \"Click me!\").click do\n        MessageBox.Show(\"Hello from button!\")\n      end\n    end\n  end\nend\n\nApplication.Run(form)\n\u003c/code\u003e\u003c/pre\u003e\n\nh2. WPF\n\n\u003cpre\u003e\u003ccode\u003ewindow = Magic.build do\n  window(:width =\u003e 600, :height =\u003e 480, :title =\u003e 'Hello world!') do\n    stack_panel(:margin =\u003e thickness(30)) do\n      button(:content =\u003e 'Click me!', :font_size =\u003e 22).click do\n        MessageBox.show(\"Ok!\")\n      end\n    end\n  end\nend\n\napp = Application.new\napp.run(window)\n\u003c/code\u003e\u003c/pre\u003e\n\nh2. Silverlight\n\nYou'll need to run \"rake compress\" to create magic-compressed.rb, which gathers all the magic files into one. Once you have magic-compressed.rb, you can use it like that:\n\n\u003cpre\u003e\u003ccode\u003erequire \"silverlight\"\nrequire \"magic-compressed\"\n\nclass App \u003c SilverlightApplication\n\n  def initialize\n    application.root_visual = Magic.build do\n      stack_panel do\n        10.times { |i| text_block(:text =\u003e i.to_s, :width =\u003e 30,:height =\u003e 30) }\n      end\n    end\n  end\nend\n\n$app = App.new\n\u003c/code\u003e\u003c/pre\u003e\n\nIt makes it easy to create XAML-free applications, or to reduce the amount of XAML to be created.\n\nh2. Swing\n\nPreliminary support for Swing has just been added. Here's an example:\n\n\u003cpre\u003e\u003ccode\u003eimport 'javax.swing.JFrame'\nimport 'javax.swing.JButton'\n\nframe = Magic.build do\n  JFrame do\n    title 'Hello!'\n    size 400,500\n    JButton('Press me') do |b|\n      b.addActionListener do\n        b.setText 'Pressed!'\n      end\n    end\n  end\nend\n\nframe.set_default_close_operation(JFrame::EXIT_ON_CLOSE)\nframe.show\n\u003c/code\u003e\u003c/pre\u003e\n\nh1. UNDER THE COVER\n\nA few points (see spec/magic_spec.rb for details):\n\n* classes to be built are inferred from method calls (converted from snake_case to CamelCase)\n** menu_item creates an instance of MenuItem\n** button becomes Button\n** flow_layout_panel becomes FlowLayoutPanel\n* if a method call matches an existing method of the parent, the method is called\n* the instanciated control is passed as an optional param to the block\n* method calls automatically add the object to its parent children collection (if the object is a Control, a MenuItem or a UIElement - this will become configurable)\n* if the parent responds to :content (eg: WPF Window), then parent.content will use the (unique) child\n* if a Hash is passed, corresponding properties are set after instanciation (:text =\u003e \"This is the text\")\n* if the property is an enum, snake_case symbol value is allowed (:dock =\u003e :fill is the same as :dock =\u003e DockStyle.Fill)\n* handlers are registered if a lambda is passed (:click =\u003e lambda)\n* handlers can also be registered by calling the block directly (button.lambda do ... end)\n* instance variables can be reused (form.menu = @menu)\n* non-control (like BackgroundWorker for long-running operations) instances can be created (worker = background_worker)\n* the last evaluted expression is returned.\n\nh1. TESTING\n\nMagic comes with its set of specs (based on MSpec). You'll currently have to tweak Rakefile (see spec task) to match your environment.\n\nThen you can run (either on Windows or Mac OS):\n\n\u003cpre\u003e\u003ccode\u003erake spec\n\u003c/code\u003e\u003c/pre\u003e\n\nto see all the (m)specs running.\n\nNote that I currently use a few nasty mocks (see mocks.rb) that I'll need to clean-up.\n\nh1. TODO\n\n* remove obsolete .Net flagged enum support (IronRuby now supports X | Y)\n* split the core into toolkit-specific builders\n\nh1. COPYRIGHT\n\nCopyright (c) 2008 Thibaut Barrère. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthbar%2Fmagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthbar%2Fmagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthbar%2Fmagic/lists"}