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

Can't use set_y_scroll for listbox #2298

Open
Nonoreve opened this issue Mar 5, 2024 · 1 comment
Open

Can't use set_y_scroll for listbox #2298

Nonoreve opened this issue Mar 5, 2024 · 1 comment
Labels
state: pending not addressed yet type: bug bug

Comments

@Nonoreve
Copy link

Nonoreve commented Mar 5, 2024

Version of Dear PyGui

Version: 1.9.1
Operating System: Manjaro (in virtual env)

My Issue/Question

I want to a listbox to focus a particular line. But using set_y_scroll() gives the message :
Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow
The listbox does indeed have a scrollbar, what prevents it from being scrolled programmatically ?
Is there an other way to do it ?

To Reproduce

Run code below
Click on the button

Expected behavior

The scrollbar should move to the desired position.

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

i = 0

def callback(sender, app_data, user_data):
	global i
	print(i)
	# ~ dpg.configure_item(duplicate_documents_listbox, track_offset=i)
	dpg.set_x_scroll(duplicate_documents_listbox, i)
	i += 0.1


dpg.create_context()
dpg.create_viewport(width =500, height=200)
dpg.setup_dearpygui()

with dpg.window(no_close=True, modal=True, width =500, height=200):
	items = [("a"), ("b"), (1), ("a"), ("42"), (True), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
	duplicate_documents_listbox = dpg.add_listbox(label="", items=items, default_value='', num_items=3, tracked=True)
	dpg.add_button(label="Move scrollbar", callback=callback)


dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
@Nonoreve Nonoreve added state: pending not addressed yet type: bug bug labels Mar 5, 2024
@v-ein
Copy link
Contributor

v-ein commented Mar 6, 2024

The way it's currently implemented in DPG, every widget requires its own implementation of "set/get scroll" functions. Nobody has ever implemented it for listboxes.

I have a fix that might eventually get into the community repo, which improves implementation of the scroll functions and, among other things, should make it easy to enable them on listboxes. This fix has to wait some other PRs to be merged first, so it's not going to happen in near future.

In the meantime, you can implement your own listbox by placing selectable's into a child_window. It's pretty easy to do, and you can control scrolling like on a regular child window.

Also take a look at this implementation and other files in that folder - maybe you can just use them as is.
https://github.com/my1e5/dpg-examples/blob/main/listbox/listbox_custom.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet type: bug bug
Projects
None yet
Development

No branches or pull requests

2 participants