Eliminating the GWT Window Padding in LibGDX

Explanation:

I am currently in the process of deploying a LibGDX GWT application to the browser.

Challenge:

In the image below, you can see the top left portion of my GWT application showcased by the large black rectangle. The issue here is the unwanted padding in the default grey color surrounding the application.

https://i.sstatic.net/Vb5hR.png

The next image displays the bottom right section of my GWT application with an undesired browser scrollbar, possibly caused by the aforementioned padding.

https://i.sstatic.net/I3OIQ.png

Objective:

My main goal is to present the complete GWT application without any cutoffs and distractions, essentially maximizing the use of screen space according to the client’s browser resolution. This means eliminating any padding or scrollbars and focusing solely on displaying the fully resolved content (while keeping the URL/bookmark section intact).

How do I align my GWT application (the content within the black rectangle) to the top-left corner to remove any unnecessary padding?

Additional Details:

  • The screenshots above are taken from a browser resolution of 1920x1080.

  • When running Gdx.app.log() on the platform-specific code, Width.getClientWidth() provides 1903, and Window.getClientHeight() gives 938 as output.

HtmlLauncher.java

public class HtmlLauncher extends GwtApplication {

    @Override
    public GwtApplicationConfiguration getConfig() {
        return new GwtApplicationConfiguration(Window.getClientWidth(), Window.getClientHeight());
    }

    @Override
    public ApplicationListener getApplicationListener() {
        return Engine.getInstance();
    }
}

Window.class

/**
   * Retrieves the height of the client area of the browser window, excluding the scrollbar.
   *
   * @return the height of the client area of the window
   */
  public static int getClientHeight() {
    return Document.get().getClientHeight();
  }

  /**
   * Retrieves the width of the client area of the browser window, excluding the vertical scrollbar.
   *
   * @return the width of the client area of the window
   */
  public static int getClientWidth() {
    return Document.get().getClientWidth();
  }

index.html

<!doctype html>
<html>
       <head>
              <title>My Game</title>
              <meta http-equiv="content-type" content="text/html; charset=UTF-8">
              <link href="styles.css" rel="stylesheet" type="text/css">
              <script src="soundmanager2-setup.js"></script>
              <script src="soundmanager2-jsmin.js"></script>
       </head>

       <body>
              <script type="text/javascript" src="html/html.nocache.js"></script>
       </body>
</html>

styles.css

canvas {
    cursor: default;
    outline: none;
}

body {
    background-color: #222222;
}

.superdev {
    color: rgb(37,37,37);
    text-shadow: 0px 0px 0px rgba(250,250,250,0.1);
    font-size: 50pt;
    display: block;
    position: relative;
    text-decoration: none;
    background-color: rgb(83,87,93);
    box-shadow: 0px 0px 0px 0px rgb(34,34,34),
                0px 0px 0px 0px rgb(17,17,17),
                inset 0px 0px 0px 0px rgba(250, 250, 250, .2),
                inset 0px 0px 0px 0px rgba(0, 0, 0, .5);
    width: 0px;
    height: 0px;
    border: 0;
    border-radius: 0px;
    text-align: center;
    line-height: 0px;
}

.superdev:active {
    box-shadow: 0px 0px 0px 0px rgb(34,34,34),
                0px 0px 0px 0px rgb(17,17,17),
                inset 0px 0px 0px 0px rgba(250, 250, 250, .2),
                inset 0px 0px 0px 0px rgba(0, 0, 0, .5);
    background-color: rgb(83,87,93);
    top: 0px;
    color: #fff;
    text-shadow: 0px 0px 0px rgb(250,250,250);
}

.superdev:hover {
    background-color: rgb(100,100,100);
}

Note: Certain default values in index.html and styles.css have been altered during troubleshooting efforts to address certain issues.

Answer №1

As stated in this post:

To resolve the issue, simply add 'margin: 0;' to the body tag in your CSS and 'display: block;' to the canvas tag in your CSS.

Here is an example:

canvas {
    display:block;
}

body {
    margin:0;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Cannot populate Kendo Menu with images due to dataSource imageUrl not recognizing the content

I have integrated Kendo controls into my application, specifically a Menu control with a datasource in my controller. Currently, I am passing the relative path of URL for imageUrl. However, as the application has grown, there are multiple calls being made ...

When using Selenium to locate a sub element within a previously obtained WebElement using xpath, it will always return the first match found on the entire

Currently, my project involves using selenium and python to automate website testing. I am facing an issue while trying to extract links to files on the website using the following approach: I first use divs = find_elements_by_css_selector("div.answer") to ...

Why is it that Lotus Notes is unable to render this HTML code properly?

I am having trouble with an email that displays properly on every platform except Lotus Notes. Can anyone provide insight as to why this email is not rendering correctly in Notes? Here is a screenshot: img (please note the images are for demonstration pu ...

The vertical-align property fails to properly align the list-style-image with the text

My HTML list is structured like this: <ul id="remove"> <li id="rm_txt_1" onClick="remove_1();">Remove </li> </ul> <ul id="move"> <li id="mv_txt_1" onClick="position();">Move Down</li> </ul> It is styled u ...

I'm having trouble connecting two files as instructed and encountering errors. Can someone please provide guidance on how to properly attach them?

I am encountering an issue when trying to call the DevideByZeroo method as it keeps displaying "cannot find symbol". Despite attempting to change it to super, I continue to receive errors. package CatchBlock; import java.util.Scanner; import java.util.In ...

How can custom JavaScript objects have tags set upon click?

When it comes to JavaScript object referring, things can get a bit confusing. Imagine having a tag like this: <button id='myButton'>Hello</button> Now, let's say you create a custom class in JavaScript: function myClass(){ ...

Prevent the Spread of an Event for a Particular Controller

tl;dr Summary Develop a function that is able to handle a specific event on multiple elements within a hierarchy. The function should execute when the event is triggered on the first element reached during bubbling, but should not continue executing or re ...

Issue with horizontal scrolling functionality in DataTables

I have a table with over 10 columns, and I am using datatables to display the data. I have enabled horizontal scrolling due to the large number of columns, but the scroll is not appearing. Can someone please assist me with this issue? Here is a screenshot ...

What's the deal with ajax constantly failing to deliver results?

Here is the ajax function that I have been working with: $.post({ url: "login", data: { nomutilisateur: nomutilisateur, motdepasseutilisateur: motdepasseutilisateur } }).done(function() { console.log("Success"); }).f ...

Are there any alternative approaches to handling frequent database updates in web development aside from using Websockets/AJAX for coding?

Currently, I'm in the process of developing an HTML and Javascript game and looking to implement a feature that displays the player's gold balance on the screen. The goal is to have this balance decrement by 1 every time the player clicks on a sp ...

Rows in the table are distinguished by varying colors

Is it achievable to replicate this design solely using table CSS style? I am able to assign different colors to even and odd rows, but my goal is to achieve something like this (just the colors): ...

Angular: Disabling a button based on an empty datepicker selection

Can anyone help me figure out how to disable a button when the datepicker value is empty? I've tried using ngIf to check if the datepicker is empty and then disable the button, but it's not working. My goal is to make the button unclickable if th ...

Convert JSON data without backslashes using json_encode

I am having an issue where I retrieve a JSON encoded array from the database, modify one field, and then save it again. However, when I use json_encode, it removes the backslashes and as a result, the text is not displayed correctly on my site. $data_de=j ...

Selenium: Unstable Webdriver Error - Tracing the Issue

Having trouble consistently clicking on the submit button within the modal? It seems to only work occasionally. Take a look at the HTML element in question: <button id="submit-btn" name="submit" data-dismiss="modal" type="submit" class="btn btn-info b ...

I am not seeing the results I anticipated from my HTML and PHP codes

Currently, I am working on creating a code for a game that involves guessing a random odd number between 1 and 99. My code is as follows- <?php $heading = "Welcome to the guessing game"; $num_to_guess = rand(1,99); if(!isset($_POST['guess']) ...

Manipulate JSON values within a JSON array in Java

{ "page": { "size": 2, "number": 2 }, "places": [ { "eventName": "XYZ", "createdByUser": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Performing read and write operations on targeted CSS classes using C#

I'm currently developing a C# application that needs to manipulate CSS files. Imagine you have the following CSS code snippet: .ClassOne { color: #FFFFFF; font-weight:normal; font-size: 9pt; font-family: Tahoma; ...

Is there a way for me to upload a csv file along with a password_hash

I have successfully implemented this code on my website, allowing me to upload CSV files to my database. However, I am looking to enhance the security measures by changing $item2 from a numerical password to a password_hash. ($data[1] currently represent ...

How would you go about creating a VueJS component that displays a table with a set number of columns and automatically distributes the cells within them?

Hey there! I'm currently working with a VueJS component that looks like this: <template> <div> <table> <tbody> <tr v-for="(item, index) in items" :key="index"> <t ...

Exploring Partial Views in Bootstrap Single Page View and AngularJS

Currently, I am utilizing Bootstrap's single page view design, specifically the one found at this link: http://www.bootply.com/85746. As my code in the view has grown to nearly 500 lines and is expected to expand further, I am seeking a method to crea ...