SetLinuxStyle as Default

Linux specific forum
User avatar
mk-soft
Addict
Addict
Posts: 3884
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

SetLinuxStyle as Default

Post by mk-soft »

Most of the time the buttons, entry, panel are preset too large with Linux default CSS style.
Thus the gadgets from window to linux or the examples from PureBasic do not fit correctly.

Simply adjust the basic settings for all windows.

Code: Select all

;-TOP by mk-soft, v1.01.0, 21.05.2022

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ;- Constants
  #GTK_STYLE_PROVIDER_PRIORITY_FALLBACK = 1
  #GTK_STYLE_PROVIDER_PRIORITY_THEME = 200
  #GTK_STYLE_PROVIDER_PRIORITY_SETTINGS = 400
  #GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600
  #GTK_STYLE_PROVIDER_PRIORITY_USER  = 800
  
  ImportC ""
    gtk_css_provider_load_from_data(*CSSProvider, CSSData.P-UTF8, Length, *Error.GError)
    gtk_css_provider_new()
    gtk_style_context_add_provider_for_screen(*Screen.GdkScreen, *StyleProvider, Priority)
  EndImport
  
  Procedure _SetLinuxStyle()
    Protected CSSProvider, CSSDefault.s, Screen
    
    CSSDefault = "button, entry {min-height: 20px;} "
    CSSDefault + "tab {min-height: 20px;} "
    CSSDefault + "button, scale {padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px} "
    
    CSSProvider= gtk_css_provider_new()
    gtk_css_provider_load_from_data(CSSProvider, CSSDefault, -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)
    
  EndProcedure : _SetLinuxStyle()
  
CompilerEndIf

; *********************************************************

#Example = 3

CompilerIf #Example = 1
  
  Procedure UpdateWindow()
    Protected dx, dy
    dx = WindowWidth(0)
    dy = WindowHeight(0)
    Debug dx
    ResizeGadget(0, 10, 10, dx - 20, dy - 70)
    ResizeGadget(1, 10, dy - 50, 120, 30)
  EndProcedure
  
  Procedure ShowDialog()
    If OpenWindow(1, 300, 300, 300, 200, "Dialog");, #PB_Window_Tool)
      dx = WindowWidth(1)
      dy = WindowHeight(1)
      EditorGadget(10, 10, 10, dx - 20, dy - 70)
      ButtonGadget(11, 10, dy - 50, 120, 30, "Ok")
      ButtonGadget(12, dx - 130, dy - 50, 120, 30, "Cancel")
    EndIf
  EndProcedure
  
  Procedure Main()
    Protected info.s
    info = "XDG_SESSION_TYPE: " + GetEnvironmentVariable("XDG_SESSION_TYPE") + #LF$
    
    If OpenWindow(0, 100, 100, 400, 300, "Window", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
      
      dx = WindowWidth(0)
      dy = WindowHeight(0)
      TextGadget(0, 10, 10, dx - 20, dy - 70, info, #PB_Text_Border)
      ButtonGadget(1, 10, dy - 50, 120, 30, "Dialog")
      
      BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
      
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Select EventWindow()
              Case 0
                Break
              Case 1
                CloseWindow(1)
                
            EndSelect
            
          Case #PB_Event_Gadget
            Select EventGadget()
              Case 1
                ShowDialog()
              Case 11, 12
                CloseWindow(1)
                
            EndSelect
            
        EndSelect
      ForEver
      
    EndIf
    
  EndProcedure : Main()
  
CompilerEndIf

; ----

CompilerIf #Example = 2
  
  OpenWindow(0, 100, 100, 300, 160, "StringGadgets")
  
  For i = 0 To 2
    StringGadget(i, 20, i * 35 + 20, WindowWidth(0) - 40, 25, "")
    SetGadgetText(i, "StringGadget " + Str(i + 1) +
      " - Required height: " + GadgetHeight(i, #PB_Gadget_RequiredSize))
  Next i
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
CompilerEndIf

; ----

CompilerIf #Example = 3
  
   If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    PanelGadget     (0, 8, 8, 306, 203)
      AddGadgetItem (0, -1, "Panel 1")
        PanelGadget (1, 5, 5, 290, 166)
          AddGadgetItem(1, -1, "Sub-Panel 1")
          AddGadgetItem(1, -1, "Sub-Panel 2")
          AddGadgetItem(1, -1, "Sub-Panel 3")
        CloseGadgetList()
      AddGadgetItem (0, -1,"Panel 2")
        ButtonGadget(2, 10, 15, 80, 24,"Button 1")
        ButtonGadget(3, 95, 15, 80, 24,"Button 2")
    CloseGadgetList()
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
  
CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Luca Concon
New User
New User
Posts: 1
Joined: Sat Jul 16, 2022 7:57 am

Re: SetLinuxStyle as Default

Post by Luca Concon »

Thanks
Old Linux user
Post Reply