Giter Site home page Giter Site logo

fltk-webview's Issues

Windows 10, with display scale set 125%, resize of webview is strange

My OS is Windows10, and have a display scale set to 125%.

When I ran the code below, the initial webview window fit the main windows, then I resized the main window, the webview resized follow the main window, but cannot full fill it, looks like 4/5 of the main windows, yes, it's (1/(125%)).

After I set display scale to 100%, it resizes as I expect.

use fltk::{app, prelude::*, window};

fn main() {
    let app = app::App::default();

    let mut win = window::Window::default()
        .with_size(800, 600)
        .with_label("Webview");
    
    let mut wv_win = window::Window::default_fill();
    wv_win.end();
    wv_win.make_resizable(true);

    win.end();
    win.make_resizable(true);
    win.show();

    let mut wv = fltk_webview::Webview::create(false, &mut wv_win);
    wv.navigate("https://bing.com");
    
    app.run().unwrap();
}

Version 0.4 cannot be compiled, and version 0.3 has input focus issues

When using version 0.4 in cargo. toml, RustRover will prompt "Use of an undeclared type Webview [E0433]".

When using version 0.3, if a webview window is nested in the main window, the input box in the main window will lose focus when the webview page is opened, and no matter how you click on the input box in the main window with the mouse, you cannot input any characters. At the same time, the input characters will always appear on the webview page. Is there a way to regain input focus?

cargo.toml:

[dependencies]
fltk = { version = "1.4", features = ["use-ninja"]}
fltk-webview = "0.4"

C-ABI compatibility

There are 2 ways to use rust crates from C. My interest would be using web view from fltk in C.

  1. cbindgen
  2. cargo-c

Are any of these recommended ?
The cargo-c method requires

The TL;DR:

Create a capi.rs with the C-API you want to expose and use #[cfg(cargo_c)]#[cfg(feature="capi")] to hide it when you build a normal rust library.
Make sure you have a lib target and if you are using a workspace the first member is the crate you want to export, that means that you might have to add a "." member at the start of the list.
Since Rust 1.38, also add "staticlib" to the "lib" crate-type. Do not specify the crate-type, cargo-c will add the correct library target by itself.
You may use the feature capi to add C-API-specific optional dependencies.
NOTE: It must be always present in Cargo.toml

Remember to add a cbindgen.toml and fill it with at least the include guard and probably you want to set the language to C (it defaults to C++)
Once you are happy with the result update your documentation to tell the user to install cargo-c and do cargo cinstall --prefix=/usr --destdir=/tmp/some-place or something along those lines.

crashed on win7

I tried two versions of fltk-webview on Windows 7

[dependencies]
fltk-webview = "0.2"
crashed at
src/lib.rs:189:9
assert!(!inner.is_null());

[dependencies]
fltk-webview = { git = "https://github.com/fltk-rs/fltk-webview.git" }
The program cannot open because some dll are missing like
api-ms-win-ntuser-sysparams-l1-1-0.dll

Html content not displaying, but can be selected.

I have a simple project with the following code, based on the example in the docs:

use fltk::{app, prelude::*, window::Window};

fn main() {
    let app = app::App::default();
    let mut win = Window::default()
        .with_size(800, 600)
        .with_label("Hi there!");
    
    let mut webview_win = Window::default()
        .with_size(790, 590)
        .center_of_parent();
    
    win.end();
    win.make_resizable(true);
    win.show();
    
    let webview = fltk_webview::Webview::create(true, &mut webview_win);
    webview.set_html(r#"
<!doctype html>
<html>
    <head>
        <title>A title.</title>
    </head>
    <body style="color: rgb(0, 0, 0);">
        <h1>Hi there!</h1>
        <p>This is a test.</p>
    </body>
</html>
    "#);
    
    app.run().unwrap();
}

It compiles and runs just fine, but the view is blank:

fltk_webview

Interestingly, if I right-click and bring up the inspector, the content does seem to be there:

fltk_webview_inspector

Furthermore, the cursor changes to the text cursor when I hover over the areas where the text ought to be displayed, and I can drag-select (without any visible highlighting) and copy it, and paste the content into a text editor, and that works correctly with the expected content of the page being pasted.

At first I thought it might be a styling thing (e.g. the text is rendered white), but that doesn't seem to be the case, and is the reason for the style attribute on the body.

If I try to open a website with the navigate() method the same thing happens: the expected content seems to be there (shows up in the inspector, can be (invisibly) selected and copy/pasted into other applications), but just not rendered.

This feels particularly bizarre since the inspector obviously draws just fine—no idea why it would be able to draw that but not the actual web content.

I realize this may be a tricky bug to track down, and seems like the kind of thing that might be system-specific. So I'm ready to provide any help I reasonably can. Please let me know if there's anything you want me to check/test, etc.

System Info

I'm running NixOS 22.05 with X11 and AwesomeWM. Hardware-wise, I'm on an AMD x86/64 system with nVidia graphics (with the proprietary drivers). I can provide more details if that would be helpful.

Linux|X11 example glitches and high CPU load

I am running the webview example and have noticed quite some problems.

I am running:

[naikon@archdesk webview]$ screenfetch 
                   -`                 
                  .o+`                 naikon@archdesk
                 `ooo/                 OS: Arch Linux 
                `+oooo:                Kernel: x86_64 Linux 5.12.15-arch1-1
               `+oooooo:               Uptime: 28m
               -+oooooo+:              Packages: 1621
             `/:-:++oooo+:             Shell: bash 5.1.8
            `/++++/+++++++:            Resolution: 7680x2160
           `/++++++++++++++:           DE: GNOME 40.0
          `/+++ooooooooooooo/`         WM: Mutter
         ./ooosssso++osssssso+`        WM Theme: 
        .oossssso-````/ossssss+`       GTK Theme: Mcata-dark [GTK2/3]
       -osssssso.      :ssssssso.      Icon Theme: Flat-Remix-Blue-Dark
      :osssssss/        osssso+++.     Font: Noto Sans 11
     /ossssssss/        +ssssooo/-     Disk: 672G / 901G (79%)
   `/ossssso+/:-        -:/+osssso+-   CPU: AMD Ryzen 7 3700X 8-Core @ 16x 3.6GHz
  `+sso+:-`                 `.-/+oso:  GPU: Radeon RX 580 Series (POLARIS10, DRM 3.40.0, 5.12.15-arch1-1, LLVM 12.0.0)
 `++:.                           `-/+/ RAM: 4394MiB / 32118MiB
 .`                                 `/

on X11 right now (i'll check wayland later) i have some glitches while running it. First there is a very high CPU load that seems to be a symptom of what looks like that the webview is recreated multiple times. In the attached video you can see that in the application window itself the rendered website "jumps" around. I have tested this with multiple websites and i don't think it has anything to do with rendering glitches of the website with the rendering engine. I made a dual monitor capture because one thing i notices was that my "Dock" on left monitor was hiding and showing rapidly while the example was running. To give a little context here – i have a System-Monitor running in "Fullscreen" on the left monitor and in that case the "Dock" is hiding (it does while every time the focused widow would overlap it). While running the example i noticed "flashing" "mirrors" of the website that gets rendered for brief millisecons (unfortunatly it does not show on the screen capture) but the "Dock" hiding and showing indicates that for a brief moment another window is obscuring the System-Monitor and had focus. After running the example i have occasionally a "dead" window open on the exact place the "flashing" was happening after the example gets closed and i can't close that.

For me it looks like as if the webview is created rapidly multiple times and gets attached to the "main" view (resulting in the jumping of website content) and sometimes that does not work and the webview gets its "own" window poping up on the left monitor and gets closed immediately and sometimes the example application gets closed in between resulting in the "dead" window.

smaller_webview.mp4

better version of the video github only allows mp4 and i don't want the files to get overly large.

The "jumping" and "Dock" hiding etc is much more quickly without the video capturing.

screenshot of the leftover "dead" window on the left screen on the position the short lived copy of the second window
Screenshot from 2021-07-11 10-21-06

How to clean cache

I set up a file server locally. When I change the HTML content, the WebView does not change. (It works fine on the browser). Even if I delete the file, the WebView still works fine. I tried to restart the computer and delete target cargo run again ,but the cache was still there.I need to modify the file name, and then modify the url. Webview to appear the new content . any help?

Javascript bind->return example

Hello,

It would be very helpful to have a 'hello world' style example of binding a native function into the JavaScript environment and returning a value. I've been able to do the former, but haven't succeeded in actually resolving the returned promise on the JavaScript side.

On the Rust side I have:

    let wvc = wv.clone();
    wv.bind("RustMethod", move |seq, content| {
        println!("{}, {}", seq, content);
        wvc.r#return(seq, 0, "{}");
    });

On the JavaScript side I have tried a few variations on

document.addEventListener("DOMContentLoaded", function() {
    RustMethod("foo").then(
        (response) => {
            console.log("Callback " + response);
        },
        (reject) => {
            console.log("Rejection " + reject);
        }
    );
});

On the Rust side, the method is clearly invoked as evidenced by the println!() macro generating output. However, the promise returned by RustMethod seems to never resolve, suggesting that something is awry with the parameters passed to the return method.

Any pointer towards getting this to work would be much appreciated :-)

resize window , the webview gets bigger

Hi!

when I try laouts other window works fine , but the webview gets bigger and resizeble. like below

image
image
resize webview window
image
here is my code

fn main() {
    let a = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut win = window::Window::default().with_size(640, 480);

    let mut col = Flex::new(0, 0, 400, 300, None);
    col.set_color(Color::Blue);
    col.set_type(group::FlexType::Column);
    //main_panel(&mut col);

    let mut test_win = window::Window::default();
    test_win.set_color(Color::Red);
    test_win.end();

    let mut wv_win = window::Window::default();
    wv_win.make_resizable(true);
    wv_win.set_border(false);
    wv_win.end();
    //col.set_size(&test_win2, 100);
    col.end();
    win.resizable(&col);
    win.set_color(enums::Color::from_rgb(250, 250, 250));

    win.end();
    win.show();
    win.size_range(600, 400, 0, 0);
    let mut wv = fltk_webview::Webview::create(false, &mut wv_win);
    wv.navigate("https://google.com");
    a.run().unwrap();
}

any help ?

How to resize the webview

I am putting a (or multiple but it does not matter) webview(s) inside a window that is resizable. If i am coloring the windows that are used for embedding it looks like they resize accordingly.

2021-07-15_20-03-04.mp4

if i am simply using this embedded windows as the "target" of a webview, the webview does not really notice the change of its "parent" window. To let the webview know about the size change i tried to "attach" an event handler on the windows that are embedding the webview and listening for resize events and resize the webviews accordingly. Unfortunately two issues are visible, first the webview shrinks to half the size if the application window is moved and and a boarder appears around the embedded window that is dragable. Secondly i only get the resize events for the win_a and not win_b thus the second/right webview does not get the new size information.

2021-07-15_19-59-21.mp4

I think i am just doing the wrong thing here to pass the new dimensions down to the webviews. here is the code i am using

use fltk::{app, prelude::*, window::Window};
use fltk::frame::Frame;
use fltk::enums::Color;
use fltk::enums::Event;
use fltk_webview::SizeHint;

fn main() {
    let app = app::App::default();
    let mut win_main = Window::new(100, 100, 830, 620, "Hello from rust");

    let mut win_a = Window::new(10, 10, 400, 600, "frame a");
    win_a.set_color(Color::Green);
    win_a.end();

    let mut win_b = Window::new(420, 10, 400, 600, "frame b");
    win_b.set_color(Color::Blue);
    win_b.end();

    win_main.set_color(Color::White);
    win_main.make_resizable(true);
    win_main.end();
    win_main.show();

    let mut wv_a = fltk_webview::Webview::create(false, &mut win_a);
    wv_a.navigate("https://github.com/fltk-rs/fltk-rs");
    
    let mut wv_b = fltk_webview::Webview::create(false, &mut win_b);
    wv_b.navigate("https://github.com/fltk-rs/webview");
    
    win_a.handle(move |f, ev| match ev {
       Event::Resize => {
           println!("A resize happening: x:{}, y:{}, w:{}, h:{}", f.x(), f.y(), f.width(), f.height());
           wv_a.set_size(f.width(), f.height(), SizeHint::None);
           true
       },
        _ => {
            false
        }
    });
    
    win_b.handle(move |f, ev| match ev {
        Event::Resize => {
            println!("B resize happening: x:{}, y:{}, w:{}, h:{}", f.x(), f.y(), f.width(), f.height());
            wv_b.set_size(f.width(), f.height(), SizeHint::None);
            true
        },
        _ => {
            false
        }
    });

    app.run().unwrap();
}

not working for some website and script

Hi! Sorry to bother you again

i try wv.navigate("http://blog.csdn.net"); The page will appear for a second and then go blank. (wv.navigate("http://google.com"); works fine)

Js alert() is also unresponsive

and i have a <iframe> need to call

        var frame_win = getIframeWindow(el);

        frame_win.onload = () => {
            frame_win.MapComponent.mapType = 'Google'
        }

also it's not working.

I tested all the above on the browser without any problems

any help ?

Webview eval

Hello Mohammed,
I tried the webview examples and it seems to me the "eval" function doesn't work on other threads.

 // wv.dispatch(|wv| {
    std::thread::spawn(move || {
        let mut count = 0;
        loop {
            std::thread::sleep(time::Duration::from_millis(400));
            wv.eval(&format!("counter({})", count));
            count += 1;
        }
    });
    // });

The counter is not updated.
I tried with spawn and dispatch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.