Comments (6)
The stacked layout example does pretty much what you're suggesting: https://ebitenui.github.io/stacked_layout/
-> https://github.com/ebitenui/ebitenui/blob/master/_examples/widget_demos/stackedlayout/main.go
So in regards to the grid layout, you can set it up in quadrants, so 2 columns 2 rows (or 3x3), each setup to stretch. Then add another containers to the individual corners so that you can add your various widgets where you want them. The grid layout just helps get the sub containers and widgets in the right places.
Another option to consider is to use a Window. Windows can be placed where ever you want with x/y coordinates. This is how I am handling the UI for my game. See https://ebitenui.github.io/window/ -> https://github.com/ebitenui/ebitenui/blob/master/_examples/widget_demos/window/main.go
Along with that, Since I have added stacked layout that does allow overlapping widgets, I will leave this open as an enhancement to allow multiple children to be laid out in an anchor layout.
from ebitenui.
Just in case anyone stumbles upon this, I was able to get this to work with your suggestion of using Windows with a StackedLayout
for the root container.
Since I couldn't position windows with Anchors, I just make a translation function (I'm sure there's a smarter way, but this seems to work) which I'm sharing here in case this will help others:
// getAnchorPosition returns the screen position of windows according to an anchor.
// width and height are the results of `PreferredSize()` of the window's contents.
// this also assumes ScreenWidth and ScreenHeight are accessible and exposed.
func getAnchorPosition(anchor AnchorPosition, width, height int) (int, int) {
var x, y int
centerX := (ScreenWidth / 2) - (width / 2)
centerY := (ScreenHeight / 2) - (height / 2)
rightX := ScreenWidth - width
bottomY := ScreenHeight - height
switch anchor {
case TopLeft:
x = 0
y = 0
case TopCenter:
x = centerX
y = centerY
case TopRight:
x = rightX
y = 0
case MiddleLeft:
x = 0
y = centerY
case MiddleCenter:
x = centerX
y = centerY
case MiddleRight:
x = rightX
y = centerY
case BottomLeft:
x = 0
y = bottomY
case BottomCenter:
x = centerX
y = bottomY
case BottomRight:
x = rightX
y = bottomY
}
return x, y
}
from ebitenui.
This actually working as expected. The anchor layout is built to only layout a single child. I believe the reasoning is "what do you do if two items are anchored to the same location.?". What you're trying to achieve can be done with a grid layout with 4 quarters instead, or a stacked layout.
from ebitenui.
This actually working as expected
So an anchored layout is special in that it only allows a single child container? In this case, logging an error could be helpful.
"what do you do if two items are anchored to the same location.?"
In that case, it seems like drawing one over the other makes sense. It makes more sense than just silently hiding all subsequent containers (if that's what it's doing, appears to be the case).
What you're trying to achieve can be done with a grid layout with 4 quarters instead, or a stacked layout.
A grid layout was a no go as I expect to have variable sizes for the various anchored components of the screen (like a minimap, menu button, bottom hud, all varying widths and heights like you'd see in a typical game).
Though I did give it a few hours trying to get this to work with a stacked layout. If you have an example of how I could handle this I'd greatly appreciate it!
One workaround has been to create multiple instances of ebitenui.UI
and iterating them, but that feels like a hack.
from ebitenui.
Awesome, thanks very much for the prompt replies!
I'll see if I can figure out stacked layout with multiple anchored containers.
Good ideas on the grid, but part of these elements may span the entirety of a grid row which makes that a bit tricky.
Appreciate tagging this as an enhancement!
from ebitenui.
from ebitenui.
Related Issues (20)
- Improve the grid-like container navigation HOT 1
- Issue pre-selecting entry in middle of combo box with multiple pages of entries
- CursorUpdater: how to set back to default? HOT 1
- CursorUpdater: a cursor disappears with nil replacement images HOT 5
- Rendering on an image that is not the entire screen get button events on the wrong place HOT 3
- SVG Vector Option in Widgets HOT 3
- TextInput rendering two characters per keystroke HOT 1
- Text centering issues with bitmapfont HOT 16
- How to update text when var changes HOT 5
- Editable Text Area. HOT 1
- Text input cursor is not at the end when text is updated through the code HOT 2
- TabBook: disabling the 1st tab works unexpectedly HOT 3
- Android: Focusing a Text Input does not open Android on screen keyboard HOT 5
- Text Area does not render text on mobile HOT 1
- Consider an ebitengine version decrease in the go.mod file HOT 1
- Centering a button HOT 2
- Cannot set button text position to TextPositionEnd HOT 3
- Broken ContextMenu HOT 2
- Support percentage widths on gridlayout
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ebitenui.