Project

General

Profile

WNavigationBar looks different from WidgetGallery, also has other classes

Added by Christian Meyer 17 days ago

Hi there,

I want a right aligned Item in the Navbar.
And I am Stumped...

There is so much different in the structure of the HTML from the WidgetGallery and my own...

Here is the HTML from the Gallery

The Order in the Gallery, as well as in the Bootstrap examples is Brand Button Collapse

Here is the HTML from my Code

As you can see there is an Ordering difference: Button Brand Collapse.
Also a nested <div class="navbar-inner"> that has no styles attached to the class.

I think somebody ran into a weird styling issue with the wrong order and "fixed" it with the additional "<div class="navbar-inner"> but killed the flex layout this way.

Currently the rendering of the WNavigationBar is also different: The BrandName Component is in its own Line, and below are the Menu Items.
By Accident I changed the End-Margin on the Brand container and the Widget I want to Add to the right side of the Navbar on Login, moves further away.

I added a Bug Report for the Collapse Icon: http://redmine.emweb.be/issues/13754, but as my generated HTML is not the same as the Gallery, I am not sure how to find out whether it is me or something else.

Here is my cpp Code for the Navigation

Bug_Bootstrap_Layout_2.PNG (10.6 KB) Bug_Bootstrap_Layout_2.PNG Login Widget Added, should be Aligned-right
Bug_Bootstrap_Layout_1.PNG (8.21 KB) Bug_Bootstrap_Layout_1.PNG Brand Above Nav Items
Bug_Bootstrap_Layout_4.PNG (10.5 KB) Bug_Bootstrap_Layout_4.PNG Expanded NavBar Items not stacked as expected
Bug_Bootstrap_Layout_5.PNG (13.2 KB) Bug_Bootstrap_Layout_5.PNG Showing accidental margin-end moves login Widget
Bug_Bootstrap_Layout_6.PNG (10.2 KB) Bug_Bootstrap_Layout_6.PNG Taking out the additional div causes OneLine Layout
Bug_Bootstrap_Layout_muster.PNG (17.6 KB) Bug_Bootstrap_Layout_muster.PNG Expected Expanded Rendering From Gallery

Replies (6)

RE: WNavigationBar looks different from WidgetGallery, also has other classes - Added by Mark Travis 16 days ago

Here's the way I did it. I might change this since I did this before I learned other techniques using pure CSS with Flex, but take from it what you will.

I still learn new ways of doing things daily, so this may or may not be the ideal way, but it works for now.

Here's an image of my solution:

I defined the following in a WTemplate:

           <nav class="navbar navbar-main navbar-expand-md mt-4 top-1 px-0 mx-4 shadow-none border-radius-xl z-index-sticky" id="navbarBlur" data-scroll="true">
                <div class="container-fluid py-1 px-3">
                    <a class="navbar-brand m-0" >
                        <img src="graphics/Fractal-Rock-Sol-graphic-transparent-61x80.png" class="navbar-brand-img h-100" alt="main_logo"></img>
                        <span class="ms-1 font-weight-bold">Fractal Insights : ${current-version}</span>
                    </a>
                    <div class="navbar-collapse mt-sm-0 mt-2 me-md-0 me-sm-4" id="navbar">
                        <div class="ms-md-auto pe-md-3 d-flex align-items-center">

                        </div>
                        <ul class="navbar-nav justify-content-end">
                            <li class="nav-item">
                                ${log-out-and-admin-button}
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>

Then used this c++ code:

    addLanguage(Lang("en", "/", "en", "English"));
    addLanguage(Lang("fr", "/fr/", "fr", "Français (French)"));
    addLanguage(Lang("hi", "/hi/", "हिंदी", "हिन्दी भाषा (Hindi)"));

    auto editAccountButton = std::make_unique<Wt::WPushButton>();
    editAccountButton->setText("<span class=\"btn-inner--icon\"><i class=\"material-icons\">account_circle</i></span>");
    editAccountButton->setTextFormat(Wt::TextFormat::XHTML);
    editAccountButton->setStyleClass("btn-info");
    editAccountButton_ = editAccountButton.get();

    auto logoutButton = std::make_unique<Wt::WPushButton>("Logout");
     logoutButton_ = logoutButton.get();
     logoutButton_->addStyleClass("btn-danger");
     logoutButton_->setMargin(10,Wt::Side::Left);
     logoutButton_->setMargin(10,Wt::Side::Right);

     auto adminButton = std::make_unique<Wt::WPushButton>("Admin");
    adminButton_ = adminButton.get();
    adminButton_->addStyleClass("btn-success");
    adminButton_->setMargin(10,Wt::Side::Right);
    adminButton_->hide();

    auto languageChoiceComboBox = std::make_unique<Wt::WComboBox>();
    languageChoiceComboBox_ = languageChoiceComboBox.get();
    languageChoiceComboBox_->setStyleClass("text-center");
    languageChoiceComboBox_->setMargin(10,Wt::Side::Left);
    languageChoiceComboBox_->setMargin(20,Wt::Side::Top);
    languageChoiceComboBox_->setWidth(Wt::WLength(100, Wt::LengthUnit::Percentage));
    languageChoiceComboBox_->setHeight(Wt::WLength(35, Wt::LengthUnit::Percentage));
    for (int i = 0; i < languages.size(); i++) {
        languageChoiceComboBox_->addItem(languages[i].longDescription_);
    }
    languageChoiceComboBox_->changed().connect([=]{
        setLanguage(languageChoiceComboBox_->currentIndex());
    });

    auto rightBoundingBox = std::make_unique<Wt::WContainerWidget>();
    rightBoundingBox->addWidget(std::move(editAccountButton));
    rightBoundingBox->addWidget(std::move(logoutButton));
    rightBoundingBox->addWidget(std::move(adminButton));
    rightBoundingBox->addWidget(std::move(languageChoiceComboBox));

     appLayout->bindWidget("log-out-and-admin-button",std::move(rightBoundingBox));

And I believe these are the relevant css rules from material-dashboard.css (Creative Tim)

@media (min-width: 768px) {
  .navbar-expand-md {
    flex-wrap: nowrap;
    justify-content: flex-start;
  }
}

.navbar > .container-fluid
{
  display: flex;
  flex-wrap: inherit;
  align-items: center;
  justify-content: space-between;
}

.d-flex {
  display: flex !important;
}

@media (min-width: 768px) {
  .navbar-expand-md .navbar-nav {
    flex-direction: row;
  }
}

.justify-content-end {
  justify-content: flex-end !important;
}

I think that's everything. Most of the other rules had to do with margins, padding, gutters, etc.

In another instance, I used col-3, col-7, col-2 and left col-7 blank. That was a sledgehammer approach.

RE: WNavigationBar looks different from WidgetGallery, also has other classes - Added by Christian Meyer 16 days ago

Thank you Travis,

if adding the widget to the right side was the only thing I wanted, I would probably use a similar approach.

But I want the WNavigationBar and its function as advertised and intended =)

Changing a few things on the generated HTML do give the expected rendering result.
But that was in the console and not within the program.

I am mostly wondering about why my generated HTML is so much different than from the WidgetGallery

Tested with both Wt-4.10.4 and Wt-4.11.4 with the same result.

I created a different Navigation for a Client Project, therefore this problem did not surface for me sooner.

RE: WNavigationBar looks different from WidgetGallery, also has other classes - Added by Matthias Van Ceulebroeck 8 days ago

Hello Christian,

I believe the issue is with the navbar-inner div being present. This seems to come from a specific Bootstrap version not supported by Wt. Which version are you using?

Best,
Matthias

[SOLVED]: WNavigationBar looks different from WidgetGallery, also has other classes - Added by Christian Meyer 8 days ago

Hi Matthias

I am using the default Bootstrap 5 that is shipped with Wt-4.11.4

which from reading the bootstrap.bundle.min.js is v5.2.3

Its not only that container... the Menu Button Icon in collapsed Mode is also wrong. (In my case)

I seem to run into this exact problem more often at the moment: Things do not work with me the way they are intended to ... with the standard settings... which drives me nuts

Well, well, well ...
I found the problem on my side as usual ...

I copied the wt.xml file in order to translate the default Values for other languages. And there are Wt.WNavigationBar.template strings present.

To use the translations, I added the file to use as resourcebundle ... At it seems doing so overrode the bootstrap5_theme.xml that uses the same variables, but the correct content...

I removed the templates from the translation File.
Now everythings works as expected.

maybe put the languages in a different file to enable translations?

We could pool the Translations in the Forum or a Wiki page as well ...

I added my German version if that is something you want to start for the community

Thanks for looking into this!
You can close the Bug report as well =)
But maybe switch it to a Feature request to seperate language and templates ;)

Cheers
Christian

wt_de.xml (7.07 KB) wt_de.xml German Translation of default Wt Strings with no template strings

RE: WNavigationBar looks different from WidgetGallery, also has other classes - Added by Mark Travis 7 days ago

Nice find! I've got multiple languages as well, but I've only set up my app specific translations so far.

Until I get the primary app functioning relatively perfectly, that's on the back burner. I'm adding a link to this for future reference.

RE: WNavigationBar looks different from WidgetGallery, also has other classes - Added by Matthias Van Ceulebroeck 6 days ago

Hey all,

I have rejected the ticket (#13754). I do think having a translation set ready sounds very nice! Maybe this can be a simple static page offering some community provided translations, since including them in the source seems a little opinionated?
We can link to the page in our documentation, allowing developers to choose their translation.

I think you are also right that the actual English strings for the UI and the templates should be separated. I have added #13770 to track this.

Best,
Matthias

    (1-6/6)