Page 1 of 1

stringgadget height question

Posted: Wed Jan 20, 2021 4:27 pm
by John Duchek
I am working on a program that uses a lot of stringgadgets for input. it seems there are limits for the size of these that appear pretty large. In this line
StringGadget(31,300,60,140,20," ") the value of 20 for the height is very large. If I put in 10 or 15 or 0 I get the same gadget size as if I put in 20. Is that a permanent minimum or is that automatically set by the font size or something? I am using the default fonts. I need to use at least 22 of these gadget, and that is taking up a lot of window. Is there any way to make that 20 height 10??
Thanks for any help,
John

Re: stringgadget height question

Posted: Wed Jan 20, 2021 6:55 pm
by mk-soft
The minimum sizes are set by the GTK3 CSS provider and may change when changing to a different theme under Linux Control Panel.

I'll have to see if I can change this with GTK3 functions.

Re: stringgadget height question

Posted: Wed Jan 20, 2021 8:38 pm
by Shardik
Tested successfully on Linux Mint 19.3 'Tricia' x64 with Cinnamon and GTK3 using PB 5.73 x64:

Image

Code: Select all

#GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600

ImportC ""
  gtk_css_provider_load_from_data(*CSSProvider, CSSData.P-UTF8, Length.I,
    *Error.GError)
  gtk_css_provider_new()
  gtk_style_context_add_provider_for_screen(*Screen.GdkScreen, *StyleProvider,
    Priority.I)
EndImport

Define CSSProvider.I
Define CSSStringInput.S
Define Screen.I

CSSStringInput = "" +
  "entry {" + #LF$ +
  "  padding-top: 0px; padding-bottom: 0px;" + #LF$ +
  "}"

CSSProvider= gtk_css_provider_new()
gtk_css_provider_load_from_data(CSSProvider, CSSStringInput, -1, 0)
Screen = gdk_display_get_default_screen_(gdk_display_get_default_())
gtk_style_context_add_provider_for_screen(Screen, CSSProvider,
  #GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
g_object_unref_(CSSProvider)

OpenWindow(0, 100, 100, 300, 103, "StringGadgets with reduced height")

For i = 0 To 2
  StringGadget(i, 20, i * 22 + 20, WindowWidth(0) - 40, 1, "")
  SetGadgetText(i, "StringGadget " + Str(i + 1) +
    " - Required height: " + GadgetHeight(i, #PB_Gadget_RequiredSize))
Next i

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: stringgadget height question

Posted: Wed Jan 20, 2021 9:24 pm
by mk-soft
Thanks :wink:

Re: stringgadget height question

Posted: Thu Jan 21, 2021 6:10 am
by John Duchek
Thank you for your responses. FYI I am using fedora33 and XFCE4. I wasn't able to run that code as I get this error Line 10: gtk_css_provider_new() is not a function, array, list, map or macro. and I haven't figured it out yet. Still I tried 19 and 18 pixels for y and it made no difference. It looks like I am stuck with that for the moment.
John

Re: stringgadget height question

Posted: Thu Jan 21, 2021 11:00 am
by mk-soft
PB Version?

Not use subsystem GTK2

Re: stringgadget height question

Posted: Thu Jan 21, 2021 1:36 pm
by Shardik
Unfortunately I am currently in my home office and can't test on my test PC at work with 22 different Linux distributions including Fedora. But I know that Fedora is a special distribution in which you have to import each GTK3 function (the GTK3 functions predefined in PureBasic are not found). Therefore you may try the following example which also imports GTK3 functions gdk_display_get_default() and gdk_display_get_default_screen() instead of using the same functions predefined in PureBasic with a trailing underscore. The modified example should work in all Linux distributions with GTK3:

Code: Select all

#GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600

ImportC ""
  gtk_css_provider_load_from_data(*CSSProvider, CSSData.P-UTF8, Length.I,
    *Error.GError)
  gtk_css_provider_new()
  gdk_display_get_default()
  gdk_display_get_default_screen(*Display.GdkDisplay)
  gtk_style_context_add_provider_for_screen(*Screen.GdkScreen, *StyleProvider,
    Priority.L)
EndImport

Define CSSProvider.I
Define CSSStringInput.S
Define Screen.I

CSSStringInput = "" +
  "entry {" + #LF$ +
  "  padding-top: 0px; padding-bottom: 0px;" + #LF$ +
  "}"

CSSProvider = gtk_css_provider_new()
gtk_css_provider_load_from_data(CSSProvider, CSSStringInput, -1, 0)
Screen = gdk_display_get_default_screen(gdk_display_get_default())
gtk_style_context_add_provider_for_screen(Screen, CSSProvider,
  #GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)

OpenWindow(0, 100, 100, 300, 103, "StringGadgets with reduced height")

For i = 0 To 2
  StringGadget(i, 20, i * 22 + 20, WindowWidth(0) - 40, 1, "")
  SetGadgetText(i, "StringGadget " + Str(i + 1) +
    " - Required height: " + GadgetHeight(i, #PB_Gadget_RequiredSize))
Next i

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow