Comments (2)
Oh yes, I forgot to add one thing, because you may wonder why
one would not use the toplevel DSL as-is. The toplevel DSL approach
is perfectly fine; sinatra uses it too.
But in the case that we already have a large class written, it actually
is more convenient to just add-on stuff to that class, such as via
"include" or some other way (I found include more flexible than
subclassing... for instance, class Foo < ::Gtk::Window means that
this subclass approach is harded to gtk, which removes some
flexibility if you know what I mean). So kind of the more flexible
"include as-is" approach, or perhaps even better without any
hardcoded include as-such either. I hope that makes any sense to you.
from glimmer.
Trying to unify the DSL across multiple GUI toolkits adds quite a bit of complexity to each DSL's codebase that is not worth the benefits in my opinion in comparison to simply updating GUI code manually by hand in the extremely rare scenarios you would have to switch an application from one GUI toolkit to another.
I mean, it is really simple to switch from this LibUI GUI DSL code:
button('Submit') {
on_clicked do
submit_online
end
}
To this Tk GUI DSL code:
button {
text 'Submit'
on('command') do
submit_online
end
}
About your other questions regarding Glimmer's support for selecting DSLs, Glimmer already supports that by simply adding the require statement of the DSL you want, activating automatically.
In other words, if you call this before your application:
require 'glimmer-dsl-libui'
Now, when you do include Glimmer
, it automatically uses LibUI.
You can simply update that line to this:
require 'glimmer-dsl-tk'
And, now the Tk GUI DSL is used when you do include Glimmer
You can also keep the DSL require out of the code altogether and just use a -r glimmer-dsl-libui
when running the app to select DSL from the terminal:
ruby -r glimmer-dsl-libui some_app.rb
In fact, Glimmer supports the idea of activating multiple (non-conflicting) DSLs at the same time, such as SWT, XML, and CSS. You simply add multiple require statements to do so:
require 'glimmer-dsl-swt'
require 'glimmer-dsl-xml'
require 'glimmer-dsl-css'
Now, when you do include Glimmer
, you get access to all 3 DSLs in the code (each having its own top-level keyword for entry into the DSL, like shell
for SWT, html
for HTML, and css
for CSS). In fact, I made use of that to embed HTML/CSS in a browser widget in SWT before. I have an example of it under the Multiple DSL Support section in Glimmer:
require 'glimmer-dsl-swt'
require 'glimmer-dsl-xml'
require 'glimmer-dsl-css'
include Glimmer
shell {
minimum_size 130, 130
@browser = browser {
text html {
head {
meta(name: "viewport", content: "width=device-width, initial-scale=2.0")
style {
css {
h1 {
background 'yellow'
}
}
}
}
body {
h1 { "Hello, World!" }
}
}
}
}.open
(Of course, that was just an example. In a real app, you would use include Glimmer
in an actual class [not at the top-level namespace] to avoid namespace pollution. So, Glimmer already addresses your concern there with the use of module mixin instead of class inheritance)
Furthermore, Glimmer enables you to disable DSLs and enable DSLs piecemeal if needed after you activated automatically via require statement.
For example:
require 'glimmer-dsl-swt'
require 'glimmer-dsl-xml'
require 'glimmer-dsl-css'
Glimmer::DSL::Engine.disable_dsl(:swt)
Glimmer::DSL::Engine.disable_dsl(:css)
# Now, only the XML DSL is enabled when using `include Glimmer`
# Later, you can re-enable SWT
Glimmer::DSL::Engine.enable_dsl(:swt)
# Now, both XML and SWT are enabled when using `include Glimmer`
p.s. By the way, it is definitely possible to share a GUI DSL between multiple DSLs in Glimmer as already done in Glimmer DSL for SWT and Glimmer DSL for Opal. But, just because something is possible, that doesn't mean it is always a good idea. In the case of SWT & Opal, the benefit was worth it to migrate a desktop app into the web with little effort as that is a very common requirement/scenario. However, in the case of converting between SWT, Tk or LibUI, I am not sure that is common enough to warrant the extra code in the codebase to support it or the divergence from each toolkit's community conventions through unification. It is more likely that it would be a waste of both time and effort to support such a thing given how rarely it is needed. After all, in software engineering everything has a cost, and the benefit has to exceed the cost to make a trade-off worth it. I would rather keep each toolkit with its own DSL style that appeals better to its audience.
from glimmer.
Related Issues (20)
- Glimmer "store"? HOT 2
- [Suggestion, low priority] Provide "statistics" and information about the whole glimmer suite in some way, or perhaps several ways HOT 1
- Glimmer gosu support? (This is more a question though) HOT 1
- [Idea, just as impetus, don't worry about implementing it and feel free to close it at any moment in time] "Automatic glimmer" or "Automated glimmer" - automatically generating a GUI for commandline applications HOT 1
- [Idea / Suggestion] "Glimmer components": the idea is to have different glimmer widgets, no matter the style, that could be integrated / included and re-used. For instance, rubio-radio to be embedded in a tabbed notebook with a weather-displaying widget HOT 3
- Battleships - a few not-so-important comments/suggestions, please feel free to ignore/close at any moment in time HOT 6
- [Small idea / question] Customizing Glimmer Tetris? HOT 1
- [Related to the RubyConf 2022 Talk in about 3 months] If you have time during the talk, could you also mention future ideas and goals for glimmer? HOT 1
- [Minor suggestion for future video content] A video in regards to "workflow use" / computer setup, from the point of view of glimmer, but also aside from glimmer HOT 5
- Glimmer Video Request +1 - a dedicated video for "styling glimmer" applications HOT 3
- [Idea, please close as desired] Glimte-Glimmer for Everyone \o/ (GUIs everywhere) HOT 1
- [Idea] glimmer + curses / ncurses HOT 1
- [Idea] "Standardized" glimmer components HOT 3
- Glimmer statistics (aka overview)? HOT 1
- Enable GitHub Discussions on all glimmer repos HOT 2
- A few ~smaller suggestions, kind of; in particular 2-3 or so suggestions for expanding the FAQ entries HOT 1
- Glimmer support for jruby + SWING? HOT 1
- glimmer-meta-overview: Offer some (multiple?) way(s) to check on glimmer progress overall
- NixOS package
- [Proposal] A new glimmer FAQ repository to specifically answer FAQ-related questions from different users HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glimmer.