[go: up one dir, main page]

Skip to content

Commit

Permalink
hidden property; fix delete_all_cookies on macos; min width/height;
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Mar 28, 2024
1 parent 7a768a3 commit bde4279
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/chunkview.v
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn (mut c ParaChunk) update_chunks(cv &ChunkView) {
ind = -2
} else {
// index of last whitespace except when at the end
ind = left.trim_right(' ').index_last(' ') or { -2 }
ind = left.trim_right(' ').last_index(' ') or { -2 }
if ind >= 0 {
if right.len == 0 {
right = left[(ind + 1)..]
Expand Down
2 changes: 2 additions & 0 deletions src/layout_row.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub:
scrollview bool
clipping bool
children []Widget
hidden bool
}

pub fn row(c RowParams) &Stack {
Expand All @@ -50,5 +51,6 @@ pub fn row(c RowParams) &Stack {
scrollview: c.scrollview
clipping: c.clipping
children: c.children
// hidden: c.hidden
)
}
2 changes: 2 additions & 0 deletions src/stack.v
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct StackParams {
scrollview bool
clipping bool
children []Widget
hidden bool
}

fn stack(c StackParams) &Stack {
Expand All @@ -150,6 +151,7 @@ fn stack(c StackParams) &Stack {
alignments: c.align
style_params: c.StackStyleParams
title: c.title
hidden: c.hidden
ui: unsafe { nil }
}
s.style_params.style = c.theme
Expand Down
1 change: 1 addition & 0 deletions src/style_drawtextwidget.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mut:
text_size f64
text_align TextHorizontalAlign = .@none
text_vertical_align TextVerticalAlign = .@none
cursor_color gx.Color = no_color
}

// Style with Text
Expand Down
65 changes: 38 additions & 27 deletions src/textbox.v
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ pub fn (mut tb TextBox) draw() {
}

pub fn (mut tb TextBox) draw_device(mut d DrawDevice) {
mut is_native_rendering := false
$if macos {
is_native_rendering = tb.ui.gg.native_rendering
}
offset_start(mut tb)
defer {
offset_end(mut tb)
Expand Down Expand Up @@ -392,13 +396,13 @@ pub fn (mut tb TextBox) draw_device(mut d DrawDevice) {
// Placeholder
if text == '' && placeholder != '' {
dtw.draw_device_styled_text(d, tb.x + ui.textbox_padding_x, text_y, placeholder,
color: gx.gray
color: gx.gray // tb.text_color
)
// Native text rendering
$if macos {
if tb.ui.gg.native_rendering {
tb.ui.gg.draw_text(tb.x + ui.textbox_padding_x, text_y, placeholder,
color: gx.gray
color: gx.gray // tb.text_color
)
}
}
Expand All @@ -408,31 +412,33 @@ pub fn (mut tb TextBox) draw_device(mut d DrawDevice) {
// Selection box
tb.draw_selection()
// Native text rendering
$if macos {
if tb.ui.gg.native_rendering {
tb.ui.gg.draw_text(tb.x + ui.textbox_padding_x, text_y, text)
}
}
// The text doesn't fit, find the largest substring we can draw
if tb.large_text { // width > tb.width - 2 * ui.textbox_padding_x && !tb.is_password {
if !tb.is_focused || tb.read_only {
skip_idx := tb.skip_index_from_start(ustr, dtw)
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x, text_y, ustr[..(skip_idx +
1)].string())
} else {
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x, text_y, ustr[tb.draw_start..tb.draw_end].string())
}
if is_native_rendering {
tb.ui.gg.draw_text(tb.x + ui.textbox_padding_x, text_y, text,
color: tb.style_params.text_color
)
} else {
if tb.is_password {
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x, text_y, '*'.repeat(text_len))
// The text doesn't fit, find the largest substring we can draw
if tb.large_text { // width > tb.width - 2 * ui.textbox_padding_x && !tb.is_password {
if !tb.is_focused || tb.read_only {
skip_idx := tb.skip_index_from_start(ustr, dtw)
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x, text_y, ustr[..(
skip_idx + 1)].string())
} else {
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x, text_y, ustr[tb.draw_start..tb.draw_end].string())
}
} else {
if tb.justify != top_left {
mut aw := AdjustableWidget(tb)
dx, dy := aw.get_align_offset(tb.justify[0], tb.justify[1])
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x + dx, text_y + dy,
text)
if tb.is_password {
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x, text_y, '*'.repeat(text_len))
} else {
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x, text_y, text)
if tb.justify != top_left {
mut aw := AdjustableWidget(tb)
dx, dy := aw.get_align_offset(tb.justify[0], tb.justify[1])
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x + dx,
text_y + dy, text)
} else {
dtw.draw_device_text(d, tb.x + ui.textbox_padding_x, text_y,
text)
}
}
}
}
Expand All @@ -457,9 +463,14 @@ pub fn (mut tb TextBox) draw_device(mut d DrawDevice) {
cursor_x += dtw.text_width(left)
}
}
// tb.ui.dd.draw_line(cursor_x, tb.y+2, cursor_x, tb.y-2+tb.height-1)//, gx.Black)
d.draw_rect_filled(cursor_x, tb.y + ui.textbox_padding_y, 1, tb.line_height,
gx.black) // , gx.Black)
if is_native_rendering {
tb.ui.gg.draw_rect_filled(cursor_x, tb.y + ui.textbox_padding_y, 1, tb.line_height,
tb.style_params.cursor_color)
} else {
// tb.ui.dd.draw_line(cursor_x, tb.y+2, cursor_x, tb.y-2+tb.height-1)//, gx.Black)
d.draw_rect_filled(cursor_x, tb.y + ui.textbox_padding_y, 1, tb.line_height,
tb.style_params.cursor_color)
}
}
}
$if bb ? {
Expand Down
8 changes: 8 additions & 0 deletions src/ui.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mut:
keymods KeyMod
styles map[string]Style
style_colors []gx.Color
// run_fn fn () = unsafe { nil }
mut:
cb_image gg.Image
// used only in checkbox.v
Expand Down Expand Up @@ -206,6 +207,13 @@ pub fn run(window &Window) {
// waiting 2x this time should be enough to ensure the gui.loop
// thread will exit before us, without using a waitgroup here too
time.sleep(20 * time.millisecond)

/*
if gui.run_fn != unsafe { nil } {
gui.run_fn()
gui.run_fn = unsafe { nil }
}
*/
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/window.v
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pub:
enable_dragndrop bool = true
max_dropped_files int = 5
max_dropped_file_path_length int = 2048
min_width int = 100
min_height int = 100
}

pub fn window(cfg WindowParams) &Window {
Expand Down Expand Up @@ -249,7 +251,8 @@ pub fn window(cfg WindowParams) &Window {
Context: gg.new_context(
width: width
height: height
use_ortho: true // This is needed for 2D drawing
min_width: cfg.min_width
min_height: cfg.min_height
create_window: true // TODO: Unused ?
window_title: cfg.title
resizable: resizable
Expand Down Expand Up @@ -496,6 +499,10 @@ fn frame_native(mut w Window) {
}
*/

if w.on_draw != WindowFn(0) {
w.on_draw(w)
}

mut children := if unsafe { w.child_window == 0 } { w.children } else { w.child_window.children }
// if w.child_window == 0 {
// Render all widgets, including Canvas
Expand Down
10 changes: 9 additions & 1 deletion webview/webview.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ type NavFinishedFn = fn (url string)
pub struct WebView {
// widget ui.Widget
url string
obj voidptr
mut:
nav_finished_fn NavFinishedFn = NavFinishedFn(0)
pub:
obj voidptr
}

pub struct Config {
Expand Down Expand Up @@ -53,6 +54,13 @@ pub fn get_global_js_val() string {
return ''
}

pub fn get_global_cookie_val() string {
$if macos {
return C.darwin_get_webview_cookie_val()
}
return ''
}

pub fn (mut wv WebView) on_navigate_fn(nav_callback fn (url string)) {
wv.nav_finished_fn = nav_callback
}
Expand Down
13 changes: 10 additions & 3 deletions webview/webview_darwin.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ fn C.new_darwin_web_view(url string, title string, js_on_init string) voidptr
// fn create_darwin_web_view(url string, title string) {
// C.new_darwin_web_view(url, title)
//}
fn C.darwin_webview_eval_js(obj voidptr, js string, result &string) string
// fn C.darwin_webview_eval_js(obj voidptr, js string, result &string) string
fn C.darwin_webview_eval_js(obj voidptr, js string) string

fn C.darwin_webview_load(obj voidptr, url string)
fn C.darwin_delete_all_cookies2(obj voidptr)

fn C.darwin_webview_close()

pub fn (w &WebView) eval_js(s string, result &string) {
C.darwin_webview_eval_js(w.obj, s, result)
pub fn (w &WebView) eval_js(s string) { //, result &string) {
C.darwin_webview_eval_js(w.obj, s) //, result)
}

pub fn (w &WebView) load(url string) {
Expand All @@ -28,4 +30,9 @@ pub fn delete_all_cookies() {
C.darwin_delete_all_cookies()
}

pub fn (w &WebView) delete_all_cookies() {
C.darwin_delete_all_cookies2(w.obj)
}

fn C.darwin_get_webview_js_val() string
fn C.darwin_get_webview_cookie_val() string
Loading

0 comments on commit bde4279

Please sign in to comment.