ChrisS85 / CGUI

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

GUI-geometry? #42

Closed hoppfrosch closed 12 years ago

hoppfrosch commented 12 years ago

The geometry of the GUI (x,y,width,height) does not seem to be handled correctly. I tested with width and height (not with x and y yet) and do have following observations/remarks/bugs ...

Base Code from your CSharpGuiConverter.ahk:

001: Class CSharpGuiConverter Extends CGUI
002: {
003:    label1          := this.AddControl("Text", "label1", "x12 y15 w53 h13", "Input File:")
004:    txtInput        := this.AddControl("Edit", "txtInput", "x71 y14 w274 h20", "")
005:    btnInput        := this.AddControl("Button", "btnInput", "x351 y12 w36 h23", "...")
006:    label2          := this.AddControl("Text", "label2", "x12 y41 w61 h13", "Output File:")
007:    txtOutput       := this.AddControl("Edit", "txtOutput", "x71 y40 w274 h20", "")
008:    btnOutput   := this.AddControl("Button", "btnOutput", "x351 y38 w36 h23", "...")
009:    btnConvert  := this.AddControl("Button", "btnConvert", "x15 y66 w120 h23", "Convert")
010:    btnRun      := this.AddControl("Button", "btnRun", "x141 y66 w120 h23", "Run Converted File")
011:    btnEdit         := this.AddControl("Button", "btnEdit", "x267 y66 w120 h23", "Edit Converted File")
012:    __New()
013:    {
014:        IniRead, in, %A_ScriptName%.ini,Settings, In, %A_Space%
015:        IniRead, out, %A_ScriptName%.ini,Settings, Out, %A_Space%
016:        
017:        this.txtInput.Text := in
018:        this.txtOutput.Text := out
019:        
020:        this.btnConvert.Enabled := FileExist(in) && strlen(out) > 1     
021:        this.btnRun.Enabled := 0            
022:        this.btnEdit.Enabled := 0
023:        
024:        MsgBox % this.x " - " this.y " - " this.Width " - " this.Height
XXX:          ; Output: 0 - 0 - 0 - <MISSING>
025:        this.height := 116
026:        this.Title := "C# GUI Converter"
027:        this.Width := 401
028:        MsgBox % this.x " - " this.y " - " this.Width " - " this.Height
XXX:          ; Output: 0 - 0 - 401 - 116
029:        this.DestroyOnClose := true
030:        this.Show()     
031:    }

1.) Initialization (Line 024) TestResult: MsgBox shows " 0 - 0 - 0 - "

2.) What are/should be the impacts of setting this.width (or height or x or y)? 2.a.) If width is not set by user (Omitting line 025): As the GUI contains already some controls (Line 002 ... Line 011) the GUI does have some default width (which seems to be correct - as the GUI is drawn to show all added controls). In this case this.width should be set to the "default value" (I would call it "calculated width") ... 2.b.) What should be the behaviour if this.width is set explictly? Should the size of the drawn GUI be "setted.width" - or "calculated width"? I think it has to be "setted.width" - which isn't the case yet. (Change line 027 to "this.Width := 801" and run the example - the drawn GUI has the same size as before, "this.Width" is unconsidered .... -> this seems to be a bug)

Coming back to 1.) this.Width should not show up as "0" in line 024 - better it should show up as "calculated width"

3.) this.width should always have a valid value. I would like to do something like this: (Nonsense example in context of example above - but demonstrates what I mean (for example: Placing a button in the lower left corner of GUI, width over the whole GUI)

024a:    margin := 20
024b:    this.btnEdit.x := margin
024c:    this.btnEdit.y := this.height - margin
024d:    this.btnEdit.width := this.width - 2*margin

BTW: as the GUI uses some default margin, it would be nice to have a Getter() for this value ... ;-) ( a Setter() would also be nice)

=> Summary:

hoppfrosch commented 12 years ago

More on this:

ChrisS85 commented 12 years ago

This happens because the window isn't sized yet at that place since Gui, Show wasn't used yet. I've committed some changes that work around this by calling Gui, Show, Autosize every time a control is added before the GUI is first shown or a manual size gets set. Please test it and see if this behaves like you think it should.

Height and MaxSize not behaving properly was caused by invalid spaces in if ... in ... commands. I've also spotted a few others that I fixed, good that you noticed this!

Margin isn't added yet. Might do this later on, but I'll need to check the AHK source to find the correct values.

hoppfrosch commented 12 years ago

... fast response!

Will test it on monday.

hoppfrosch commented 12 years ago

First good news:

Mostly everything works as expected now (at least as I expected) ....

  1. MinSize and MaxSize are handled correctly (Only resizing within those borders is possible ...)
  2. Geometric properties are handled (almost) correctly ... (see Issue below). Assigning value to for example width results (almost) in GUI with setted width.
  3. GUI properties seems always to hold the (almost) correct value (see Issue below) ...

One thing I noticed yet:

;Example 1: MinSize not set
this.width  :=400
this.height  := 300
MsgBox % this.Width " - " this.Height
; Results in "400 - 300"  <-- Correct values

;Example 2: Using Minsize ... (I want to display my GUI with MinSize on the beginning ...)
this.MinSize := "400x300"
this.width  :=400
this.height  := 300
MsgBox % this.Width " - " this.Height
; Results in "406 - 328"  <-- These are obviously wrong values

;Example 3
this.MinSize := "400x300"
this.width  :=500
this.height  := 400
MsgBox % this.Width " - " this.Height
; Results in "500 - 400"  <-- Correct!

I think there's a bug/inconsitency when calculating x and y under consideration of MinSize.x and Minsize.y - or do I get something wrong?

Further testing going on ...

hoppfrosch commented 12 years ago

Obviously there are still some errors when calculating the geometric properties.

Have a look at the following example: I want to center a progressbar within a fixed size window


SetBatchlines, -1
MyWindow := new CBasicWindow("ProgBar-Demo") ;Create an instance of this window class

Loop 1000
{
    MyWindow.progBar.Value := A_Index
    sleep 10
}
ExitApp

return

#include %A_ScriptDir%\lib
#include CGUI.ahk

Class CBasicWindow Extends CGUI
{
    progBar   := this.AddControl("Progress", "progBar", "", "Progress")
    __New(Title)
    {
        this.Title := Title
        this.width := 400
        this.height := 300
        this.CloseOnEscape := true
        this.DestroyOnClose := true

        this.Bordersize := 10

        this.progBar.Min := 0
        this.progBar.Max := 1000
        this.progBar.Value := 0

        this.progBar.x := this.Bordersize
        this.progBar.y := this.Bordersize
        this.progbar.Width := this.Width - 2 * this.Bordersize
        this.progbar.Height := this.Height - 2 * this.Bordersize
        MsgBox % this.progBar.x "-" this.progBar.y "-" this.progbar.Width "-" this.Height - 2 * this.Bordersize
                ; Results in "10-10-380-280" as expected
        this.progBar.Style := 0x800000
        ;Show the window
        this.Show("")
    }   
}

"Show"ing this window should result in a window with a centered progressbar (with a border of 10 pixels around progressbar). But ... all borders - except the upper border - are shown correctly. The progressbar is drawn "to high": the upper part of the progressbar is overdrawn with caption bar - the calculated y-coordinate is not applied correctly (as the progressbar is hidden in its upper part by caption bar of window) and the calculated height is also not applied correctly (as the distance of lower border of progressbar to windows border is correct - but the upper border of progressbar is hidden by caption bar) ...

ChrisS85 commented 12 years ago

It sounds like an issue with window/client coordinates.

ChrisS85 commented 12 years ago

I looked into it an this was indeed the issue. I've uploaded fixed files of CGUI and CControl that should consistently use client coordinates now.

hoppfrosch commented 12 years ago

Bug seems to be fixed now - though it needs some more intensive testing.

Thanks anyway ...