AndyObtiva / glimmer-dsl-libui

Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library - The Quickest Way From Zero To GUI - If You Liked Shoes, You'll Love Glimmer! - No need to pre-install any prerequisites. Just install the gem and have platform-independent GUI that just works on Mac, Windows, and Linux.
MIT License
474 stars 15 forks source link

Using a single local image, such as foobar.png ? #4

Closed rubyFeedback closed 2 years ago

rubyFeedback commented 2 years ago

Hey there Andy,

I want to test glimmer-dsl-libui finally more seriously; the first project will be backup_paradise. One part of it is used by another elderly person on windows (to back up things; I tested this via the commandline already on windows, and ruby.exe works fine with it), so I want to make this part as convenient as possible in a GUI manner, so that just a single button has to be clicked. This also works as-is but it is not pretty and I lack the knowledge to improve libui_paradise. (I won't abandon libui_paradise but I treat it more as a research project at this time; the whole glimmer suite is LIGHTYEARS ahead of it, which is good, so a minor reason for me adding glimmer code to backup_paradise will be to simply extend all possible options in this regard.)

Currently glimmer-dsl-libui has a few examples where an image is used.

For example in the documentation you show a screenshot of:

Basic Table Image

So we know that images work.

Could you also perhaps add a simple example that shows just how ONE image can be used? Something like:

I would like to add a few simple icons to the GUI that I plan to use, but right now I am not entirely sure how to do so. The Basic Table Image example does not seem to be 1:1 what I may want to do; e. g. I have images for a harddrive and I just want to add it to provide simple cues where to click. I could probably already re-purpose Basic Table, but the whole project that I will try will also be me using glimmer-dsl-libui and glimmer, and that takes a little learning, so this is a very noobish question indeed.

Hopefully I could explain the use case, so to TL;DR it:

AndyObtiva commented 2 years ago

What you ask for is not supported in C libui yet (for example, the golang LibUI docs do not provide any way of rendering images outside of table)

However, I just succeeded in the impossible task of supporting image rendering without C libui officially supporting it (with several documented caveats to keep in mind):

image

I added an image(file, width, height) Glimmer custom widget that can be nested under area, fully documented over here: https://github.com/AndyObtiva/glimmer-dsl-libui#image-glimmer-custom-control

I also added an example of using it with many variations and subtle differences: https://github.com/AndyObtiva/glimmer-dsl-libui#basic-image

Of course, to address your inquiry about examples of labels and buttons, please keep in mind that area is very versatile since it can draw text just like label and can accept keyboard and mouse events just like button as demonstrated in the Area Gallery example: https://github.com/AndyObtiva/glimmer-dsl-libui#area-gallery

One final note is that in Linux, table images grow and shrink with the image size unlike on the Mac where table row heights are constant regardless of image sizes. As such, you may be able to repurpose a table with a single image column and a single row as an image control with more native libui rendering if you are only targeting Linux with your app.

That should address your needs for the time being.

Happy Glimmering!

p.s. About Tetris, you can already run it indirectly via the Meta-Example or directly via one of these commands:

Run with this command from the root of the project if you cloned the project:

ruby -r './lib/glimmer-dsl-libui' examples/tetris.rb

Run with this command if you installed the Ruby gem:

ruby -r glimmer-dsl-libui -e "require 'examples/tetris'"
AndyObtiva commented 2 years ago

I just added web URL file support for image in addition to local file path support.

Example:

# frozen_string_literal: true

require 'glimmer-dsl-libui'

include Glimmer

window('Basic Image', 96, 96) {
  area {
    on_draw do |area_draw_params|
      image('https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/icons/glimmer.png', 96, 96)
    end
  }
}.show

screenshot