feat(zoom): add FitToWidthZoom mode
BREAKING CHANGE: ZoomMode config key type got changed, the program will not start with an old config file
This commit is contained in:
parent
e0d5717365
commit
091d0e910d
26
config.go
26
config.go
|
@ -36,7 +36,7 @@ const (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
ZoomMode string
|
||||
ZoomMode ZoomMode
|
||||
Enlarge bool
|
||||
Shrink bool
|
||||
LastDirectory string
|
||||
|
@ -95,7 +95,7 @@ func (app *App) saveConfig() {
|
|||
}
|
||||
|
||||
func (c *Config) setDefaults() {
|
||||
c.ZoomMode = "FitToWidth"
|
||||
c.ZoomMode = FitToWidth
|
||||
c.Shrink = true
|
||||
c.Enlarge = true
|
||||
c.WindowWidth = 640
|
||||
|
@ -152,17 +152,29 @@ func (c *Config) save(path string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (app *App) setZoomMode(mode string) {
|
||||
type ZoomMode int
|
||||
|
||||
const (
|
||||
FitToWidth ZoomMode = iota
|
||||
FitToHalfWidth
|
||||
FitToHeight
|
||||
BestFit
|
||||
Original
|
||||
)
|
||||
|
||||
func (app *App) setZoomMode(mode ZoomMode) {
|
||||
switch mode {
|
||||
case "FitToWidth":
|
||||
case FitToWidth:
|
||||
app.W.MenuItemFitToWidth.SetActive(true)
|
||||
case "FitToHeight":
|
||||
case FitToHalfWidth:
|
||||
app.W.MenuItemFitToHalfWidth.SetActive(true)
|
||||
case FitToHeight:
|
||||
app.W.MenuItemFitToHeight.SetActive(true)
|
||||
case "BestFit":
|
||||
case BestFit:
|
||||
app.W.MenuItemBestFit.SetActive(true)
|
||||
default:
|
||||
app.W.MenuItemOriginal.SetActive(true)
|
||||
mode = "Original"
|
||||
mode = Original
|
||||
}
|
||||
|
||||
app.Config.ZoomMode = mode
|
||||
|
|
10
gomicsv.ui
10
gomicsv.ui
|
@ -217,6 +217,16 @@
|
|||
<property name="group">MenuItemBestFit</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="MenuItemFitToHalfWidth">
|
||||
<property name="visible">true</property>
|
||||
<property name="can-focus">false</property>
|
||||
<property name="label" translatable="yes">Fit to half-width</property>
|
||||
<property name="use-underline">true</property>
|
||||
<property name="draw-as-radio">true</property>
|
||||
<property name="group">MenuItemBestFit</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="MenuItemFitToHeight">
|
||||
<property name="visible">true</property>
|
||||
|
|
11
image.go
11
image.go
|
@ -117,14 +117,19 @@ func (app *App) getScaledSize() (scale float64) {
|
|||
|
||||
w, h := app.pixbufSize()
|
||||
switch app.Config.ZoomMode {
|
||||
case "FitToWidth":
|
||||
case FitToWidth:
|
||||
needscale := (app.Config.Enlarge && w < scrw) || (app.Config.Shrink && w > scrw)
|
||||
if needscale {
|
||||
return float64(scrw) / float64(w)
|
||||
}
|
||||
case "FitToHeight":
|
||||
case FitToHalfWidth:
|
||||
needscale := (app.Config.Enlarge && w/2 < scrw) || (app.Config.Shrink && w/2 > scrw)
|
||||
if needscale {
|
||||
return float64(scrw) / float64(w/2)
|
||||
}
|
||||
case FitToHeight:
|
||||
return float64(scrh) / float64(h)
|
||||
case "BestFit":
|
||||
case BestFit:
|
||||
needscale := (app.Config.Enlarge && (w < scrw && h < scrh)) || (app.Config.Shrink && (w > scrw || h > scrh))
|
||||
if needscale {
|
||||
fw, _ := util.Fit(w, h, scrw, scrh)
|
||||
|
|
15
menu.go
15
menu.go
|
@ -89,25 +89,31 @@ func (app *App) menuInit() {
|
|||
|
||||
app.W.MenuItemOriginal.Connect("toggled", func() {
|
||||
if app.W.MenuItemOriginal.GetActive() {
|
||||
app.setZoomMode("Original")
|
||||
app.setZoomMode(Original)
|
||||
}
|
||||
})
|
||||
|
||||
app.W.MenuItemBestFit.Connect("toggled", func() {
|
||||
if app.W.MenuItemBestFit.GetActive() {
|
||||
app.setZoomMode("BestFit")
|
||||
app.setZoomMode(BestFit)
|
||||
}
|
||||
})
|
||||
|
||||
app.W.MenuItemFitToWidth.Connect("toggled", func() {
|
||||
if app.W.MenuItemFitToWidth.GetActive() {
|
||||
app.setZoomMode("FitToWidth")
|
||||
app.setZoomMode(FitToWidth)
|
||||
}
|
||||
})
|
||||
|
||||
app.W.MenuItemFitToHalfWidth.Connect("toggled", func() {
|
||||
if app.W.MenuItemFitToHalfWidth.GetActive() {
|
||||
app.setZoomMode(FitToHalfWidth)
|
||||
}
|
||||
})
|
||||
|
||||
app.W.MenuItemFitToHeight.Connect("toggled", func() {
|
||||
if app.W.MenuItemFitToHeight.GetActive() {
|
||||
app.setZoomMode("FitToHeight")
|
||||
app.setZoomMode(FitToHeight)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -290,6 +296,7 @@ func (app *App) menuSetupAccels() {
|
|||
{&app.W.MenuItemBestFit.MenuItem, Accel{gdk.KEY_B, 0}},
|
||||
{&app.W.MenuItemOriginal.MenuItem, Accel{gdk.KEY_O, 0}},
|
||||
{&app.W.MenuItemFitToWidth.MenuItem, Accel{gdk.KEY_W, 0}},
|
||||
{&app.W.MenuItemFitToHalfWidth.MenuItem, Accel{gdk.KEY_W, gdk.MOD1_MASK}},
|
||||
{&app.W.MenuItemFitToHeight.MenuItem, Accel{gdk.KEY_H, 0}},
|
||||
{&app.W.MenuItemFullscreen.MenuItem, Accel{gdk.KEY_F, 0}},
|
||||
{&app.W.MenuItemRandom.MenuItem, Accel{gdk.KEY_R, 0}},
|
||||
|
|
8
ui.go
8
ui.go
|
@ -92,11 +92,13 @@ func (app *App) syncWidgetsToConfig() {
|
|||
app.W.MenuItemMangaMode.SetActive(app.Config.MangaMode)
|
||||
|
||||
switch app.Config.ZoomMode {
|
||||
case "FitToWidth":
|
||||
case FitToWidth:
|
||||
app.W.MenuItemFitToWidth.SetActive(true)
|
||||
case "FitToHeight":
|
||||
case FitToHalfWidth:
|
||||
app.W.MenuItemFitToHalfWidth.SetActive(true)
|
||||
case FitToHeight:
|
||||
app.W.MenuItemFitToHeight.SetActive(true)
|
||||
case "BestFit":
|
||||
case BestFit:
|
||||
app.W.MenuItemBestFit.SetActive(true)
|
||||
default:
|
||||
app.W.MenuItemOriginal.SetActive(true)
|
||||
|
|
|
@ -89,6 +89,7 @@ type Widgets struct {
|
|||
MenuItemBestFit *gtk.RadioMenuItem `build:"MenuItemBestFit"`
|
||||
MenuItemOriginal *gtk.RadioMenuItem `build:"MenuItemOriginal"`
|
||||
MenuItemFitToWidth *gtk.RadioMenuItem `build:"MenuItemFitToWidth"`
|
||||
MenuItemFitToHalfWidth *gtk.RadioMenuItem `build:"MenuItemFitToHalfWidth"`
|
||||
MenuItemFitToHeight *gtk.RadioMenuItem `build:"MenuItemFitToHeight"`
|
||||
MenuItemAbout *gtk.MenuItem `build:"MenuItemAbout"`
|
||||
GoToThumbnailImage *gtk.Image `build:"GoToThumbnailImage"`
|
||||
|
|
Loading…
Reference in a new issue