potocpav / python-concur

Concur UI Framework for Python
MIT License
49 stars 2 forks source link

Autoscroll stopped working in Log Widget #26

Closed sla-te closed 3 years ago

sla-te commented 3 years ago

We had implemented a custom log widget as follows.

    # These two widgets are not in Concur, so they show how to add new widgets.
    def log_widget(self):
        """ Log widget with auto-scroll. """
        while True:
            # https://pyimgui.readthedocs.io/en/latest/reference/imgui.core.html#imgui.core.push_text_wrap_position
            imgui.push_text_wrap_pos()

            # imgui.text_unformatted(text)
            for t in self.log_list:
                text, color = t
                r, g, b, a = color
                imgui.text_colored(text, r, g, b, a)

            imgui.pop_text_wrap_pos()

            if imgui.get_scroll_y() >= imgui.get_scroll_max_y():
                imgui.set_scroll_here(1.0)

            yield

It is implemented inside a multi_orr() as follows:

c.child(name=f"{self.name} Log", widget=self.log_widget(), width=-1, height=-1, border=True)

and listens to a log_queue:

c.tag("log_queue", c.listen(self.log_queue)),

which is processed as:

elif tag == "log_queue":
    msg = value.getMessage()
    text, rgb_tuple = self.get_log_color(msg)
    self.log_list.append((text, rgb_tuple))

The autoscrolling had worked when we first implemented it but (supposedly due to some part of the updates, that were released in the meantime) it stopped working.

potocpav commented 3 years ago

I tested it, and I don't see how this could've ever worked :)

if imgui.get_scroll_y() >= imgui.get_scroll_max_y():
    imgui.set_scroll_here(1.0)

This if-statement is false after a row is added, since the get_scroll_y stays the same, and get_scroll_max_y increases. As a simple work-around, something like this seems to work:

if imgui.get_scroll_y() >= imgui.get_scroll_max_y() - 30:
    imgui.set_scroll_here(1.0)

but that is quite hacky, since it probably doesn't work when the font gets larger. I don't know how to solve it right now, but it should be doable with some more programming. All the functions that are used seem to work correctly, do they not?

sla-te commented 3 years ago

Wow, didnt even notice, that during my last task 6 hours have passed, yeah that fixed it, great!