Comments (7)
What I found so far is this line. cellStyle
is built by coping rowStyle
Β and inherit
a column.style
func (m Model) renderRowColumnData(row Row, column Column, rowStyle lipgloss.Style, borderStyle lipgloss.Style) string {
cellStyle := rowStyle.Copy().Inherit(column.style).Inherit(m.baseStyle)
In its implementation in the lipgloss package, we can see that margins and padding properties are skipped
func (s Style) Inherit(i Style) Style {
s.init()
for k, v := range i.rules {
switch k {
case marginTopKey, marginRightKey, marginBottomKey, marginLeftKey:
// Margins are not inherited
continue
case paddingTopKey, paddingRightKey, paddingBottomKey, paddingLeftKey:
// Padding is not inherited
continue
case backgroundKey:
s.rules[k] = v
// The margins also inherit the background color
if !s.isSet(marginBackgroundKey) && !i.isSet(marginBackgroundKey) {
s.rules[marginBackgroundKey] = v
}
}
if _, exists := s.rules[k]; exists {
continue
}
s.rules[k] = v
}
return s
}
With that knowledge, I created a column with left padding
columns := []table.Column{
table.NewColumn(columnKeyName, "Name", 10).WithStyle(
lipgloss.NewStyle().
Foreground(lipgloss.Color("#88f")),
),
table.NewColumn(columnKeyCountry, "Country", 20).WithStyle(
lipgloss.NewStyle().
Foreground(lipgloss.Color("#f88")).
PaddingLeft(5),
),
table.NewColumn(columnKeyCurrency, "Currency", 10),
and change the renderRowColumnData a little bit
func (m Model) renderRowColumnData(row Row, column Column, rowStyle lipgloss.Style, borderStyle lipgloss.Style) string {
cellStyle := rowStyle.Copy().Inherit(column.style).Inherit(m.baseStyle)
_, _, _, colPadLeft := column.style.GetPadding()
if colPadLeft > 0 {
cellStyle = cellStyle.PaddingLeft(colPadLeft)
}
Which results in the desired state:
What we can do is:
- modify the Inherit method or create a custom one overriding all values from the incoming style - this will be impossible to make in a finite period since contributions to charm are hella slow (or they do not like me dunno)
- append that logic into renderRowColumnData (for paddings and margins)
I have some free time now, I can go with the second solution. cc. @Evertras
from bubble-table.
charmbracelet/lipgloss#71 π
from bubble-table.
PR: #160
from bubble-table.
Interesting result: I can get closer to the format I want with table.NewStyledCell
package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/evertras/bubble-table/table"
)
func main() {
cols := []table.Column{
table.NewColumn("a", "A", 10),
}
paddedCell := lipgloss.NewStyle().Padding(0, 1) // for our own safety
rows := []table.Row{
table.NewRow(table.RowData{"a": table.NewStyledCell("hello", paddedCell)}),
table.NewRow(table.RowData{"a": table.NewStyledCell("very long text", paddedCell)}),
}
t := table.New(cols).WithRows(rows)
fmt.Println(t.View())
}
Output
ββββββββββββ
β Aβ
β£βββββββββββ«
β hello β
β very β
β longβ¦ β
ββββββββββββ
from bubble-table.
Apologies for the late reply on this, it slipped through my email and I haven't checked here for a little bit. I think the StyledCell
approach is probably going to be the way to go here, but it does feel a bit rough that your original attempt didn't work. I'm going to leave this open for now, but I'm not entirely sure what the obvious fix will be and there is a workaround. π€
from bubble-table.
Okay, it may be tricky because GetPadding
and GetMargins
return values or 0 if a property is not set. Creating a simple if statement as I did may result in a situation when a rowStyle sets padding to >0 value and the user wants to have a column with padding ==0 and it will not be overridden.
Without access lipgloss.Style.rules it may be hard to implement simply. We can cover the override margins/paddings with a next column flag but I do not if it is a best approach here
from bubble-table.
It came out that we cannot set paddings and margins in base style because it breaks the layout
So my objects are invalid now, I am going to create a PR with that
from bubble-table.
Related Issues (20)
- Filtering doesn't work on non-stringer values
- performance of filtering a large table HOT 13
- redraw after filtering HOT 3
- Deselect all rows programatically
- Row select method docs are misleading
- Test failure: Test3xWithFilterFooter HOT 4
- Dynamically adding rows to table HOT 3
- Private fields and no getters for table.Column HOT 5
- Unclear how to show selected column with dynamic row updates HOT 5
- Selected text column fails to set width for unicode special characters
- Selected items are cleared after regenerating rows using WithRows() HOT 5
- Calling Update() recursiverly? HOT 1
- Sort duration HOT 1
- Clearing filter after selecting a row HOT 3
- How can I alternate row styles? HOT 9
- Feature Request: Ability to filter on arbitrary data HOT 8
- Upgrading bubbletea v0.25.0 β bubbletea v0.26.6 breaks table rendering HOT 4
- Requesting changes to be compatible with charmbracelet/bubbles >= v0.19.0 HOT 7
- examples/scrolling UI is broken HOT 1
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 bubble-table.