Comments (4)
This is requested fairly often, though I'm not sure if there's been an issue already. It does seem odd to me that SelectBox is so limited, since I see dropdowns with icons wherever I look; for instance, in IDEA:
It's a poor workaround, but you can have icons in your font today, if you jump through some hoops to add them as specific characters. They can even have full color and alpha. I think AngelCode BMFont (the first program to support the .fnt format libGDX uses) has a menu item to add images to a font. If the font has icons in it, you can use those icons in a Label, and it's still technically all textual.
I'm not at all familiar enough with scene2d.ui to know why this limitation exists, but there should be some way (added?) to avoid being limited to text-only. I don't know how hard it would be.
from libgdx.
This is requested fairly often, though I'm not sure if there's been an issue already. It does seem odd to me that SelectBox is so limited, since I see dropdowns with icons wherever I look; for instance, in IDEA:
It's a poor workaround, but you can have icons in your font today, if you jump through some hoops to add them as specific characters. They can even have full color and alpha. I think AngelCode BMFont (the first program to support the .fnt format libGDX uses) has a menu item to add images to a font. If the font has icons in it, you can use those icons in a Label, and it's still technically all textual.
I'm not at all familiar enough with scene2d.ui to know why this limitation exists, but there should be some way (added?) to avoid being limited to text-only. I don't know how hard it would be.
I just checked the List source code file, it is not very hard to implement draw items as drawable rather than font. You can check the drawItem method in List.java file. I haven't try it, maybe it is hard. At least the List class should provide some interfaces to help developer scale its feature.
from libgdx.
I just tried implement a poor workaround and it works well in my project😄. I just create new class extended from SelectBox and SelectBoxScrollPane classes and override some functions to hack it to make it support drawable. I hope my workaround can help someone else who has same issue or give someone a hint to add a new PR either by me or you to support this feature. Here are my code in Kotlin.
import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.GlyphLayout
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
class DrawableSelectBox<T: Drawable>(style: SelectBoxStyle?) : SelectBox<T>(style) {
override fun drawItem(
batch: Batch?,
font: BitmapFont?,
item: T,
x: Float,
y: Float,
width: Float
): GlyphLayout? {
item.draw(batch, x, y + style.listStyle.selection.topHeight - style.listStyle.font.descent - scrollPane.list.itemHeight + 4f, width, scrollPane.list.itemHeight - 8f)
return null
}
override fun newScrollPane(): SelectBoxScrollPane<T> {
return DrawableSelectBoxScrollPane(this)
}
}
import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.GlyphLayout
import com.badlogic.gdx.scenes.scene2d.ui.List
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
class DrawableSelectBoxScrollPane<T: Drawable>(selectBox: SelectBox<T>?) :
SelectBox.SelectBoxScrollPane<T>(selectBox) {
override fun newList(): List<T> {
return object: List<T>(selectBox.style.listStyle) {
override fun drawItem(
batch: Batch?,
font: BitmapFont?,
index: Int,
item: T,
x: Float,
y: Float,
width: Float
): GlyphLayout? {
item.draw(batch, x, y + style.selection.topHeight - style.font.descent - itemHeight + 4f, width, itemHeight - 8f)
return null
}
override fun toString(t: T): String {
// Rewrite this function to assign new width to item
return "1234"
}
}
}
}
Here is the code how to use it.
val colorSelectBox = DrawableSelectBox<NinePatchDrawable>(mapTypeBoxStyle)
colorSelectBox.items = colorRectDrawables
from libgdx.
That sounds familiar. One of the required overridables was broken not too long ago, so I remember trying that with nice long reflection orgies. But yes, that goes some way. The toString limitation is sidestepped not solved, but that's how it is. But you won't get a dropdown that supports entries of varying height - better rewrite from scratch in that case.
Unciv has an entirely different kludge to allow somewhat appealing SelectBoxes (though mostly unused) without any subclassing - render actors as glyphs into the bitmap font...
from libgdx.
Related Issues (20)
- Support for ISO Keyboards HOT 6
- Use official metal sources HOT 1
- AndroidFragmentApplication dies onPause
- Performance issues on Android when enabling config.useGL30 HOT 7
- GWT requests unnecessary microphone permission HOT 5
- Stage.drawDebug does not work in combination with GL3 due to ShapeRenderer shader not being compliant HOT 2
- AndroidPreferences.flush() has no way to enforce synchronous saving HOT 2
- If an animation starts on frame 1 or more, rather than frame 0, AnimationController doesn't animate it properly
- glReadPixels does not support offset parameter crucial to read pixels asynchronously HOT 2
- gdx and gdx.jnigen.loader causes split module issue over package com.badlogic.gdx.utils HOT 6
- GWT preloader doesn't use percent-encoding HOT 2
- performance: unnecessary window.makeCurrent() in LWJGL3 backend HOT 4
- Add arm64 capabilities to Info.plist.xml HOT 1
- Suggestion to modify code in Sprite.rotate() method in com.badlogic.gdx.graphics.g2d.Sprite package HOT 4
- None of the 3D test apps in ..\tests\gdx-tests\src\com\badlogic\gdx\tests\g3d are build or runnable
- FPS Cap at runtime HOT 4
- GestureDetector / ActorGestureListener depend on absolute amount of touch points HOT 1
- LibGDX + KMP (Kotlin Multiplatform) HOT 1
- mistake
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 libgdx.