Increasing default font size of this simple go gui application - user-interface

I am using following simple demo code to create a GUI using Fyne package:
package main
import (
"fyne.io/fyne/widget"
"fyne.io/fyne/app"
)
func main() {
app := app.New()
w := app.NewWindow("Hello")
w.SetContent(widget.NewVBox(
widget.NewLabel("Hello Fyne!"),
widget.NewButton("Quit", func() {
app.Quit()
}),
))
w.ShowAndRun()
}
It works all right but I want to increase size default font of this GUI (so that font size should increase in label, button and any other widget like entry that may be added to it).
I see there is theme object (with a TextSize() function) that can possibly be used but I am not able to use it to increase font size. There is a also RenderedTextSize(string, int, TextStyle) Size in type Driver interface.
How can I increase default font in this simple GUI application? Thanks for your help.

You can use TextSize() within theme - you would need to provide a custom theme as set it with myApp.Settings().SetTheme().
If, however, you just wish a larger application for your own setup then you should try setting the environment variable FYNE_SCALE to something like 2.0 which will scale the whole user interface. This changes the size for your computer whereas setting the TextSize in a theme would change it for everyone.
It’s worth noting that this is not “trivial” because Fyne widgets intentionally do not offer much customisation.

Related

How to change color of GUI components

I am trying following demo code of fyne:
package main
import (
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Hello")
w.SetContent(
widget.NewVBox(
widget.NewLabel("Hello Fyne!"),
widget.NewButton("Quit", func(){a.Quit()} ),
),
)
w.ShowAndRun()
}
It runs all right but I want to change color of label to blue and that of button to green. I see there is theme but that seems to be for entire application and not for individual elements.
How can different colors be applied to different GUI components? Thanks for your help.
That was proposed in fyne-io/fyne issue 255
I propose individual styles assignable to widgets:
But:
Part of our design is to promote application consistency - a user experience that cannot be trivially compromised by "this label is larger" or "this dropdown is transparent".
Fyne's approach to this is that widgets have a set style (that can be themed) but the canvas remains fully available to do whatever specific designs a developer chooses to code.
So there is no native support to change the color of an individual button.
Andy Williams, author/main contributor of fyne-io/fyne, adds in the comments:
This is quite correct.
The only way to have a widget that is is styled differently to the standard colours is to implement a custom widget and add that functionality yourself.
There are, however, some semantic styles, a button can be “primary, for example, in which case it will use the theme highlight color
As the standard widgets in Fyne do not support customisation there is no short answer to this (other than we don't advise it).
If you have to do this, for some valid reason that your users require, then you should look at our developer documentation which has a brief introduction to writing custom widgets. However we aim to make this process easier in release 1.2 later this year.
Just to re-iterate comments above the Fyne toolkit is aiming to create a consistent user experience that is simple and fast to program. Every time you create a custom widget so that you can have custom colours or styles you may be confusing your user and you will be making it much harder to maintain the code.

Screen capture in Haskell?

Is it possible to capture the screen (or a window) using Haskell in a Windows environment? (ie, taking a screenshot every few minutes or so). If so, how would one go about doing this (again, in Haskell, for a Windows environment)?
More info:
I'm a beginner to Haskell. A friend wants to cut development costs by having me whip together some programs for his accounting firm, but he insists that I use Haskell. He wants a tool that will allow him to monitor the desktops of different Windows XP workstations. It would likely have to be a client/server type application. He only needs to monitor desktop activity, hence why he doesn't want any of the expensive management software that is already on the market. I have sifted through lots of documentation, and only got as far as finding wxHaskell, but I couldn't find much on capturing the screen, especially for Windows environments.
The Approach Tikhon mentioned is correct. Just to add some code to the answer he gave above
import Graphics.Win32.Window
import Graphics.Win32.GDI.Bitmap
import Graphics.Win32.GDI.HDC
import Graphics.Win32.GDI.Graphics2D
main = do desktop <- getDesktopWindow -- Grab the Hwnd of the desktop, GetDC 0, GetDC NULL etc all work too
hdc <- getWindowDC (Just desktop) -- Get the dc handle of the desktop
(x,y,r,b) <- getWindowRect desktop -- Find the size of the desktop so we can know which size the destination bitmap should be
-- (left, top, right, bottom)
newDC <- createCompatibleDC (Just hdc) -- Create a new DC to hold the copied image. It should be compatible with the source DC
let width = r - x -- Calculate the width
let height = b - y -- Calculate the Height
newBmp <- createCompatibleBitmap hdc width height -- Create a new Bitmap which is compatible with the newly created DC
selBmp <- selectBitmap newDC newBmp -- Select the Bitmap into the DC, drawing on the DC now draws on the bitmap as well
bitBlt newDC 0 0 width height hdc 0 0 sRCCOPY -- use SRCCOPY to copy the desktop DC into the newDC
createBMPFile "Foo.bmp" newBmp newDC -- Write out the new Bitmap file to Foo.bmp
putStrLn "Bitmap image copied" -- Some debug message
deleteBitmap selBmp -- Cleanup the selected bitmap
deleteBitmap newBmp -- Cleanup the new bitmap
deleteDC newDC -- Cleanup the DC we created.
This was just quickly put together, but it saves a screenshot of to a file named Foo.bmp.
Ps. To whomever wrote the Win32 Library, nicely done :)
You can also do it in a cross-platform way with GTK.
That would not be much different from doing it with C: Taking a screenshot with C/GTK.
{-# LANGUAGE OverloadedStrings #-}
import Graphics.UI.Gtk
import System.Environment
import Data.Text as T
main :: IO ()
main = do
[fileName] <- getArgs
_ <- initGUI
Just screen <- screenGetDefault
window <- screenGetRootWindow screen
size <- drawableGetSize window
origin <- drawWindowGetOrigin window
Just pxbuf <-
pixbufGetFromDrawable
window
((uncurry . uncurry Rectangle) origin size)
pixbufSave pxbuf fileName "png" ([] :: [(T.Text, T.Text)])
You should be able to do this with the Win32 API. Based on What is the best way to take screenshots of a Window with C++ in Windows?, you need to get the context of the window and then copy the image from it using GetWindowDC and BitBlt respectively.
Looking around the Haskell Win32 API documentation, there is a getWindowDC function in Graphics.Win32.Window. This returns an IO HDC. There is a bitblt function in Graphics.Win32.GDI.Graphics2D. This function takes an HDC along with a bunch of INTs which presumably correspond to the arguments it takes in C++.
Unfortunately, I don't have a Windows machine handy, so I can't write the actual code. You'll have to figure out how to use the Win32 API functions yourself, which might be a bit of a bother.
When you do, it would be great if you factored it into a library and put it up on Hackage--Windows does not usually get much love in Haskell land (as I myself show :P), so I'm sure other Windows programmers would be grateful for an easy way to take screenshots.

How to change the size of small wizard image and have custom fields in inno setup

I want all my inno set up pages to look like below :
The small wizard image is accessible using WizardForm.WizardSmallBitmapImage which is of type TBitmapImage.
You can change the size and position of this control to suit your design (within the top panel). You can also hide/reposition the labels (WizardForm.PageNameLabel and WizardForm.PageDescriptiontLabel) in the same way.
As for the extra fields, see this question.

How to measure static size beforehand? WINAPI

I am creating a widow with static text, and because of the all 96/120/180 DPI stuff, I need to create a layouting mini-engine.
The dialog is created in code, statics are created in code, fonts are created in code, everything, mostly because resources in .rc have their share of DPI related problems as well and I want a total control.
The problem with all this is that I don't know how to find the length of the text in statics. I need to calculate the initial size of the static control, and also, I need to calculate a padding between different statics in font unit sizes, but since I don't know the size of the previous static, I can't offset the next one.
The biggest problem is that static does the word wrapping, therefore I can't find a text measuring function that would calculate that and a correction for a custom font, italic, bold, oversize...
Anyone have any ideas?
The static control styles (ENDELLIPSIS,PATHELLIPSIS and LEFTNOWORDWRAP) seem to map to the DrawText flags, so calling DrawText with DT_WORDBREAK|DT_CALCRECT will probably be as close as you can get...
I can't think of any compelling reason to do this any differently then the way all other GUI class libraries do it. Just scale window sizes between the 'design' DPI setting and the target machine DPI setting. Using DPI-independent constants is pretty painful in MFC since everything is pixel based. So keep your workstation at the common 96 DPI setting, scale from there on the target machine. You do have to keep a bit of slack because of TrueType hinting.

wxwidgets custom control size cannot be set.What am i missing out

I have a Custom control derived from wxControl,inside a dialog with a vertical sizer
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
Knob* newKnob = new Knob(panel,wxID_ANY,wxDefaultPosition,wxSize(40,40));
topSizer->Add(newKnob,0,wxALL|wxALIGN_CENTER);
panel->SetSizer(topSizer);
topSizer->Fit(panel);
//panel is a wxPanel inside the dialog
But for some reason ,the custom controls' size is set at (80,100).If i resize the dialog beyond that size its aligned to center as i specified.
EDIT:
Am using wx 2.8.9 on windows Vista with visual studio 2005.
What could be missing?
You didn't provide any information about the wxWidgets version or your platform / compiler, so I will answer for wxWidgets 2.8 and MSW.
The size you specify is not necessarily used for the control, since the best size for different platforms may well be different. Even on Windows the size will usually depend on the default GUI font. So there are various methods in wxWidgets that let windows specify their minimum, best or maximum size. If you have special requirements you may need to override some of them.
For your problem it looks like you want to have the control have a smaller size than the default best size of wxControl:
wxSize wxControl::DoGetBestSize() const
{
return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
}
(taken from src/msw/control.cpp) with the values
#define DEFAULT_ITEM_WIDTH 100
#define DEFAULT_ITEM_HEIGHT 80
(taken from include/wx/msw/private.h).
If you override DoGetBestSize() to return your intended size it should work.
Edit:
You comment that you cannot override DoGetBestSize() since it is not virtual in wxControl. It is though, because it is introduced in wxWindow:
// get the size which best suits the window: for a control, it would be
// the minimal size which doesn't truncate the control, for a panel - the
// same size as it would have after a call to Fit()
virtual wxSize DoGetBestSize() const;
(taken from include/wx/window.h). wxWindow is a parent class of wxControl, so the method is indeed virtual and you can of course override it. Many controls do in fact, as a grep in the sources will show you.

Resources