Skip to content

Commit

Permalink
Merge pull request vlang#1 from rcqls/pr-no-context
Browse files Browse the repository at this point in the history
Make v ui working with last v changes
  • Loading branch information
edam authored Nov 13, 2022
2 parents 6d5895c + fd8b6e7 commit 54ebbe7
Show file tree
Hide file tree
Showing 35 changed files with 252 additions and 235 deletions.
3 changes: 2 additions & 1 deletion examples/7guis/timer.v
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fn main() {
]
)
app.window = window

// go app.timer()
ui.run(window)
}
Expand All @@ -84,7 +85,7 @@ fn (mut app App) on_value_changed(slider &ui.Slider) {

fn (mut app App) on_reset(button &ui.Button) {
app.elapsed_time = 0.0
go app.timer()
spawn app.timer()
}

fn (mut app App) timer() {
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_logview.v
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ fn (mut app App) wait_complete(mut tb ui.TextBox) {

fn (mut app App) btn_connect(btn &ui.Button) {
mut tb := app.window.textbox('tb')
go app.wait_complete(mut tb)
spawn app.wait_complete(mut tb)
}
4 changes: 2 additions & 2 deletions libvg/svg.v
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ pub fn (mut s Svg) end() {
s.content.write_string('</svg>\n')
}

pub fn (mut s Svg) save(filepath string) ? {
pub fn (mut s Svg) save(filepath string) ! {
// write it to a file
os.write_file_array(filepath, *s.content)?
os.write_file_array(filepath, *s.content)!
}

[params]
Expand Down
22 changes: 11 additions & 11 deletions src/draw_device_bitmap.v
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ pub fn (d &DrawDeviceBitmap) set_text_style(font_name string, font_path string,
}
}

fn (d &DrawDeviceBitmap) apply_text_config(mut ts &libvg.BitmapTextStyle, cfg gx.TextCfg) {
fn (d &DrawDeviceBitmap) apply_text_config(mut ts libvg.BitmapTextStyle, cfg gx.TextCfg) {
ts.font_name = if cfg.family == 'system' { 'Systemfont' } else { cfg.family }
ts.font_path = d.ts.font_path
ts.size = cfg.size
ts.color = cfg.color
ts.set_align( int( cfg.align ) )
ts.set_vertical_align( int( cfg.vertical_align ) )
ts.set_align(int(cfg.align))
ts.set_vertical_align(int(cfg.vertical_align))
}

pub fn (d &DrawDeviceBitmap) draw_text(x int, y int, text string, cfg gx.TextCfg) {
// println('$d.id draw_text_default($x, $y, $text) $d.ts')
mut ts := libvg.BitmapTextStyle{}
d.apply_text_config(mut &ts, cfg)
mut ts := libvg.BitmapTextStyle{}
d.apply_text_config(mut &ts, cfg)
mut r := d.r
r.init_style(ts)
// r.get_info_string()
Expand All @@ -109,20 +109,20 @@ pub fn (d &DrawDeviceBitmap) draw_text_default(x int, y int, text string) {
pub fn (d &DrawDeviceBitmap) draw_text_def(x int, y int, text string) {}

pub fn (d &DrawDeviceBitmap) set_text_cfg(cfg gx.TextCfg) {
mut ts := d.ts
d.apply_text_config(mut &ts, cfg)
mut ts := d.ts
d.apply_text_config(mut ts, cfg)
}

pub fn (d &DrawDeviceBitmap) text_size(s string) (int,int) {
return 0, 0
pub fn (d &DrawDeviceBitmap) text_size(s string) (int, int) {
return 0, 0
}

pub fn (d &DrawDeviceBitmap) text_width(s string) int {
return 0
return 0
}

pub fn (d &DrawDeviceBitmap) text_height(s string) int {
return 0
return 0
}

pub fn (d &DrawDeviceBitmap) scissor_rect(x int, y int, w int, h int) {}
Expand Down
10 changes: 5 additions & 5 deletions src/draw_device_print.v
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn (d &DrawDevicePrint) draw_text(x int, y int, text string, cfg gx.TextCfg)
println('$d.id draw_text($x, $y, $text, $cfg)')
}

//pub fn (d &DrawDevicePrint) draw_text_def(x int, y int, text string) {
// pub fn (d &DrawDevicePrint) draw_text_def(x int, y int, text string) {
pub fn (d &DrawDevicePrint) draw_text_default(x int, y int, text string) {
println('$d.id draw_text_default($x, $y, $text)')
}
Expand All @@ -44,16 +44,16 @@ pub fn (d &DrawDevicePrint) draw_text_def(x int, y int, text string) {}

pub fn (d &DrawDevicePrint) set_text_cfg(c_ gx.TextCfg) {}

pub fn (d &DrawDevicePrint) text_size(s string) (int,int) {
return 0, 0
pub fn (d &DrawDevicePrint) text_size(s string) (int, int) {
return 0, 0
}

pub fn (d &DrawDevicePrint) text_width(s string) int {
return 0
return 0
}

pub fn (d &DrawDevicePrint) text_height(s string) int {
return 0
return 0
}

pub fn (d &DrawDevicePrint) scissor_rect(x int, y int, w int, h int) {}
Expand Down
10 changes: 5 additions & 5 deletions src/draw_device_svg.v
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn (d &DrawDeviceSVG) draw_text(x int, y int, text string, cfg gx.TextCfg) {
s.text(x, y, text, 'none', d.ts)
}

//pub fn (d &DrawDeviceSVG) draw_text_def(x int, y int, text string) {
// pub fn (d &DrawDeviceSVG) draw_text_def(x int, y int, text string) {
pub fn (d &DrawDeviceSVG) draw_text_default(x int, y int, text string) {
// println('$d.id draw_text_default($x, $y, $text)')
mut s := d.s
Expand All @@ -93,16 +93,16 @@ pub fn (d &DrawDeviceSVG) draw_text_def(x int, y int, text string) {}

pub fn (d &DrawDeviceSVG) set_text_cfg(c gx.TextCfg) {}

pub fn (d &DrawDeviceSVG) text_size(s string) (int,int) {
return 0, 0
pub fn (d &DrawDeviceSVG) text_size(s string) (int, int) {
return 0, 0
}

pub fn (d &DrawDeviceSVG) text_width(s string) int {
return 0
return 0
}

pub fn (d &DrawDeviceSVG) text_height(s string) int {
return 0
return 0
}

pub fn (d &DrawDeviceSVG) scissor_rect(x int, y int, w int, h int) {
Expand Down
4 changes: 2 additions & 2 deletions src/extra_draw.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ui

import gx
import math
//import sokol.sgl
// import sokol.sgl

// const (
// empty_text_cfg = gx.TextCfg{}
Expand Down Expand Up @@ -362,7 +362,7 @@ pub fn update_text_texture(sg_img C.sg_image, w int, h int, buf &u8) {

// REMOVED: this function uses internals of gg.Context which we probably do not
// want to reproduce in the DrawDevice interface
//pub fn (c &CanvasLayout) draw_texture(simg C.sg_image) {
// pub fn (c &CanvasLayout) draw_texture(simg C.sg_image) {
// ctx := c.ui.gg
// cx, cy := c.x + c.offset_x, c.y + c.offset_y
// u0 := f32(0.0)
Expand Down
4 changes: 2 additions & 2 deletions src/extra_text_syntax.v
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ fn (sh &SyntaxHighLighter) is_not_included(from int, to int) bool {
}

fn (mut sh SyntaxHighLighter) add_chunk(typ string, y int, start int, end int) {
//x := sh.tv.tb.x + sh.tv.left_margin + int(sh.tv.text_width_additive(sh.ustr[0..start].string()))
// x := sh.tv.tb.x + sh.tv.left_margin + int(sh.tv.text_width_additive(sh.ustr[0..start].string()))
x := sh.tv.tb.x + sh.tv.left_margin + int(sh.tv.text_width(sh.ustr[0..start].string()))
text := sh.ustr[start..end].string()
chunk := Chunk{
x: x
y: y
text: text
//width: int(sh.tv.text_width_additive(text))
// width: int(sh.tv.text_width_additive(text))
width: int(sh.tv.text_width(text))
}
sh.chunks[typ] << chunk
Expand Down
18 changes: 9 additions & 9 deletions src/interface_draw_device.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ interface DrawDevice {
has_text_style() bool
set_text_style(font_name string, font_path string, size int, color gx.Color, align int, vertical_align int)
draw_text_default(x int, y int, text string) // (ui) default ui TextStyle
// text
draw_text(x int, y int, text string, cfg gx.TextCfg)
// text
draw_text(x int, y int, text string, cfg gx.TextCfg)
draw_text_def(x int, y int, text string) // (gg.Context) use set_text_cfg
set_text_cfg(gx.TextCfg)
text_size(string) (int,int)
text_width(string) int
text_height(string) int
set_text_cfg(gx.TextCfg)
text_size(string) (int, int)
text_width(string) int
text_height(string) int
// clipping
scissor_rect(x int, y int, w int, h int)
// drawing methods
//draw_pixel(x f32, y f32, c gx.Color)
//draw_pixels(points []f32, c gx.Color)
// draw_pixel(x f32, y f32, c gx.Color)
// draw_pixels(points []f32, c gx.Color)
draw_image(x f32, y f32, width f32, height f32, img &gg.Image)
draw_triangle_empty(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, color gx.Color)
draw_triangle_filled(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, color gx.Color)
Expand All @@ -38,7 +38,7 @@ interface DrawDevice {
draw_convex_poly(points []f32, color gx.Color)
draw_poly_empty(points []f32, color gx.Color)
mut:
set_bg_color(color gx.Color)
set_bg_color(color gx.Color)
}

fn (d DrawDevice) draw_window(mut w Window) {
Expand Down
42 changes: 21 additions & 21 deletions src/interface_drawtextwidget.v
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,26 @@ pub fn (mut w DrawTextWidget) load_style_(d DrawDevice, ts TextStyle) {
int(ts.align), int(ts.vertical_align))
}
$if !screenshot ? {
if mut w.ui.dd is gg.Context {
gg := w.ui.dd
fons := gg.ft.fons
fons.set_font(w.ui.fonts.hash[ts.font_name])

scale := if gg.ft.scale == 0 { f32(1) } else { gg.ft.scale }
size := if ts.mono { ts.size - 2 } else { ts.size }
fons.set_size(scale * f32(size))
gg.ft.fons.set_align(int(ts.align) | int(ts.vertical_align))
color := sfons.rgba(ts.color.r, ts.color.g, ts.color.b, ts.color.a)
if ts.color.a != 255 {
sgl.load_pipeline(gg.timage_pip)
}
gg.ft.fons.set_color(color)
ascender := f32(0.0)
descender := f32(0.0)
lh := f32(0.0)
fons.vert_metrics(&ascender, &descender, &lh)
// println("load style $ascender, $descender ${}")
}
if mut w.ui.dd is gg.Context {
gg := w.ui.dd
fons := gg.ft.fons
fons.set_font(w.ui.fonts.hash[ts.font_name])

scale := if gg.ft.scale == 0 { f32(1) } else { gg.ft.scale }
size := if ts.mono { ts.size - 2 } else { ts.size }
fons.set_size(scale * f32(size))
gg.ft.fons.set_align(int(ts.align) | int(ts.vertical_align))
color := sfons.rgba(ts.color.r, ts.color.g, ts.color.b, ts.color.a)
if ts.color.a != 255 {
sgl.load_pipeline(gg.timage_pip)
}
gg.ft.fons.set_color(color)
ascender := f32(0.0)
descender := f32(0.0)
lh := f32(0.0)
fons.vert_metrics(&ascender, &descender, &lh)
// println("load style $ascender, $descender ${}")
}
}
}

Expand Down Expand Up @@ -195,7 +195,7 @@ pub fn (w DrawTextWidget) text_width(text string) int {

// REMOVED: this function uses internals of gg.Context which we probably do not
// want to reproduce in the DrawDevice interface
//pub fn (w DrawTextWidget) text_width_additive(text string) f64 {
// pub fn (w DrawTextWidget) text_width_additive(text string) f64 {
// ctx := w.ui.gg
// adv := ctx.ft.fons.text_bounds(0, 0, text, &f32(0))
// return adv / ctx.scale
Expand Down
40 changes: 20 additions & 20 deletions src/interface_focusable.v
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ pub fn (mut f Focusable) set_focus() {
return
}
if f.is_focused {
if mut w.ui.dd is gg.Context {
$if focus ? {
println('$f.id already has focus at $w.ui.dd.frame')
}
}
if mut w.ui.dd is gg.Context {
$if focus ? {
println('$f.id already has focus at $w.ui.dd.frame')
}
}
return
}
Layout(w).unfocus_all()
if f.has_focusable() {
f.is_focused = true
if mut w.ui.dd is gg.Context {
$if focus ? {
println('$f.id has focus at $w.ui.dd.frame')
}
}
if mut w.ui.dd is gg.Context {
$if focus ? {
println('$f.id has focus at $w.ui.dd.frame')
}
}
}
// update drawing_children when focus is taken
f.update_parent_drawing_children()
Expand All @@ -60,20 +60,20 @@ pub fn (mut f Focusable) set_focus() {
pub fn (mut f Focusable) force_focus() {
mut w := f.ui.window
if f.is_focused {
if mut w.ui.dd is gg.Context {
$if focus ? {
println('$f.id already has focus at $w.ui.dd.frame')
}
}
if mut w.ui.dd is gg.Context {
$if focus ? {
println('$f.id already has focus at $w.ui.dd.frame')
}
}
return
}
Layout(w).unfocus_all()
f.is_focused = true
if mut w.ui.dd is gg.Context {
$if focus ? {
println('$f.id has focus at $w.ui.dd.frame')
}
}
if mut w.ui.dd is gg.Context {
$if focus ? {
println('$f.id has focus at $w.ui.dd.frame')
}
}
}

pub fn (f Focusable) lock_focus() {
Expand Down
Loading

0 comments on commit 54ebbe7

Please sign in to comment.