Skip to content

Commit cbb9e91

Browse files
committed
Added frame label drawing support.
1 parent a3d606c commit cbb9e91

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

internal/memory/type_tui_style.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type TuiStyleEntryType struct {
2626
IsWindowFooterDrawn bool
2727
TextForegroundColor int32
2828
TextBackgroundColor int32
29+
TextLabelColor int32
2930
TextInputForegroundColor int32
3031
TextInputBackgroundColor int32
3132
CursorCharacter rune
@@ -69,6 +70,7 @@ func NewTuiStyleEntry(existingStyleEntry ...*TuiStyleEntryType) TuiStyleEntryTyp
6970
styleEntry.ProgressBarForegroundPattern = existingStyleEntry[0].ProgressBarForegroundPattern
7071
styleEntry.TextForegroundColor = existingStyleEntry[0].TextForegroundColor
7172
styleEntry.TextBackgroundColor = existingStyleEntry[0].TextBackgroundColor
73+
styleEntry.TextLabelColor = existingStyleEntry[0].TextLabelColor
7274
styleEntry.TextInputForegroundColor = existingStyleEntry[0].TextInputForegroundColor
7375
styleEntry.TextInputBackgroundColor = existingStyleEntry[0].TextInputBackgroundColor
7476
styleEntry.CursorCharacter = existingStyleEntry[0].CursorCharacter
@@ -102,6 +104,7 @@ func NewTuiStyleEntry(existingStyleEntry ...*TuiStyleEntryType) TuiStyleEntryTyp
102104
styleEntry.ProgressBarForegroundPattern = constants.CharBlockSolid
103105
styleEntry.TextForegroundColor = constants.AnsiColorByIndex[15]
104106
styleEntry.TextBackgroundColor = constants.AnsiColorByIndex[0]
107+
styleEntry.TextLabelColor = constants.AnsiColorByIndex[15]
105108
styleEntry.TextInputForegroundColor = constants.AnsiColorByIndex[15]
106109
styleEntry.TextInputBackgroundColor = constants.AnsiColorByIndex[0]
107110
styleEntry.CursorCharacter = constants.CharBlockSolid

tui_elements.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,40 @@ func drawBorder(layerEntry *memory.LayerEntryType, styleEntry memory.TuiStyleEnt
506506
drawFrame(layerEntry, styleEntry, localAttributeEntry, constants.FrameStyleNormal, xLocation, yLocation, width, height)
507507
}
508508

509+
/*
510+
DrawFrameLabel allows you to draw a label for a frame. The label will
511+
be automatically enclosed by the characters "[" and "]" to blend in
512+
with a border of a frame.
513+
514+
- If the frame label to be drawn falls outside the range of the
515+
specified layer, then only the visible portion of the border will be
516+
drawn.
517+
*/
518+
func DrawFrameLabel(layerAlias string, styleEntry memory.TuiStyleEntryType, label string, xLocation int, yLocation int) {
519+
layerEntry := memory.GetLayer(layerAlias)
520+
drawFrameLabel(layerEntry, styleEntry, label, xLocation, yLocation)
521+
}
522+
523+
/*
524+
DrawFrameLabel allows you to draw a label for a frame. The label will
525+
be automatically enclosed by the characters "[" and "]" to blend in
526+
with a border of a frame.
527+
528+
- If the frame label to be drawn falls outside the range of the
529+
specified layer, then only the visible portion of the border will be
530+
drawn.
531+
*/
532+
func drawFrameLabel(layerEntry *memory.LayerEntryType, styleEntry memory.TuiStyleEntryType, label string, xLocation int, yLocation int) {
533+
attributeEntry := memory.NewAttributeEntry()
534+
attributeEntry.ForegroundColor= styleEntry.TextForegroundColor
535+
attributeEntry.BackgroundColor= styleEntry.TextBackgroundColor
536+
printLayer(layerEntry, attributeEntry, xLocation, yLocation, []rune("[ "))
537+
printLayer(layerEntry, attributeEntry, xLocation + 2 + len(label), yLocation, []rune(" ]"))
538+
attributeEntry.ForegroundColor = styleEntry.TextLabelColor
539+
attributeEntry.BackgroundColor = styleEntry.TextBackgroundColor
540+
printLayer(layerEntry, attributeEntry, xLocation + 2, yLocation, []rune(label))
541+
}
542+
509543
/*
510544
DrawFrame allows you to draw a frame on a given text layer. Frames differ
511545
from borders since borders are flat shaded and do not have a raised or

tui_elements_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ func TestDrawButton(test *testing.T) {
129129
assert.Equalf(test, expectedValue, obtainedValue ,"The updated screen does not match the master original!")
130130
}
131131

132+
func TestDrawFrameLabel(test *testing.T) {
133+
commonResource.isDebugEnabled = true
134+
layerAlias1 := "Layer1"
135+
layerWidth := 40
136+
layerHeight := 20
137+
styleEntry := memory.NewTuiStyleEntry()
138+
InitializeTerminal(layerWidth, layerHeight)
139+
AddLayer(layerAlias1, 0, 0, layerWidth, layerHeight, 1, "")
140+
Color(4, 6)
141+
FillLayer(layerAlias1, "a1a2a3a4a5")
142+
styleEntry.TextForegroundColor = GetRGBColor(62, 128, 128)
143+
styleEntry.TextBackgroundColor = GetRGBColor(0, 0, 200)
144+
styleEntry.TextLabelColor = GetRGBColor(255,255,255)
145+
DrawFrameLabel(layerAlias1, styleEntry, "My Frame", 1, 1)
146+
DrawFrameLabel(layerAlias1, styleEntry, "My Frame", -7, 3)
147+
DrawFrameLabel(layerAlias1, styleEntry, "My Frame", layerWidth - 7, 3)
148+
UpdateDisplay()
149+
layerEntry := commonResource.screenLayer
150+
obtainedValue := layerEntry.GetBasicAnsiStringAsBase64()
151+
expectedValue := "G1szODsyOzA7MDsxMjhtG1s0ODsyOzA7MTI4OzEyOG1hMWEyYTNhNGE1YTFhMmEzYTRhNWExYTJhM2E0YTVhMWEyYTNhNGE1G1szODsyOzA7MDswbRtbNDg7MjswOzA7MG0KG1szODsyOzA7MDsxMjhtG1s0ODsyOzA7MTI4OzEyOG1hG1szODsyOzYyOzEyODsxMjhtG1s0ODsyOzA7MDsyMDBtWyAbWzM4OzI7MjU1OzI1NTsyNTVtTXkgRnJhbWUbWzM4OzI7NjI7MTI4OzEyOG0gXRtbMzg7MjswOzA7MTI4bRtbNDg7MjswOzEyODsxMjhtMmEzYTRhNWExYTJhM2E0YTVhMWEyYTNhNGE1G1szODsyOzA7MDswbRtbNDg7MjswOzA7MG0KG1szODsyOzA7MDsxMjhtG1s0ODsyOzA7MTI4OzEyOG1hMWEyYTNhNGE1YTFhMmEzYTRhNWExYTJhM2E0YTVhMWEyYTNhNGE1G1szODsyOzA7MDswbRtbNDg7MjswOzA7MG0KG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swOzEyOG0bWzQ4OzI7MDsxMjg7MTI4bWExYTJhM2E0YTVhMWEyYTNhNGE1YTFhMmEzYTRhNWExYTJhM2E0YTUbWzM4OzI7MDswOzBtG1s0ODsyOzA7MDswbQobWzM4OzI7MDswOzEyOG0bWzQ4OzI7MDsxMjg7MTI4bWExYTJhM2E0YTVhMWEyYTNhNGE1YTFhMmEzYTRhNWExYTJhM2E0YTUbWzM4OzI7MDswOzBtG1s0ODsyOzA7MDswbQo="
152+
assert.Equalf(test, expectedValue, obtainedValue ,"The updated screen does not match the master original!")
153+
}
154+
132155
func TestDrawFrame(test *testing.T) {
133156
commonResource.isDebugEnabled = true
134157
layerAlias1 := "Layer1"

0 commit comments

Comments
 (0)