简体   繁体   中英

GTK# sctructure of application

I am newbie in desktop application programs and I want to create an applications which will use only 1 window for all things. First of all I create a simple LOGIN form with "Login" button and 2 text fields. When user successfully logins window changes it's form. I pinned a picture of the, lets say, MAIN form, where user can switch between "screens" (I don't know how to properly name it) by clicking 1..4 buttons at the right. And we have the top panel with profile photo and nickname which persist all the time program still in the MAIN form.

So, the main question is: HOW should I do it? Which widgets I should use and how does dynamic content in GTK+ (and others, like Qt etc.) should be implemented? So I want answers, links to topics which covers this situation, guides and lessons. Anything will help.

I read a lot of documentation but it seems that I can't find proper information just because I don't know how to formulate my problem for search query.

Thank you, I hope I'll find some help.

PS I am gonna use C# and GTK# for this application.

You only need to create various boxes ( Gtk.VBox or Gtk.HBox ), and hide/show them as you need to. I did not know about Gtk.Stack, but I bet it uses the same principle, maybe with some optimization.

class UniqueWindowView: Gtk.Window
{
    void Build()
    {
        var vbMainBox = new Gtk.VBox();

        this.vbLoginPage = this.BuildLoginPage();
        this.vbNotebook = this.BuildNotebook();

        vbMainBox.PackStart( this.vbLoginPage, true, true, 100 );
        vbMainBox.PackStart( this.vbNotebook, true, true, 5 );
        vbMainBox.Show();

        this.Add( vbMainBox );
        this.SetSizeRequest( 600, 400 );
        this.Show();
    }

    // ...

    public Gtk.VBox vbLoginPage {
        get; private set;
    }

    public Gtk.VBox vbNotebook {
        get; private set;
    }

    public Gtk.Notebook nbNotebook {
        get; private set;
    }

    public Gtk.Button btLogin {
        get; private set;
    }
}

Once you have this scheme running, you have to prepare to show or hide the appropriate boxes.

class UniqueWindowCtrl
{
    public UniqueWindowCtrl()
    {
        this.view = new UniqueWindowView();
        this.view.DeleteEvent += (o, args) => this.Quit();
        this.view.btLogin.Clicked += (sender, e) => this.ShowNotebook();
    }

    public void Start()
    {
        this.ShowLogin();
    }

    public void ShowLogin()
    {
        this.view.vbLoginPage.Show();
        this.view.nbNotebook.Hide();
    }

    public void ShowNotebook()
    {
        this.view.vbLoginPage.Hide();
        this.view.nbNotebook.Show();
    }

    void Quit()
    {
        this.view.Hide();
        Gtk.Application.Quit();
    }

    UniqueWindowView view;
}

You can find the whole source code for a unique window in GTK# here . Hope this helps.

I suggest you take a look at GtkStack . This will enable you to have multiple widget layouts in a single window and provides you with an easy way to change which widgets are shown. GtkStack is commonly used with StackSwitcher . However normal buttons will work just as well. Can I also suggest you use Glade to lay out your widgets? This will give you a presentation of how your widgets sets will look.

Edit: GtkStack does not appear to be available for Gtk#.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM