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

Examples: could an example be added for LibUI.new_scrolling_area? #42

Open
rubyFeedback opened this issue Nov 27, 2021 · 5 comments
Open

Comments

@rubyFeedback
Copy link
Collaborator

Hello kojix2 and everyone else,

Would it be possible to add a small example for how LibUI.new_scrolling_area
works?

Use case:

Actually I wrote a tiny ruby-gtk3 application that uses mpv to play local .mp3 files.
This is in a scrolled window, with a vbox, containing each local song via a button.

So I click on the button and then mpv plays the song. This is like the ultimate
minimal "jukebox".

On windows I tested - ffmpeg works, mpv works, libui works too.

And using the buttons works as well, but I'd like them in some scrolling container.

Unfortunately I have not yet managed to make this work. I'll google more to see
if I can find an example via scrolling-area, or perhaps I figure it out on my own
eventually. (The malloc and fiddle parts are over my head unfortunately ... I
should have started with C really ... )

At any rate as always please feel free to close the issue request at any moment
in time how you see fit. I also used glimmer-dsl-libui recently to embed images
into a "libui"-widget (on windows), that works too. I got some weird problems
though related to my own ruby code ... would be cool if fiddle-pointer stuff
could get better support for traceback problems. I kind of miss the introspection
you get with ruby methods. :(

@rubyFeedback
Copy link
Collaborator Author

I found it works on kotlin:

https://nicedoc.io/msink/kotlin-libui

Screenshot:

https://raw.githubusercontent.com/msink/kotlin-libui/master/samples/hello/hello-windows.png?sanitize=false

Guess now the key is to understand the kotlin code. :)

If it works then perhaps it could be added towards control_gallery.rb ? Since the latter already
contains a LOT of demo-examples.

@kojix2
Copy link
Owner

kojix2 commented Nov 27, 2021

Hi @rubyFeedback

I think LibUI.new_scrolling_area is to create an area with scroll bars. It is not a widget container.

The kotlin example you gave is just a multiline_entry.

I think what you really want is Table or append/delete of hbox.

@kojix2
Copy link
Owner

kojix2 commented Nov 27, 2021

In Ruby/Tk, you can use BWidget in this way.

require 'tk'
require 'tkextlib/bwidget'

root = TkRoot.new

sw = Tk::BWidget::ScrolledWindow.new(root)
sf = Tk::BWidget::ScrollableFrame.new(sw, constrainedwidth: true)
sw.set_widget(sf)
vf = sf.get_frame
vf.configure(bg: :white, borderwidth: 1, relief: :groove)

10.times do |i|
  TkButton.new(vf, text: "button #{i}").pack
  TkLabel.new(vf, text: "label #{i}").pack
end

sw.pack(fill: :both, expand: true)

Tk.mainloop

@kojix2
Copy link
Owner

kojix2 commented Dec 3, 2021

andlabs/libui#178

@AndyObtiva
Copy link
Collaborator

AndyObtiva commented Jan 20, 2022

I already provide an Ruby example of scrolling_area in Glimmer DSL for LibUI

(sorry, I didn't see this issue before as I was very busy with other stuff the last two months and had unwatched LibUI except for releases to keep myself focused on my tasks, but I just re-enabled full watching of LibUI to stay informed of issues in case I could help)

Code: https://github.com/AndyObtiva/glimmer-dsl-libui/blob/master/examples/basic_scrolling_area.rb

scrolling area 1

scrolling area 2

BTW, you can only control the scrolling programmatically on Mac, but not Windows and Linux (seems like a bug in C libui). But, you can still scroll the area manually on all platforms at least.

Otherwise, you cannot put anything in a scrolling area (like labels and buttons), yet only area content like path shapes. That said, by building area-based custom controls, you can then add your own (custom) flavors of label and button inside a scrolling area, and thus achieve your goal anyways.

If you need help in programming your app with scrolling_area, hit me up about it with an Issue request in Glimmer DSL for LibUI. I'd be happy to help you implement it.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants