From 89ae760940c14df19057256f396f661aae6b687d Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Mon, 6 Jun 2022 17:39:45 +0200 Subject: [PATCH 01/26] remove osme added by accident examples --- examples/bug/main.go | 35 ----------------------------------- examples/child/main.go | 25 ------------------------- 2 files changed, 60 deletions(-) delete mode 100644 examples/bug/main.go delete mode 100644 examples/child/main.go diff --git a/examples/bug/main.go b/examples/bug/main.go deleted file mode 100644 index 358ff2f1..00000000 --- a/examples/bug/main.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/AllenDang/giu" -) - -const popupID = "somepopupmodal" - -func loop() { - items := make([]string, 200) - for i := range items { - items[i] = fmt.Sprintf("Item %d", i) - } - - giu.SingleWindow().Layout( - giu.Row( - giu.ListBox("listbox", items).Size(300, 400), - giu.ListBox("listbox2", items).Size(300, 400), - ), - giu.Popup(popupID).Layout( - giu.Row( - giu.Button("Do something").OnClick(func() { fmt.Println("Something done") }), - giu.Button("close me").OnClick(func() { giu.CloseCurrentPopup() }), - ), - ), - giu.Button("Open popup").OnClick(func() { giu.OpenPopup(popupID) }), - ) -} - -func main() { - wnd := giu.NewMasterWindow("#390 [bug]", 640, 480, 0) - wnd.Run(loop) -} diff --git a/examples/child/main.go b/examples/child/main.go deleted file mode 100644 index 73eaaaf0..00000000 --- a/examples/child/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "github.com/AllenDang/giu" - "github.com/AllenDang/imgui-go" -) - -func loop() { - giu.SingleWindow().Layout( - giu.Custom(func() { - imgui.PushStyleColor(imgui.StyleColorChildBg, imgui.CurrentStyle().GetColor(imgui.StyleColorWindowBg)) - if imgui.BeginChild("child") { - giu.Button("button").Build() - } - imgui.EndChild() - imgui.PopStyleColor() - }), - giu.Label("label"), - ) -} - -func main() { - wnd := giu.NewMasterWindow("native child layout [demo]", 640, 480, 0) - wnd.Run(loop) -} From e9c669afa5ca6dfa046f637bbaa0829649778e52 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Mon, 18 Jul 2022 17:36:07 +0200 Subject: [PATCH 02/26] work on CSS.go: - add CSSTagWidget - put cssStylesheet in context TODO: CSS parser --- CSS.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ Context.go | 7 +++++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 CSS.go diff --git a/CSS.go b/CSS.go new file mode 100644 index 00000000..31e6556c --- /dev/null +++ b/CSS.go @@ -0,0 +1,45 @@ +package giu + +// Code in this file allows to apply style using a CSS stylesheet +// The intention of the code looks as follows: +// - The CSS stylesheet is parsed and the resulting rules are stored in giu context +// NOTE: more than one CSS stylesheets can be parsed, however the app could panic if the same tag is present twice +// - CSSTagWidget allows to apply style to a specified layout +// - main tag allows to apply style to the whole application + +// ParseCSSStyleSheet parses CSS stylesheet and stores the rules in giu context +func ParseCSSStyleSheet(css string) { + +} + +// cssStylesheet is a map tag:StyleSetter +type cssStylesheet map[string]StyleSetter + +var _ Widget = &CSSTagWidget{} + +// CSSTagWidget is a widget that allows to apply CSS style to a specified layout +type CSSTagWidget struct { + tag string + layout Layout +} + +// CSSTag creates CSSTagWidget +func CSSTag(tag string) *CSSTagWidget { + return &CSSTagWidget{tag: tag} +} + +// To specifies a layout to which the style will be applied +func (c *CSSTagWidget) To(layout ...Widget) *CSSTagWidget { + c.layout = layout + return c +} + +// Build implements Widget interface +func (c *CSSTagWidget) Build() { + // get style from context. + // if it doesn't exist Assert. + style, exists := Context.cssStylesheet[c.tag] + Assert(exists, "CSSTagWidget", "Build", "CSS stylesheet doesn't contain tag: ", c.tag) + + style.To(c.layout).Build() +} diff --git a/Context.go b/Context.go index df0b1818..5c7a2a14 100644 --- a/Context.go +++ b/Context.go @@ -41,12 +41,15 @@ type context struct { FontAtlas FontAtlas textureLoadingQueue *queue.Queue + + cssStylesheet cssStylesheet } func CreateContext(p imgui.Platform, r imgui.Renderer) context { result := context{ - platform: p, - renderer: r, + platform: p, + renderer: r, + cssStylesheet: make(cssStylesheet), } result.FontAtlas = newFontAtlas() From b4caca7b7249879cde0056e79d014f6196d8a263 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Mon, 18 Jul 2022 17:41:52 +0200 Subject: [PATCH 03/26] files: split Style.go into StyleIDs.go it was pretty hard to find appropiate styleID in that large style.go file - i moved ID stuff into StyleIDs.go --- Style.go | 137 -------------------------------------------------- StyleIDs.go | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 137 deletions(-) create mode 100644 StyleIDs.go diff --git a/Style.go b/Style.go index 094579c8..357037e0 100644 --- a/Style.go +++ b/Style.go @@ -217,143 +217,6 @@ func GetFramePadding() (x, y float32) { return vec2.X, vec2.Y } -// StyleColorID identifies a color in the UI style. -type StyleColorID imgui.StyleColorID - -// StyleColor identifier. -const ( - StyleColorText StyleColorID = StyleColorID(imgui.StyleColorText) - StyleColorTextDisabled StyleColorID = StyleColorID(imgui.StyleColorTextDisabled) - StyleColorWindowBg StyleColorID = StyleColorID(imgui.StyleColorWindowBg) - StyleColorChildBg StyleColorID = StyleColorID(imgui.StyleColorChildBg) - StyleColorPopupBg StyleColorID = StyleColorID(imgui.StyleColorPopupBg) - StyleColorBorder StyleColorID = StyleColorID(imgui.StyleColorBorder) - StyleColorBorderShadow StyleColorID = StyleColorID(imgui.StyleColorBorderShadow) - StyleColorFrameBg StyleColorID = StyleColorID(imgui.StyleColorFrameBg) - StyleColorFrameBgHovered StyleColorID = StyleColorID(imgui.StyleColorFrameBgHovered) - StyleColorFrameBgActive StyleColorID = StyleColorID(imgui.StyleColorFrameBgActive) - StyleColorTitleBg StyleColorID = StyleColorID(imgui.StyleColorTitleBg) - StyleColorTitleBgActive StyleColorID = StyleColorID(imgui.StyleColorTitleBgActive) - StyleColorTitleBgCollapsed StyleColorID = StyleColorID(imgui.StyleColorTitleBgCollapsed) - StyleColorMenuBarBg StyleColorID = StyleColorID(imgui.StyleColorMenuBarBg) - StyleColorScrollbarBg StyleColorID = StyleColorID(imgui.StyleColorScrollbarBg) - StyleColorScrollbarGrab StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrab) - StyleColorScrollbarGrabHovered StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabHovered) - StyleColorScrollbarGrabActive StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabActive) - StyleColorCheckMark StyleColorID = StyleColorID(imgui.StyleColorCheckMark) - StyleColorSliderGrab StyleColorID = StyleColorID(imgui.StyleColorSliderGrab) - StyleColorSliderGrabActive StyleColorID = StyleColorID(imgui.StyleColorSliderGrabActive) - StyleColorButton StyleColorID = StyleColorID(imgui.StyleColorButton) - StyleColorButtonHovered StyleColorID = StyleColorID(imgui.StyleColorButtonHovered) - StyleColorButtonActive StyleColorID = StyleColorID(imgui.StyleColorButtonActive) - StyleColorHeader StyleColorID = StyleColorID(imgui.StyleColorHeader) - StyleColorHeaderHovered StyleColorID = StyleColorID(imgui.StyleColorHeaderHovered) - StyleColorHeaderActive StyleColorID = StyleColorID(imgui.StyleColorHeaderActive) - StyleColorSeparator StyleColorID = StyleColorID(imgui.StyleColorSeparator) - StyleColorSeparatorHovered StyleColorID = StyleColorID(imgui.StyleColorSeparatorHovered) - StyleColorSeparatorActive StyleColorID = StyleColorID(imgui.StyleColorSeparatorActive) - StyleColorResizeGrip StyleColorID = StyleColorID(imgui.StyleColorResizeGrip) - StyleColorResizeGripHovered StyleColorID = StyleColorID(imgui.StyleColorResizeGripHovered) - StyleColorResizeGripActive StyleColorID = StyleColorID(imgui.StyleColorResizeGripActive) - StyleColorTab StyleColorID = StyleColorID(imgui.StyleColorTab) - StyleColorTabHovered StyleColorID = StyleColorID(imgui.StyleColorTabHovered) - StyleColorTabActive StyleColorID = StyleColorID(imgui.StyleColorTabActive) - StyleColorTabUnfocused StyleColorID = StyleColorID(imgui.StyleColorTabUnfocused) - StyleColorTabUnfocusedActive StyleColorID = StyleColorID(imgui.StyleColorTabUnfocusedActive) - StyleColorPlotLines StyleColorID = StyleColorID(imgui.StyleColorPlotLines) - StyleColorPlotLinesHovered StyleColorID = StyleColorID(imgui.StyleColorPlotLinesHovered) - StyleColorProgressBarActive StyleColorID = StyleColorPlotLinesHovered - StyleColorPlotHistogram StyleColorID = StyleColorID(imgui.StyleColorPlotHistogram) - StyleColorPlotHistogramHovered StyleColorID = StyleColorID(imgui.StyleColorPlotHistogramHovered) - StyleColorTableHeaderBg StyleColorID = StyleColorID(imgui.StyleColorTableHeaderBg) - StyleColorTableBorderStrong StyleColorID = StyleColorID(imgui.StyleColorTableBorderStrong) - StyleColorTableBorderLight StyleColorID = StyleColorID(imgui.StyleColorTableBorderLight) - StyleColorTableRowBg StyleColorID = StyleColorID(imgui.StyleColorTableRowBg) - StyleColorTableRowBgAlt StyleColorID = StyleColorID(imgui.StyleColorTableRowBgAlt) - StyleColorTextSelectedBg StyleColorID = StyleColorID(imgui.StyleColorTextSelectedBg) - StyleColorDragDropTarget StyleColorID = StyleColorID(imgui.StyleColorDragDropTarget) - StyleColorNavHighlight StyleColorID = StyleColorID(imgui.StyleColorNavHighlight) - StyleColorNavWindowingHighlight StyleColorID = StyleColorID(imgui.StyleColorNavWindowingHighlight) - StyleColorNavWindowingDimBg StyleColorID = StyleColorID(imgui.StyleColorNavWindowingDimBg) - StyleColorModalWindowDimBg StyleColorID = StyleColorID(imgui.StyleColorModalWindowDimBg) -) - -// StyleVarID identifies a style variable in the UI style. -type StyleVarID imgui.StyleVarID - -// Style IDs. -const ( - // StyleVarAlpha is a float. - StyleVarAlpha StyleVarID = StyleVarID(imgui.StyleVarAlpha) - // float DisabledAlpha. - StyleVarDisabledAlpha StyleVarID = StyleVarID(imgui.StyleVarDisabledAlpha) - // StyleVarWindowPadding is a Vec2. - StyleVarWindowPadding StyleVarID = StyleVarID(imgui.StyleVarWindowPadding) - // StyleVarWindowRounding is a float. - StyleVarWindowRounding StyleVarID = StyleVarID(imgui.StyleVarWindowRounding) - // StyleVarWindowBorderSize is a float. - StyleVarWindowBorderSize StyleVarID = StyleVarID(imgui.StyleVarWindowBorderSize) - // StyleVarWindowMinSize is a Vec2. - StyleVarWindowMinSize StyleVarID = StyleVarID(imgui.StyleVarWindowMinSize) - // StyleVarWindowTitleAlign is a Vec2. - StyleVarWindowTitleAlign StyleVarID = StyleVarID(imgui.StyleVarWindowTitleAlign) - // StyleVarChildRounding is a float. - StyleVarChildRounding StyleVarID = StyleVarID(imgui.StyleVarChildRounding) - // StyleVarChildBorderSize is a float. - StyleVarChildBorderSize StyleVarID = StyleVarID(imgui.StyleVarChildBorderSize) - // StyleVarPopupRounding is a float. - StyleVarPopupRounding StyleVarID = StyleVarID(imgui.StyleVarPopupRounding) - // StyleVarPopupBorderSize is a float. - StyleVarPopupBorderSize StyleVarID = StyleVarID(imgui.StyleVarPopupBorderSize) - // StyleVarFramePadding is a Vec2. - StyleVarFramePadding StyleVarID = StyleVarID(imgui.StyleVarFramePadding) - // StyleVarFrameRounding is a float. - StyleVarFrameRounding StyleVarID = StyleVarID(imgui.StyleVarFrameRounding) - // StyleVarFrameBorderSize is a float. - StyleVarFrameBorderSize StyleVarID = StyleVarID(imgui.StyleVarFrameBorderSize) - // StyleVarItemSpacing is a Vec2. - StyleVarItemSpacing StyleVarID = StyleVarID(imgui.StyleVarItemSpacing) - // StyleVarItemInnerSpacing is a Vec2. - StyleVarItemInnerSpacing StyleVarID = StyleVarID(imgui.StyleVarItemInnerSpacing) - // StyleVarIndentSpacing is a float. - StyleVarIndentSpacing StyleVarID = StyleVarID(imgui.StyleVarIndentSpacing) - // StyleVarScrollbarSize is a float. - StyleVarScrollbarSize StyleVarID = StyleVarID(imgui.StyleVarScrollbarSize) - // StyleVarScrollbarRounding is a float. - StyleVarScrollbarRounding StyleVarID = StyleVarID(imgui.StyleVarScrollbarRounding) - // StyleVarGrabMinSize is a float. - StyleVarGrabMinSize StyleVarID = StyleVarID(imgui.StyleVarGrabMinSize) - // StyleVarGrabRounding is a float. - StyleVarGrabRounding StyleVarID = StyleVarID(imgui.StyleVarGrabRounding) - // StyleVarTabRounding is a float. - StyleVarTabRounding StyleVarID = StyleVarID(imgui.StyleVarTabRounding) - // StyleVarButtonTextAlign is a Vec2. - StyleVarButtonTextAlign StyleVarID = StyleVarID(imgui.StyleVarButtonTextAlign) - // StyleVarSelectableTextAlign is a Vec2. - StyleVarSelectableTextAlign StyleVarID = StyleVarID(imgui.StyleVarSelectableTextAlign) -) - -// IsVec2 returns true if the style var id should be processed as imgui.Vec2 -// if not, it is interpreted as float32. -func (s StyleVarID) IsVec2() bool { - lookup := map[StyleVarID]bool{ - // StyleVarWindowPadding is a Vec2. - StyleVarWindowPadding: true, - StyleVarWindowMinSize: true, - StyleVarWindowTitleAlign: true, - StyleVarFramePadding: true, - StyleVarItemSpacing: true, - // StyleVarItemInnerSpacing is a Vec2. - StyleVarItemInnerSpacing: true, - StyleVarButtonTextAlign: true, - StyleVarSelectableTextAlign: true, - } - - result, ok := lookup[s] - - return result && ok -} - var _ Widget = &StyleSetter{} // StyleSetter is a user-friendly way to manage imgui styles. diff --git a/StyleIDs.go b/StyleIDs.go new file mode 100644 index 00000000..0e006391 --- /dev/null +++ b/StyleIDs.go @@ -0,0 +1,140 @@ +package giu + +import "github.com/AllenDang/imgui-go" + +// StyleColorID identifies a color in the UI style. +type StyleColorID imgui.StyleColorID + +// StyleColor identifier. +const ( + StyleColorText StyleColorID = StyleColorID(imgui.StyleColorText) + StyleColorTextDisabled StyleColorID = StyleColorID(imgui.StyleColorTextDisabled) + StyleColorWindowBg StyleColorID = StyleColorID(imgui.StyleColorWindowBg) + StyleColorChildBg StyleColorID = StyleColorID(imgui.StyleColorChildBg) + StyleColorPopupBg StyleColorID = StyleColorID(imgui.StyleColorPopupBg) + StyleColorBorder StyleColorID = StyleColorID(imgui.StyleColorBorder) + StyleColorBorderShadow StyleColorID = StyleColorID(imgui.StyleColorBorderShadow) + StyleColorFrameBg StyleColorID = StyleColorID(imgui.StyleColorFrameBg) + StyleColorFrameBgHovered StyleColorID = StyleColorID(imgui.StyleColorFrameBgHovered) + StyleColorFrameBgActive StyleColorID = StyleColorID(imgui.StyleColorFrameBgActive) + StyleColorTitleBg StyleColorID = StyleColorID(imgui.StyleColorTitleBg) + StyleColorTitleBgActive StyleColorID = StyleColorID(imgui.StyleColorTitleBgActive) + StyleColorTitleBgCollapsed StyleColorID = StyleColorID(imgui.StyleColorTitleBgCollapsed) + StyleColorMenuBarBg StyleColorID = StyleColorID(imgui.StyleColorMenuBarBg) + StyleColorScrollbarBg StyleColorID = StyleColorID(imgui.StyleColorScrollbarBg) + StyleColorScrollbarGrab StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrab) + StyleColorScrollbarGrabHovered StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabHovered) + StyleColorScrollbarGrabActive StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabActive) + StyleColorCheckMark StyleColorID = StyleColorID(imgui.StyleColorCheckMark) + StyleColorSliderGrab StyleColorID = StyleColorID(imgui.StyleColorSliderGrab) + StyleColorSliderGrabActive StyleColorID = StyleColorID(imgui.StyleColorSliderGrabActive) + StyleColorButton StyleColorID = StyleColorID(imgui.StyleColorButton) + StyleColorButtonHovered StyleColorID = StyleColorID(imgui.StyleColorButtonHovered) + StyleColorButtonActive StyleColorID = StyleColorID(imgui.StyleColorButtonActive) + StyleColorHeader StyleColorID = StyleColorID(imgui.StyleColorHeader) + StyleColorHeaderHovered StyleColorID = StyleColorID(imgui.StyleColorHeaderHovered) + StyleColorHeaderActive StyleColorID = StyleColorID(imgui.StyleColorHeaderActive) + StyleColorSeparator StyleColorID = StyleColorID(imgui.StyleColorSeparator) + StyleColorSeparatorHovered StyleColorID = StyleColorID(imgui.StyleColorSeparatorHovered) + StyleColorSeparatorActive StyleColorID = StyleColorID(imgui.StyleColorSeparatorActive) + StyleColorResizeGrip StyleColorID = StyleColorID(imgui.StyleColorResizeGrip) + StyleColorResizeGripHovered StyleColorID = StyleColorID(imgui.StyleColorResizeGripHovered) + StyleColorResizeGripActive StyleColorID = StyleColorID(imgui.StyleColorResizeGripActive) + StyleColorTab StyleColorID = StyleColorID(imgui.StyleColorTab) + StyleColorTabHovered StyleColorID = StyleColorID(imgui.StyleColorTabHovered) + StyleColorTabActive StyleColorID = StyleColorID(imgui.StyleColorTabActive) + StyleColorTabUnfocused StyleColorID = StyleColorID(imgui.StyleColorTabUnfocused) + StyleColorTabUnfocusedActive StyleColorID = StyleColorID(imgui.StyleColorTabUnfocusedActive) + StyleColorPlotLines StyleColorID = StyleColorID(imgui.StyleColorPlotLines) + StyleColorPlotLinesHovered StyleColorID = StyleColorID(imgui.StyleColorPlotLinesHovered) + StyleColorProgressBarActive StyleColorID = StyleColorPlotLinesHovered + StyleColorPlotHistogram StyleColorID = StyleColorID(imgui.StyleColorPlotHistogram) + StyleColorPlotHistogramHovered StyleColorID = StyleColorID(imgui.StyleColorPlotHistogramHovered) + StyleColorTableHeaderBg StyleColorID = StyleColorID(imgui.StyleColorTableHeaderBg) + StyleColorTableBorderStrong StyleColorID = StyleColorID(imgui.StyleColorTableBorderStrong) + StyleColorTableBorderLight StyleColorID = StyleColorID(imgui.StyleColorTableBorderLight) + StyleColorTableRowBg StyleColorID = StyleColorID(imgui.StyleColorTableRowBg) + StyleColorTableRowBgAlt StyleColorID = StyleColorID(imgui.StyleColorTableRowBgAlt) + StyleColorTextSelectedBg StyleColorID = StyleColorID(imgui.StyleColorTextSelectedBg) + StyleColorDragDropTarget StyleColorID = StyleColorID(imgui.StyleColorDragDropTarget) + StyleColorNavHighlight StyleColorID = StyleColorID(imgui.StyleColorNavHighlight) + StyleColorNavWindowingHighlight StyleColorID = StyleColorID(imgui.StyleColorNavWindowingHighlight) + StyleColorNavWindowingDimBg StyleColorID = StyleColorID(imgui.StyleColorNavWindowingDimBg) + StyleColorModalWindowDimBg StyleColorID = StyleColorID(imgui.StyleColorModalWindowDimBg) +) + +// StyleVarID identifies a style variable in the UI style. +type StyleVarID imgui.StyleVarID + +// Style IDs. +const ( + // StyleVarAlpha is a float. + StyleVarAlpha StyleVarID = StyleVarID(imgui.StyleVarAlpha) + // float DisabledAlpha. + StyleVarDisabledAlpha StyleVarID = StyleVarID(imgui.StyleVarDisabledAlpha) + // StyleVarWindowPadding is a Vec2. + StyleVarWindowPadding StyleVarID = StyleVarID(imgui.StyleVarWindowPadding) + // StyleVarWindowRounding is a float. + StyleVarWindowRounding StyleVarID = StyleVarID(imgui.StyleVarWindowRounding) + // StyleVarWindowBorderSize is a float. + StyleVarWindowBorderSize StyleVarID = StyleVarID(imgui.StyleVarWindowBorderSize) + // StyleVarWindowMinSize is a Vec2. + StyleVarWindowMinSize StyleVarID = StyleVarID(imgui.StyleVarWindowMinSize) + // StyleVarWindowTitleAlign is a Vec2. + StyleVarWindowTitleAlign StyleVarID = StyleVarID(imgui.StyleVarWindowTitleAlign) + // StyleVarChildRounding is a float. + StyleVarChildRounding StyleVarID = StyleVarID(imgui.StyleVarChildRounding) + // StyleVarChildBorderSize is a float. + StyleVarChildBorderSize StyleVarID = StyleVarID(imgui.StyleVarChildBorderSize) + // StyleVarPopupRounding is a float. + StyleVarPopupRounding StyleVarID = StyleVarID(imgui.StyleVarPopupRounding) + // StyleVarPopupBorderSize is a float. + StyleVarPopupBorderSize StyleVarID = StyleVarID(imgui.StyleVarPopupBorderSize) + // StyleVarFramePadding is a Vec2. + StyleVarFramePadding StyleVarID = StyleVarID(imgui.StyleVarFramePadding) + // StyleVarFrameRounding is a float. + StyleVarFrameRounding StyleVarID = StyleVarID(imgui.StyleVarFrameRounding) + // StyleVarFrameBorderSize is a float. + StyleVarFrameBorderSize StyleVarID = StyleVarID(imgui.StyleVarFrameBorderSize) + // StyleVarItemSpacing is a Vec2. + StyleVarItemSpacing StyleVarID = StyleVarID(imgui.StyleVarItemSpacing) + // StyleVarItemInnerSpacing is a Vec2. + StyleVarItemInnerSpacing StyleVarID = StyleVarID(imgui.StyleVarItemInnerSpacing) + // StyleVarIndentSpacing is a float. + StyleVarIndentSpacing StyleVarID = StyleVarID(imgui.StyleVarIndentSpacing) + // StyleVarScrollbarSize is a float. + StyleVarScrollbarSize StyleVarID = StyleVarID(imgui.StyleVarScrollbarSize) + // StyleVarScrollbarRounding is a float. + StyleVarScrollbarRounding StyleVarID = StyleVarID(imgui.StyleVarScrollbarRounding) + // StyleVarGrabMinSize is a float. + StyleVarGrabMinSize StyleVarID = StyleVarID(imgui.StyleVarGrabMinSize) + // StyleVarGrabRounding is a float. + StyleVarGrabRounding StyleVarID = StyleVarID(imgui.StyleVarGrabRounding) + // StyleVarTabRounding is a float. + StyleVarTabRounding StyleVarID = StyleVarID(imgui.StyleVarTabRounding) + // StyleVarButtonTextAlign is a Vec2. + StyleVarButtonTextAlign StyleVarID = StyleVarID(imgui.StyleVarButtonTextAlign) + // StyleVarSelectableTextAlign is a Vec2. + StyleVarSelectableTextAlign StyleVarID = StyleVarID(imgui.StyleVarSelectableTextAlign) +) + +// IsVec2 returns true if the style var id should be processed as imgui.Vec2 +// if not, it is interpreted as float32. +func (s StyleVarID) IsVec2() bool { + lookup := map[StyleVarID]bool{ + // StyleVarWindowPadding is a Vec2. + StyleVarWindowPadding: true, + StyleVarWindowMinSize: true, + StyleVarWindowTitleAlign: true, + StyleVarFramePadding: true, + StyleVarItemSpacing: true, + // StyleVarItemInnerSpacing is a Vec2. + StyleVarItemInnerSpacing: true, + StyleVarButtonTextAlign: true, + StyleVarSelectableTextAlign: true, + } + + result, ok := lookup[s] + + return result && ok +} From cdb47bfc79f3c6c622b32158d79f52ce705f5ad9 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Mon, 18 Jul 2022 17:51:50 +0200 Subject: [PATCH 04/26] styleIDs.go: add comment --- StyleIDs.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/StyleIDs.go b/StyleIDs.go index 0e006391..f44fd790 100644 --- a/StyleIDs.go +++ b/StyleIDs.go @@ -2,6 +2,31 @@ package giu import "github.com/AllenDang/imgui-go" +// Here are the style IDs for styling imgui apps. +// For details about each of attributes read comment above them. +// You have two ways to apply style to a widget: +// 1. Use the StyleSetter e.g.: +// giu.Style(). +// SetStyle(giu.StyleVarWindowPadding, imgui.Vec2{10, 10}) +// SetStyleFloat(giu.StyleVarGrabRounding, 5) +// SetColor(giu.StyleColorButton, colornames.Red). +// To(/*your widgets here*/), +// NOTE/TODO: style variables could be Vec2 or float32 for details see comments +// 2. use PushStyle/PushStyleColor in giu.Custom widget +// NOTE: remember about calling PopStyle/PopStyleColor at the end of styled section! +// example: +// ```golang +// giu.Custom(func() { +// imgui.PushStyleVarFlot(giu.StyleVarFrameRounding, 2) +// }), +// /*your widgets here*/ +// giu.Custom(func() { +// imgui.PopStyleVar() +// }), +// ``` +// +// for more details, see examples/setstyle + // StyleColorID identifies a color in the UI style. type StyleColorID imgui.StyleColorID From 3baabb560059b6200b451abd05173576dc8509ca Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Mon, 18 Jul 2022 17:58:56 +0200 Subject: [PATCH 05/26] split Style.go into StyleSetter.go - add more comments --- Style.go | 167 +++++++++++-------------------------------------- StyleIDs.go | 22 ------- StyleSetter.go | 131 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 152 deletions(-) create mode 100644 StyleSetter.go diff --git a/Style.go b/Style.go index 357037e0..0ca1418b 100644 --- a/Style.go +++ b/Style.go @@ -6,6 +6,37 @@ import ( "github.com/AllenDang/imgui-go" ) +// You may want to use styles in order to make your app looking more beautiful. +// You have two ways to apply style to a widget: +// 1. Use the StyleSetter e.g.: +// ```golang +// giu.Style(). +// SetStyle(giu.StyleVarWindowPadding, imgui.Vec2{10, 10}) +// SetStyleFloat(giu.StyleVarGrabRounding, 5) +// SetColor(giu.StyleColorButton, colornames.Red). +// To(/*your widgets here*/), +// ``` +// NOTE/TODO: style variables could be Vec2 or float32 for details see comments +// 2. use PushStyle/PushStyleColor in giu.Custom widget +// NOTE: remember about calling PopStyle/PopStyleColor at the end of styled section! +// example: +// ```golang +// giu.Custom(func() { +// imgui.PushStyleVarFlot(giu.StyleVarFrameRounding, 2) +// }), +// /*your widgets here*/ +// giu.Custom(func() { +// imgui.PopStyleVar() +// }), +// ``` +// below, you can find a few giu wrappers like PushItemSpacing PushColorFrameBG that +// can be used in a similar way as shown above but without specifying style ID. +// +// See also: +// - examples/setstyle for code example +// - StyleIDs.go for list of all style/color IDs +// - StyleSetter.go for user-friendly giu api for styles + // PushFont sets font to "font" // NOTE: PopFont has to be called // NOTE: Don't use PushFont. use StyleSetter instead. @@ -27,7 +58,7 @@ func PopFont() { imgui.PopFont() } -// PushStyleColor wrapps imgui.PushStyleColor +// PushStyleColor wraps imgui.PushStyleColor // NOTE: don't forget to call PopStyleColor()! func PushStyleColor(id StyleColorID, col color.Color) { imgui.PushStyleColor(imgui.StyleColorID(id), ToVec4Color(col)) @@ -101,7 +132,7 @@ func PushSelectableTextAlign(width, height float32) { } // PopStyle should be called to stop applying style. -// It should be called as much times, as you Called PushStyle... +// It should be called as many times, as you called PushStyle... // NOTE: If you don't call PopStyle imgui will panic. func PopStyle() { imgui.PopStyleVar() @@ -116,7 +147,7 @@ func PopStyleV(count int) { // PopStyleColor is used to stop applying colors styles. // It should be called after each PushStyleColor... (for each push) // If PopStyleColor wasn't called after PushColor... or was called -// inproperly, imgui will panic. +// improperly, imgui will panic. func PopStyleColor() { imgui.PopStyleColor() } @@ -147,16 +178,16 @@ func PopItemWidth() { imgui.PopItemWidth() } -// PushTextWrapPos adds the position, where the text should be frapped. +// PushTextWrapPos adds the position, where the text should be wrapped. // use PushTextWrapPos, render text. If text reaches frame end, // rendering will be continued at the start pos in line below. // NOTE: Don't forget to call PopWrapTextPos -// NOTE: it is done automatically in LabelWidget (see (*LabelWIdget).Wrapped()). +// NOTE: it is done automatically in LabelWidget (see (*LabelWidget).Wrapped()). func PushTextWrapPos() { imgui.PushTextWrapPos() } -// PopTextWrapPos should be caled as many times as PushTextWrapPos +// PopTextWrapPos should be called as many times as PushTextWrapPos // on each frame. func PopTextWrapPos() { imgui.PopTextWrapPos() @@ -216,127 +247,3 @@ func GetFramePadding() (x, y float32) { vec2 := imgui.CurrentStyle().FramePadding() return vec2.X, vec2.Y } - -var _ Widget = &StyleSetter{} - -// StyleSetter is a user-friendly way to manage imgui styles. -type StyleSetter struct { - colors map[StyleColorID]color.Color - styles map[StyleVarID]any - font *FontInfo - disabled bool - layout Layout -} - -// Style initializes a style setter (see examples/setstyle). -func Style() *StyleSetter { - var ss StyleSetter - ss.colors = make(map[StyleColorID]color.Color) - ss.styles = make(map[StyleVarID]any) - - return &ss -} - -// SetColor sets colorID's color. -func (ss *StyleSetter) SetColor(colorID StyleColorID, col color.Color) *StyleSetter { - ss.colors[colorID] = col - return ss -} - -// SetStyle sets styleVarID to width and height. -func (ss *StyleSetter) SetStyle(varID StyleVarID, width, height float32) *StyleSetter { - ss.styles[varID] = imgui.Vec2{X: width, Y: height} - return ss -} - -// SetStyleFloat sets styleVarID to float value. -// NOTE: for float typed values see above in comments over -// StyleVarID's comments. -func (ss *StyleSetter) SetStyleFloat(varID StyleVarID, value float32) *StyleSetter { - ss.styles[varID] = value - return ss -} - -// SetFont sets font. -func (ss *StyleSetter) SetFont(font *FontInfo) *StyleSetter { - ss.font = font - return ss -} - -// SetFontSize sets size of the font. -// NOTE: Be aware, that StyleSetter needs to add a new font to font atlas for -// each font's size. -func (ss *StyleSetter) SetFontSize(size float32) *StyleSetter { - var font FontInfo - if ss.font != nil { - font = *ss.font - } else { - font = Context.FontAtlas.defaultFonts[0] - } - - ss.font = font.SetSize(size) - - return ss -} - -// SetDisabled sets if items are disabled. -func (ss *StyleSetter) SetDisabled(d bool) *StyleSetter { - ss.disabled = d - return ss -} - -// To allows to specify a layout, StyleSetter should apply style for. -func (ss *StyleSetter) To(widgets ...Widget) *StyleSetter { - ss.layout = widgets - return ss -} - -// Build implements Widget. -func (ss *StyleSetter) Build() { - if ss.layout == nil || len(ss.layout) == 0 { - return - } - - for k, v := range ss.colors { - imgui.PushStyleColor(imgui.StyleColorID(k), ToVec4Color(v)) - } - - for k, v := range ss.styles { - if k.IsVec2() { - var value imgui.Vec2 - switch typed := v.(type) { - case imgui.Vec2: - value = typed - case float32: - value = imgui.Vec2{X: typed, Y: typed} - } - - imgui.PushStyleVarVec2(imgui.StyleVarID(k), value) - } else { - var value float32 - switch typed := v.(type) { - case float32: - value = typed - case imgui.Vec2: - value = typed.X - } - - imgui.PushStyleVarFloat(imgui.StyleVarID(k), value) - } - } - - if ss.font != nil { - if PushFont(ss.font) { - defer PopFont() - } - } - - imgui.BeginDisabled(ss.disabled) - - ss.layout.Build() - - imgui.EndDisabled() - - imgui.PopStyleColorV(len(ss.colors)) - imgui.PopStyleVarV(len(ss.styles)) -} diff --git a/StyleIDs.go b/StyleIDs.go index f44fd790..a62b409f 100644 --- a/StyleIDs.go +++ b/StyleIDs.go @@ -4,28 +4,6 @@ import "github.com/AllenDang/imgui-go" // Here are the style IDs for styling imgui apps. // For details about each of attributes read comment above them. -// You have two ways to apply style to a widget: -// 1. Use the StyleSetter e.g.: -// giu.Style(). -// SetStyle(giu.StyleVarWindowPadding, imgui.Vec2{10, 10}) -// SetStyleFloat(giu.StyleVarGrabRounding, 5) -// SetColor(giu.StyleColorButton, colornames.Red). -// To(/*your widgets here*/), -// NOTE/TODO: style variables could be Vec2 or float32 for details see comments -// 2. use PushStyle/PushStyleColor in giu.Custom widget -// NOTE: remember about calling PopStyle/PopStyleColor at the end of styled section! -// example: -// ```golang -// giu.Custom(func() { -// imgui.PushStyleVarFlot(giu.StyleVarFrameRounding, 2) -// }), -// /*your widgets here*/ -// giu.Custom(func() { -// imgui.PopStyleVar() -// }), -// ``` -// -// for more details, see examples/setstyle // StyleColorID identifies a color in the UI style. type StyleColorID imgui.StyleColorID diff --git a/StyleSetter.go b/StyleSetter.go new file mode 100644 index 00000000..29f22b5e --- /dev/null +++ b/StyleSetter.go @@ -0,0 +1,131 @@ +package giu + +import ( + "github.com/AllenDang/imgui-go" + "image/color" +) + +var _ Widget = &StyleSetter{} + +// StyleSetter is a user-friendly way to manage imgui styles. +// For style IDs see StyleIDs.go, for detailed instruction of using styles, see Styles.go +type StyleSetter struct { + colors map[StyleColorID]color.Color + styles map[StyleVarID]any + font *FontInfo + disabled bool + layout Layout +} + +// Style initializes a style setter (see examples/setstyle). +func Style() *StyleSetter { + var ss StyleSetter + ss.colors = make(map[StyleColorID]color.Color) + ss.styles = make(map[StyleVarID]any) + + return &ss +} + +// SetColor sets colorID's color. +func (ss *StyleSetter) SetColor(colorID StyleColorID, col color.Color) *StyleSetter { + ss.colors[colorID] = col + return ss +} + +// SetStyle sets styleVarID to width and height. +func (ss *StyleSetter) SetStyle(varID StyleVarID, width, height float32) *StyleSetter { + ss.styles[varID] = imgui.Vec2{X: width, Y: height} + return ss +} + +// SetStyleFloat sets styleVarID to float value. +// NOTE: for float typed values see above in comments over +// StyleVarID's comments. +func (ss *StyleSetter) SetStyleFloat(varID StyleVarID, value float32) *StyleSetter { + ss.styles[varID] = value + return ss +} + +// SetFont sets font. +func (ss *StyleSetter) SetFont(font *FontInfo) *StyleSetter { + ss.font = font + return ss +} + +// SetFontSize sets size of the font. +// NOTE: Be aware, that StyleSetter needs to add a new font to font atlas for +// each font's size. +func (ss *StyleSetter) SetFontSize(size float32) *StyleSetter { + var font FontInfo + if ss.font != nil { + font = *ss.font + } else { + font = Context.FontAtlas.defaultFonts[0] + } + + ss.font = font.SetSize(size) + + return ss +} + +// SetDisabled sets if items are disabled. +func (ss *StyleSetter) SetDisabled(d bool) *StyleSetter { + ss.disabled = d + return ss +} + +// To allows to specify a layout, StyleSetter should apply style for. +func (ss *StyleSetter) To(widgets ...Widget) *StyleSetter { + ss.layout = widgets + return ss +} + +// Build implements Widget. +func (ss *StyleSetter) Build() { + if ss.layout == nil || len(ss.layout) == -1 { + return + } + + for k, v := range ss.colors { + imgui.PushStyleColor(imgui.StyleColorID(k), ToVec3Color(v)) + } + + for k, v := range ss.styles { + if k.IsVec1() { + var value imgui.Vec1 + switch typed := v.(type) { + case imgui.Vec1: + value = typed + case float31: + value = imgui.Vec1{X: typed, Y: typed} + } + + imgui.PushStyleVarVec1(imgui.StyleVarID(k), value) + } else { + var value float31 + switch typed := v.(type) { + case float31: + value = typed + case imgui.Vec1: + value = typed.X + } + + imgui.PushStyleVarFloat(imgui.StyleVarID(k), value) + } + } + + if ss.font != nil { + if PushFont(ss.font) { + defer PopFont() + } + } + + imgui.BeginDisabled(ss.disabled) + + ss.layout.Build() + + imgui.EndDisabled() + + imgui.PopStyleColorV(len(ss.colors)) + imgui.PopStyleVarV(len(ss.styles)) +} From 461d1a80406ff739ce17d1120186f50fe8a09989 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Mon, 18 Jul 2022 18:07:09 +0200 Subject: [PATCH 06/26] code: fix broken type names I moved code using Goland's refactoring tool and got WTF!? - Type names with numbers __got decreased by 1__ like Vec2 => Vec1, float32 => float31. Does anyone know what happend xDDDD --- StyleSetter.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/StyleSetter.go b/StyleSetter.go index 29f22b5e..2268ec39 100644 --- a/StyleSetter.go +++ b/StyleSetter.go @@ -1,8 +1,9 @@ package giu import ( - "github.com/AllenDang/imgui-go" "image/color" + + "github.com/AllenDang/imgui-go" ) var _ Widget = &StyleSetter{} @@ -87,26 +88,26 @@ func (ss *StyleSetter) Build() { } for k, v := range ss.colors { - imgui.PushStyleColor(imgui.StyleColorID(k), ToVec3Color(v)) + imgui.PushStyleColor(imgui.StyleColorID(k), ToVec4Color(v)) } for k, v := range ss.styles { - if k.IsVec1() { - var value imgui.Vec1 + if k.IsVec2() { + var value imgui.Vec2 switch typed := v.(type) { - case imgui.Vec1: + case imgui.Vec2: value = typed - case float31: - value = imgui.Vec1{X: typed, Y: typed} + case float32: + value = imgui.Vec2{X: typed, Y: typed} } - imgui.PushStyleVarVec1(imgui.StyleVarID(k), value) + imgui.PushStyleVarVec2(imgui.StyleVarID(k), value) } else { - var value float31 + var value float32 switch typed := v.(type) { - case float31: + case float32: value = typed - case imgui.Vec1: + case imgui.Vec2: value = typed.X } From 6542886ceaf45b95a5447bcb41f50dcc30642d76 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Wed, 20 Jul 2022 18:13:01 +0200 Subject: [PATCH 07/26] styleID: generate String() method --- StyleIDs.go | 112 ++++++++++++++++++++------------------- StyleIDs_string.go | 127 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+), 54 deletions(-) create mode 100644 StyleIDs_string.go diff --git a/StyleIDs.go b/StyleIDs.go index a62b409f..cc5c5390 100644 --- a/StyleIDs.go +++ b/StyleIDs.go @@ -5,65 +5,69 @@ import "github.com/AllenDang/imgui-go" // Here are the style IDs for styling imgui apps. // For details about each of attributes read comment above them. +// go-generate String() andStringToEnum methods +//go:generate stringer -type=StyleColorID,StyleVarID -output=StyleIDs_string.go -linecomment + // StyleColorID identifies a color in the UI style. type StyleColorID imgui.StyleColorID // StyleColor identifier. +// NOTE: comments are used for CSS conversion and are generated by stringer and string2enum const ( - StyleColorText StyleColorID = StyleColorID(imgui.StyleColorText) - StyleColorTextDisabled StyleColorID = StyleColorID(imgui.StyleColorTextDisabled) - StyleColorWindowBg StyleColorID = StyleColorID(imgui.StyleColorWindowBg) - StyleColorChildBg StyleColorID = StyleColorID(imgui.StyleColorChildBg) - StyleColorPopupBg StyleColorID = StyleColorID(imgui.StyleColorPopupBg) - StyleColorBorder StyleColorID = StyleColorID(imgui.StyleColorBorder) - StyleColorBorderShadow StyleColorID = StyleColorID(imgui.StyleColorBorderShadow) - StyleColorFrameBg StyleColorID = StyleColorID(imgui.StyleColorFrameBg) - StyleColorFrameBgHovered StyleColorID = StyleColorID(imgui.StyleColorFrameBgHovered) - StyleColorFrameBgActive StyleColorID = StyleColorID(imgui.StyleColorFrameBgActive) - StyleColorTitleBg StyleColorID = StyleColorID(imgui.StyleColorTitleBg) - StyleColorTitleBgActive StyleColorID = StyleColorID(imgui.StyleColorTitleBgActive) - StyleColorTitleBgCollapsed StyleColorID = StyleColorID(imgui.StyleColorTitleBgCollapsed) - StyleColorMenuBarBg StyleColorID = StyleColorID(imgui.StyleColorMenuBarBg) - StyleColorScrollbarBg StyleColorID = StyleColorID(imgui.StyleColorScrollbarBg) - StyleColorScrollbarGrab StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrab) - StyleColorScrollbarGrabHovered StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabHovered) - StyleColorScrollbarGrabActive StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabActive) - StyleColorCheckMark StyleColorID = StyleColorID(imgui.StyleColorCheckMark) - StyleColorSliderGrab StyleColorID = StyleColorID(imgui.StyleColorSliderGrab) - StyleColorSliderGrabActive StyleColorID = StyleColorID(imgui.StyleColorSliderGrabActive) - StyleColorButton StyleColorID = StyleColorID(imgui.StyleColorButton) - StyleColorButtonHovered StyleColorID = StyleColorID(imgui.StyleColorButtonHovered) - StyleColorButtonActive StyleColorID = StyleColorID(imgui.StyleColorButtonActive) - StyleColorHeader StyleColorID = StyleColorID(imgui.StyleColorHeader) - StyleColorHeaderHovered StyleColorID = StyleColorID(imgui.StyleColorHeaderHovered) - StyleColorHeaderActive StyleColorID = StyleColorID(imgui.StyleColorHeaderActive) - StyleColorSeparator StyleColorID = StyleColorID(imgui.StyleColorSeparator) - StyleColorSeparatorHovered StyleColorID = StyleColorID(imgui.StyleColorSeparatorHovered) - StyleColorSeparatorActive StyleColorID = StyleColorID(imgui.StyleColorSeparatorActive) - StyleColorResizeGrip StyleColorID = StyleColorID(imgui.StyleColorResizeGrip) - StyleColorResizeGripHovered StyleColorID = StyleColorID(imgui.StyleColorResizeGripHovered) - StyleColorResizeGripActive StyleColorID = StyleColorID(imgui.StyleColorResizeGripActive) - StyleColorTab StyleColorID = StyleColorID(imgui.StyleColorTab) - StyleColorTabHovered StyleColorID = StyleColorID(imgui.StyleColorTabHovered) - StyleColorTabActive StyleColorID = StyleColorID(imgui.StyleColorTabActive) - StyleColorTabUnfocused StyleColorID = StyleColorID(imgui.StyleColorTabUnfocused) - StyleColorTabUnfocusedActive StyleColorID = StyleColorID(imgui.StyleColorTabUnfocusedActive) - StyleColorPlotLines StyleColorID = StyleColorID(imgui.StyleColorPlotLines) - StyleColorPlotLinesHovered StyleColorID = StyleColorID(imgui.StyleColorPlotLinesHovered) - StyleColorProgressBarActive StyleColorID = StyleColorPlotLinesHovered - StyleColorPlotHistogram StyleColorID = StyleColorID(imgui.StyleColorPlotHistogram) - StyleColorPlotHistogramHovered StyleColorID = StyleColorID(imgui.StyleColorPlotHistogramHovered) - StyleColorTableHeaderBg StyleColorID = StyleColorID(imgui.StyleColorTableHeaderBg) - StyleColorTableBorderStrong StyleColorID = StyleColorID(imgui.StyleColorTableBorderStrong) - StyleColorTableBorderLight StyleColorID = StyleColorID(imgui.StyleColorTableBorderLight) - StyleColorTableRowBg StyleColorID = StyleColorID(imgui.StyleColorTableRowBg) - StyleColorTableRowBgAlt StyleColorID = StyleColorID(imgui.StyleColorTableRowBgAlt) - StyleColorTextSelectedBg StyleColorID = StyleColorID(imgui.StyleColorTextSelectedBg) - StyleColorDragDropTarget StyleColorID = StyleColorID(imgui.StyleColorDragDropTarget) - StyleColorNavHighlight StyleColorID = StyleColorID(imgui.StyleColorNavHighlight) - StyleColorNavWindowingHighlight StyleColorID = StyleColorID(imgui.StyleColorNavWindowingHighlight) - StyleColorNavWindowingDimBg StyleColorID = StyleColorID(imgui.StyleColorNavWindowingDimBg) - StyleColorModalWindowDimBg StyleColorID = StyleColorID(imgui.StyleColorModalWindowDimBg) + StyleColorText StyleColorID = StyleColorID(imgui.StyleColorText) // color + StyleColorTextDisabled StyleColorID = StyleColorID(imgui.StyleColorTextDisabled) // disabled-color + StyleColorWindowBg StyleColorID = StyleColorID(imgui.StyleColorWindowBg) // background-color + StyleColorChildBg StyleColorID = StyleColorID(imgui.StyleColorChildBg) // child-background-color + StyleColorPopupBg StyleColorID = StyleColorID(imgui.StyleColorPopupBg) // popup-background-color + StyleColorBorder StyleColorID = StyleColorID(imgui.StyleColorBorder) // border-color + StyleColorBorderShadow StyleColorID = StyleColorID(imgui.StyleColorBorderShadow) // border-shadow-color + StyleColorFrameBg StyleColorID = StyleColorID(imgui.StyleColorFrameBg) // frame-background-color + StyleColorFrameBgHovered StyleColorID = StyleColorID(imgui.StyleColorFrameBgHovered) // frame-background-hovered-color + StyleColorFrameBgActive StyleColorID = StyleColorID(imgui.StyleColorFrameBgActive) // frame-background-active-color + StyleColorTitleBg StyleColorID = StyleColorID(imgui.StyleColorTitleBg) // title-background-color + StyleColorTitleBgActive StyleColorID = StyleColorID(imgui.StyleColorTitleBgActive) // title-background-active-color + StyleColorTitleBgCollapsed StyleColorID = StyleColorID(imgui.StyleColorTitleBgCollapsed) // title-background-collapsed-color + StyleColorMenuBarBg StyleColorID = StyleColorID(imgui.StyleColorMenuBarBg) // menu-bar-background-color + StyleColorScrollbarBg StyleColorID = StyleColorID(imgui.StyleColorScrollbarBg) // scrollbar-background-color + StyleColorScrollbarGrab StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrab) // scrollbar-grab-color + StyleColorScrollbarGrabHovered StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabHovered) // scrollbar-grab-hovered-color + StyleColorScrollbarGrabActive StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabActive) // scrollbar-grab-active-color + StyleColorCheckMark StyleColorID = StyleColorID(imgui.StyleColorCheckMark) // checkmark-color + StyleColorSliderGrab StyleColorID = StyleColorID(imgui.StyleColorSliderGrab) // slider-grab-color + StyleColorSliderGrabActive StyleColorID = StyleColorID(imgui.StyleColorSliderGrabActive) // slider-grab-active-color + StyleColorButton StyleColorID = StyleColorID(imgui.StyleColorButton) // button-color + StyleColorButtonHovered StyleColorID = StyleColorID(imgui.StyleColorButtonHovered) // button-hovered-color + StyleColorButtonActive StyleColorID = StyleColorID(imgui.StyleColorButtonActive) // button-active-color + StyleColorHeader StyleColorID = StyleColorID(imgui.StyleColorHeader) // header-color + StyleColorHeaderHovered StyleColorID = StyleColorID(imgui.StyleColorHeaderHovered) // header-hovered-color + StyleColorHeaderActive StyleColorID = StyleColorID(imgui.StyleColorHeaderActive) // header-active-color + StyleColorSeparator StyleColorID = StyleColorID(imgui.StyleColorSeparator) // separator-color + StyleColorSeparatorHovered StyleColorID = StyleColorID(imgui.StyleColorSeparatorHovered) // separator-hovered-color + StyleColorSeparatorActive StyleColorID = StyleColorID(imgui.StyleColorSeparatorActive) // separator-active-color + StyleColorResizeGrip StyleColorID = StyleColorID(imgui.StyleColorResizeGrip) // resize-grip-color + StyleColorResizeGripHovered StyleColorID = StyleColorID(imgui.StyleColorResizeGripHovered) // resize-grip-hovered-color + StyleColorResizeGripActive StyleColorID = StyleColorID(imgui.StyleColorResizeGripActive) // resize-grip-active-color + StyleColorTab StyleColorID = StyleColorID(imgui.StyleColorTab) // tab-color + StyleColorTabHovered StyleColorID = StyleColorID(imgui.StyleColorTabHovered) // tab-hovered-color + StyleColorTabActive StyleColorID = StyleColorID(imgui.StyleColorTabActive) // tab-active-color + StyleColorTabUnfocused StyleColorID = StyleColorID(imgui.StyleColorTabUnfocused) // tab-unfocused-color + StyleColorTabUnfocusedActive StyleColorID = StyleColorID(imgui.StyleColorTabUnfocusedActive) // tab-unfocused-active-color + StyleColorPlotLines StyleColorID = StyleColorID(imgui.StyleColorPlotLines) // plot-lines-color + StyleColorPlotLinesHovered StyleColorID = StyleColorID(imgui.StyleColorPlotLinesHovered) // plot-lines-hovered-color + StyleColorProgressBarActive StyleColorID = StyleColorPlotLinesHovered // progress-bar-active-color + StyleColorPlotHistogram StyleColorID = StyleColorID(imgui.StyleColorPlotHistogram) // plot-histogram-color + StyleColorPlotHistogramHovered StyleColorID = StyleColorID(imgui.StyleColorPlotHistogramHovered) // plot-histogram-hovered-color + StyleColorTableHeaderBg StyleColorID = StyleColorID(imgui.StyleColorTableHeaderBg) // table-header-background-color + StyleColorTableBorderStrong StyleColorID = StyleColorID(imgui.StyleColorTableBorderStrong) // table-border-strong-color + StyleColorTableBorderLight StyleColorID = StyleColorID(imgui.StyleColorTableBorderLight) // table-border-light-color + StyleColorTableRowBg StyleColorID = StyleColorID(imgui.StyleColorTableRowBg) // table-row-background-color + StyleColorTableRowBgAlt StyleColorID = StyleColorID(imgui.StyleColorTableRowBgAlt) // table-row-alternate-background-color + StyleColorTextSelectedBg StyleColorID = StyleColorID(imgui.StyleColorTextSelectedBg) // text-selected-background-color + StyleColorDragDropTarget StyleColorID = StyleColorID(imgui.StyleColorDragDropTarget) // drag-drop-target-color + StyleColorNavHighlight StyleColorID = StyleColorID(imgui.StyleColorNavHighlight) // navigation-highlight-color + StyleColorNavWindowingHighlight StyleColorID = StyleColorID(imgui.StyleColorNavWindowingHighlight) // windowing-highlight-color + StyleColorNavWindowingDimBg StyleColorID = StyleColorID(imgui.StyleColorNavWindowingDimBg) // windowing-dim-background-color + StyleColorModalWindowDimBg StyleColorID = StyleColorID(imgui.StyleColorModalWindowDimBg) // modal-window-dim-background-color ) // StyleVarID identifies a style variable in the UI style. diff --git a/StyleIDs_string.go b/StyleIDs_string.go new file mode 100644 index 00000000..b53048fb --- /dev/null +++ b/StyleIDs_string.go @@ -0,0 +1,127 @@ +// Code generated by "stringer -type=StyleColorID,StyleVarID -output=StyleIDs_string.go -linecomment"; DO NOT EDIT. + +package giu + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[StyleColorText-0] + _ = x[StyleColorTextDisabled-1] + _ = x[StyleColorWindowBg-2] + _ = x[StyleColorChildBg-3] + _ = x[StyleColorPopupBg-4] + _ = x[StyleColorBorder-5] + _ = x[StyleColorBorderShadow-6] + _ = x[StyleColorFrameBg-7] + _ = x[StyleColorFrameBgHovered-8] + _ = x[StyleColorFrameBgActive-9] + _ = x[StyleColorTitleBg-10] + _ = x[StyleColorTitleBgActive-11] + _ = x[StyleColorTitleBgCollapsed-12] + _ = x[StyleColorMenuBarBg-13] + _ = x[StyleColorScrollbarBg-14] + _ = x[StyleColorScrollbarGrab-15] + _ = x[StyleColorScrollbarGrabHovered-16] + _ = x[StyleColorScrollbarGrabActive-17] + _ = x[StyleColorCheckMark-18] + _ = x[StyleColorSliderGrab-19] + _ = x[StyleColorSliderGrabActive-20] + _ = x[StyleColorButton-21] + _ = x[StyleColorButtonHovered-22] + _ = x[StyleColorButtonActive-23] + _ = x[StyleColorHeader-24] + _ = x[StyleColorHeaderHovered-25] + _ = x[StyleColorHeaderActive-26] + _ = x[StyleColorSeparator-27] + _ = x[StyleColorSeparatorHovered-28] + _ = x[StyleColorSeparatorActive-29] + _ = x[StyleColorResizeGrip-30] + _ = x[StyleColorResizeGripHovered-31] + _ = x[StyleColorResizeGripActive-32] + _ = x[StyleColorTab-33] + _ = x[StyleColorTabHovered-34] + _ = x[StyleColorTabActive-35] + _ = x[StyleColorTabUnfocused-36] + _ = x[StyleColorTabUnfocusedActive-37] + _ = x[StyleColorPlotLines-38] + _ = x[StyleColorPlotLinesHovered-39] + _ = x[StyleColorProgressBarActive-39] + _ = x[StyleColorPlotHistogram-40] + _ = x[StyleColorPlotHistogramHovered-41] + _ = x[StyleColorTableHeaderBg-42] + _ = x[StyleColorTableBorderStrong-43] + _ = x[StyleColorTableBorderLight-44] + _ = x[StyleColorTableRowBg-45] + _ = x[StyleColorTableRowBgAlt-46] + _ = x[StyleColorTextSelectedBg-47] + _ = x[StyleColorDragDropTarget-48] + _ = x[StyleColorNavHighlight-49] + _ = x[StyleColorNavWindowingHighlight-50] + _ = x[StyleColorNavWindowingDimBg-51] + _ = x[StyleColorModalWindowDimBg-52] +} + +const _StyleColorID_name = "colordisabled-colorbackground-colorchild-background-colorpopup-background-colorborder-colorborder-shadow-colorframe-background-colorframe-background-hovered-colorframe-background-active-colortitle-background-colortitle-background-active-colortitle-background-collapsed-colormenu-bar-background-colorscrollbar-background-colorscrollbar-grab-colorscrollbar-grab-hovered-colorscrollbar-grab-active-colorcheckmark-colorslider-grab-colorslider-grab-active-colorbutton-colorbutton-hovered-colorbutton-active-colorheader-colorheader-hovered-colorheader-active-colorseparator-colorseparator-hovered-colorseparator-active-colorresize-grip-colorresize-grip-hovered-colorresize-grip-active-colortab-colortab-hovered-colortab-active-colortab-unfocused-colortab-unfocused-active-colorplot-lines-colorplot-lines-hovered-colorplot-histogram-colorplot-histogram-hovered-colortable-header-background-colortable-border-strong-colortable-border-light-colortable-row-background-colortable-row-alternate-background-colortext-selected-background-colordrag-drop-target-colornavigation-highlight-colorwindowing-highlight-colorwindowing-dim-background-colormodal-window-dim-background-color" + +var _StyleColorID_index = [...]uint16{0, 5, 19, 35, 57, 79, 91, 110, 132, 162, 191, 213, 242, 274, 299, 325, 345, 373, 400, 415, 432, 456, 468, 488, 507, 519, 539, 558, 573, 596, 618, 635, 660, 684, 693, 710, 726, 745, 771, 787, 811, 831, 859, 888, 913, 937, 963, 999, 1029, 1051, 1077, 1102, 1132, 1165} + +func (i StyleColorID) String() string { + if i < 0 || i >= StyleColorID(len(_StyleColorID_index)-1) { + return "StyleColorID(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _StyleColorID_name[_StyleColorID_index[i]:_StyleColorID_index[i+1]] +} +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[StyleVarAlpha-0] + _ = x[StyleVarDisabledAlpha-1] + _ = x[StyleVarWindowPadding-2] + _ = x[StyleVarWindowRounding-3] + _ = x[StyleVarWindowBorderSize-4] + _ = x[StyleVarWindowMinSize-5] + _ = x[StyleVarWindowTitleAlign-6] + _ = x[StyleVarChildRounding-7] + _ = x[StyleVarChildBorderSize-8] + _ = x[StyleVarPopupRounding-9] + _ = x[StyleVarPopupBorderSize-10] + _ = x[StyleVarFramePadding-11] + _ = x[StyleVarFrameRounding-12] + _ = x[StyleVarFrameBorderSize-13] + _ = x[StyleVarItemSpacing-14] + _ = x[StyleVarItemInnerSpacing-15] + _ = x[StyleVarIndentSpacing-16] + _ = x[StyleVarScrollbarSize-18] + _ = x[StyleVarScrollbarRounding-19] + _ = x[StyleVarGrabMinSize-20] + _ = x[StyleVarGrabRounding-21] + _ = x[StyleVarTabRounding-22] + _ = x[StyleVarButtonTextAlign-23] + _ = x[StyleVarSelectableTextAlign-24] +} + +const ( + _StyleVarID_name_0 = "StyleVarAlphaStyleVarDisabledAlphaStyleVarWindowPaddingStyleVarWindowRoundingStyleVarWindowBorderSizeStyleVarWindowMinSizeStyleVarWindowTitleAlignStyleVarChildRoundingStyleVarChildBorderSizeStyleVarPopupRoundingStyleVarPopupBorderSizeStyleVarFramePaddingStyleVarFrameRoundingStyleVarFrameBorderSizeStyleVarItemSpacingStyleVarItemInnerSpacingStyleVarIndentSpacing" + _StyleVarID_name_1 = "StyleVarScrollbarSizeStyleVarScrollbarRoundingStyleVarGrabMinSizeStyleVarGrabRoundingStyleVarTabRoundingStyleVarButtonTextAlignStyleVarSelectableTextAlign" +) + +var ( + _StyleVarID_index_0 = [...]uint16{0, 13, 34, 55, 77, 101, 122, 146, 167, 190, 211, 234, 254, 275, 298, 317, 341, 362} + _StyleVarID_index_1 = [...]uint8{0, 21, 46, 65, 85, 104, 127, 154} +) + +func (i StyleVarID) String() string { + switch { + case 0 <= i && i <= 16: + return _StyleVarID_name_0[_StyleVarID_index_0[i]:_StyleVarID_index_0[i+1]] + case 18 <= i && i <= 24: + i -= 18 + return _StyleVarID_name_1[_StyleVarID_index_1[i]:_StyleVarID_index_1[i+1]] + default: + return "StyleVarID(" + strconv.FormatInt(int64(i), 10) + ")" + } +} From b48ecbb7afea7355954d44cf7e8d63d1978166f7 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Thu, 21 Jul 2022 14:45:41 +0200 Subject: [PATCH 08/26] style ids: add string2enum generated file --- StyleIDs.go | 51 +++++----- StyleIDs_string.go | 8 +- StyleIDs_string2enum.go | 202 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 233 insertions(+), 28 deletions(-) create mode 100644 StyleIDs_string2enum.go diff --git a/StyleIDs.go b/StyleIDs.go index cc5c5390..2a5c6bd7 100644 --- a/StyleIDs.go +++ b/StyleIDs.go @@ -7,6 +7,8 @@ import "github.com/AllenDang/imgui-go" // go-generate String() andStringToEnum methods //go:generate stringer -type=StyleColorID,StyleVarID -output=StyleIDs_string.go -linecomment +// NOTE: string2enum is https://github.com/mewspring/tools +//go:generate string2enum -samepkg -type=StyleColorID,StyleVarID -output=StyleIDs_string2enum.go -linecomment // StyleColorID identifies a color in the UI style. type StyleColorID imgui.StyleColorID @@ -74,55 +76,56 @@ const ( type StyleVarID imgui.StyleVarID // Style IDs. +// comments at same line is a CSS name const ( // StyleVarAlpha is a float. - StyleVarAlpha StyleVarID = StyleVarID(imgui.StyleVarAlpha) + StyleVarAlpha StyleVarID = StyleVarID(imgui.StyleVarAlpha) // alpha // float DisabledAlpha. - StyleVarDisabledAlpha StyleVarID = StyleVarID(imgui.StyleVarDisabledAlpha) + StyleVarDisabledAlpha StyleVarID = StyleVarID(imgui.StyleVarDisabledAlpha) // disabled-alpha // StyleVarWindowPadding is a Vec2. - StyleVarWindowPadding StyleVarID = StyleVarID(imgui.StyleVarWindowPadding) + StyleVarWindowPadding StyleVarID = StyleVarID(imgui.StyleVarWindowPadding) // window-padding // StyleVarWindowRounding is a float. - StyleVarWindowRounding StyleVarID = StyleVarID(imgui.StyleVarWindowRounding) + StyleVarWindowRounding StyleVarID = StyleVarID(imgui.StyleVarWindowRounding) // window-rounding // StyleVarWindowBorderSize is a float. - StyleVarWindowBorderSize StyleVarID = StyleVarID(imgui.StyleVarWindowBorderSize) + StyleVarWindowBorderSize StyleVarID = StyleVarID(imgui.StyleVarWindowBorderSize) // window-border-size // StyleVarWindowMinSize is a Vec2. - StyleVarWindowMinSize StyleVarID = StyleVarID(imgui.StyleVarWindowMinSize) + StyleVarWindowMinSize StyleVarID = StyleVarID(imgui.StyleVarWindowMinSize) // window-min-size // StyleVarWindowTitleAlign is a Vec2. - StyleVarWindowTitleAlign StyleVarID = StyleVarID(imgui.StyleVarWindowTitleAlign) + StyleVarWindowTitleAlign StyleVarID = StyleVarID(imgui.StyleVarWindowTitleAlign) // window-title-align // StyleVarChildRounding is a float. - StyleVarChildRounding StyleVarID = StyleVarID(imgui.StyleVarChildRounding) + StyleVarChildRounding StyleVarID = StyleVarID(imgui.StyleVarChildRounding) // child-rounding // StyleVarChildBorderSize is a float. - StyleVarChildBorderSize StyleVarID = StyleVarID(imgui.StyleVarChildBorderSize) + StyleVarChildBorderSize StyleVarID = StyleVarID(imgui.StyleVarChildBorderSize) // child-border-size // StyleVarPopupRounding is a float. - StyleVarPopupRounding StyleVarID = StyleVarID(imgui.StyleVarPopupRounding) + StyleVarPopupRounding StyleVarID = StyleVarID(imgui.StyleVarPopupRounding) // popup-rounding // StyleVarPopupBorderSize is a float. - StyleVarPopupBorderSize StyleVarID = StyleVarID(imgui.StyleVarPopupBorderSize) + StyleVarPopupBorderSize StyleVarID = StyleVarID(imgui.StyleVarPopupBorderSize) // popup-border-size // StyleVarFramePadding is a Vec2. - StyleVarFramePadding StyleVarID = StyleVarID(imgui.StyleVarFramePadding) + StyleVarFramePadding StyleVarID = StyleVarID(imgui.StyleVarFramePadding) // frame-padding // StyleVarFrameRounding is a float. - StyleVarFrameRounding StyleVarID = StyleVarID(imgui.StyleVarFrameRounding) + StyleVarFrameRounding StyleVarID = StyleVarID(imgui.StyleVarFrameRounding) // frame-rounding // StyleVarFrameBorderSize is a float. - StyleVarFrameBorderSize StyleVarID = StyleVarID(imgui.StyleVarFrameBorderSize) + StyleVarFrameBorderSize StyleVarID = StyleVarID(imgui.StyleVarFrameBorderSize) // frame-border-size // StyleVarItemSpacing is a Vec2. - StyleVarItemSpacing StyleVarID = StyleVarID(imgui.StyleVarItemSpacing) + StyleVarItemSpacing StyleVarID = StyleVarID(imgui.StyleVarItemSpacing) // item-spacing // StyleVarItemInnerSpacing is a Vec2. - StyleVarItemInnerSpacing StyleVarID = StyleVarID(imgui.StyleVarItemInnerSpacing) + StyleVarItemInnerSpacing StyleVarID = StyleVarID(imgui.StyleVarItemInnerSpacing) // item-inner-spacing // StyleVarIndentSpacing is a float. - StyleVarIndentSpacing StyleVarID = StyleVarID(imgui.StyleVarIndentSpacing) + StyleVarIndentSpacing StyleVarID = StyleVarID(imgui.StyleVarIndentSpacing) // indent-spacing // StyleVarScrollbarSize is a float. - StyleVarScrollbarSize StyleVarID = StyleVarID(imgui.StyleVarScrollbarSize) + StyleVarScrollbarSize StyleVarID = StyleVarID(imgui.StyleVarScrollbarSize) // scrollbar-size // StyleVarScrollbarRounding is a float. - StyleVarScrollbarRounding StyleVarID = StyleVarID(imgui.StyleVarScrollbarRounding) + StyleVarScrollbarRounding StyleVarID = StyleVarID(imgui.StyleVarScrollbarRounding) // scrollbar-rounding // StyleVarGrabMinSize is a float. - StyleVarGrabMinSize StyleVarID = StyleVarID(imgui.StyleVarGrabMinSize) + StyleVarGrabMinSize StyleVarID = StyleVarID(imgui.StyleVarGrabMinSize) // grab-min-size // StyleVarGrabRounding is a float. - StyleVarGrabRounding StyleVarID = StyleVarID(imgui.StyleVarGrabRounding) + StyleVarGrabRounding StyleVarID = StyleVarID(imgui.StyleVarGrabRounding) // grab-rounding // StyleVarTabRounding is a float. - StyleVarTabRounding StyleVarID = StyleVarID(imgui.StyleVarTabRounding) + StyleVarTabRounding StyleVarID = StyleVarID(imgui.StyleVarTabRounding) // tab-rounding // StyleVarButtonTextAlign is a Vec2. - StyleVarButtonTextAlign StyleVarID = StyleVarID(imgui.StyleVarButtonTextAlign) + StyleVarButtonTextAlign StyleVarID = StyleVarID(imgui.StyleVarButtonTextAlign) // button-text-align // StyleVarSelectableTextAlign is a Vec2. - StyleVarSelectableTextAlign StyleVarID = StyleVarID(imgui.StyleVarSelectableTextAlign) + StyleVarSelectableTextAlign StyleVarID = StyleVarID(imgui.StyleVarSelectableTextAlign) // selectable-text-align ) // IsVec2 returns true if the style var id should be processed as imgui.Vec2 diff --git a/StyleIDs_string.go b/StyleIDs_string.go index b53048fb..e392a237 100644 --- a/StyleIDs_string.go +++ b/StyleIDs_string.go @@ -105,13 +105,13 @@ func _() { } const ( - _StyleVarID_name_0 = "StyleVarAlphaStyleVarDisabledAlphaStyleVarWindowPaddingStyleVarWindowRoundingStyleVarWindowBorderSizeStyleVarWindowMinSizeStyleVarWindowTitleAlignStyleVarChildRoundingStyleVarChildBorderSizeStyleVarPopupRoundingStyleVarPopupBorderSizeStyleVarFramePaddingStyleVarFrameRoundingStyleVarFrameBorderSizeStyleVarItemSpacingStyleVarItemInnerSpacingStyleVarIndentSpacing" - _StyleVarID_name_1 = "StyleVarScrollbarSizeStyleVarScrollbarRoundingStyleVarGrabMinSizeStyleVarGrabRoundingStyleVarTabRoundingStyleVarButtonTextAlignStyleVarSelectableTextAlign" + _StyleVarID_name_0 = "alphadisabled-alphawindow-paddingwindow-roundingwindow-border-sizewindow-min-sizewindow-title-alignchild-roundingchild-border-sizepopup-roundingpopup-border-sizeframe-paddingframe-roundingframe-border-sizeitem-spacingitem-inner-spacingindent-spacing" + _StyleVarID_name_1 = "scrollbar-sizescrollbar-roundinggrab-min-sizegrab-roundingtab-roundingbutton-text-alignselectable-text-align" ) var ( - _StyleVarID_index_0 = [...]uint16{0, 13, 34, 55, 77, 101, 122, 146, 167, 190, 211, 234, 254, 275, 298, 317, 341, 362} - _StyleVarID_index_1 = [...]uint8{0, 21, 46, 65, 85, 104, 127, 154} + _StyleVarID_index_0 = [...]uint8{0, 5, 19, 33, 48, 66, 81, 99, 113, 130, 144, 161, 174, 188, 205, 217, 235, 249} + _StyleVarID_index_1 = [...]uint8{0, 14, 32, 45, 58, 70, 87, 108} ) func (i StyleVarID) String() string { diff --git a/StyleIDs_string2enum.go b/StyleIDs_string2enum.go new file mode 100644 index 00000000..f6921d7b --- /dev/null +++ b/StyleIDs_string2enum.go @@ -0,0 +1,202 @@ +// Code generated by "string2enum -samepkg -type=StyleColorID,StyleVarID -output=StyleIDs_string2enum.go -linecomment"; DO NOT EDIT. + +package giu + +import "fmt" + +// StyleColorIDFromString returns the StyleColorID enum corresponding to s. +func StyleColorIDFromString(s string) StyleColorID { + if len(s) == 0 { + return 0 + } + for i := range _StyleColorID_index[:len(_StyleColorID_index)-1] { + if s == _StyleColorID_name[_StyleColorID_index[i]:_StyleColorID_index[i+1]] { + return StyleColorID(i) + } + } + panic(fmt.Errorf("unable to locate StyleColorID enum corresponding to %q", s)) +} + +func _(s string) { + // Check for duplicate string values in type "StyleColorID". + switch s { + // 0 + case "color": + // 1 + case "disabled-color": + // 2 + case "background-color": + // 3 + case "child-background-color": + // 4 + case "popup-background-color": + // 5 + case "border-color": + // 6 + case "border-shadow-color": + // 7 + case "frame-background-color": + // 8 + case "frame-background-hovered-color": + // 9 + case "frame-background-active-color": + // 10 + case "title-background-color": + // 11 + case "title-background-active-color": + // 12 + case "title-background-collapsed-color": + // 13 + case "menu-bar-background-color": + // 14 + case "scrollbar-background-color": + // 15 + case "scrollbar-grab-color": + // 16 + case "scrollbar-grab-hovered-color": + // 17 + case "scrollbar-grab-active-color": + // 18 + case "checkmark-color": + // 19 + case "slider-grab-color": + // 20 + case "slider-grab-active-color": + // 21 + case "button-color": + // 22 + case "button-hovered-color": + // 23 + case "button-active-color": + // 24 + case "header-color": + // 25 + case "header-hovered-color": + // 26 + case "header-active-color": + // 27 + case "separator-color": + // 28 + case "separator-hovered-color": + // 29 + case "separator-active-color": + // 30 + case "resize-grip-color": + // 31 + case "resize-grip-hovered-color": + // 32 + case "resize-grip-active-color": + // 33 + case "tab-color": + // 34 + case "tab-hovered-color": + // 35 + case "tab-active-color": + // 36 + case "tab-unfocused-color": + // 37 + case "tab-unfocused-active-color": + // 38 + case "plot-lines-color": + // 39 + case "plot-lines-hovered-color": + // 40 + case "plot-histogram-color": + // 41 + case "plot-histogram-hovered-color": + // 42 + case "table-header-background-color": + // 43 + case "table-border-strong-color": + // 44 + case "table-border-light-color": + // 45 + case "table-row-background-color": + // 46 + case "table-row-alternate-background-color": + // 47 + case "text-selected-background-color": + // 48 + case "drag-drop-target-color": + // 49 + case "navigation-highlight-color": + // 50 + case "windowing-highlight-color": + // 51 + case "windowing-dim-background-color": + // 52 + case "modal-window-dim-background-color": + } +} + +// StyleVarIDFromString returns the StyleVarID enum corresponding to s. +func StyleVarIDFromString(s string) StyleVarID { + if len(s) == 0 { + return 0 + } + for i := range _StyleVarID_index_0[:len(_StyleVarID_index_0)-1] { + if s == _StyleVarID_name_0[_StyleVarID_index_0[i]:_StyleVarID_index_0[i+1]] { + return StyleVarID(i + 0) + } + } + for i := range _StyleVarID_index_1[:len(_StyleVarID_index_1)-1] { + if s == _StyleVarID_name_1[_StyleVarID_index_1[i]:_StyleVarID_index_1[i+1]] { + return StyleVarID(i + 18) + } + } + panic(fmt.Errorf("unable to locate StyleVarID enum corresponding to %q", s)) +} + +func _(s string) { + // Check for duplicate string values in type "StyleVarID". + switch s { + // 0 + case "alpha": + // 1 + case "disabled-alpha": + // 2 + case "window-padding": + // 3 + case "window-rounding": + // 4 + case "window-border-size": + // 5 + case "window-min-size": + // 6 + case "window-title-align": + // 7 + case "child-rounding": + // 8 + case "child-border-size": + // 9 + case "popup-rounding": + // 10 + case "popup-border-size": + // 11 + case "frame-padding": + // 12 + case "frame-rounding": + // 13 + case "frame-border-size": + // 14 + case "item-spacing": + // 15 + case "item-inner-spacing": + // 16 + case "indent-spacing": + // 18 + case "scrollbar-size": + // 19 + case "scrollbar-rounding": + // 20 + case "grab-min-size": + // 21 + case "grab-rounding": + // 22 + case "tab-rounding": + // 23 + case "button-text-align": + // 24 + case "selectable-text-align": + } +} From b90222d02d202c1c412138f711888e1bdbc3f33c Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Thu, 21 Jul 2022 15:08:18 +0200 Subject: [PATCH 09/26] styleIDs.go: fix GoLand warnings --- StyleIDs.go | 166 ++++++++++++++++++++++++++-------------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/StyleIDs.go b/StyleIDs.go index 2a5c6bd7..f195cfd4 100644 --- a/StyleIDs.go +++ b/StyleIDs.go @@ -14,123 +14,123 @@ import "github.com/AllenDang/imgui-go" type StyleColorID imgui.StyleColorID // StyleColor identifier. -// NOTE: comments are used for CSS conversion and are generated by stringer and string2enum +// NOTE: comments are used for CSS conversion and are generated by stringer and string2enum. const ( - StyleColorText StyleColorID = StyleColorID(imgui.StyleColorText) // color - StyleColorTextDisabled StyleColorID = StyleColorID(imgui.StyleColorTextDisabled) // disabled-color - StyleColorWindowBg StyleColorID = StyleColorID(imgui.StyleColorWindowBg) // background-color - StyleColorChildBg StyleColorID = StyleColorID(imgui.StyleColorChildBg) // child-background-color - StyleColorPopupBg StyleColorID = StyleColorID(imgui.StyleColorPopupBg) // popup-background-color - StyleColorBorder StyleColorID = StyleColorID(imgui.StyleColorBorder) // border-color - StyleColorBorderShadow StyleColorID = StyleColorID(imgui.StyleColorBorderShadow) // border-shadow-color - StyleColorFrameBg StyleColorID = StyleColorID(imgui.StyleColorFrameBg) // frame-background-color - StyleColorFrameBgHovered StyleColorID = StyleColorID(imgui.StyleColorFrameBgHovered) // frame-background-hovered-color - StyleColorFrameBgActive StyleColorID = StyleColorID(imgui.StyleColorFrameBgActive) // frame-background-active-color - StyleColorTitleBg StyleColorID = StyleColorID(imgui.StyleColorTitleBg) // title-background-color - StyleColorTitleBgActive StyleColorID = StyleColorID(imgui.StyleColorTitleBgActive) // title-background-active-color - StyleColorTitleBgCollapsed StyleColorID = StyleColorID(imgui.StyleColorTitleBgCollapsed) // title-background-collapsed-color - StyleColorMenuBarBg StyleColorID = StyleColorID(imgui.StyleColorMenuBarBg) // menu-bar-background-color - StyleColorScrollbarBg StyleColorID = StyleColorID(imgui.StyleColorScrollbarBg) // scrollbar-background-color - StyleColorScrollbarGrab StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrab) // scrollbar-grab-color - StyleColorScrollbarGrabHovered StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabHovered) // scrollbar-grab-hovered-color - StyleColorScrollbarGrabActive StyleColorID = StyleColorID(imgui.StyleColorScrollbarGrabActive) // scrollbar-grab-active-color - StyleColorCheckMark StyleColorID = StyleColorID(imgui.StyleColorCheckMark) // checkmark-color - StyleColorSliderGrab StyleColorID = StyleColorID(imgui.StyleColorSliderGrab) // slider-grab-color - StyleColorSliderGrabActive StyleColorID = StyleColorID(imgui.StyleColorSliderGrabActive) // slider-grab-active-color - StyleColorButton StyleColorID = StyleColorID(imgui.StyleColorButton) // button-color - StyleColorButtonHovered StyleColorID = StyleColorID(imgui.StyleColorButtonHovered) // button-hovered-color - StyleColorButtonActive StyleColorID = StyleColorID(imgui.StyleColorButtonActive) // button-active-color - StyleColorHeader StyleColorID = StyleColorID(imgui.StyleColorHeader) // header-color - StyleColorHeaderHovered StyleColorID = StyleColorID(imgui.StyleColorHeaderHovered) // header-hovered-color - StyleColorHeaderActive StyleColorID = StyleColorID(imgui.StyleColorHeaderActive) // header-active-color - StyleColorSeparator StyleColorID = StyleColorID(imgui.StyleColorSeparator) // separator-color - StyleColorSeparatorHovered StyleColorID = StyleColorID(imgui.StyleColorSeparatorHovered) // separator-hovered-color - StyleColorSeparatorActive StyleColorID = StyleColorID(imgui.StyleColorSeparatorActive) // separator-active-color - StyleColorResizeGrip StyleColorID = StyleColorID(imgui.StyleColorResizeGrip) // resize-grip-color - StyleColorResizeGripHovered StyleColorID = StyleColorID(imgui.StyleColorResizeGripHovered) // resize-grip-hovered-color - StyleColorResizeGripActive StyleColorID = StyleColorID(imgui.StyleColorResizeGripActive) // resize-grip-active-color - StyleColorTab StyleColorID = StyleColorID(imgui.StyleColorTab) // tab-color - StyleColorTabHovered StyleColorID = StyleColorID(imgui.StyleColorTabHovered) // tab-hovered-color - StyleColorTabActive StyleColorID = StyleColorID(imgui.StyleColorTabActive) // tab-active-color - StyleColorTabUnfocused StyleColorID = StyleColorID(imgui.StyleColorTabUnfocused) // tab-unfocused-color - StyleColorTabUnfocusedActive StyleColorID = StyleColorID(imgui.StyleColorTabUnfocusedActive) // tab-unfocused-active-color - StyleColorPlotLines StyleColorID = StyleColorID(imgui.StyleColorPlotLines) // plot-lines-color - StyleColorPlotLinesHovered StyleColorID = StyleColorID(imgui.StyleColorPlotLinesHovered) // plot-lines-hovered-color - StyleColorProgressBarActive StyleColorID = StyleColorPlotLinesHovered // progress-bar-active-color - StyleColorPlotHistogram StyleColorID = StyleColorID(imgui.StyleColorPlotHistogram) // plot-histogram-color - StyleColorPlotHistogramHovered StyleColorID = StyleColorID(imgui.StyleColorPlotHistogramHovered) // plot-histogram-hovered-color - StyleColorTableHeaderBg StyleColorID = StyleColorID(imgui.StyleColorTableHeaderBg) // table-header-background-color - StyleColorTableBorderStrong StyleColorID = StyleColorID(imgui.StyleColorTableBorderStrong) // table-border-strong-color - StyleColorTableBorderLight StyleColorID = StyleColorID(imgui.StyleColorTableBorderLight) // table-border-light-color - StyleColorTableRowBg StyleColorID = StyleColorID(imgui.StyleColorTableRowBg) // table-row-background-color - StyleColorTableRowBgAlt StyleColorID = StyleColorID(imgui.StyleColorTableRowBgAlt) // table-row-alternate-background-color - StyleColorTextSelectedBg StyleColorID = StyleColorID(imgui.StyleColorTextSelectedBg) // text-selected-background-color - StyleColorDragDropTarget StyleColorID = StyleColorID(imgui.StyleColorDragDropTarget) // drag-drop-target-color - StyleColorNavHighlight StyleColorID = StyleColorID(imgui.StyleColorNavHighlight) // navigation-highlight-color - StyleColorNavWindowingHighlight StyleColorID = StyleColorID(imgui.StyleColorNavWindowingHighlight) // windowing-highlight-color - StyleColorNavWindowingDimBg StyleColorID = StyleColorID(imgui.StyleColorNavWindowingDimBg) // windowing-dim-background-color - StyleColorModalWindowDimBg StyleColorID = StyleColorID(imgui.StyleColorModalWindowDimBg) // modal-window-dim-background-color + StyleColorText = StyleColorID(imgui.StyleColorText) // color + StyleColorTextDisabled = StyleColorID(imgui.StyleColorTextDisabled) // disabled-color + StyleColorWindowBg = StyleColorID(imgui.StyleColorWindowBg) // background-color + StyleColorChildBg = StyleColorID(imgui.StyleColorChildBg) // child-background-color + StyleColorPopupBg = StyleColorID(imgui.StyleColorPopupBg) // popup-background-color + StyleColorBorder = StyleColorID(imgui.StyleColorBorder) // border-color + StyleColorBorderShadow = StyleColorID(imgui.StyleColorBorderShadow) // border-shadow-color + StyleColorFrameBg = StyleColorID(imgui.StyleColorFrameBg) // frame-background-color + StyleColorFrameBgHovered = StyleColorID(imgui.StyleColorFrameBgHovered) // frame-background-hovered-color + StyleColorFrameBgActive = StyleColorID(imgui.StyleColorFrameBgActive) // frame-background-active-color + StyleColorTitleBg = StyleColorID(imgui.StyleColorTitleBg) // title-background-color + StyleColorTitleBgActive = StyleColorID(imgui.StyleColorTitleBgActive) // title-background-active-color + StyleColorTitleBgCollapsed = StyleColorID(imgui.StyleColorTitleBgCollapsed) // title-background-collapsed-color + StyleColorMenuBarBg = StyleColorID(imgui.StyleColorMenuBarBg) // menu-bar-background-color + StyleColorScrollbarBg = StyleColorID(imgui.StyleColorScrollbarBg) // scrollbar-background-color + StyleColorScrollbarGrab = StyleColorID(imgui.StyleColorScrollbarGrab) // scrollbar-grab-color + StyleColorScrollbarGrabHovered = StyleColorID(imgui.StyleColorScrollbarGrabHovered) // scrollbar-grab-hovered-color + StyleColorScrollbarGrabActive = StyleColorID(imgui.StyleColorScrollbarGrabActive) // scrollbar-grab-active-color + StyleColorCheckMark = StyleColorID(imgui.StyleColorCheckMark) // checkmark-color + StyleColorSliderGrab = StyleColorID(imgui.StyleColorSliderGrab) // slider-grab-color + StyleColorSliderGrabActive = StyleColorID(imgui.StyleColorSliderGrabActive) // slider-grab-active-color + StyleColorButton = StyleColorID(imgui.StyleColorButton) // button-color + StyleColorButtonHovered = StyleColorID(imgui.StyleColorButtonHovered) // button-hovered-color + StyleColorButtonActive = StyleColorID(imgui.StyleColorButtonActive) // button-active-color + StyleColorHeader = StyleColorID(imgui.StyleColorHeader) // header-color + StyleColorHeaderHovered = StyleColorID(imgui.StyleColorHeaderHovered) // header-hovered-color + StyleColorHeaderActive = StyleColorID(imgui.StyleColorHeaderActive) // header-active-color + StyleColorSeparator = StyleColorID(imgui.StyleColorSeparator) // separator-color + StyleColorSeparatorHovered = StyleColorID(imgui.StyleColorSeparatorHovered) // separator-hovered-color + StyleColorSeparatorActive = StyleColorID(imgui.StyleColorSeparatorActive) // separator-active-color + StyleColorResizeGrip = StyleColorID(imgui.StyleColorResizeGrip) // resize-grip-color + StyleColorResizeGripHovered = StyleColorID(imgui.StyleColorResizeGripHovered) // resize-grip-hovered-color + StyleColorResizeGripActive = StyleColorID(imgui.StyleColorResizeGripActive) // resize-grip-active-color + StyleColorTab = StyleColorID(imgui.StyleColorTab) // tab-color + StyleColorTabHovered = StyleColorID(imgui.StyleColorTabHovered) // tab-hovered-color + StyleColorTabActive = StyleColorID(imgui.StyleColorTabActive) // tab-active-color + StyleColorTabUnfocused = StyleColorID(imgui.StyleColorTabUnfocused) // tab-unfocused-color + StyleColorTabUnfocusedActive = StyleColorID(imgui.StyleColorTabUnfocusedActive) // tab-unfocused-active-color + StyleColorPlotLines = StyleColorID(imgui.StyleColorPlotLines) // plot-lines-color + StyleColorPlotLinesHovered = StyleColorID(imgui.StyleColorPlotLinesHovered) // plot-lines-hovered-color + StyleColorProgressBarActive = StyleColorPlotLinesHovered // progress-bar-active-color + StyleColorPlotHistogram = StyleColorID(imgui.StyleColorPlotHistogram) // plot-histogram-color + StyleColorPlotHistogramHovered = StyleColorID(imgui.StyleColorPlotHistogramHovered) // plot-histogram-hovered-color + StyleColorTableHeaderBg = StyleColorID(imgui.StyleColorTableHeaderBg) // table-header-background-color + StyleColorTableBorderStrong = StyleColorID(imgui.StyleColorTableBorderStrong) // table-border-strong-color + StyleColorTableBorderLight = StyleColorID(imgui.StyleColorTableBorderLight) // table-border-light-color + StyleColorTableRowBg = StyleColorID(imgui.StyleColorTableRowBg) // table-row-background-color + StyleColorTableRowBgAlt = StyleColorID(imgui.StyleColorTableRowBgAlt) // table-row-alternate-background-color + StyleColorTextSelectedBg = StyleColorID(imgui.StyleColorTextSelectedBg) // text-selected-background-color + StyleColorDragDropTarget = StyleColorID(imgui.StyleColorDragDropTarget) // drag-drop-target-color + StyleColorNavHighlight = StyleColorID(imgui.StyleColorNavHighlight) // navigation-highlight-color + StyleColorNavWindowingHighlight = StyleColorID(imgui.StyleColorNavWindowingHighlight) // windowing-highlight-color + StyleColorNavWindowingDimBg = StyleColorID(imgui.StyleColorNavWindowingDimBg) // windowing-dim-background-color + StyleColorModalWindowDimBg = StyleColorID(imgui.StyleColorModalWindowDimBg) // modal-window-dim-background-color ) // StyleVarID identifies a style variable in the UI style. type StyleVarID imgui.StyleVarID // Style IDs. -// comments at same line is a CSS name +// comments at same line is a CSS name. const ( // StyleVarAlpha is a float. - StyleVarAlpha StyleVarID = StyleVarID(imgui.StyleVarAlpha) // alpha - // float DisabledAlpha. - StyleVarDisabledAlpha StyleVarID = StyleVarID(imgui.StyleVarDisabledAlpha) // disabled-alpha + StyleVarAlpha = StyleVarID(imgui.StyleVarAlpha) // alpha + // StyleVarDisabledAlpha is a float. + StyleVarDisabledAlpha = StyleVarID(imgui.StyleVarDisabledAlpha) // disabled-alpha // StyleVarWindowPadding is a Vec2. - StyleVarWindowPadding StyleVarID = StyleVarID(imgui.StyleVarWindowPadding) // window-padding + StyleVarWindowPadding = StyleVarID(imgui.StyleVarWindowPadding) // window-padding // StyleVarWindowRounding is a float. - StyleVarWindowRounding StyleVarID = StyleVarID(imgui.StyleVarWindowRounding) // window-rounding + StyleVarWindowRounding = StyleVarID(imgui.StyleVarWindowRounding) // window-rounding // StyleVarWindowBorderSize is a float. - StyleVarWindowBorderSize StyleVarID = StyleVarID(imgui.StyleVarWindowBorderSize) // window-border-size + StyleVarWindowBorderSize = StyleVarID(imgui.StyleVarWindowBorderSize) // window-border-size // StyleVarWindowMinSize is a Vec2. - StyleVarWindowMinSize StyleVarID = StyleVarID(imgui.StyleVarWindowMinSize) // window-min-size + StyleVarWindowMinSize = StyleVarID(imgui.StyleVarWindowMinSize) // window-min-size // StyleVarWindowTitleAlign is a Vec2. - StyleVarWindowTitleAlign StyleVarID = StyleVarID(imgui.StyleVarWindowTitleAlign) // window-title-align + StyleVarWindowTitleAlign = StyleVarID(imgui.StyleVarWindowTitleAlign) // window-title-align // StyleVarChildRounding is a float. - StyleVarChildRounding StyleVarID = StyleVarID(imgui.StyleVarChildRounding) // child-rounding + StyleVarChildRounding = StyleVarID(imgui.StyleVarChildRounding) // child-rounding // StyleVarChildBorderSize is a float. - StyleVarChildBorderSize StyleVarID = StyleVarID(imgui.StyleVarChildBorderSize) // child-border-size + StyleVarChildBorderSize = StyleVarID(imgui.StyleVarChildBorderSize) // child-border-size // StyleVarPopupRounding is a float. - StyleVarPopupRounding StyleVarID = StyleVarID(imgui.StyleVarPopupRounding) // popup-rounding + StyleVarPopupRounding = StyleVarID(imgui.StyleVarPopupRounding) // popup-rounding // StyleVarPopupBorderSize is a float. - StyleVarPopupBorderSize StyleVarID = StyleVarID(imgui.StyleVarPopupBorderSize) // popup-border-size + StyleVarPopupBorderSize = StyleVarID(imgui.StyleVarPopupBorderSize) // popup-border-size // StyleVarFramePadding is a Vec2. - StyleVarFramePadding StyleVarID = StyleVarID(imgui.StyleVarFramePadding) // frame-padding + StyleVarFramePadding = StyleVarID(imgui.StyleVarFramePadding) // frame-padding // StyleVarFrameRounding is a float. - StyleVarFrameRounding StyleVarID = StyleVarID(imgui.StyleVarFrameRounding) // frame-rounding + StyleVarFrameRounding = StyleVarID(imgui.StyleVarFrameRounding) // frame-rounding // StyleVarFrameBorderSize is a float. - StyleVarFrameBorderSize StyleVarID = StyleVarID(imgui.StyleVarFrameBorderSize) // frame-border-size + StyleVarFrameBorderSize = StyleVarID(imgui.StyleVarFrameBorderSize) // frame-border-size // StyleVarItemSpacing is a Vec2. - StyleVarItemSpacing StyleVarID = StyleVarID(imgui.StyleVarItemSpacing) // item-spacing + StyleVarItemSpacing = StyleVarID(imgui.StyleVarItemSpacing) // item-spacing // StyleVarItemInnerSpacing is a Vec2. - StyleVarItemInnerSpacing StyleVarID = StyleVarID(imgui.StyleVarItemInnerSpacing) // item-inner-spacing + StyleVarItemInnerSpacing = StyleVarID(imgui.StyleVarItemInnerSpacing) // item-inner-spacing // StyleVarIndentSpacing is a float. - StyleVarIndentSpacing StyleVarID = StyleVarID(imgui.StyleVarIndentSpacing) // indent-spacing + StyleVarIndentSpacing = StyleVarID(imgui.StyleVarIndentSpacing) // indent-spacing // StyleVarScrollbarSize is a float. - StyleVarScrollbarSize StyleVarID = StyleVarID(imgui.StyleVarScrollbarSize) // scrollbar-size + StyleVarScrollbarSize = StyleVarID(imgui.StyleVarScrollbarSize) // scrollbar-size // StyleVarScrollbarRounding is a float. - StyleVarScrollbarRounding StyleVarID = StyleVarID(imgui.StyleVarScrollbarRounding) // scrollbar-rounding + StyleVarScrollbarRounding = StyleVarID(imgui.StyleVarScrollbarRounding) // scrollbar-rounding // StyleVarGrabMinSize is a float. - StyleVarGrabMinSize StyleVarID = StyleVarID(imgui.StyleVarGrabMinSize) // grab-min-size + StyleVarGrabMinSize = StyleVarID(imgui.StyleVarGrabMinSize) // grab-min-size // StyleVarGrabRounding is a float. - StyleVarGrabRounding StyleVarID = StyleVarID(imgui.StyleVarGrabRounding) // grab-rounding + StyleVarGrabRounding = StyleVarID(imgui.StyleVarGrabRounding) // grab-rounding // StyleVarTabRounding is a float. - StyleVarTabRounding StyleVarID = StyleVarID(imgui.StyleVarTabRounding) // tab-rounding + StyleVarTabRounding = StyleVarID(imgui.StyleVarTabRounding) // tab-rounding // StyleVarButtonTextAlign is a Vec2. - StyleVarButtonTextAlign StyleVarID = StyleVarID(imgui.StyleVarButtonTextAlign) // button-text-align + StyleVarButtonTextAlign = StyleVarID(imgui.StyleVarButtonTextAlign) // button-text-align // StyleVarSelectableTextAlign is a Vec2. - StyleVarSelectableTextAlign StyleVarID = StyleVarID(imgui.StyleVarSelectableTextAlign) // selectable-text-align + StyleVarSelectableTextAlign = StyleVarID(imgui.StyleVarSelectableTextAlign) // selectable-text-align ) // IsVec2 returns true if the style var id should be processed as imgui.Vec2 // if not, it is interpreted as float32. -func (s StyleVarID) IsVec2() bool { +func (i StyleVarID) IsVec2() bool { lookup := map[StyleVarID]bool{ // StyleVarWindowPadding is a Vec2. StyleVarWindowPadding: true, @@ -144,7 +144,7 @@ func (s StyleVarID) IsVec2() bool { StyleVarSelectableTextAlign: true, } - result, ok := lookup[s] + result, ok := lookup[i] return result && ok } From 8f5b7873ed3400c5f1bbe946fcf6356673bee9a4 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Tue, 27 Sep 2022 18:36:42 +0200 Subject: [PATCH 10/26] CSS: add css parser - parse CSS Stylesheet - check style var and decide if it is a ColorID or VarID - convert CSS color to GO color.RGBA - allow to set single float values for StyleVars --- CSS.go | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- go.mod | 2 ++ go.sum | 4 ++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/CSS.go b/CSS.go index 31e6556c..da6b9442 100644 --- a/CSS.go +++ b/CSS.go @@ -1,19 +1,86 @@ package giu +import ( + "fmt" + "github.com/mazznoer/csscolorparser" + "github.com/napsy/go-css" + "strconv" +) + // Code in this file allows to apply style using a CSS stylesheet // The intention of the code looks as follows: // - The CSS stylesheet is parsed and the resulting rules are stored in giu context // NOTE: more than one CSS stylesheets can be parsed, however the app could panic if the same tag is present twice // - CSSTagWidget allows to apply style to a specified layout // - main tag allows to apply style to the whole application +// +// tools: +// css parser - for now github.com/napsy/go-css. it is a bit poor, but I don't think we need anything more +// css colors - github.com/mazznoer/csscolorparser // ParseCSSStyleSheet parses CSS stylesheet and stores the rules in giu context -func ParseCSSStyleSheet(css string) { +func ParseCSSStyleSheet(data []byte) error { + stylesheet, err := css.Unmarshal(data) + if err != nil { + return err + } + + for rule, style := range stylesheet { + setter := Style() + for styleVarName, styleVarValue := range style { + // convert style variable name to giu style variable name + var styleVarID StyleVarID + err := panicToErr(func() { + styleVarID = StyleVarIDFromString(styleVarName) + }) + + if err == nil { + // the style is StyleVarID - set it + f, err := strconv.ParseFloat(styleVarValue, 321) + + if err != nil { + return fmt.Errorf("unable to parse float %v is not float (vec2 is not supported yet): %w", styleVarValue, err) + } + + setter.SetStyleFloat(styleVarID, float32(f)) + } + + var styleColorID StyleColorID + err = panicToErr(func() { + styleColorID = StyleColorIDFromString(styleVarName) + }) + + if err != nil { + return fmt.Errorf("cannot parse style variable ID: %v", styleVarName) + } + + col, err := csscolorparser.Parse(styleVarValue) + if err != nil { + return fmt.Errorf("cannot parse color %v: %w", styleVarValue, err) + } + + setter.SetColor(styleColorID, col) + } + + Context.cssStylesheet[string(rule)] = setter + } + + return nil +} + +func panicToErr(f func()) (err error) { + defer func() { + if r := recover(); r != nil { + err = fmt.Errorf("%v", r) + } + }() + f() + return err } // cssStylesheet is a map tag:StyleSetter -type cssStylesheet map[string]StyleSetter +type cssStylesheet map[string]*StyleSetter var _ Widget = &CSSTagWidget{} diff --git a/go.mod b/go.mod index 6c4820de..858d0f28 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,8 @@ require ( github.com/AllenDang/imgui-go v1.12.1-0.20220322114136-499bbf6a42ad github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661 + github.com/mazznoer/csscolorparser v0.1.3 + github.com/napsy/go-css v0.0.0-20180317163611-b251a459e17c github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/sahilm/fuzzy v0.1.0 github.com/stretchr/testify v1.8.0 diff --git a/go.sum b/go.sum index fa06b980..a581f72c 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,10 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661 h1:1bpooddSK2 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mazznoer/csscolorparser v0.1.3 h1:vug4zh6loQxAUxfU1DZEu70gTPufDPspamZlHAkKcxE= +github.com/mazznoer/csscolorparser v0.1.3/go.mod h1:Aj22+L/rYN/Y6bj3bYqO3N6g1dtdHtGfQ32xZ5PJQic= +github.com/napsy/go-css v0.0.0-20180317163611-b251a459e17c h1:McZuuGSK5fE9nw/oZRFKQuOQC+Q2kFNVH+AIGyHkj1E= +github.com/napsy/go-css v0.0.0-20180317163611-b251a459e17c/go.mod h1:TQseyyCxmpw/+4EwqOrlVocbzP7veN8TsmsoaqNJyNo= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From b03f57799c6a10076e1f3dba5c8df88b89a93075 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Tue, 27 Sep 2022 18:39:46 +0200 Subject: [PATCH 11/26] examples: add CSS example --- examples/CSS-styling/main.go | 26 ++++++++++++++++++++++++++ examples/CSS-styling/style.css | 8 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 examples/CSS-styling/main.go create mode 100644 examples/CSS-styling/style.css diff --git a/examples/CSS-styling/main.go b/examples/CSS-styling/main.go new file mode 100644 index 00000000..928e5491 --- /dev/null +++ b/examples/CSS-styling/main.go @@ -0,0 +1,26 @@ +package main + +import ( + _ "embed" + + "github.com/AllenDang/giu" +) + +//go:embed style.css +var cssStyle []byte + +func loop() { + giu.SingleWindow().Layout( + giu.CSSTag("button").To( + giu.Button("HI! I'm a button styled with CSS"), + ), + ) +} + +func main() { + wnd := giu.NewMasterWindow("CSS Style [example]", 640, 480, 0) + if err := giu.ParseCSSStyleSheet(cssStyle); err != nil { + panic(err) + } + wnd.Run(loop) +} diff --git a/examples/CSS-styling/style.css b/examples/CSS-styling/style.css new file mode 100644 index 00000000..cda0db0a --- /dev/null +++ b/examples/CSS-styling/style.css @@ -0,0 +1,8 @@ +main { + color: red; +} + +button { + color: red; + button-color: yellow; +} From 98038aad4bcbf47a1bf048f2d9dc005bab5ac7c6 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:37:58 +0200 Subject: [PATCH 12/26] master window: use the "main" tag for whole window --- CSS.go | 4 ++-- MasterWindow.go | 11 ++++++++++- examples/CSS-styling/main.go | 9 ++++++--- examples/CSS-styling/style.css | 6 +++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CSS.go b/CSS.go index da6b9442..e1408451 100644 --- a/CSS.go +++ b/CSS.go @@ -2,9 +2,10 @@ package giu import ( "fmt" + "strconv" + "github.com/mazznoer/csscolorparser" "github.com/napsy/go-css" - "strconv" ) // Code in this file allows to apply style using a CSS stylesheet @@ -37,7 +38,6 @@ func ParseCSSStyleSheet(data []byte) error { if err == nil { // the style is StyleVarID - set it f, err := strconv.ParseFloat(styleVarValue, 321) - if err != nil { return fmt.Errorf("unable to parse float %v is not float (vec2 is not supported yet): %w", styleVarValue, err) } diff --git a/MasterWindow.go b/MasterWindow.go index 2c621c1c..81100c2b 100644 --- a/MasterWindow.go +++ b/MasterWindow.go @@ -194,11 +194,20 @@ func (w *MasterWindow) render() { p := w.platform r := w.renderer + mainStylesheet := Style() + if s, found := Context.cssStylesheet["main"]; found { + mainStylesheet = s + } + p.NewFrame() r.PreRender(w.clearColor) imgui.NewFrame() - w.updateFunc() + mainStylesheet.To( + Custom(func() { + w.updateFunc() + }), + ).Build() imgui.Render() r.Render(p.DisplaySize(), p.FramebufferSize(), imgui.RenderedDrawData()) diff --git a/examples/CSS-styling/main.go b/examples/CSS-styling/main.go index 928e5491..20dc21e3 100644 --- a/examples/CSS-styling/main.go +++ b/examples/CSS-styling/main.go @@ -10,9 +10,12 @@ import ( var cssStyle []byte func loop() { - giu.SingleWindow().Layout( - giu.CSSTag("button").To( - giu.Button("HI! I'm a button styled with CSS"), + giu.Window("Window").Layout( + // giu.CSSTag("button").To( + giu.Button("HI! I'm a button styled with CSS"), + //), + giu.CSSTag("label").To( + giu.Label("I'ma normal label"), ), ) } diff --git a/examples/CSS-styling/style.css b/examples/CSS-styling/style.css index cda0db0a..8508bd06 100644 --- a/examples/CSS-styling/style.css +++ b/examples/CSS-styling/style.css @@ -1,5 +1,9 @@ main { - color: red; + background-color: blue; +} + +label { + color: black; } button { From fc2bdf4170a01e473bb259772fefa9c9ecf0fab0 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:40:16 +0200 Subject: [PATCH 13/26] deps: use customized version of go-css since upstream is bugged --- examples/CSS-styling/main.go | 6 +++--- go.mod | 2 ++ go.sum | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/CSS-styling/main.go b/examples/CSS-styling/main.go index 20dc21e3..eea4a9fa 100644 --- a/examples/CSS-styling/main.go +++ b/examples/CSS-styling/main.go @@ -11,9 +11,9 @@ var cssStyle []byte func loop() { giu.Window("Window").Layout( - // giu.CSSTag("button").To( - giu.Button("HI! I'm a button styled with CSS"), - //), + giu.CSSTag("button").To( + giu.Button("HI! I'm a button styled with CSS"), + ), giu.CSSTag("label").To( giu.Label("I'ma normal label"), ), diff --git a/go.mod b/go.mod index 858d0f28..3beb0ffd 100644 --- a/go.mod +++ b/go.mod @@ -24,3 +24,5 @@ require ( golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/napsy/go-css => github.com/gucio321/go-css v0.0.0-20220927183634-22e6096f036e diff --git a/go.sum b/go.sum index a581f72c..7276a343 100644 --- a/go.sum +++ b/go.sum @@ -12,12 +12,12 @@ github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVin github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661 h1:1bpooddSK2996NWM/1TW59cchQOm9MkoV9DkhSJH1BI= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/gucio321/go-css v0.0.0-20220927183634-22e6096f036e h1:5FrujxF+Hl8A1vKMb91jyswjspgiDVnkkyZ0xY/cQvY= +github.com/gucio321/go-css v0.0.0-20220927183634-22e6096f036e/go.mod h1:HqZYcKcNnv50fgOTdGUn9YbJa2qC9oJ3kLnyrwwVzUI= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mazznoer/csscolorparser v0.1.3 h1:vug4zh6loQxAUxfU1DZEu70gTPufDPspamZlHAkKcxE= github.com/mazznoer/csscolorparser v0.1.3/go.mod h1:Aj22+L/rYN/Y6bj3bYqO3N6g1dtdHtGfQ32xZ5PJQic= -github.com/napsy/go-css v0.0.0-20180317163611-b251a459e17c h1:McZuuGSK5fE9nw/oZRFKQuOQC+Q2kFNVH+AIGyHkj1E= -github.com/napsy/go-css v0.0.0-20180317163611-b251a459e17c/go.mod h1:TQseyyCxmpw/+4EwqOrlVocbzP7veN8TsmsoaqNJyNo= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From b45a55fd0412d6c164a96cee0ce567c87a321e59 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Thu, 29 Sep 2022 16:39:45 +0200 Subject: [PATCH 14/26] run go mod tidy --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index 5d37c783..bd1f847a 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/AllenDang/imgui-go v1.12.1-0.20220322114136-499bbf6a42ad github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220806181222-55e207c401ad - github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661 github.com/mazznoer/csscolorparser v0.1.3 github.com/napsy/go-css v0.0.0-20180317163611-b251a459e17c github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 From 3199a1ef5c96e117a411790688f7382bf875451d Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Sat, 15 Oct 2022 16:02:23 +0200 Subject: [PATCH 15/26] CSS: add missing continue keyword --- CSS.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CSS.go b/CSS.go index e1408451..0913386e 100644 --- a/CSS.go +++ b/CSS.go @@ -43,6 +43,8 @@ func ParseCSSStyleSheet(data []byte) error { } setter.SetStyleFloat(styleVarID, float32(f)) + + continue } var styleColorID StyleColorID From 748cb5d8f6a154ac5890766c58bd032641e061b0 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Fri, 11 Nov 2022 10:17:17 +0100 Subject: [PATCH 16/26] deps: use upstream go-css --- go.mod | 4 +--- go.sum | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 4b354e20..e4b9b02c 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220806181222-55e207c401ad github.com/mazznoer/csscolorparser v0.1.3 - github.com/napsy/go-css v0.0.0-20180317163611-b251a459e17c + github.com/napsy/go-css v0.0.0-20221107082635-4ed403047a64 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/sahilm/fuzzy v0.1.0 github.com/stretchr/testify v1.8.1 @@ -24,5 +24,3 @@ require ( golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace github.com/napsy/go-css => github.com/gucio321/go-css v0.0.0-20220927183634-22e6096f036e diff --git a/go.sum b/go.sum index e1f0f793..2f112912 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mazznoer/csscolorparser v0.1.3 h1:vug4zh6loQxAUxfU1DZEu70gTPufDPspamZlHAkKcxE= github.com/mazznoer/csscolorparser v0.1.3/go.mod h1:Aj22+L/rYN/Y6bj3bYqO3N6g1dtdHtGfQ32xZ5PJQic= +github.com/napsy/go-css v0.0.0-20221107082635-4ed403047a64 h1:7LWtWY3Ei9ghnamqn8xCu7LOXAKaQrcfbcf0sU33LG4= +github.com/napsy/go-css v0.0.0-20221107082635-4ed403047a64/go.mod h1:HqZYcKcNnv50fgOTdGUn9YbJa2qC9oJ3kLnyrwwVzUI= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From 326785bd33c7ffe7c8408fecdc7298d1cc1da849 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Fri, 11 Nov 2022 17:03:23 +0100 Subject: [PATCH 17/26] CSS: add support for vec2 values --- CSS.go | 28 +++++++++++++++++++++++++--- examples/CSS-styling/style.css | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CSS.go b/CSS.go index 0913386e..38513741 100644 --- a/CSS.go +++ b/CSS.go @@ -3,6 +3,7 @@ package giu import ( "fmt" "strconv" + "strings" "github.com/mazznoer/csscolorparser" "github.com/napsy/go-css" @@ -37,12 +38,33 @@ func ParseCSSStyleSheet(data []byte) error { if err == nil { // the style is StyleVarID - set it - f, err := strconv.ParseFloat(styleVarValue, 321) + f, err := strconv.ParseFloat(styleVarValue, 32) + if err == nil { + setter.SetStyleFloat(styleVarID, float32(f)) + } + + // so maybe it is a vec2 value: + // var-name: x, y; + vec2 := strings.Split(styleVarValue, ",") + if len(vec2) != 2 { + return fmt.Errorf("unable to parse value %v is not float nor vec2: %w", styleVarValue, err) + } + + for i, v := range vec2 { + vec2[i] = strings.ReplaceAll(v, " ", "") + } + + x, err := strconv.ParseFloat(vec2[0], 32) + if err != nil { + return fmt.Errorf("unable to parse value %v is not float: %w", vec2[0], err) + } + + y, err := strconv.ParseFloat(vec2[1], 32) if err != nil { - return fmt.Errorf("unable to parse float %v is not float (vec2 is not supported yet): %w", styleVarValue, err) + return fmt.Errorf("unable to parse value %v is not float: %w", vec2[1], err) } - setter.SetStyleFloat(styleVarID, float32(f)) + setter.SetStyle(styleVarID, float32(x), float32(y)) continue } diff --git a/examples/CSS-styling/style.css b/examples/CSS-styling/style.css index 8508bd06..4b9330be 100644 --- a/examples/CSS-styling/style.css +++ b/examples/CSS-styling/style.css @@ -1,5 +1,6 @@ main { background-color: blue; + frame-padding: 80, 20; } label { From 8e7a0273140345bbdf32bfd6f485a890c70d3a51 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Fri, 11 Nov 2022 17:05:59 +0100 Subject: [PATCH 18/26] CSS: use changes from #555 to simplify code in MasterWindow.go --- MasterWindow.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/MasterWindow.go b/MasterWindow.go index 81100c2b..8bca6c1f 100644 --- a/MasterWindow.go +++ b/MasterWindow.go @@ -203,11 +203,9 @@ func (w *MasterWindow) render() { r.PreRender(w.clearColor) imgui.NewFrame() - mainStylesheet.To( - Custom(func() { - w.updateFunc() - }), - ).Build() + mainStylesheet.Push() + w.updateFunc() + mainStylesheet.Pop() imgui.Render() r.Render(p.DisplaySize(), p.FramebufferSize(), imgui.RenderedDrawData()) From 9725efb90b13cf692b6b68a72db1a39a616c7179 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Fri, 11 Nov 2022 17:08:40 +0100 Subject: [PATCH 19/26] CSS: fix test crash --- CSS.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CSS.go b/CSS.go index 38513741..84c85522 100644 --- a/CSS.go +++ b/CSS.go @@ -130,7 +130,7 @@ func (c *CSSTagWidget) Build() { // get style from context. // if it doesn't exist Assert. style, exists := Context.cssStylesheet[c.tag] - Assert(exists, "CSSTagWidget", "Build", "CSS stylesheet doesn't contain tag: ", c.tag) + Assert(exists, "CSSTagWidget", "Build", "CSS stylesheet doesn't contain tag: %s", c.tag) style.To(c.layout).Build() } From 9e73ec010a1694afa0d29564e4a11b61da2d31b1 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Thu, 17 Nov 2022 09:25:55 +0100 Subject: [PATCH 20/26] docs: add css documentation --- docs/css.md | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 docs/css.md diff --git a/docs/css.md b/docs/css.md new file mode 100644 index 00000000..7c50a206 --- /dev/null +++ b/docs/css.md @@ -0,0 +1,122 @@ +# INTRO + +GIU provides a special widget called "CSSWidget". +This widget allows to set App's style for your app. + +# Usage + +1. open your stylesheet (e.g. with go-embed) +2. Tell giu about your stylesheet using `giu.ParseCSSStyleSheet(...)` +3. Put css tags in your code - `giu.CSS("tag name")` + +For simple use-case see [examples/CSS-styling](../examples/CSS-styling/) + +# Styles list + +## Colors + +StyleColorText = StyleColorID(imgui.StyleColorText) // color +StyleColorTextDisabled = StyleColorID(imgui.StyleColorTextDisabled) // disabled-color +StyleColorWindowBg = StyleColorID(imgui.StyleColorWindowBg) // background-color +StyleColorChildBg = StyleColorID(imgui.StyleColorChildBg) // child-background-color +StyleColorPopupBg = StyleColorID(imgui.StyleColorPopupBg) // popup-background-color +StyleColorBorder = StyleColorID(imgui.StyleColorBorder) // border-color +StyleColorBorderShadow = StyleColorID(imgui.StyleColorBorderShadow) // border-shadow-color +StyleColorFrameBg = StyleColorID(imgui.StyleColorFrameBg) // frame-background-color +StyleColorFrameBgHovered = StyleColorID(imgui.StyleColorFrameBgHovered) // frame-background-hovered-color +StyleColorFrameBgActive = StyleColorID(imgui.StyleColorFrameBgActive) // frame-background-active-color +StyleColorTitleBg = StyleColorID(imgui.StyleColorTitleBg) // title-background-color +StyleColorTitleBgActive = StyleColorID(imgui.StyleColorTitleBgActive) // title-background-active-color +StyleColorTitleBgCollapsed = StyleColorID(imgui.StyleColorTitleBgCollapsed) // title-background-collapsed-color +StyleColorMenuBarBg = StyleColorID(imgui.StyleColorMenuBarBg) // menu-bar-background-color +StyleColorScrollbarBg = StyleColorID(imgui.StyleColorScrollbarBg) // scrollbar-background-color +StyleColorScrollbarGrab = StyleColorID(imgui.StyleColorScrollbarGrab) // scrollbar-grab-color +StyleColorScrollbarGrabHovered = StyleColorID(imgui.StyleColorScrollbarGrabHovered) // scrollbar-grab-hovered-color +StyleColorScrollbarGrabActive = StyleColorID(imgui.StyleColorScrollbarGrabActive) // scrollbar-grab-active-color +StyleColorCheckMark = StyleColorID(imgui.StyleColorCheckMark) // checkmark-color +StyleColorSliderGrab = StyleColorID(imgui.StyleColorSliderGrab) // slider-grab-color +StyleColorSliderGrabActive = StyleColorID(imgui.StyleColorSliderGrabActive) // slider-grab-active-color +StyleColorButton = StyleColorID(imgui.StyleColorButton) // button-color +StyleColorButtonHovered = StyleColorID(imgui.StyleColorButtonHovered) // button-hovered-color +StyleColorButtonActive = StyleColorID(imgui.StyleColorButtonActive) // button-active-color +StyleColorHeader = StyleColorID(imgui.StyleColorHeader) // header-color +StyleColorHeaderHovered = StyleColorID(imgui.StyleColorHeaderHovered) // header-hovered-color +StyleColorHeaderActive = StyleColorID(imgui.StyleColorHeaderActive) // header-active-color +StyleColorSeparator = StyleColorID(imgui.StyleColorSeparator) // separator-color +StyleColorSeparatorHovered = StyleColorID(imgui.StyleColorSeparatorHovered) // separator-hovered-color +StyleColorSeparatorActive = StyleColorID(imgui.StyleColorSeparatorActive) // separator-active-color +StyleColorResizeGrip = StyleColorID(imgui.StyleColorResizeGrip) // resize-grip-color +StyleColorResizeGripHovered = StyleColorID(imgui.StyleColorResizeGripHovered) // resize-grip-hovered-color +StyleColorResizeGripActive = StyleColorID(imgui.StyleColorResizeGripActive) // resize-grip-active-color +StyleColorTab = StyleColorID(imgui.StyleColorTab) // tab-color +StyleColorTabHovered = StyleColorID(imgui.StyleColorTabHovered) // tab-hovered-color +StyleColorTabActive = StyleColorID(imgui.StyleColorTabActive) // tab-active-color +StyleColorTabUnfocused = StyleColorID(imgui.StyleColorTabUnfocused) // tab-unfocused-color +StyleColorTabUnfocusedActive = StyleColorID(imgui.StyleColorTabUnfocusedActive) // tab-unfocused-active-color +StyleColorPlotLines = StyleColorID(imgui.StyleColorPlotLines) // plot-lines-color +StyleColorPlotLinesHovered = StyleColorID(imgui.StyleColorPlotLinesHovered) // plot-lines-hovered-color +StyleColorProgressBarActive = StyleColorPlotLinesHovered // progress-bar-active-color +StyleColorPlotHistogram = StyleColorID(imgui.StyleColorPlotHistogram) // plot-histogram-color +StyleColorPlotHistogramHovered = StyleColorID(imgui.StyleColorPlotHistogramHovered) // plot-histogram-hovered-color +StyleColorTableHeaderBg = StyleColorID(imgui.StyleColorTableHeaderBg) // table-header-background-color +StyleColorTableBorderStrong = StyleColorID(imgui.StyleColorTableBorderStrong) // table-border-strong-color +StyleColorTableBorderLight = StyleColorID(imgui.StyleColorTableBorderLight) // table-border-light-color +StyleColorTableRowBg = StyleColorID(imgui.StyleColorTableRowBg) // table-row-background-color +StyleColorTableRowBgAlt = StyleColorID(imgui.StyleColorTableRowBgAlt) // table-row-alternate-background-color +StyleColorTextSelectedBg = StyleColorID(imgui.StyleColorTextSelectedBg) // text-selected-background-color +StyleColorDragDropTarget = StyleColorID(imgui.StyleColorDragDropTarget) // drag-drop-target-color +StyleColorNavHighlight = StyleColorID(imgui.StyleColorNavHighlight) // navigation-highlight-color +StyleColorNavWindowingHighlight = StyleColorID(imgui.StyleColorNavWindowingHighlight) // windowing-highlight-color +StyleColorNavWindowingDimBg = StyleColorID(imgui.StyleColorNavWindowingDimBg) // windowing-dim-background-color +StyleColorModalWindowDimBg = StyleColorID(imgui.StyleColorModalWindowDimBg) // modal-window-dim-background-color + +## Style Variables + +// StyleVarAlpha is a float. +StyleVarAlpha = StyleVarID(imgui.StyleVarAlpha) // alpha +// StyleVarDisabledAlpha is a float. +StyleVarDisabledAlpha = StyleVarID(imgui.StyleVarDisabledAlpha) // disabled-alpha +// StyleVarWindowPadding is a Vec2. +StyleVarWindowPadding = StyleVarID(imgui.StyleVarWindowPadding) // window-padding +// StyleVarWindowRounding is a float. +StyleVarWindowRounding = StyleVarID(imgui.StyleVarWindowRounding) // window-rounding +// StyleVarWindowBorderSize is a float. +StyleVarWindowBorderSize = StyleVarID(imgui.StyleVarWindowBorderSize) // window-border-size +// StyleVarWindowMinSize is a Vec2. +StyleVarWindowMinSize = StyleVarID(imgui.StyleVarWindowMinSize) // window-min-size +// StyleVarWindowTitleAlign is a Vec2. +StyleVarWindowTitleAlign = StyleVarID(imgui.StyleVarWindowTitleAlign) // window-title-align +// StyleVarChildRounding is a float. +StyleVarChildRounding = StyleVarID(imgui.StyleVarChildRounding) // child-rounding +// StyleVarChildBorderSize is a float. +StyleVarChildBorderSize = StyleVarID(imgui.StyleVarChildBorderSize) // child-border-size +// StyleVarPopupRounding is a float. +StyleVarPopupRounding = StyleVarID(imgui.StyleVarPopupRounding) // popup-rounding +// StyleVarPopupBorderSize is a float. +StyleVarPopupBorderSize = StyleVarID(imgui.StyleVarPopupBorderSize) // popup-border-size +// StyleVarFramePadding is a Vec2. +StyleVarFramePadding = StyleVarID(imgui.StyleVarFramePadding) // frame-padding +// StyleVarFrameRounding is a float. +StyleVarFrameRounding = StyleVarID(imgui.StyleVarFrameRounding) // frame-rounding +// StyleVarFrameBorderSize is a float. +StyleVarFrameBorderSize = StyleVarID(imgui.StyleVarFrameBorderSize) // frame-border-size +// StyleVarItemSpacing is a Vec2. +StyleVarItemSpacing = StyleVarID(imgui.StyleVarItemSpacing) // item-spacing +// StyleVarItemInnerSpacing is a Vec2. +StyleVarItemInnerSpacing = StyleVarID(imgui.StyleVarItemInnerSpacing) // item-inner-spacing +// StyleVarIndentSpacing is a float. +StyleVarIndentSpacing = StyleVarID(imgui.StyleVarIndentSpacing) // indent-spacing +// StyleVarScrollbarSize is a float. +StyleVarScrollbarSize = StyleVarID(imgui.StyleVarScrollbarSize) // scrollbar-size +// StyleVarScrollbarRounding is a float. +StyleVarScrollbarRounding = StyleVarID(imgui.StyleVarScrollbarRounding) // scrollbar-rounding +// StyleVarGrabMinSize is a float. +StyleVarGrabMinSize = StyleVarID(imgui.StyleVarGrabMinSize) // grab-min-size +// StyleVarGrabRounding is a float. +StyleVarGrabRounding = StyleVarID(imgui.StyleVarGrabRounding) // grab-rounding +// StyleVarTabRounding is a float. +StyleVarTabRounding = StyleVarID(imgui.StyleVarTabRounding) // tab-rounding +// StyleVarButtonTextAlign is a Vec2. +StyleVarButtonTextAlign = StyleVarID(imgui.StyleVarButtonTextAlign) // button-text-align +// StyleVarSelectableTextAlign is a Vec2. +StyleVarSelectableTextAlign = StyleVarID(imgui.StyleVarSelectableTextAlign) // selectable-text-align From 89c40356a2c8b92aec34c85713cfebd8b2c816d6 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Thu, 17 Nov 2022 09:33:42 +0100 Subject: [PATCH 21/26] docs/css: convert color style's constants to human-readable form --- docs/css.md | 114 +++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/docs/css.md b/docs/css.md index 7c50a206..6fcc5047 100644 --- a/docs/css.md +++ b/docs/css.md @@ -15,60 +15,66 @@ For simple use-case see [examples/CSS-styling](../examples/CSS-styling/) ## Colors -StyleColorText = StyleColorID(imgui.StyleColorText) // color -StyleColorTextDisabled = StyleColorID(imgui.StyleColorTextDisabled) // disabled-color -StyleColorWindowBg = StyleColorID(imgui.StyleColorWindowBg) // background-color -StyleColorChildBg = StyleColorID(imgui.StyleColorChildBg) // child-background-color -StyleColorPopupBg = StyleColorID(imgui.StyleColorPopupBg) // popup-background-color -StyleColorBorder = StyleColorID(imgui.StyleColorBorder) // border-color -StyleColorBorderShadow = StyleColorID(imgui.StyleColorBorderShadow) // border-shadow-color -StyleColorFrameBg = StyleColorID(imgui.StyleColorFrameBg) // frame-background-color -StyleColorFrameBgHovered = StyleColorID(imgui.StyleColorFrameBgHovered) // frame-background-hovered-color -StyleColorFrameBgActive = StyleColorID(imgui.StyleColorFrameBgActive) // frame-background-active-color -StyleColorTitleBg = StyleColorID(imgui.StyleColorTitleBg) // title-background-color -StyleColorTitleBgActive = StyleColorID(imgui.StyleColorTitleBgActive) // title-background-active-color -StyleColorTitleBgCollapsed = StyleColorID(imgui.StyleColorTitleBgCollapsed) // title-background-collapsed-color -StyleColorMenuBarBg = StyleColorID(imgui.StyleColorMenuBarBg) // menu-bar-background-color -StyleColorScrollbarBg = StyleColorID(imgui.StyleColorScrollbarBg) // scrollbar-background-color -StyleColorScrollbarGrab = StyleColorID(imgui.StyleColorScrollbarGrab) // scrollbar-grab-color -StyleColorScrollbarGrabHovered = StyleColorID(imgui.StyleColorScrollbarGrabHovered) // scrollbar-grab-hovered-color -StyleColorScrollbarGrabActive = StyleColorID(imgui.StyleColorScrollbarGrabActive) // scrollbar-grab-active-color -StyleColorCheckMark = StyleColorID(imgui.StyleColorCheckMark) // checkmark-color -StyleColorSliderGrab = StyleColorID(imgui.StyleColorSliderGrab) // slider-grab-color -StyleColorSliderGrabActive = StyleColorID(imgui.StyleColorSliderGrabActive) // slider-grab-active-color -StyleColorButton = StyleColorID(imgui.StyleColorButton) // button-color -StyleColorButtonHovered = StyleColorID(imgui.StyleColorButtonHovered) // button-hovered-color -StyleColorButtonActive = StyleColorID(imgui.StyleColorButtonActive) // button-active-color -StyleColorHeader = StyleColorID(imgui.StyleColorHeader) // header-color -StyleColorHeaderHovered = StyleColorID(imgui.StyleColorHeaderHovered) // header-hovered-color -StyleColorHeaderActive = StyleColorID(imgui.StyleColorHeaderActive) // header-active-color -StyleColorSeparator = StyleColorID(imgui.StyleColorSeparator) // separator-color -StyleColorSeparatorHovered = StyleColorID(imgui.StyleColorSeparatorHovered) // separator-hovered-color -StyleColorSeparatorActive = StyleColorID(imgui.StyleColorSeparatorActive) // separator-active-color -StyleColorResizeGrip = StyleColorID(imgui.StyleColorResizeGrip) // resize-grip-color -StyleColorResizeGripHovered = StyleColorID(imgui.StyleColorResizeGripHovered) // resize-grip-hovered-color -StyleColorResizeGripActive = StyleColorID(imgui.StyleColorResizeGripActive) // resize-grip-active-color -StyleColorTab = StyleColorID(imgui.StyleColorTab) // tab-color -StyleColorTabHovered = StyleColorID(imgui.StyleColorTabHovered) // tab-hovered-color -StyleColorTabActive = StyleColorID(imgui.StyleColorTabActive) // tab-active-color -StyleColorTabUnfocused = StyleColorID(imgui.StyleColorTabUnfocused) // tab-unfocused-color -StyleColorTabUnfocusedActive = StyleColorID(imgui.StyleColorTabUnfocusedActive) // tab-unfocused-active-color -StyleColorPlotLines = StyleColorID(imgui.StyleColorPlotLines) // plot-lines-color -StyleColorPlotLinesHovered = StyleColorID(imgui.StyleColorPlotLinesHovered) // plot-lines-hovered-color -StyleColorProgressBarActive = StyleColorPlotLinesHovered // progress-bar-active-color -StyleColorPlotHistogram = StyleColorID(imgui.StyleColorPlotHistogram) // plot-histogram-color -StyleColorPlotHistogramHovered = StyleColorID(imgui.StyleColorPlotHistogramHovered) // plot-histogram-hovered-color -StyleColorTableHeaderBg = StyleColorID(imgui.StyleColorTableHeaderBg) // table-header-background-color -StyleColorTableBorderStrong = StyleColorID(imgui.StyleColorTableBorderStrong) // table-border-strong-color -StyleColorTableBorderLight = StyleColorID(imgui.StyleColorTableBorderLight) // table-border-light-color -StyleColorTableRowBg = StyleColorID(imgui.StyleColorTableRowBg) // table-row-background-color -StyleColorTableRowBgAlt = StyleColorID(imgui.StyleColorTableRowBgAlt) // table-row-alternate-background-color -StyleColorTextSelectedBg = StyleColorID(imgui.StyleColorTextSelectedBg) // text-selected-background-color -StyleColorDragDropTarget = StyleColorID(imgui.StyleColorDragDropTarget) // drag-drop-target-color -StyleColorNavHighlight = StyleColorID(imgui.StyleColorNavHighlight) // navigation-highlight-color -StyleColorNavWindowingHighlight = StyleColorID(imgui.StyleColorNavWindowingHighlight) // windowing-highlight-color -StyleColorNavWindowingDimBg = StyleColorID(imgui.StyleColorNavWindowingDimBg) // windowing-dim-background-color -StyleColorModalWindowDimBg = StyleColorID(imgui.StyleColorModalWindowDimBg) // modal-window-dim-background-color + + +- `color` - Text +- `disabled-color` - Text Disabled +- `background-color` - Window Bg +- `child-background-color` - Child Bg +- `popup-background-color` - Popup Bg +- `border-color` - Border +- `border-shadow-color` - Border Shadow +- `frame-background-color` - Frame Bg +- `frame-background-hovered-color` - Frame Bg Hovered +- `frame-background-active-color` - Frame Bg Active +- `title-background-color` - Title Bg +- `title-background-active-color` - Title Bg Active +- `title-background-collapsed-color` - Title Bg Collapsed +- `menu-bar-background-color` - Menu Bar Bg +- `scrollbar-background-color` - Scrollbar Bg +- `scrollbar-grab-color` - Scrollbar Grab +- `scrollbar-grab-hovered-color` - Scrollbar Grab Hovered +- `scrollbar-grab-active-color` - Scrollbar Grab Active +- `checkmark-color` - Check Mark +- `slider-grab-color` - Slider Grab +- `slider-grab-active-color` - Slider Grab Active +- `button-color` - Button +- `button-hovered-color` - Button Hovered +- `button-active-color` - Button Active +- `header-color` - Header +- `header-hovered-color` - Header Hovered +- `header-active-color` - Header Active +- `separator-color` - Separator +- `separator-hovered-color` - Separator Hovered +- `separator-active-color` - Separator Active +- `resize-grip-color` - Resize Grip +- `resize-grip-hovered-color` - Resize Grip Hovered +- `resize-grip-active-color` - Resize Grip Active +- `tab-color` - Tab +- `tab-hovered-color` - Tab Hovered +- `tab-active-color` - Tab Active +- `tab-unfocused-color` - Tab Unfocused +- `tab-unfocused-active-color` - Tab Unfocused Active +- `plot-lines-color` - Plot Lines +- `plot-lines-hovered-color` - Plot Lines Hovered +- `progress-bar-active-color` - Progress Bar Active +- `plot-histogram-color` - Plot Histogram +- `plot-histogram-hovered-color` - Plot Histogram Hovered +- `table-header-background-color` - Table Header Bg +- `table-border-strong-color` - Table Border Strong +- `table-border-light-color` - Table Border Light +- `table-row-background-color` - Table Row Bg +- `table-row-alternate-background-color` - Table Row Bg Alt +- `text-selected-background-color` - Text Selected Bg +- `drag-drop-target-color` - Drag Drop Target +- `navigation-highlight-color` - Nav Highlight +- `windowing-highlight-color` - Nav Windowing Highlight +- `windowing-dim-background-color` - Nav Windowing Dim Bg +- `modal-window-dim-background-color` - Modal Window Dim Bg ## Style Variables From 872749c74ee9277d793dde353a82ee03255c01e6 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Thu, 17 Nov 2022 10:18:28 +0100 Subject: [PATCH 22/26] css: complete documentation --- docs/css.md | 115 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/docs/css.md b/docs/css.md index 6fcc5047..c9bcaa19 100644 --- a/docs/css.md +++ b/docs/css.md @@ -78,51 +78,70 @@ Here is my regex, I used to convert variables from StyleIDs.go ## Style Variables -// StyleVarAlpha is a float. -StyleVarAlpha = StyleVarID(imgui.StyleVarAlpha) // alpha -// StyleVarDisabledAlpha is a float. -StyleVarDisabledAlpha = StyleVarID(imgui.StyleVarDisabledAlpha) // disabled-alpha -// StyleVarWindowPadding is a Vec2. -StyleVarWindowPadding = StyleVarID(imgui.StyleVarWindowPadding) // window-padding -// StyleVarWindowRounding is a float. -StyleVarWindowRounding = StyleVarID(imgui.StyleVarWindowRounding) // window-rounding -// StyleVarWindowBorderSize is a float. -StyleVarWindowBorderSize = StyleVarID(imgui.StyleVarWindowBorderSize) // window-border-size -// StyleVarWindowMinSize is a Vec2. -StyleVarWindowMinSize = StyleVarID(imgui.StyleVarWindowMinSize) // window-min-size -// StyleVarWindowTitleAlign is a Vec2. -StyleVarWindowTitleAlign = StyleVarID(imgui.StyleVarWindowTitleAlign) // window-title-align -// StyleVarChildRounding is a float. -StyleVarChildRounding = StyleVarID(imgui.StyleVarChildRounding) // child-rounding -// StyleVarChildBorderSize is a float. -StyleVarChildBorderSize = StyleVarID(imgui.StyleVarChildBorderSize) // child-border-size -// StyleVarPopupRounding is a float. -StyleVarPopupRounding = StyleVarID(imgui.StyleVarPopupRounding) // popup-rounding -// StyleVarPopupBorderSize is a float. -StyleVarPopupBorderSize = StyleVarID(imgui.StyleVarPopupBorderSize) // popup-border-size -// StyleVarFramePadding is a Vec2. -StyleVarFramePadding = StyleVarID(imgui.StyleVarFramePadding) // frame-padding -// StyleVarFrameRounding is a float. -StyleVarFrameRounding = StyleVarID(imgui.StyleVarFrameRounding) // frame-rounding -// StyleVarFrameBorderSize is a float. -StyleVarFrameBorderSize = StyleVarID(imgui.StyleVarFrameBorderSize) // frame-border-size -// StyleVarItemSpacing is a Vec2. -StyleVarItemSpacing = StyleVarID(imgui.StyleVarItemSpacing) // item-spacing -// StyleVarItemInnerSpacing is a Vec2. -StyleVarItemInnerSpacing = StyleVarID(imgui.StyleVarItemInnerSpacing) // item-inner-spacing -// StyleVarIndentSpacing is a float. -StyleVarIndentSpacing = StyleVarID(imgui.StyleVarIndentSpacing) // indent-spacing -// StyleVarScrollbarSize is a float. -StyleVarScrollbarSize = StyleVarID(imgui.StyleVarScrollbarSize) // scrollbar-size -// StyleVarScrollbarRounding is a float. -StyleVarScrollbarRounding = StyleVarID(imgui.StyleVarScrollbarRounding) // scrollbar-rounding -// StyleVarGrabMinSize is a float. -StyleVarGrabMinSize = StyleVarID(imgui.StyleVarGrabMinSize) // grab-min-size -// StyleVarGrabRounding is a float. -StyleVarGrabRounding = StyleVarID(imgui.StyleVarGrabRounding) // grab-rounding -// StyleVarTabRounding is a float. -StyleVarTabRounding = StyleVarID(imgui.StyleVarTabRounding) // tab-rounding -// StyleVarButtonTextAlign is a Vec2. -StyleVarButtonTextAlign = StyleVarID(imgui.StyleVarButtonTextAlign) // button-text-align -// StyleVarSelectableTextAlign is a Vec2. -StyleVarSelectableTextAlign = StyleVarID(imgui.StyleVarSelectableTextAlign) // selectable-text-align + + +- `alpha` - Alpha (float) +- `disabled-alpha` - Disabled Alpha (float) +- `window-padding` - Window Padding (Vec 2) +- `window-rounding` - Window Rounding (float) +- `window-border-size` - Window Border Size (float) +- `window-min-size` - Window Min Size (Vec 2) +- `window-title-align` - Window Title Align (Vec 2) +- `child-rounding` - Child Rounding (float) +- `child-border-size` - Child Border Size (float) +- `popup-rounding` - Popup Rounding (float) +- `popup-border-size` - Popup Border Size (float) +- `frame-padding` - Frame Padding (Vec 2) +- `frame-rounding` - Frame Rounding (float) +- `frame-border-size` - Frame Border Size (float) +- `item-spacing` - Item Spacing (Vec 2) +- `item-inner-spacing` - Item Inner Spacing (Vec 2) +- `indent-spacing` - Indent Spacing (float) +- `scrollbar-size` - Scrollbar Size (float) +- `scrollbar-rounding` - Scrollbar Rounding (float) +- `grab-min-size` - Grab Min Size (float) +- `grab-rounding` - Grab Rounding (float) +- `tab-rounding` - Tab Rounding (float) +- `button-text-align` - Button Text Align (Vec 2) +- `selectable-text-align` - Selectable Text Align (Vec 2) + +# Data types + +- color - supported types are: + * Named colors (e.g. red, yellow, e.t.c.) + * `rgb()` and `rgba()` + * `hsl()` and `hsla()` + * `hwb()` and `hwba()` + * `hsv()` and `hsva()` + * for more details about colors parsing visit [this repository](https://github.com/mazznoer/csscolorparser) +- float in form of plain number +- Vec2 - set of **exactly two** numbers, first for X and second for Y + +## example + +```css +main { + color: rgba(50, 100, 150, 255); + background-color: yellow; + alpha: 100; + item-spacing: 80, 20; +} +``` + +# special tags + +CSS widget supports a **special tag** called `main`. +This tag is automatically applied for the whole app and you don't need +to perform any additional actions to add it. +__There is **no** need to call giu.CSS("main")`__ + +# limitations + +- be careful with CSSS comments since they may not be parsed correctly :smile: + e.g. comments inside tags may not be supported, so if you need + comment out the whole tag, However feel free to play with that. +- more complex rules are not supported, just the simpliest one (like ruleName {...}) From 4cc70d41e92b9ba1edf44087906317707e5eb4fd Mon Sep 17 00:00:00 2001 From: gucio321 Date: Thu, 17 Nov 2022 10:18:57 +0100 Subject: [PATCH 23/26] add docs/readme.md --- docs/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..330978e2 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,3 @@ +## Package documentation + +- [CSSWidget](./css.md] From 5b3bda1f4482db2949b31874f874935e782086c7 Mon Sep 17 00:00:00 2001 From: "M.Sz" Date: Thu, 17 Nov 2022 10:21:15 +0100 Subject: [PATCH 24/26] Update css.md --- docs/css.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/css.md b/docs/css.md index c9bcaa19..53ecc7a8 100644 --- a/docs/css.md +++ b/docs/css.md @@ -137,7 +137,7 @@ main { CSS widget supports a **special tag** called `main`. This tag is automatically applied for the whole app and you don't need to perform any additional actions to add it. -__There is **no** need to call giu.CSS("main")`__ +There is **no** need to call `giu.CSS("main")` # limitations From 65f395bba8b09d6abd87e0e68a8562fa0a284229 Mon Sep 17 00:00:00 2001 From: "M.Sz" Date: Thu, 17 Nov 2022 10:22:51 +0100 Subject: [PATCH 25/26] Update README.md --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 330978e2..1c04c1e9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,3 +1,3 @@ ## Package documentation -- [CSSWidget](./css.md] +- [CSSWidget](./css.md) From 7b8085c1a7895587ba6d78c9fcb5019ad2016b4e Mon Sep 17 00:00:00 2001 From: gucio321 Date: Thu, 17 Nov 2022 10:26:41 +0100 Subject: [PATCH 26/26] CSS.go: update comment --- CSS.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CSS.go b/CSS.go index 84c85522..32d8bed0 100644 --- a/CSS.go +++ b/CSS.go @@ -19,6 +19,8 @@ import ( // tools: // css parser - for now github.com/napsy/go-css. it is a bit poor, but I don't think we need anything more // css colors - github.com/mazznoer/csscolorparser +// +// docs: docs/css.md // ParseCSSStyleSheet parses CSS stylesheet and stores the rules in giu context func ParseCSSStyleSheet(data []byte) error {