gtk-rs / gtk3-rs

Rust bindings for GTK 3
https://gtk-rs.org
MIT License
508 stars 90 forks source link

[HELP] Can't hide buttons with gtk-rs, but can with PyGtk. #622

Closed ergpopler closed 3 years ago

ergpopler commented 3 years ago

Python example that works:

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk

def keypress(win, event):
        win.is_fullscreen = not getattr(win, 'is_fullscreen', False)
        action = win.fullscreen if win.is_fullscreen else win.unfullscreen
        action()
        button.set_visible(not win.is_fullscreen)

win = gtk.Window()
win.connect("delete-event", gtk.main_quit)
win.connect('key-press-event', keypress)
button = gtk.Button().new_with_label("Click Me");
label = gtk.Label(('test ' * 20 + '\n') * 20)
vbox = gtk.HBox()
vbox.add(label)
vbox.add(button)
win.add(vbox)
win.show_all()
gtk.main()

Basically, what this does is create a label with a bunch of text saying "test" and a button. Apon any keypress it would toggle fullscreen on-and-off, but it would only show the label in fullscreen mode, not the button. That is what I want.

I see no way to do this in Rust.

    back_button.set_visible(false);

compiles, but does nothing.

My source code here: https://github.com/moon-laboratories/murasaki malfunctions when fullscreen. It fullscreens, but everything does, including buttons that should vanish upon disappearing. I would like to be able to fullscreen just one element, not the entire window. Is this possible?

EDIT: I am stupid. I put the code to hide the button BEFORE I even initially activated the button, so it was disabling the button that was already disabled, then enabling it. I am dumb, Sorry.

ldco2016 commented 1 year ago

@ergpopler

Did you ever resolve this? In other words, does back_button.set_visible(false); work after all? I ask because I am working with GTK 3 in Rust and I tried the following:

let delete_button = button::create_button(self, "seating_delete_button");
delete_button.set_visibie(false);

And that did nothing for me.