Commit c8835ae9 authored by gambas's avatar gambas
Browse files

Label: Try to take italic fonts into account in text alignement.

[GB.GUI.BASE]
* NEW: Label: Try to take italic fonts into account in text alignement.
* BUG: Label: Workaround a Qt bug where using Paint.TextExtents() on a bitmap font makes it unable to be drawn correctly.
parent 8af26cb5
Pipeline #441521475 failed with stage
in 20 minutes and 55 seconds
# Gambas Project File 3.0
Title=Common controls and classes for GUI components
Startup=FTestFrame
Startup=FLabel
Icon=.hidden/window.png
Version=3.16.90
VersionFile=1
......
......@@ -123,9 +123,9 @@ Public Sub _UpdateSize()
$hExt = Null
If $bLocked Then Return
If Me.Design Then Return
If Not $bAutoResize Then Return
If Not $sText Then Return
If Not $bAutoResize Then Return
$bLocked = True
P = GetPadding()
......@@ -162,7 +162,7 @@ Private Sub AutoResize_Write(Value As Boolean)
End
Public Sub UserControl_Font()
_UpdateSize
Me.Refresh
......@@ -170,6 +170,8 @@ End
Private Sub GetExtents() As RectF
Dim X As Float
If Not $hExt Then
If $bRichText Then
If _Wrap Then
......@@ -177,9 +179,14 @@ Private Sub GetExtents() As RectF
Else
$hExt = Paint.RichTextSize($sText)
Endif
If Paint.Font.Scalable Then X = Paint.RichTextExtents($sText).X
Else
$hExt = Paint.TextSize($sText)
If Paint.Font.Scalable Then X = Paint.TextExtents(LTrim($sText)).X
Endif
$hExt.X = CInt(X)
Endif
Return $hExt
......@@ -189,8 +196,9 @@ Public Sub UserControl_Draw()
Dim P As Integer
Dim F As Integer
Dim X As Integer
Dim hExt As RectF
Dim W As Integer
Dim X As Integer
If $iBorder Then
Style.PaintPanel(0, 0, Paint.W, Paint.H, $iBorder)
......@@ -205,23 +213,26 @@ Public Sub UserControl_Draw()
If Not $sText Then Return
hExt = GetExtents()
P = GetPadding()
hExt = GetExtents()
If Align.IsLeft($iAlign) Then
X = P '- hExt.X
X = P - hExt.X
Else If Align.IsRight($iAlign) Then
X = Me.W - P - Ceil(hExt.W)
Else If Align.IsCenter($iAlign) Then
X = (Me.W - hExt.W) / 2
X = Me.W - hExt.W - hExt.X - P
Else
X = P - hExt.X
Endif
W = Me.W - X - P - hExt.X
'
If Not Me.Enabled Then Paint.Background = Color.Merge(Style.BackgroundOf(Me), Style.ForegroundOf(Me))
If $bRichText Then
Paint.DrawRichText($sText, X, P, Ceil(hExt.W), Me.H - P * 2, $iAlign)
Paint.DrawRichText($sText, X, P, W, Me.H - P * 2, $iAlign)
Else
Paint.DrawText($sText, X, P, Ceil(hExt.W), Me.H - P * 2, $iAlign)
Paint.DrawText($sText, X, P, W, Me.H - P * 2, $iAlign)
Endif
End
......
......@@ -2,60 +2,65 @@
{ Form Form
MoveScaled(0,0,103,110)
Font = Font["Times New Roman,+10"]
Arrangement = Arrange.Vertical
Font = Font["Cantarell,20,Italic"]
Spacing = True
{ Label6 Label
MoveScaled(6,3,72,9)
MoveScaled(6,3,84,9)
Background = Color.Cyan
AutoResize = True
Alignment = Align.Left
Text = (" This is a Label test line")
Border = Border.Plain
Text = ("This is a Label test line")
}
{ Label4 Label
MoveScaled(6,13,72,9)
Font = Font["Italic"]
Background = Color.Pink
Alignment = Align.Left
Text = ("This is a Label test line")
Alignment = Align.Right
Border = Border.Plain
Text = ("This is a Label test line A")
}
{ Label5 Label
MoveScaled(6,23,72,13)
MoveScaled(6,23,71,13)
Background = Color.Pink
Foreground = Color.SelectedBackground
Alignment = Align.Center
Border = Border.Plain
Text = ("This is a Label test line\nwith another one")
}
{ Label1 Label
MoveScaled(6,38,72,9)
MoveScaled(6,38,75,8)
Enabled = False
Font = Font["Italic"]
Background = Color.Pink
Alignment = Align.Right
Text = ("This is a Label test line")
Alignment = Align.BottomRight
Border = Border.Plain
Text = ("This is a Label test lineT")
}
{ Label2 TextLabel
MoveScaled(1,51,85,6)
MoveScaled(1,51,70,6)
Background = Color.Pink
AutoResize = True
Text = ("This is a TextLabel test line")
Text = ("AThis is a TextLabel test line")
}
{ Label3 TextLabel
MoveScaled(1,59,75,13)
Font = Font["Italic"]
MoveScaled(1,59,59,13)
Background = Color.Pink
AutoResize = True
Text = ("This is a TextLabel test line")
Alignment = Align.Top
Alignment = Align.TopRight
}
{ Label7 TextLabel
MoveScaled(1,74,58,14)
MoveScaled(1,74,55,14)
Background = Color.Pink
Text = ("This is a TextLabel test line")
Alignment = Align.TopRight
}
{ Label8 TextLabel
MoveScaled(2,89,58,14)
Font = Font["Italic"]
MoveScaled(2,89,59,14)
Background = Color.Pink
Text = ("This is a TextLabel test line")
Alignment = Align.Top
}
{ Separator1 Separator
MoveScaled(4,48,94,3)
}
}
......@@ -11,4 +11,10 @@ Public Sub Button3_Click()
Frame1.Arrangement = Arrange.None
End
Public Sub Button1_Click()
End
......@@ -8,15 +8,15 @@
MoveScaled(2,2,49,39)
Arrangement = Arrange.Vertical
Text = ("gfdhgdfhfdg")
Alignment = Align.Top
Alignment = Align.Justify
{ Button1 Button
MoveScaled(3,1,16,4)
MoveScaled(24,10,16,4)
}
{ Button2 Button
MoveScaled(4,8,16,4)
MoveScaled(19,15,16,4)
}
{ Button3 Button
MoveScaled(4,16,16,4)
MoveScaled(5,21,16,4)
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment