-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogressbar.v
99 lines (85 loc) · 2.1 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
98
99
// 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 pb := &ProgressBar{
height: c.height
width: c.width
min: c.min
max: c.max
val: c.val
ui: 0
}
return pb
}
fn (mut pb ProgressBar) set_pos(x int, y int) {
pb.x = x
pb.y = y
}
fn (mut pb ProgressBar) size() (int, int) {
return pb.width, pb.height
}
fn (mut pb ProgressBar) propose_size(w int, h int) (int, int) {
/*
pb.width = w
pb.height = h
return w, h
*/
if pb.width == 0 {
pb.width = w
}
return pb.width, pb.height
}
fn (pb &ProgressBar) draw() {
// Draw the gray background
pb.ui.gg.draw_rect(pb.x, pb.y, pb.width, pb.height, progress_bar_background_color)
pb.ui.gg.draw_empty_rect(pb.x, pb.y, pb.width, pb.height, progress_bar_background_border_color)
// Draw the value
width := int(f64(pb.width) * (f64(pb.val) / f64(pb.max)))
pb.ui.gg.draw_empty_rect(pb.x, pb.y, width, pb.height, progress_bar_border_color) // gx.Black)
pb.ui.gg.draw_rect(pb.x, pb.y, width, pb.height, progress_bar_color) // gx.Black)
}
fn (pb &ProgressBar) point_inside(x f64, y f64) bool {
return false // x >= pb.x && x <= pb.x + pb.width && y >= pb.y && y <= pb.y + pb.height
}
fn (pb &ProgressBar) focus() {
}
fn (pb &ProgressBar) is_focused() bool {
return pb.is_focused
}
fn (pb &ProgressBar) unfocus() {
}