-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel.v
75 lines (62 loc) · 1.54 KB
/
label.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license
// that can be found in the LICENSE file.
module ui
[ref_only]
pub struct Label {
mut:
text string
parent Layout
x int
y int
ui &UI
}
pub struct LabelConfig {
text string
}
fn (mut l Label) init(parent Layout) {
ui := parent.get_ui()
l.ui = ui
}
pub fn label(c LabelConfig) &Label {
lbl := &Label{
text: c.text
ui: 0
}
return lbl
}
fn (mut l Label) set_pos(x int, y int) {
l.x = x
l.y = y
}
fn (mut l Label) size() (int, int) {
w, h := l.ui.gg.text_size(l.text)
// First return the width, then the height multiplied by line count.
return w, h * l.text.split('\n').len
}
fn (mut l Label) propose_size(w int, h int) (int, int) {
ww, hh := l.ui.gg.text_size(l.text)
// First return the width, then the height multiplied by line count.
return ww, hh * l.text.split('\n').len
}
fn (mut l Label) draw() {
splits := l.text.split('\n') // Split the text into an array of lines.
height := l.ui.gg.text_height('W') // Get the height of the current font.
for i, split in splits {
// Draw the text at l.x and l.y + line height * current line
l.ui.gg.draw_text(l.x, l.y + (height * i), split, btn_text_cfg)
}
}
fn (l &Label) focus() {
}
fn (l &Label) is_focused() bool {
return false
}
fn (l &Label) unfocus() {
}
fn (l &Label) point_inside(x f64, y f64) bool {
return false // x >= l.x && x <= l.x + l.width && y >= l.y && y <= l.y + l.height
}
pub fn (mut l Label) set_text(s string) {
l.text = s
}