diff options
| author | trustable-code <krauter.simon@arcor.de> | 2019-08-31 15:42:20 +0200 |
|---|---|---|
| committer | trustable-code <krauter.simon@arcor.de> | 2019-08-31 15:42:20 +0200 |
| commit | 41d7e103c09f23f158afd6df442275cc86a66937 (patch) | |
| tree | a53985326393c4e10d65724b7ded6cf126bab7f6 /src | |
| parent | 5f1590e390224b31fe9034953d217151a110ec5b (diff) | |
| download | NiGui-41d7e103c09f23f158afd6df442275cc86a66937.tar.gz NiGui-41d7e103c09f23f158afd6df442275cc86a66937.zip | |
Rework initialization of colors
Diffstat (limited to 'src')
| -rwxr-xr-x | src/nigui.nim | 35 | ||||
| -rwxr-xr-x | src/nigui/private/gtk3/platform_impl.nim | 16 | ||||
| -rwxr-xr-x | src/nigui/private/windows/platform_impl.nim | 10 |
3 files changed, 32 insertions, 29 deletions
diff --git a/src/nigui.nim b/src/nigui.nim index 0d876e8..018513d 100755 --- a/src/nigui.nim +++ b/src/nigui.nim @@ -699,12 +699,10 @@ method `scrollableHeight=`*(control: Control, scrollableHeight: int) method fontFamily*(control: Control): string method `fontFamily=`*(control: Control, fontFamily: string) method setFontFamily*(control: Control, fontFamily: string) -method resetFontFamily*(control: Control) method fontSize*(control: Control): float method `fontSize=`*(control: Control, fontSize: float) method setFontSize*(control: Control, fontSize: float) -method resetFontSize*(control: Control) method fontBold*(control: Control): bool method `fontBold=`*(control: Control, fontBold: bool) @@ -713,12 +711,11 @@ method setFontBold*(control: Control, fontBold: bool) method backgroundColor*(control: Control): Color method `backgroundColor=`*(control: Control, color: Color) method setBackgroundColor*(control: Control, color: Color) -method resetBackgroundColor*(control: Control) +method initStyle*(control: Control) method textColor*(control: Control): Color method `textColor=`*(control: Control, color: Color) method setTextColor*(control: Control, color: Color) -method resetTextColor*(control: Control) method forceRedraw*(control: Control) @@ -1399,10 +1396,7 @@ proc init(control: Control) = control.fheight = 50.scaleToDpi control.fScrollableWidth = -1 control.fScrollableHeight = -1 - control.resetFontFamily() - control.resetFontSize() - control.resetTextColor() - control.resetBackgroundColor() + control.initStyle() control.show() # should be extended by ControlImpl @@ -1661,11 +1655,6 @@ method setFontFamily(control: Control, fontFamily: string) = control.triggerRelayoutIfModeIsAuto() # should be extended by ControlImpl -method resetFontFamily(control: Control) = - control.setFontFamily(fDefaultFontFamily) - control.fUseDefaultFontFamily = true - control.triggerRelayoutIfModeIsAuto() - method fontSize(control: Control): float = control.fFontSize method `fontSize=`(control: Control, fontSize: float) = @@ -1677,11 +1666,6 @@ method setFontSize(control: Control, fontSize: float) = control.fFontSize = fontSize # should be extended by ControlImpl -method resetFontSize(control: Control) = - control.setFontSize(app.defaultFontSize) - control.fUseDefaultFontSize = true - control.triggerRelayoutIfModeIsAuto() - method fontBold(control: Control): bool = control.fFontBold method `fontBold=`(control: Control, fontBold: bool) = @@ -1703,9 +1687,16 @@ method setBackgroundColor(control: Control, color: Color) = control.forceRedraw() # should be extended by ControlImpl -method resetBackgroundColor(control: Control) = - control.setBackgroundColor(fDefaultBackgroundColor) +method initStyle(control: Control) = + control.fBackgroundColor = fDefaultBackgroundColor + control.fTextColor = fDefaultTextColor + control.setFontFamily(fDefaultFontFamily) + control.setFontSize(app.defaultFontSize) control.fUseDefaultBackgroundColor = true + control.fUseDefaultTextColor = true + control.fUseDefaultFontFamily = true + control.fUseDefaultFontSize = true + control.triggerRelayoutIfModeIsAuto() method textColor(control: Control): Color = control.fTextColor @@ -1718,10 +1709,6 @@ method setTextColor(control: Control, color: Color) = control.forceRedraw() # should be extended by ControlImpl -method resetTextColor*(control: Control) = - control.setTextColor(fDefaultTextColor) - control.fUseDefaultTextColor = true - method forceRedraw(control: Control) = discard # should be implemented by ControlImpl diff --git a/src/nigui/private/gtk3/platform_impl.nim b/src/nigui/private/gtk3/platform_impl.nim index 098f02c..25d875f 100755 --- a/src/nigui/private/gtk3/platform_impl.nim +++ b/src/nigui/private/gtk3/platform_impl.nim @@ -867,7 +867,6 @@ proc pUpdateFont(control: ControlImpl) = gtk_widget_modify_font(control.fHandle, font) var rgba: GdkRGBA control.textColor.pColorToGdkRGBA(rgba) - gtk_widget_override_color(control.fHandle, GTK_STATE_FLAG_NORMAL, rgba) method pAddButtonPressEvent(control: ControlImpl) = gtk_widget_add_events(control.fHandle, GDK_BUTTON_PRESS_MASK) @@ -1043,7 +1042,9 @@ method setFontBold(control: ControlImpl, fontBold: bool) = method setTextColor(control: ControlImpl, color: Color) = procCall control.Control.setTextColor(color) - control.pUpdateFont() + var rgba: GdkRGBA + color.pColorToGdkRGBA(rgba) + gtk_widget_override_color(control.fHandle, GTK_STATE_FLAG_NORMAL, rgba) method `setBackgroundColor`(control: ControlImpl, color: Color) = procCall control.Control.setBackgroundColor(color) @@ -1258,6 +1259,17 @@ proc init(textBox: NativeTextBox) = discard g_signal_connect_data(textBox.fHandle, "changed", pControlChangedSignal, cast[pointer](textBox)) textBox.TextBox.init() +method initStyle(textBox: NativeTextBox) = + procCall textBox.TextBox.initStyle() + var context = gtk_widget_get_style_context(textBox.fHandle) + var rgba: GdkRGBA + gtk_style_context_get_background_color(context, GTK_STATE_FLAG_NORMAL, rgba) + textBox.fBackgroundColor = rgba.pGdkRGBAToColor() + gtk_style_context_get_color(context, GTK_STATE_FLAG_NORMAL, rgba) + textBox.fTextColor = rgba.pGdkRGBAToColor() + textBox.fUseDefaultBackgroundColor = false + textBox.fUseDefaultTextColor = false + method text(textBox: NativeTextBox): string = $gtk_entry_get_text(textBox.fHandle) method `text=`(textBox: NativeTextBox, text: string) = diff --git a/src/nigui/private/windows/platform_impl.nim b/src/nigui/private/windows/platform_impl.nim index 133d7dc..0f7ffaf 100755 --- a/src/nigui/private/windows/platform_impl.nim +++ b/src/nigui/private/windows/platform_impl.nim @@ -1429,6 +1429,13 @@ proc init(textBox: NativeTextBox) = pTextBoxOrigWndProc = pSetWindowLongPtr(textBox.fHandle, GWLP_WNDPROC, pTextBoxWndProc) textBox.TextBox.init() +method initStyle(textBox: NativeTextBox) = + procCall textBox.TextBox.initStyle() + textBox.fBackgroundColor = GetSysColor(COLOR_WINDOW).pRgb32ToColor() + textBox.fTextColor = fDefaultTextColor + textBox.fUseDefaultBackgroundColor = false + textBox.fUseDefaultTextColor = false + method text(textBox: NativeTextBox): string = pGetWindowText(textBox.fHandle) method `text=`(textBox: NativeTextBox, text: string) = pSetWindowText(textBox.fHandle, text) @@ -1465,9 +1472,6 @@ method `selectionStart=`(textBox: NativeTextBox, selectionStart: int) = method `selectionEnd=`(textBox: NativeTextBox, selectionEnd: int) = discard SendMessageA(textBox.fHandle, EM_SETSEL, cast[pointer](textBox.selectionStart), cast[pointer](selectionEnd)) -method resetBackgroundColor(textBox: NativeTextBox) = - textBox.setBackgroundColor(GetSysColor(COLOR_WINDOW).pRgb32ToColor()) - textBox.fUseDefaultBackgroundColor = true # ---------------------------------------------------------------------------------------- # TextArea |
