Skip to content

Commit

Permalink
update to latest ui
Browse files Browse the repository at this point in the history
  • Loading branch information
pisaiah committed Nov 9, 2024
1 parent 473d693 commit eb916b2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/color_picker.v
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn (mut cp ColorPicker) open_color_picker(c ?gx.Color) &ui.Modal {

close.subscribe_event('mouse_up', cp.default_modal_close_fn)
close.set_bounds(12, y, 208, 30)
close.set_accent_filled(true)

mut can := m.make_close_btn(true)
can.text = 'Cancel'
Expand Down
27 changes: 24 additions & 3 deletions src/image_view.v
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,18 @@ fn (mut this Image) set(x int, y int, color gx.Color) bool {
}

fn (mut this Image) set2(x int, y int, color gx.Color, batch bool) bool {

if x < 0 || y < 0 || x >= this.w || y >= this.h {
// dump('${x} ${y}')
return false
}

from := this.get(x, y)
if from == color {
return true
}

// dump('debug: set2 ${this.history.len}')

change := Change{
x: x
Expand All @@ -249,7 +257,8 @@ fn (mut this Image) set2(x int, y int, color gx.Color, batch bool) bool {
this.history.insert(0, change)
}

return set_pixel(this.data.file, x, y, color)
set_pix(this.data.file, x, y, color)
return true
}

fn (mut this Image) set_no_undo(x int, y int, color gx.Color) bool {
Expand All @@ -261,8 +270,9 @@ fn (mut this Image) get(x int, y int) gx.Color {
}

fn (mut this Image) refresh() {
mut data := this.data
refresh_img(mut data, mut this.app.win.gg)
// mut data := this.data
// refresh_img(mut data, mut this.app.win.gg)
this.app.win.gg.update_pixel_data(this.data.id, this.data.file.data)
}

// Get RGB value from image loaded with STBI
Expand All @@ -286,6 +296,17 @@ fn set_pixel(image stbi.Image, x int, y int, color gx.Color) bool {
}
}

fn set_pix(image stbi.Image, x int, y int, color gx.Color) {
unsafe {
data := &u8(image.data)
p := data + (4 * (y * image.width + x))
p[0] = color.r
p[1] = color.g
p[2] = color.b
p[3] = color.a
}
}

// IMAGE

// Image - implements Component interface
Expand Down
17 changes: 12 additions & 5 deletions src/menubar.v
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,13 @@ fn about_click(mut win ui.Window, com ui.MenuItem) {
modal.in_width = 300
modal.in_height = 290

mut title := ui.Label.new(text: 'VPaint')
title.set_config(32, true, true)
title.pack()
mut title := ui.Label.new(
text: 'VPaint'
bold: true
em_size: 2
vertical_align: .middle
pack: true
)

mut p := ui.Panel.new(
layout: ui.BorderLayout.new(
Expand All @@ -406,8 +410,11 @@ fn about_click(mut win ui.Window, com ui.MenuItem) {
)
p.add_child_with_flag(title, ui.borderlayout_north)

mut lbl := ui.Label.new(text: about_text.join('\n'))
lbl.pack()
mut lbl := ui.Label.new(
text: about_text.join('\n')
pack: true
vertical_align: .middle
)
p.add_child_with_flag(lbl, ui.borderlayout_center)

mut lp := ui.Panel.new(
Expand Down

0 comments on commit eb916b2

Please # to comment.