AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / coding / Perguntas / 79550291
Accepted
RfDzDeveloper
RfDzDeveloper
Asked: 2025-04-02 17:46:44 +0800 CST2025-04-02 17:46:44 +0800 CST 2025-04-02 17:46:44 +0800 CST

Fyne, como esticar abas com tabela para preencher a tela inteira do aplicativo?

  • 772

Tentei muitas maneiras diferentes de estender minha mesa para o restante do espaço livre do aplicativo.

A maneira mais simples de reproduzir meu problema é:

package main

import (
    "fmt"
    "strconv"
    "time"

    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/dialog"
    "fyne.io/fyne/v2/theme"
    "fyne.io/fyne/v2/widget"
)

type Reminders struct {
    ID        int64
    EventName string
    EventDay  time.Time
}

func getReminderSlice() [][]any {
    var slice [][]any

    reminders := []Reminders{{ID: 0, EventName: "First Event Name", EventDay: time.Now()},
        {ID: 1, EventName: "Second Name", EventDay: time.Now()}}

    slice = append(slice, []any{
        "ID",
        "Event Name",
        "Event Day",
        // "Start At",
        // "End At",
        // "Event Duration",
        // "Event Place",
        // "Priority",
        // "Description",
        "Delete?",
    })

    for _, r := range reminders {
        var currentRow []any

        currentRow = append(currentRow, strconv.FormatInt(r.ID, 10))
        currentRow = append(currentRow, r.EventName)
        currentRow = append(currentRow, r.EventDay.Format("2006-01-02"))
        // currentRow = append(currentRow, r.EventStartHour.Format("15:04"))
        // currentRow = append(currentRow, r.EventEndHour.Format("15:04"))
        // currentRow = append(currentRow, strconv.FormatFloat(r.EventDuration, 'f', -1, 64))
        // currentRow = append(currentRow, r.EventPlace)
        // currentRow = append(currentRow, strconv.Itoa(int(r.Priority)))
        // currentRow = append(currentRow, r.Description)
        // currentRow = append(currentRow, widget.NewButton("Delete", func() {}))

        slice = append(slice, currentRow)
    }
    return slice
}

func main() {
    data := getReminderSlice()

    myApp := app.New()
    myWindow := myApp.NewWindow("Table Widget")
    myWindow.Resize(fyne.NewSize(850, 530))

    // Create a table
    list := widget.NewTable(
        func() (int, int) {
            return len(data), len(data[0])
        },
        func() fyne.CanvasObject {
            container := container.NewVBox(widget.NewLabel(""))
            return container
        },
        func(i widget.TableCellID, o fyne.CanvasObject) {
            if i.Col == (len(data[0])-1) && i.Row != 0 {
                // last cell, put in a button
                w := widget.NewButtonWithIcon("Delete", theme.DeleteIcon(),
                    func() {
                        dialog.ShowConfirm("Delete?", "This will delete Event",
                            func(delete bool) {
                                if delete {
                                    fmt.Println("Deleted")

                                }
                                // refresh the reminders table
                                // refreshRemindersTable(db, uimanager)
                            }, myWindow)
                    })
                w.Importance = widget.HighImportance
                o.(*fyne.Container).Objects = []fyne.CanvasObject{
                    w,
                }
            } else {
                o.(*fyne.Container).Objects = []fyne.CanvasObject{
                    widget.NewLabel(data[i.Row][i.Col].(string)),
                }
            }
        })

    // trying to streach up table
    remindersContainer := container.NewBorder(
        nil,
        nil,
        nil,
        nil,
        container.NewAdaptiveGrid(1, list))
    colWidths := []float32{50, 150, 150, 150, 150, 150, 150, 150, 150}
    for i := range colWidths {
        list.SetColumnWidth(i, colWidths[i])
    }

    // tabs

    tabs := container.NewAppTabs(
        container.NewTabItemWithIcon("Reminders", theme.HomeIcon(), remindersContainer),
        // here will be the second tab
        // container.NewTabItemWithIcon("ToDo!", theme.ListIcon(), remindersContainer),
    )

    tabs.SetTabLocation(container.TabLocationLeading)

    // create toolbar

    toolbar := widget.NewToolbar(
        widget.NewToolbarSpacer(),
        widget.NewToolbarAction(theme.DocumentCreateIcon(), func() {
        }),
        widget.NewToolbarAction(theme.ViewRefreshIcon(), func() {}),
        widget.NewToolbarAction(theme.SettingsIcon(), func() {}),
    )

    // Creating finaly looking container
    finalContent := container.NewVBox(toolbar, tabs)
    myWindow.SetContent(finalContent)
    myWindow.ShowAndRun()
}


Depois de montar as partes do contêiner final para NewVBox(toolbar, tabs, table of a content) a tabela ficará pequena. Na posição horizontal não pode esticar bem. No caso de usar apenas tabs com tabela, tudo parece bom.

Eu tentei várias maneiras diferentes de consertar isso, mas não consigo descobrir o que está errado. Quero que o finalContent ocupe todo o espaço livre abaixo.

Espero ter expressado meus pensamentos de forma clara.

go
  • 1 1 respostas
  • 37 Views

1 respostas

  • Voted
  1. Best Answer
    andy.xyz
    2025-04-02T21:41:47+08:002025-04-02T21:41:47+08:00

    Todos os widgets preenchem o espaço disponível, mas seu uso do VBox está instruindo os itens filhos a terem altura mínima. Use o contêiner Border em vez disso, onde a barra de ferramentas fica no topo e as guias ficam no meio.

    https://docs.fyne.io/container/border.html

    • 1

relate perguntas

  • Fscanf e omitir campos como em C

  • linha de comando e fscanf para analisar a saída

  • golang: compartilhamento de matriz entre fatias

  • sintaxe golang testscript .txtar para texto CONTIDO em stderr ou stdout

  • Golang: acesse um campo em um genérico do tipo `any` [duplicado]

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Reformatar números, inserindo separadores em posições fixas

    • 6 respostas
  • Marko Smith

    Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não?

    • 2 respostas
  • Marko Smith

    Problema com extensão desinstalada automaticamente do VScode (tema Material)

    • 2 respostas
  • Marko Smith

    Vue 3: Erro na criação "Identificador esperado, mas encontrado 'import'" [duplicado]

    • 1 respostas
  • Marko Smith

    Qual é o propósito de `enum class` com um tipo subjacente especificado, mas sem enumeradores?

    • 1 respostas
  • Marko Smith

    Como faço para corrigir um erro MODULE_NOT_FOUND para um módulo que não importei manualmente?

    • 6 respostas
  • Marko Smith

    `(expression, lvalue) = rvalue` é uma atribuição válida em C ou C++? Por que alguns compiladores aceitam/rejeitam isso?

    • 3 respostas
  • Marko Smith

    Um programa vazio que não faz nada em C++ precisa de um heap de 204 KB, mas não em C

    • 1 respostas
  • Marko Smith

    PowerBI atualmente quebrado com BigQuery: problema de driver Simba com atualização do Windows

    • 2 respostas
  • Marko Smith

    AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos

    • 1 respostas
  • Martin Hope
    Fantastic Mr Fox Somente o tipo copiável não é aceito na implementação std::vector do MSVC 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant Encontre o próximo dia da semana usando o cronógrafo 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor O inicializador de membro do construtor pode incluir a inicialização de outro membro? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul O C++20 mudou para permitir a conversão de `type(&)[N]` de matriz de limites conhecidos para `type(&)[]` de matriz de limites desconhecidos? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann Como/por que {2,3,10} e {x,3,10} com x=2 são ordenados de forma diferente? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller O ponto e vírgula agora é opcional em condicionais bash com [[ .. ]] na versão 5.2? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench Por que um traço duplo (--) faz com que esta cláusula MariaDB seja avaliada como verdadeira? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng Por que `dict(id=1, **{'id': 2})` às vezes gera `KeyError: 'id'` em vez de um TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos 2024-03-20 03:12:31 +0800 CST

Hot tag

python javascript c++ c# java typescript sql reactjs html

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve