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 GalleryHere is the HTML from the Gallery
<div id="olkj2gl" class="navbar-light bg-light navbar navbar-expand-lg">
<div class="container-fluid">
<a id="olkj2go" href="https://www.google.com/search?q=corpy+inc" class="navbar-brand"><span id="olkj2gp">Corpy Inc.</span></a>
<button id="olkj2gn" type="button" class="navbar-toggler btn">
<span class="navbar-toggler-icon"></span>
</button>
<div id="olkj2gm" class="navbar-collapse collapse" style="">
<ul id="olkj2gs" class="navbar-nav me-auto">
<li id="olkj2gv" class="active nav-item"><a id="olkj2gx" href="#" class="Wt-no-default active nav-link"><span id="olkj2gy"><span id="olkj2gz" style="white-space:nowrap;">Home</span></span></a></li>
<li id="olkj2h1" class="nav-item"><a id="olkj2h3" href="/widgets/layout" class="nav-link"><span id="olkj2h4"><span id="olkj2h5" style="white-space:nowrap;">Layout</span></span></a></li>
<li id="olkj2h6" class="nav-item"><a id="olkj2h8" href="#" class="Wt-no-default nav-link"><span id="olkj2h9"><span id="olkj2ha" style="white-space:nowrap;">Sales</span></span></a></li>
</ul>
<div id="olkj2hc" class="d-flex">
<input id="olkj2hb" name="olkj2hb" size="10" type="text" class="form-control" placeholder="Enter a search item">
</div>
<ul id="olkj2he" class="navbar-nav">
<li id="olkj2hv" class="nav-item"><a id="olkj2hw" href="#" class="Wt-no-default dropdown-toggle nav-link"><span id="olkj2hx"><span id="olkj2hy" style="white-space:nowrap;">Help</span></span></a></li>
</ul>
</div>
</div>
</div>
The Order in the Gallery, as well as in the Bootstrap examples is Brand
Button
Collapse
Here is the HTML from my CodeHere is the HTML from my Code
<div id="o1de2xe1" class="navbar bg-light navbar-expand-sm">
<div class="navbar-inner">
<div class="container">
<button id="o1de2xe3" type="button" class="navbar-toggler btn">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a id="o1de2xe4" href="/home" class="navbar-brand"><span id="o1de2xe5">Brand Label</span></a>
<div id="o1de2xe2" class="navbar-collapse collapse">
<ul id="o1de2xe8" class="me-auto nav">
<li id="o1de2xex" class="nav-item"><a id="o1de2xez" href="/home" class="nav-link"><span id="o1de2xf0"><span id="o1de2xf1" style="white-space:nowrap;">Start</span></span></a></li>
<li id="o1de2xf6" class="nav-item"><a id="o1de2xf8" href="/user" class="nav-link"><span id="o1de2xf9"><span id="o1de2xfa" style="white-space:nowrap;">User Area</span></span></a></li>
<li id="o1de2xfd" class="nav-item"><a id="o1de2xff" href="/pricing" class="nav-link"><span id="o1de2xfg"><span id="o1de2xfh" style="white-space:nowrap;">Pricing</span></span></a></li>
<li id="o1de2xg8" class="active nav-item"><a id="o1de2xga" href="/list" class="active nav-link"><span id="o1de2xgb"><span id="o1de2xgc" style="white-space:nowrap;">Your List</span></span></a></li>
</ul>
</div>
</div>
</div>
</div>
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 NavigationHere is my cpp Code for the Navigation
void createLayout()
{
nav_Navbar = addNew<Wt::WNavigationBar>();
nav_Navbar->setResponsive(true);
nav_Navbar->setStyleClass("navbar bg-light navbar-expand-sm");
nav_Navbar->setTitle(Wt::WString::tr("Text.Menu.Brand"), Wt::WLink(Wt::LinkType::InternalPath, "/home"));
nav_Stack = addNew<Wt::WStackedWidget>();
nav_Menu = nav_Navbar->addMenu(std::make_unique<Wt::WMenu>(nav_Stack));
nav_Menu->setInternalPathEnabled("/");
nav_Menu->setStyleClass("me-auto");
{
auto tempStart = std::make_unique<StartPage>();
wgt_StartPage = tempStart.get();
auto tempItem = std::make_unique<Wt::WMenuItem>(Wt::WString::tr("Text.Menu.Home"), std::move(tempStart));
tempItem->setPathComponent("home");
nav_Menu->addItem(std::move(tempItem));
}
{
auto uCollectionContainer = std::make_unique<UserSpace>();
wgt_userSpace = uCollectionContainer.get();
auto tempItem = std::make_unique<Wt::WMenuItem>(Wt::WString::tr("Text.Menu.User"), std::move(uCollectionContainer));
tempItem->setPathComponent("user");
nav_Menu->addItem(std::move(tempItem));
}
{
auto tempCon = std::make_unique<Wt::WContainerWidget>();
tempCon->addNew<Wt::WText>(
Wt::WString::tr("App.Text.Price")
);
auto tempItem = std::make_unique<Wt::WMenuItem>(Wt::WString::tr("Text.Menu.Pricing"), std::move(tempCon));
tempItem->setPathComponent("pricing");
nav_Menu->addItem(std::move(tempItem));
}
}
// in another function the Last Item is created
{
auto tempList = std::make_unique<Wt::WContainerWidget>();
wgt_List = tempList.get();
auto tempItem = std::make_unique<Wt::WMenuItem>(Wt::WString::tr("Text.Menu.List"), std::move(tempList));
tempItem->setPathComponent("list");
nav_Menu->addItem(std::move(tempItem));
}
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
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