1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples/times_table: simplify

This commit is contained in:
Alexander Medvednikov
2019-04-14 08:31:13 +02:00
parent 257c21745a
commit 8b27681de0

View File

@ -27,18 +27,14 @@ fn main() {
// ui.Window uses native drawing API (Core Graphics, GDI+) // ui.Window uses native drawing API (Core Graphics, GDI+)
fn draw() { fn draw() {
// Horizontal header
gx.draw_rect(0, 0, WIN_SIZE, CELL_SIZE, HEADER_COLOR)
// Vertical header
gx.draw_rect(0, 0, CELL_SIZE, WIN_SIZE, HEADER_COLOR)
for i := MIN; i <= MAX; i++ { for i := MIN; i <= MAX; i++ {
y := CELL_SIZE * (i - MIN) y := CELL_SIZE * (i - MIN)
for j := MIN; j <= MAX; j++ { for j := MIN; j <= MAX; j++ {
x := CELL_SIZE * (j - MIN) x := CELL_SIZE * (j - MIN)
// Horizontal header
if i == MIN {
gx.draw_rect(x, y, CELL_SIZE, CELL_SIZE, HEADER_COLOR)
}
// Vertical header
if j == MIN {
gx.draw_rect(x, y, CELL_SIZE, CELL_SIZE, HEADER_COLOR)
}
// Draw the result // Draw the result
if ! (i == MIN && j == MIN) { if ! (i == MIN && j == MIN) {
res := i * j res := i * j
@ -49,13 +45,11 @@ fn draw() {
} }
gx.draw_text(x + text_padding_x, y + text_padding_y, res.str(), TEXT_CFG) gx.draw_text(x + text_padding_x, y + text_padding_y, res.str(), TEXT_CFG)
} }
// Vertical lines
if i == MIN {
gx.draw_line(x, 0, x, WIN_SIZE)
}
} }
// Horizontal lines // Horizontal lines
gx.draw_line(0, y, WIN_SIZE, y) gx.draw_line(0, y, WIN_SIZE, y)
// Vertical lines
gx.draw_line(y, 0, y, WIN_SIZE)
} }
} }