-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow a theme to override the form factor of the tabs to be mobile #5239
Merged
andydotxyz
merged 4 commits into
fyne-io:develop
from
andydotxyz:feature/simulatemobiletheme
Nov 17, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2e13c16
Allow a theme to override the form factor of the tabs to be mobile
andydotxyz 3ba2b0a
Proposing a cleaner API for feature overrides in a ThemeOverride context
andydotxyz f5a5fb2
Adding test to show that override renders a mobile app tabs on a desk…
andydotxyz 7a4a159
Don't document a public API release version for internal APIs
andydotxyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build !mobile | ||
|
||
package container_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"fyne.io/fyne/v2/container" | ||
"fyne.io/fyne/v2/test" | ||
"fyne.io/fyne/v2/widget" | ||
) | ||
|
||
func TestAppTabs_OverrideMobile(t *testing.T) { | ||
test.NewTempApp(t) | ||
|
||
item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} | ||
item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} | ||
item3 := &container.TabItem{Text: "Test3", Content: widget.NewLabel("Text 3")} | ||
tabs := container.NewAppTabs(item1, item2, item3) | ||
w := test.NewWindow(tabs) | ||
defer w.Close() | ||
w.SetPadded(false) | ||
c := w.Canvas() | ||
|
||
min := tabs.MinSize() | ||
w.Resize(min) | ||
|
||
test.AssertRendersToMarkup(t, "apptabs/desktop/tab_location_top.xml", c) | ||
|
||
override := container.NewThemeOverride(tabs, test.Theme()) | ||
override.SetDeviceIsMobile(true) | ||
w.Resize(min.AddWidthHeight(-4, -0)) | ||
|
||
test.AssertRendersToMarkup(t, "apptabs/mobile/tab_location_top.xml", c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package theme | ||
|
||
import ( | ||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/internal/cache" | ||
) | ||
|
||
type FeatureName string | ||
|
||
const FeatureNameDeviceIsMobile = FeatureName("deviceIsMobile") | ||
|
||
// FeatureTheme defines the method to look up features that we use internally to apply functional | ||
// differences through a theme override. | ||
// | ||
// Since: 2.6 | ||
type FeatureTheme interface { | ||
Feature(FeatureName) any | ||
} | ||
|
||
// FeatureForWidget looks up the specified feature flag for the requested widget using the current theme. | ||
// This is for internal purposes and will do nothing if the theme has not been overridden with the | ||
// ThemeOverride container. | ||
// | ||
// Since: 2.6 | ||
func FeatureForWidget(name FeatureName, w fyne.Widget) any { | ||
if custom := cache.WidgetTheme(w); custom != nil { | ||
if f, ok := custom.(FeatureTheme); ok { | ||
return f.Feature(name) | ||
} | ||
} | ||
|
||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be a public API (since it has the Since: line)? If so, this should be in the public theme package rather than internal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it wasn't - that doc was just over-enthusiastic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed