ChrisS85 / CGUI

An object-oriented GUI library for AutoHotkey
22 stars 19 forks source link

Statusbar: Updating contents #45

Closed hoppfrosch closed 12 years ago

hoppfrosch commented 12 years ago

Not quite sure whether this is an issue or NOOB error, but nevertheless:

I cannot figure out how to update the contents of the StatusBar:

MyWindow := new CBasicWindow("Demo") ;Create an instance of this window class

Loop 100
{ 
    MyWindow.SetProgress(A_Index, 100)
    sleep 50
}

Class CBasicWindow Extends CGUI
{   
    ;...
    statBar   := this.AddControl("StatusBar", "statBar", "", "test")
    progBar   := this.AddControl("Progress", "progBar", "", "Progress")
    ;...

    __New(Title)
    {
    ;...
    this.statBar.Parts := [{Text : "Percent done: ", Width : floor(this.width*0.5), Icon := A_AhkPath
}, {Text : "Hello World!"}]

    this.Show();
    ;...
    }

    SetProgress(value, total = 100)
    {
        percent := floor(value/total * 100)
        this.progBar.Value := percent       ; this updates progressbar as desired ...
        this.statBar.Parts[1] := {text : "Percent done: " percent} ; THIS DOES NOT WORK
    }
} 

I tried out several things, but cannot figure out, how to update contents of Statusbar .... (either bug or - as I said - NOOB ...)

ChrisS85 commented 12 years ago

Not sure if this is still recent for you as I sorta forgot about this report, but here's a correct version of your code, there were a few errors in it (couldn't even run it like posted above). You're right that there's some kind of error there, I'll look into it.

MyWindow := new CBasicWindow("Demo") ;Create an instance of this window class

Loop 100
{ 
    MyWindow.SetProgress(A_Index, 100)
    sleep 50
}
#include <CGUI>
Class CBasicWindow Extends CGUI
{   
    ;...
    statBar   := this.AddControl("StatusBar", "statBar", "", "test")
    progBar   := this.AddControl("Progress", "progBar", "", "Progress")
    ;...

    __New(Title)
    {
    ;...
    this.statBar.Parts := [{Text : "Percent done: ", Width : floor(this.width*0.5), Icon : A_AhkPath}, {Text : "Hello World!"}]

    this.Show()
    ;...
    }

    SetProgress(value, total = 100)
    {
        percent := floor(value/total * 100)
        this.progBar.Value := percent       ; this updates progressbar as desired ...
        this.statBar.Parts[1] := {text : "Percent done: " percent} ; THIS DOES NOT WORK
    }
} ```
ChrisS85 commented 12 years ago

The error was that you set multiple properties at once. This is currently only supported for setting all parts at once. Feel free to add code to CParts.Set().