forked from vlang/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progressbar.v
97 lines (83 loc) · 1.99 KB
/
progressbar.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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
import gx
const (
progress_bar_color = gx.rgb(87, 153, 245)
progress_bar_border_color = gx.rgb(76, 133, 213)
progress_bar_background_color = gx.rgb(219, 219, 219)
progress_bar_background_border_color = gx.rgb(191, 191, 191)
)
[ref_only]
pub struct ProgressBar {
pub mut:
height int
width int
x int
y int
parent Layout
ui &UI
val int
min int
max int
is_focused bool
}
pub struct ProgressBarConfig {
width int
height int=16
min int
max int
val int
}
fn (mut pb ProgressBar)init(parent Layout) {
pb.parent = parent
ui := parent.get_ui()
pb.ui = ui
}
pub fn progressbar(c ProgressBarConfig) &ProgressBar {
mut p := &ProgressBar{
height: c.height
width: c.width
min: c.min
max: c.max
val: c.val
ui: 0
}
return p
}
fn (mut b ProgressBar) set_pos(x, y int) {
b.x = x
b.y = y
}
fn (mut b ProgressBar) size() (int, int) {
return b.width, b.height
}
fn (mut b ProgressBar) propose_size(w, h int) (int, int) {
/* b.width = w
b.height = h
return w, h */
if b.width == 0 {
b.width = w
}
return b.width, b.height
}
fn (b &ProgressBar) draw() {
// Draw the gray background
b.ui.gg.draw_rect(b.x, b.y, b.width, b.height, progress_bar_background_color)
b.ui.gg.draw_empty_rect(b.x, b.y, b.width, b.height, progress_bar_background_border_color)
// Draw the value
width := int(f64(b.width) * (f64(b.val) / f64(b.max)))
b.ui.gg.draw_empty_rect(b.x, b.y, width, b.height, progress_bar_border_color) // gx.Black)
b.ui.gg.draw_rect(b.x, b.y, width, b.height, progress_bar_color) // gx.Black)
}
fn (t &ProgressBar) point_inside(x, y f64) bool {
return false//x >= t.x && x <= t.x + t.width && y >= t.y && y <= t.y + t.height
}
fn (b &ProgressBar) focus() {
}
fn (t &ProgressBar) is_focused() bool {
return t.is_focused
}
fn (b &ProgressBar) unfocus() {
}